2020-02-14 08:45:49 +01:00
|
|
|
print("running venus test script")
|
2020-02-11 10:41:41 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local vp_util = dofile("vp_util.lua")
|
|
|
|
|
|
|
|
local function for_range_test()
|
|
|
|
local a = 0
|
2020-02-11 10:41:41 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
for i = 0,5 do
|
|
|
|
a = a + i
|
|
|
|
end
|
2020-02-12 12:51:02 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
assert(a == 15)
|
2020-02-11 10:41:41 +01:00
|
|
|
end
|
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
for_range_test()
|
2020-02-12 12:51:02 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local function for_in_test()
|
|
|
|
local testt = {
|
|
|
|
venus = "awesome",
|
|
|
|
"lots of test",1,2,
|
|
|
|
test2 = "hi"
|
|
|
|
}
|
2020-02-11 10:41:41 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local reft = {}
|
|
|
|
for i,el in pairs(testt) do
|
|
|
|
reft[i] = el
|
|
|
|
end
|
|
|
|
assert(vp_util.dftc(reft, testt))
|
|
|
|
|
|
|
|
reft = {}
|
|
|
|
for _,el in pairs(testt) do
|
|
|
|
table.insert(reft,el)
|
|
|
|
end
|
|
|
|
|
|
|
|
local reft2 = {}
|
|
|
|
foreach el in testt do
|
|
|
|
table.insert(reft2,el)
|
|
|
|
end
|
|
|
|
assert(vp_util.dftc(reft, reft2))
|
2020-02-11 10:41:41 +01:00
|
|
|
end
|
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
for_in_test()
|
|
|
|
|
|
|
|
// comments
|
|
|
|
## yay a comment
|
2020-02-11 10:41:41 +01:00
|
|
|
//comment
|
2020-02-11 17:08:37 +01:00
|
|
|
assert("//"=="/".."/")
|
2020-02-14 08:45:49 +01:00
|
|
|
-- another comment
|
2020-02-11 17:08:37 +01:00
|
|
|
assert([[
|
|
|
|
##]]=="#".."#","comment within [[string]] falsely detected")
|
2020-02-11 10:41:41 +01:00
|
|
|
|
2020-02-12 10:53:41 +01:00
|
|
|
assert([[
|
|
|
|
fn]]=="f".."n")
|
2020-02-11 10:41:41 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local function shadow_test()
|
|
|
|
local fn a()
|
|
|
|
return "function"
|
|
|
|
end
|
|
|
|
assert(a()=="function")
|
|
|
|
|
|
|
|
local reft = {}
|
|
|
|
do
|
|
|
|
(fn(...)
|
|
|
|
local a = {...}
|
|
|
|
foreach a in a do
|
|
|
|
table.insert(reft,a)
|
|
|
|
end
|
|
|
|
end)("a","still a","also a")
|
|
|
|
end
|
|
|
|
assert(vp_util.dftc(reft, {"a","still a","also a"}))
|
|
|
|
|
|
|
|
local n
|
|
|
|
{
|
|
|
|
local a = 12
|
|
|
|
n = a
|
|
|
|
}
|
|
|
|
assert(n == 12)
|
|
|
|
|
|
|
|
assert(a()=="function")
|
2020-02-11 17:08:37 +01:00
|
|
|
end
|
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
shadow_test()
|
2020-02-12 10:53:41 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local function t() {
|
2020-02-12 10:53:41 +01:00
|
|
|
return "hi"
|
2020-02-11 10:41:41 +01:00
|
|
|
}
|
2020-02-12 10:53:41 +01:00
|
|
|
assert(t()=="hi")
|
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local fn t2() {
|
2020-02-12 10:53:41 +01:00
|
|
|
return "also hi"
|
|
|
|
}
|
2020-02-14 08:45:49 +01:00
|
|
|
assert(type(t2)=="function")
|
2020-02-12 10:53:41 +01:00
|
|
|
assert(t2()=="also hi")
|
2020-02-11 10:41:41 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local b = true
|
2020-02-11 10:41:41 +01:00
|
|
|
if (true) {
|
2020-02-14 08:45:49 +01:00
|
|
|
b = "weewoo"
|
2020-02-11 10:41:41 +01:00
|
|
|
}
|
2020-02-14 08:45:49 +01:00
|
|
|
assert(b == "weewoo")
|
2020-02-11 10:41:41 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local reft = {}
|
2020-02-11 10:41:41 +01:00
|
|
|
for i = 0, 10 {
|
2020-02-14 08:45:49 +01:00
|
|
|
table.insert(reft,i)
|
2020-02-11 10:41:41 +01:00
|
|
|
}
|
2020-02-14 08:45:49 +01:00
|
|
|
assert(vp_util.dftc(reft,{0,1,2,3,4,5,6,7,8,9,10}))
|
2020-02-11 10:41:41 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local reft2 = {}
|
2020-02-12 10:53:41 +01:00
|
|
|
foreach el in {"lot's of test",2,"3",1} {
|
2020-02-14 08:45:49 +01:00
|
|
|
table.insert(reft2,el)
|
2020-02-12 10:53:41 +01:00
|
|
|
}
|
2020-02-14 08:45:49 +01:00
|
|
|
assert(vp_util.dftc(reft2,{"lot's of test",2,"3",1}))
|
2020-02-12 10:53:41 +01:00
|
|
|
|
|
|
|
{
|
2020-02-14 08:45:49 +01:00
|
|
|
local reft = {}
|
2020-02-12 10:53:41 +01:00
|
|
|
local i = 0
|
|
|
|
while i < 10 {
|
|
|
|
i = i + 1
|
|
|
|
if i%3 == 0 {
|
2020-02-14 08:45:49 +01:00
|
|
|
table.insert(reft,i)
|
2020-02-12 10:53:41 +01:00
|
|
|
} elseif i%4 == 0 {
|
2020-02-14 08:45:49 +01:00
|
|
|
table.insert(reft,i/4)
|
2020-02-12 10:53:41 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-14 08:45:49 +01:00
|
|
|
assert(vp_util.dftc(reft,{3,1,6,2,9}))
|
2020-02-12 10:53:41 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local function callit(fun,t1,t2)
|
2020-02-12 12:51:02 +01:00
|
|
|
return fun(t1,t2)
|
2020-02-11 10:41:41 +01:00
|
|
|
end
|
|
|
|
|
2020-02-12 12:51:02 +01:00
|
|
|
assert(
|
|
|
|
callit(() => {
|
|
|
|
return "testing"
|
|
|
|
})
|
|
|
|
== "testing")
|
|
|
|
|
|
|
|
assert(
|
|
|
|
callit((k,v) => {
|
|
|
|
return k.." = "..v
|
|
|
|
}, "this test", "more test")
|
2020-02-12 13:44:59 +01:00
|
|
|
== "this test = more test"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert(
|
|
|
|
callit((a , b) => {
|
|
|
|
return (a-b)*4
|
|
|
|
}, 10, 6) == 16
|
|
|
|
)
|
2020-02-11 10:41:41 +01:00
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
assert(callit(()=>{},false)==nil)
|
|
|
|
|
2020-02-13 11:56:24 +01:00
|
|
|
---
|
|
|
|
--comment
|
|
|
|
--
|
2020-02-12 10:53:41 +01:00
|
|
|
|
|
|
|
local i = 0
|
|
|
|
local j = 0
|
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
j = j + 2
|
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local function decj()
|
2020-02-13 11:56:24 +01:00
|
|
|
j--
|
|
|
|
return j-- not a decrement, only returns n, this is a comment
|
2020-02-12 10:53:41 +01:00
|
|
|
end
|
2020-02-13 11:56:24 +01:00
|
|
|
assert(decj()==1)
|
|
|
|
assert(j == 1)
|
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
local fn reti()
|
2020-02-13 11:56:24 +01:00
|
|
|
-- this only returns i the -- is a comment
|
|
|
|
return i--
|
|
|
|
end
|
|
|
|
|
|
|
|
i++
|
|
|
|
assert(reti() == 2)
|
|
|
|
|
|
|
|
-- () => {}
|
|
|
|
|
2020-02-13 13:44:59 +01:00
|
|
|
j+= 3
|
|
|
|
assert(j == 4)
|
2020-02-13 11:56:24 +01:00
|
|
|
j *=-8
|
2020-02-13 13:44:59 +01:00
|
|
|
assert(j ==-32)
|
|
|
|
j /= -4
|
|
|
|
assert(j== 8)
|
2020-02-13 11:56:24 +01:00
|
|
|
j ^= 2
|
2020-02-13 13:44:59 +01:00
|
|
|
assert(j == 64)
|
|
|
|
j-= 32
|
|
|
|
assert(j ==32)
|
|
|
|
j .=" test"
|
|
|
|
assert(j == "32 test")
|
|
|
|
|
2020-02-14 08:45:49 +01:00
|
|
|
print("venus test end")
|