-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.venus
212 lines (171 loc) · 2.96 KB
/
test.venus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
print("running venus test script")
local vp_util = dofile("vc_util.lua")
local function for_range_test()
local a = 0
for i = 0,5 do
a = a + i
end
assert(a == 15)
end
for_range_test()
local function for_in_test()
local testt = {
venus = "awesome",
"lots of test",1,2,
test2 = "hi"
}
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))
end
for_in_test()
-- comments
## yay a comment
##comment
assert("##"=="#".."#")
-- another comment
assert([[
##]]=="#".."#","comment within [[string]] falsely detected")
assert([[
fn]]=="f".."n")
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
do {
local a = 12
n = a
}
assert(n == 12)
assert(a()=="function")
end
shadow_test()
local function t() {
return "hi"
}
assert(t()=="hi")
local fn t2() {
return "also hi"
}
assert(type(t2)=="function")
assert(t2()=="also hi")
local b = true
if (true) {
b = "weewoo"
}
assert(b == "weewoo")
local reft = {}
for i = 0, 10 {
table.insert(reft,i)
}
assert(vp_util.dftc(reft,{0,1,2,3,4,5,6,7,8,9,10}))
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}))
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)
} else {}
}
assert(vp_util.dftc(reft,{3,1,6,2,9}))
}
local function callit(fun,t1,t2)
return fun(t1,t2)
end
assert(
callit(() => {
return "testing"
})
== "testing")
assert(
callit((k,v) => {
return k.." = "..v
}, "this test", "more test")
== "this test = more test"
)
assert(
callit((a , b) => {
return (a-b)*4
}, 10, 6) == 16
)
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)
-- () => {}
j+= 3
assert(j == 4)
j *=-8
assert(j ==-32)
j /= -4
assert(j== 8)
j ^= 2
assert(j == 64)
j-= 32
assert(j ==32)
j .=" test"
assert(j == "32 test")
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"}))
assert(not (() => {if(true){return}return true})())
local ctt = {test = "hello"}
ctt.test .= " world"
assert(ctt.test == "hello world")
print("venus test end")