VenusParser/test.venus

207 lines
2.8 KiB
Plaintext
Raw Normal View History

print("running venus test script")
2020-02-11 10:41:41 +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
for i = 0,5 do
a = a + i
end
2020-02-12 12:51:02 +01:00
assert(a == 15)
2020-02-11 10:41:41 +01:00
end
for_range_test()
2020-02-12 12:51:02 +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
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
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("//"=="/".."/")
-- another comment
2020-02-11 17:08:37 +01:00
assert([[
##]]=="#".."#","comment within [[string]] falsely detected")
2020-02-11 10:41:41 +01:00
assert([[
fn]]=="f".."n")
2020-02-11 10:41:41 +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
2020-02-18 10:14:48 +01:00
do {
local a = 12
n = a
}
assert(n == 12)
assert(a()=="function")
2020-02-11 17:08:37 +01:00
end
shadow_test()
local function t() {
return "hi"
2020-02-11 10:41:41 +01:00
}
assert(t()=="hi")
local fn t2() {
return "also hi"
}
assert(type(t2)=="function")
assert(t2()=="also hi")
2020-02-11 10:41:41 +01:00
local b = true
2020-02-11 10:41:41 +01:00
if (true) {
b = "weewoo"
2020-02-11 10:41:41 +01:00
}
assert(b == "weewoo")
2020-02-11 10:41:41 +01:00
local reft = {}
2020-02-11 10:41:41 +01:00
for i = 0, 10 {
table.insert(reft,i)
2020-02-11 10:41:41 +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
local reft2 = {}
foreach el in {"lot's of test",2,"3",1} {
table.insert(reft2,el)
}
assert(vp_util.dftc(reft2,{"lot's of test",2,"3",1}))
2020-02-18 10:14:48 +01:00
do {
local reft = {}
local i = 0
while i < 10 {
i = i + 1
if i%3 == 0 {
table.insert(reft,i)
} elseif i%4 == 0 {
table.insert(reft,i/4)
}
}
assert(vp_util.dftc(reft,{3,1,6,2,9}))
}
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
assert(callit(()=>{},false)==nil)
---
--comment
--
local i = 0
local j = 0
i = i + 1
j = j + 2
local function decj()
j--
return j-- not a decrement, only returns n, this is a comment
end
assert(decj()==1)
assert(j == 1)
local fn reti()
-- 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)
j *=-8
2020-02-13 13:44:59 +01:00
assert(j ==-32)
j /= -4
assert(j== 8)
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-18 15:13:59 +01:00
local tt = {
{"hello", "there"},
{"venus", "test"}
}
local fn concatsub(t) {
local ret = {}
foreach el in t {
table.insert(ret,table.concat(el," "))
}
return ret
}
assert(vp_util.dftc(concatsub(tt),{"hello there", "venus test"}))
print("venus test end")