aboutsummaryrefslogtreecommitdiff
path: root/testes/constructs.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/constructs.lua')
-rw-r--r--testes/constructs.lua36
1 files changed, 20 insertions, 16 deletions
diff --git a/testes/constructs.lua b/testes/constructs.lua
index 0d9ec92d..6ac68166 100644
--- a/testes/constructs.lua
+++ b/testes/constructs.lua
@@ -11,6 +11,7 @@ local function checkload (s, msg)
11end 11end
12 12
13-- testing semicollons 13-- testing semicollons
14local a
14do ;;; end 15do ;;; end
15; do ; a = 3; assert(a == 3) end; 16; do ; a = 3; assert(a == 3) end;
16; 17;
@@ -49,10 +50,10 @@ assert((((nil and true) or false) and true) == false)
49 50
50local a,b = 1,nil; 51local a,b = 1,nil;
51assert(-(1 or 2) == -1 and (1 and 2)+(-1.25 or -4) == 0.75); 52assert(-(1 or 2) == -1 and (1 and 2)+(-1.25 or -4) == 0.75);
52x = ((b or a)+1 == 2 and (10 or a)+1 == 11); assert(x); 53local x = ((b or a)+1 == 2 and (10 or a)+1 == 11); assert(x);
53x = (((2<3) or 1) == true and (2<3 and 4) == 4); assert(x); 54x = (((2<3) or 1) == true and (2<3 and 4) == 4); assert(x);
54 55
55x,y=1,2; 56local x, y = 1, 2;
56assert((x>y) and x or y == 2); 57assert((x>y) and x or y == 2);
57x,y=2,1; 58x,y=2,1;
58assert((x>y) and x or y == 2); 59assert((x>y) and x or y == 2);
@@ -77,13 +78,13 @@ do -- testing operators with diffent kinds of constants
77 local gab = f(o1, o2) 78 local gab = f(o1, o2)
78 79
79 _ENV.XX = o1 80 _ENV.XX = o1
80 code = string.format("return XX %s %s", op, o2) 81 local code = string.format("return XX %s %s", op, o2)
81 res = assert(load(code))() 82 local res = assert(load(code))()
82 assert(res == gab) 83 assert(res == gab)
83 84
84 _ENV.XX = o2 85 _ENV.XX = o2
85 local code = string.format("return (%s) %s XX", o1, op) 86 code = string.format("return (%s) %s XX", o1, op)
86 local res = assert(load(code))() 87 res = assert(load(code))()
87 assert(res == gab) 88 assert(res == gab)
88 89
89 code = string.format("return (%s) %s %s", o1, op, o2) 90 code = string.format("return (%s) %s %s", o1, op, o2)
@@ -92,6 +93,7 @@ do -- testing operators with diffent kinds of constants
92 end 93 end
93 end 94 end
94 end 95 end
96 _ENV.XX = nil
95end 97end
96 98
97 99
@@ -100,7 +102,7 @@ repeat until 1; repeat until true;
100while false do end; while nil do end; 102while false do end; while nil do end;
101 103
102do -- test old bug (first name could not be an `upvalue') 104do -- test old bug (first name could not be an `upvalue')
103 local a; function f(x) x={a=1}; x={x=1}; x={G=1} end 105 local a; local function f(x) x={a=1}; x={x=1}; x={G=1} end
104end 106end
105 107
106 108
@@ -128,7 +130,7 @@ do -- bug since 5.4.0
128end 130end
129 131
130 132
131function f (i) 133local function f (i)
132 if type(i) ~= 'number' then return i,'jojo'; end; 134 if type(i) ~= 'number' then return i,'jojo'; end;
133 if i > 0 then return i, f(i-1); end; 135 if i > 0 then return i, f(i-1); end;
134end 136end
@@ -154,10 +156,10 @@ end
154assert(f(3) == 'a' and f(12) == 'b' and f(26) == 'c' and f(100) == nil) 156assert(f(3) == 'a' and f(12) == 'b' and f(26) == 'c' and f(100) == nil)
155 157
156for i=1,1000 do break; end; 158for i=1,1000 do break; end;
157n=100; 159local n=100;
158i=3; 160local i=3;
159t = {}; 161local t = {};
160a=nil 162local a=nil
161while not a do 163while not a do
162 a=0; for i=1,n do for i=i,1,-1 do a=a+1; t[i]=1; end; end; 164 a=0; for i=1,n do for i=i,1,-1 do a=a+1; t[i]=1; end; end;
163end 165end
@@ -200,14 +202,14 @@ a={y=1}
200x = {a.y} 202x = {a.y}
201assert(x[1] == 1) 203assert(x[1] == 1)
202 204
203function f(i) 205local function f (i)
204 while 1 do 206 while 1 do
205 if i>0 then i=i-1; 207 if i>0 then i=i-1;
206 else return; end; 208 else return; end;
207 end; 209 end;
208end; 210end;
209 211
210function g(i) 212local function g(i)
211 while 1 do 213 while 1 do
212 if i>0 then i=i-1 214 if i>0 then i=i-1
213 else return end 215 else return end
@@ -272,7 +274,7 @@ function g (a,b,c,d,e)
272 if not (a>=b or c or d and e or nil) then return 0; else return 1; end; 274 if not (a>=b or c or d and e or nil) then return 0; else return 1; end;
273end 275end
274 276
275function h (a,b,c,d,e) 277local function h (a,b,c,d,e)
276 while (a>=b or c or (d and e) or nil) do return 1; end; 278 while (a>=b or c or (d and e) or nil) do return 1; end;
277 return 0; 279 return 0;
278end; 280end;
@@ -300,7 +302,7 @@ do
300 assert(a==2) 302 assert(a==2)
301end 303end
302 304
303function F(a) 305local function F (a)
304 assert(debug.getinfo(1, "n").name == 'F') 306 assert(debug.getinfo(1, "n").name == 'F')
305 return a,2,3 307 return a,2,3
306end 308end
@@ -393,6 +395,8 @@ for n = 1, level do
393 if i % 60000 == 0 then print('+') end 395 if i % 60000 == 0 then print('+') end
394 end 396 end
395end 397end
398IX = nil
399_G.GLOB1 = nil
396------------------------------------------------------------------ 400------------------------------------------------------------------
397 401
398-- testing some syntax errors (chosen through 'gcov') 402-- testing some syntax errors (chosen through 'gcov')