diff options
Diffstat (limited to '')
-rwxr-xr-x[-rw-r--r--] | testes/all.lua | 8 | ||||
-rw-r--r-- | testes/api.lua | 6 | ||||
-rw-r--r-- | testes/attrib.lua | 24 | ||||
-rw-r--r-- | testes/bwcoercion.lua | 2 | ||||
-rw-r--r-- | testes/calls.lua | 15 | ||||
-rw-r--r-- | testes/closure.lua | 2 | ||||
-rw-r--r-- | testes/code.lua | 24 | ||||
-rw-r--r-- | testes/constructs.lua | 2 | ||||
-rw-r--r-- | testes/coroutine.lua | 65 | ||||
-rw-r--r-- | testes/db.lua | 21 | ||||
-rw-r--r-- | testes/errors.lua | 16 | ||||
-rw-r--r-- | testes/files.lua | 58 | ||||
-rw-r--r-- | testes/gc.lua | 25 | ||||
-rw-r--r-- | testes/goto.lua | 170 | ||||
-rw-r--r-- | testes/libs/lib22.c | 51 | ||||
-rw-r--r-- | testes/literals.lua | 2 | ||||
-rw-r--r-- | testes/locals.lua | 42 | ||||
-rw-r--r-- | testes/main.lua | 13 | ||||
-rw-r--r-- | testes/math.lua | 21 | ||||
-rw-r--r-- | testes/nextvar.lua | 23 | ||||
-rw-r--r-- | testes/pm.lua | 6 | ||||
-rw-r--r-- | testes/strings.lua | 1 | ||||
-rw-r--r-- | testes/tracegc.lua | 2 | ||||
-rw-r--r-- | testes/utf8.lua | 13 |
24 files changed, 526 insertions, 86 deletions
diff --git a/testes/all.lua b/testes/all.lua index 5c7ebfa5..d3e2f123 100644..100755 --- a/testes/all.lua +++ b/testes/all.lua | |||
@@ -2,6 +2,10 @@ | |||
2 | -- $Id: testes/all.lua $ | 2 | -- $Id: testes/all.lua $ |
3 | -- See Copyright Notice in file lua.h | 3 | -- See Copyright Notice in file lua.h |
4 | 4 | ||
5 | global <const> * | ||
6 | |||
7 | global _soft, _port, _nomsg | ||
8 | global T | ||
5 | 9 | ||
6 | local version = "Lua 5.5" | 10 | local version = "Lua 5.5" |
7 | if _VERSION ~= version then | 11 | if _VERSION ~= version then |
@@ -34,7 +38,7 @@ if usertests then | |||
34 | end | 38 | end |
35 | 39 | ||
36 | -- tests should require debug when needed | 40 | -- tests should require debug when needed |
37 | debug = nil | 41 | global debug; debug = nil |
38 | 42 | ||
39 | 43 | ||
40 | if usertests then | 44 | if usertests then |
@@ -71,7 +75,7 @@ do -- ( | |||
71 | 75 | ||
72 | -- track messages for tests not performed | 76 | -- track messages for tests not performed |
73 | local msgs = {} | 77 | local msgs = {} |
74 | function Message (m) | 78 | global function Message (m) |
75 | if not _nomsg then | 79 | if not _nomsg then |
76 | print(m) | 80 | print(m) |
77 | msgs[#msgs+1] = string.sub(m, 3, -3) | 81 | msgs[#msgs+1] = string.sub(m, 3, -3) |
diff --git a/testes/api.lua b/testes/api.lua index 49e3f9b9..b3791654 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
@@ -114,7 +114,7 @@ end | |||
114 | 114 | ||
115 | -- testing warnings | 115 | -- testing warnings |
116 | T.testC([[ | 116 | T.testC([[ |
117 | warningC "#This shold be a" | 117 | warningC "#This should be a" |
118 | warningC " single " | 118 | warningC " single " |
119 | warning "warning" | 119 | warning "warning" |
120 | warningC "#This should be " | 120 | warningC "#This should be " |
@@ -162,7 +162,7 @@ do -- test returning more results than fit in the caller stack | |||
162 | end | 162 | end |
163 | 163 | ||
164 | 164 | ||
165 | do -- testing multipe returns | 165 | do -- testing multiple returns |
166 | local function foo (n) | 166 | local function foo (n) |
167 | if n > 0 then return n, foo(n - 1) end | 167 | if n > 0 then return n, foo(n - 1) end |
168 | end | 168 | end |
@@ -902,7 +902,7 @@ F = function (x) | |||
902 | assert(T.udataval(A) == B) | 902 | assert(T.udataval(A) == B) |
903 | debug.getmetatable(A) -- just access it | 903 | debug.getmetatable(A) -- just access it |
904 | end | 904 | end |
905 | A = x -- ressurect userdata | 905 | A = x -- resurrect userdata |
906 | B = udval | 906 | B = udval |
907 | return 1,2,3 | 907 | return 1,2,3 |
908 | end | 908 | end |
diff --git a/testes/attrib.lua b/testes/attrib.lua index d8b6e0f3..f4156086 100644 --- a/testes/attrib.lua +++ b/testes/attrib.lua | |||
@@ -308,11 +308,11 @@ else | |||
308 | _ENV.x, _ENV.y = nil | 308 | _ENV.x, _ENV.y = nil |
309 | end | 309 | end |
310 | 310 | ||
311 | |||
311 | _ENV = _G | 312 | _ENV = _G |
312 | 313 | ||
313 | 314 | ||
314 | -- testing preload | 315 | -- testing preload |
315 | |||
316 | do | 316 | do |
317 | local p = package | 317 | local p = package |
318 | package = {} | 318 | package = {} |
@@ -331,6 +331,26 @@ do | |||
331 | assert(type(package.path) == "string") | 331 | assert(type(package.path) == "string") |
332 | end | 332 | end |
333 | 333 | ||
334 | |||
335 | do print("testing external strings") | ||
336 | package.cpath = DC"?" | ||
337 | local lib2 = require"lib2-v2" | ||
338 | local t = {} | ||
339 | for _, len in ipairs{0, 10, 39, 40, 41, 1000} do | ||
340 | local str = string.rep("a", len) | ||
341 | local str1 = lib2.newstr(str) | ||
342 | assert(str == str1) | ||
343 | assert(not T or T.hash(str) == T.hash(str1)) | ||
344 | t[str1] = 20; assert(t[str] == 20 and t[str1] == 20) | ||
345 | t[str] = 10; assert(t[str1] == 10) | ||
346 | local tt = {[str1] = str1} | ||
347 | assert(next(tt) == str1 and next(tt, str1) == nil) | ||
348 | assert(tt[str] == str) | ||
349 | local str2 = lib2.newstr(str1) | ||
350 | assert(str == str2 and t[str2] == 10 and tt[str2] == str) | ||
351 | end | ||
352 | end | ||
353 | |||
334 | print('+') | 354 | print('+') |
335 | 355 | ||
336 | end --] | 356 | end --] |
@@ -447,7 +467,7 @@ do | |||
447 | end | 467 | end |
448 | 468 | ||
449 | 469 | ||
450 | -- test of large float/integer indices | 470 | -- test of large float/integer indices |
451 | 471 | ||
452 | -- compute maximum integer where all bits fit in a float | 472 | -- compute maximum integer where all bits fit in a float |
453 | local maxint = math.maxinteger | 473 | local maxint = math.maxinteger |
diff --git a/testes/bwcoercion.lua b/testes/bwcoercion.lua index cd735ab0..0544944d 100644 --- a/testes/bwcoercion.lua +++ b/testes/bwcoercion.lua | |||
@@ -4,7 +4,7 @@ local strsub = string.sub | |||
4 | 4 | ||
5 | local print = print | 5 | local print = print |
6 | 6 | ||
7 | _ENV = nil | 7 | global none |
8 | 8 | ||
9 | -- Try to convert a value to an integer, without assuming any coercion. | 9 | -- Try to convert a value to an integer, without assuming any coercion. |
10 | local function toint (x) | 10 | local function toint (x) |
diff --git a/testes/calls.lua b/testes/calls.lua index 942fad72..0dacb85a 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
@@ -1,6 +1,8 @@ | |||
1 | -- $Id: testes/calls.lua $ | 1 | -- $Id: testes/calls.lua $ |
2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | global <const> * | ||
5 | |||
4 | print("testing functions and calls") | 6 | print("testing functions and calls") |
5 | 7 | ||
6 | local debug = require "debug" | 8 | local debug = require "debug" |
@@ -22,7 +24,7 @@ assert(not pcall(type)) | |||
22 | 24 | ||
23 | 25 | ||
24 | -- testing local-function recursion | 26 | -- testing local-function recursion |
25 | fact = false | 27 | global fact = false |
26 | do | 28 | do |
27 | local res = 1 | 29 | local res = 1 |
28 | local function fact (n) | 30 | local function fact (n) |
@@ -63,7 +65,7 @@ a.b.c:f2('k', 12); assert(a.b.c.k == 12) | |||
63 | 65 | ||
64 | print('+') | 66 | print('+') |
65 | 67 | ||
66 | t = nil -- 'declare' t | 68 | global t = nil -- 'declare' t |
67 | function f(a,b,c) local d = 'a'; t={a,b,c,d} end | 69 | function f(a,b,c) local d = 'a'; t={a,b,c,d} end |
68 | 70 | ||
69 | f( -- this line change must be valid | 71 | f( -- this line change must be valid |
@@ -75,7 +77,7 @@ assert(t[1] == 1 and t[2] == 2 and t[3] == 3 and t[4] == 'a') | |||
75 | 77 | ||
76 | t = nil -- delete 't' | 78 | t = nil -- delete 't' |
77 | 79 | ||
78 | function fat(x) | 80 | global function fat(x) |
79 | if x <= 1 then return 1 | 81 | if x <= 1 then return 1 |
80 | else return x*load("return fat(" .. x-1 .. ")", "")() | 82 | else return x*load("return fat(" .. x-1 .. ")", "")() |
81 | end | 83 | end |
@@ -107,7 +109,7 @@ end | |||
107 | 109 | ||
108 | _G.deep = nil -- "declaration" (used by 'all.lua') | 110 | _G.deep = nil -- "declaration" (used by 'all.lua') |
109 | 111 | ||
110 | function deep (n) | 112 | global function deep (n) |
111 | if n>0 then deep(n-1) end | 113 | if n>0 then deep(n-1) end |
112 | end | 114 | end |
113 | deep(10) | 115 | deep(10) |
@@ -352,7 +354,7 @@ assert(not load(function () return true end)) | |||
352 | 354 | ||
353 | -- small bug | 355 | -- small bug |
354 | local t = {nil, "return ", "3"} | 356 | local t = {nil, "return ", "3"} |
355 | f, msg = load(function () return table.remove(t, 1) end) | 357 | local f, msg = load(function () return table.remove(t, 1) end) |
356 | assert(f() == nil) -- should read the empty chunk | 358 | assert(f() == nil) -- should read the empty chunk |
357 | 359 | ||
358 | -- another small bug (in 5.2.1) | 360 | -- another small bug (in 5.2.1) |
@@ -388,7 +390,8 @@ assert(load("return _ENV", nil, nil, 123)() == 123) | |||
388 | 390 | ||
389 | 391 | ||
390 | -- load when _ENV is not first upvalue | 392 | -- load when _ENV is not first upvalue |
391 | local x; XX = 123 | 393 | global XX; local x |
394 | XX = 123 | ||
392 | local function h () | 395 | local function h () |
393 | local y=x -- use 'x', so that it becomes 1st upvalue | 396 | local y=x -- use 'x', so that it becomes 1st upvalue |
394 | return XX -- global name | 397 | return XX -- global name |
diff --git a/testes/closure.lua b/testes/closure.lua index d3b9f621..0c2e96c0 100644 --- a/testes/closure.lua +++ b/testes/closure.lua | |||
@@ -1,6 +1,8 @@ | |||
1 | -- $Id: testes/closure.lua $ | 1 | -- $Id: testes/closure.lua $ |
2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | global <const> * | ||
5 | |||
4 | print "testing closures" | 6 | print "testing closures" |
5 | 7 | ||
6 | do -- bug in 5.4.7 | 8 | do -- bug in 5.4.7 |
diff --git a/testes/code.lua b/testes/code.lua index 111717ce..380ff70c 100644 --- a/testes/code.lua +++ b/testes/code.lua | |||
@@ -1,6 +1,8 @@ | |||
1 | -- $Id: testes/code.lua $ | 1 | -- $Id: testes/code.lua $ |
2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | global <const> * | ||
5 | |||
4 | if T==nil then | 6 | if T==nil then |
5 | (Message or print)('\n >>> testC not active: skipping opcode tests <<<\n') | 7 | (Message or print)('\n >>> testC not active: skipping opcode tests <<<\n') |
6 | return | 8 | return |
@@ -405,8 +407,8 @@ do -- tests for table access in upvalues | |||
405 | end | 407 | end |
406 | 408 | ||
407 | -- de morgan | 409 | -- de morgan |
408 | checkequal(function () local a; if not (a or b) then b=a end end, | 410 | checkequal(function () local a, b; if not (a or b) then b=a end end, |
409 | function () local a; if (not a and not b) then b=a end end) | 411 | function () local a, b; if (not a and not b) then b=a end end) |
410 | 412 | ||
411 | checkequal(function (l) local a; return 0 <= a and a <= l end, | 413 | checkequal(function (l) local a; return 0 <= a and a <= l end, |
412 | function (l) local a; return not (not(a >= 0) or not(a <= l)) end) | 414 | function (l) local a; return not (not(a >= 0) or not(a <= l)) end) |
@@ -480,5 +482,23 @@ do -- basic check for SETLIST | |||
480 | assert(count == 1) | 482 | assert(count == 1) |
481 | end | 483 | end |
482 | 484 | ||
485 | |||
486 | do print("testing code for integer limits") | ||
487 | local function checkints (n) | ||
488 | local source = string.format( | ||
489 | "local a = {[true] = 0X%x}; return a[true]", n) | ||
490 | local f = assert(load(source)) | ||
491 | checkKlist(f, {n}) | ||
492 | assert(f() == n) | ||
493 | f = load(string.dump(f)) | ||
494 | assert(f() == n) | ||
495 | end | ||
496 | |||
497 | checkints(math.maxinteger) | ||
498 | checkints(math.mininteger) | ||
499 | checkints(-1) | ||
500 | |||
501 | end | ||
502 | |||
483 | print 'OK' | 503 | print 'OK' |
484 | 504 | ||
diff --git a/testes/constructs.lua b/testes/constructs.lua index 3f6d506f..94f670c7 100644 --- a/testes/constructs.lua +++ b/testes/constructs.lua | |||
@@ -60,7 +60,7 @@ assert((x>y) and x or y == 2); | |||
60 | 60 | ||
61 | assert(1234567890 == tonumber('1234567890') and 1234567890+1 == 1234567891) | 61 | assert(1234567890 == tonumber('1234567890') and 1234567890+1 == 1234567891) |
62 | 62 | ||
63 | do -- testing operators with diffent kinds of constants | 63 | do -- testing operators with different kinds of constants |
64 | -- operands to consider: | 64 | -- operands to consider: |
65 | -- * fit in register | 65 | -- * fit in register |
66 | -- * constant doesn't fit in register | 66 | -- * constant doesn't fit in register |
diff --git a/testes/coroutine.lua b/testes/coroutine.lua index 17f6ceba..4881d964 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua | |||
@@ -156,12 +156,12 @@ do | |||
156 | st, msg = coroutine.close(co) | 156 | st, msg = coroutine.close(co) |
157 | assert(st and msg == nil) | 157 | assert(st and msg == nil) |
158 | 158 | ||
159 | local main = coroutine.running() | ||
159 | 160 | ||
160 | -- cannot close the running coroutine | 161 | -- cannot close 'main' |
161 | local st, msg = pcall(coroutine.close, coroutine.running()) | 162 | local st, msg = pcall(coroutine.close, main); |
162 | assert(not st and string.find(msg, "running")) | 163 | assert(not st and string.find(msg, "main")) |
163 | 164 | ||
164 | local main = coroutine.running() | ||
165 | 165 | ||
166 | -- cannot close a "normal" coroutine | 166 | -- cannot close a "normal" coroutine |
167 | ;(coroutine.wrap(function () | 167 | ;(coroutine.wrap(function () |
@@ -169,20 +169,19 @@ do | |||
169 | assert(not st and string.find(msg, "normal")) | 169 | assert(not st and string.find(msg, "normal")) |
170 | end))() | 170 | end))() |
171 | 171 | ||
172 | -- cannot close a coroutine while closing it | 172 | do -- close a coroutine while closing it |
173 | do | ||
174 | local co | 173 | local co |
175 | co = coroutine.create( | 174 | co = coroutine.create( |
176 | function() | 175 | function() |
177 | local x <close> = func2close(function() | 176 | local x <close> = func2close(function() |
178 | coroutine.close(co) -- try to close it again | 177 | coroutine.close(co) -- close it again |
179 | end) | 178 | end) |
180 | coroutine.yield(20) | 179 | coroutine.yield(20) |
181 | end) | 180 | end) |
182 | local st, msg = coroutine.resume(co) | 181 | local st, msg = coroutine.resume(co) |
183 | assert(st and msg == 20) | 182 | assert(st and msg == 20) |
184 | st, msg = coroutine.close(co) | 183 | st, msg = coroutine.close(co) |
185 | assert(not st and string.find(msg, "running coroutine")) | 184 | assert(st and msg == nil) |
186 | end | 185 | end |
187 | 186 | ||
188 | -- to-be-closed variables in coroutines | 187 | -- to-be-closed variables in coroutines |
@@ -289,6 +288,56 @@ do | |||
289 | end | 288 | end |
290 | 289 | ||
291 | 290 | ||
291 | do print("coroutines closing itself") | ||
292 | global <const> coroutine, string, os | ||
293 | global <const> assert, error, pcall | ||
294 | |||
295 | local X = nil | ||
296 | |||
297 | local function new () | ||
298 | return coroutine.create(function (what) | ||
299 | |||
300 | local <close>var = func2close(function (t, err) | ||
301 | if what == "yield" then | ||
302 | coroutine.yield() | ||
303 | elseif what == "error" then | ||
304 | error(200) | ||
305 | else | ||
306 | X = "Ok" | ||
307 | return X | ||
308 | end | ||
309 | end) | ||
310 | |||
311 | -- do an unprotected call so that coroutine becomes non-yieldable | ||
312 | string.gsub("a", "a", function () | ||
313 | assert(not coroutine.isyieldable()) | ||
314 | -- do protected calls while non-yieldable, to add recovery | ||
315 | -- entries (setjmp) to the stack | ||
316 | assert(pcall(pcall, function () | ||
317 | -- 'close' works even while non-yieldable | ||
318 | coroutine.close() -- close itself | ||
319 | os.exit(false) -- not reacheable | ||
320 | end)) | ||
321 | end) | ||
322 | end) | ||
323 | end | ||
324 | |||
325 | local co = new() | ||
326 | local st, msg = coroutine.resume(co, "ret") | ||
327 | assert(st and msg == nil) | ||
328 | assert(X == "Ok") | ||
329 | |||
330 | local co = new() | ||
331 | local st, msg = coroutine.resume(co, "error") | ||
332 | assert(not st and msg == 200) | ||
333 | |||
334 | local co = new() | ||
335 | local st, msg = coroutine.resume(co, "yield") | ||
336 | assert(not st and string.find(msg, "attempt to yield")) | ||
337 | |||
338 | end | ||
339 | |||
340 | |||
292 | -- yielding across C boundaries | 341 | -- yielding across C boundaries |
293 | 342 | ||
294 | local co = coroutine.wrap(function() | 343 | local co = coroutine.wrap(function() |
diff --git a/testes/db.lua b/testes/db.lua index 3c821ab7..0f174f17 100644 --- a/testes/db.lua +++ b/testes/db.lua | |||
@@ -349,8 +349,11 @@ end, "crl") | |||
349 | 349 | ||
350 | 350 | ||
351 | function f(a,b) | 351 | function f(a,b) |
352 | -- declare some globals to check that they don't interfere with 'getlocal' | ||
353 | global collectgarbage | ||
352 | collectgarbage() | 354 | collectgarbage() |
353 | local _, x = debug.getlocal(1, 1) | 355 | local _, x = debug.getlocal(1, 1) |
356 | global assert, g, string | ||
354 | local _, y = debug.getlocal(1, 2) | 357 | local _, y = debug.getlocal(1, 2) |
355 | assert(x == a and y == b) | 358 | assert(x == a and y == b) |
356 | assert(debug.setlocal(2, 3, "pera") == "AA".."AA") | 359 | assert(debug.setlocal(2, 3, "pera") == "AA".."AA") |
@@ -386,7 +389,9 @@ function g (...) | |||
386 | f(AAAA,B) | 389 | f(AAAA,B) |
387 | assert(AAAA == "pera" and B == "manga") | 390 | assert(AAAA == "pera" and B == "manga") |
388 | do | 391 | do |
392 | global * | ||
389 | local B = 13 | 393 | local B = 13 |
394 | global<const> assert | ||
390 | local x,y = debug.getlocal(1,5) | 395 | local x,y = debug.getlocal(1,5) |
391 | assert(x == 'B' and y == 13) | 396 | assert(x == 'B' and y == 13) |
392 | end | 397 | end |
@@ -431,7 +436,7 @@ do | |||
431 | assert(a == nil and not b) | 436 | assert(a == nil and not b) |
432 | end | 437 | end |
433 | 438 | ||
434 | -- testing iteraction between multiple values x hooks | 439 | -- testing interaction between multiple values x hooks |
435 | do | 440 | do |
436 | local function f(...) return 3, ... end | 441 | local function f(...) return 3, ... end |
437 | local count = 0 | 442 | local count = 0 |
@@ -587,7 +592,7 @@ t = getupvalues(foo2) | |||
587 | assert(t.a == 1 and t.b == 2 and t.c == 3) | 592 | assert(t.a == 1 and t.b == 2 and t.c == 3) |
588 | assert(debug.setupvalue(foo1, 1, "xuxu") == "b") | 593 | assert(debug.setupvalue(foo1, 1, "xuxu") == "b") |
589 | assert(({debug.getupvalue(foo2, 3)})[2] == "xuxu") | 594 | assert(({debug.getupvalue(foo2, 3)})[2] == "xuxu") |
590 | -- upvalues of C functions are allways "called" "" (the empty string) | 595 | -- upvalues of C functions are always named "" (the empty string) |
591 | assert(debug.getupvalue(string.gmatch("x", "x"), 1) == "") | 596 | assert(debug.getupvalue(string.gmatch("x", "x"), 1) == "") |
592 | 597 | ||
593 | 598 | ||
@@ -701,7 +706,7 @@ assert(debug.traceback(print, 4) == print) | |||
701 | assert(string.find(debug.traceback("hi", 4), "^hi\n")) | 706 | assert(string.find(debug.traceback("hi", 4), "^hi\n")) |
702 | assert(string.find(debug.traceback("hi"), "^hi\n")) | 707 | assert(string.find(debug.traceback("hi"), "^hi\n")) |
703 | assert(not string.find(debug.traceback("hi"), "'debug.traceback'")) | 708 | assert(not string.find(debug.traceback("hi"), "'debug.traceback'")) |
704 | assert(string.find(debug.traceback("hi", 0), "'debug.traceback'")) | 709 | assert(string.find(debug.traceback("hi", 0), "'traceback'")) |
705 | assert(string.find(debug.traceback(), "^stack traceback:\n")) | 710 | assert(string.find(debug.traceback(), "^stack traceback:\n")) |
706 | 711 | ||
707 | do -- C-function names in traceback | 712 | do -- C-function names in traceback |
@@ -829,7 +834,7 @@ end | |||
829 | 834 | ||
830 | co = coroutine.create(function (x) f(x) end) | 835 | co = coroutine.create(function (x) f(x) end) |
831 | a, b = coroutine.resume(co, 3) | 836 | a, b = coroutine.resume(co, 3) |
832 | t = {"'coroutine.yield'", "'f'", "in function <"} | 837 | t = {"'yield'", "'f'", "in function <"} |
833 | while coroutine.status(co) == "suspended" do | 838 | while coroutine.status(co) == "suspended" do |
834 | checktraceback(co, t) | 839 | checktraceback(co, t) |
835 | a, b = coroutine.resume(co) | 840 | a, b = coroutine.resume(co) |
@@ -839,7 +844,7 @@ t[1] = "'error'" | |||
839 | checktraceback(co, t) | 844 | checktraceback(co, t) |
840 | 845 | ||
841 | 846 | ||
842 | -- test acessing line numbers of a coroutine from a resume inside | 847 | -- test accessing line numbers of a coroutine from a resume inside |
843 | -- a C function (this is a known bug in Lua 5.0) | 848 | -- a C function (this is a known bug in Lua 5.0) |
844 | 849 | ||
845 | local function g(x) | 850 | local function g(x) |
@@ -966,9 +971,9 @@ local debug = require'debug' | |||
966 | local a = 12 -- a local variable | 971 | local a = 12 -- a local variable |
967 | 972 | ||
968 | local n, v = debug.getlocal(1, 1) | 973 | local n, v = debug.getlocal(1, 1) |
969 | assert(n == "(temporary)" and v == debug) -- unkown name but known value | 974 | assert(n == "(temporary)" and v == debug) -- unknown name but known value |
970 | n, v = debug.getlocal(1, 2) | 975 | n, v = debug.getlocal(1, 2) |
971 | assert(n == "(temporary)" and v == 12) -- unkown name but known value | 976 | assert(n == "(temporary)" and v == 12) -- unknown name but known value |
972 | 977 | ||
973 | -- a function with an upvalue | 978 | -- a function with an upvalue |
974 | local f = function () local x; return a end | 979 | local f = function () local x; return a end |
@@ -1018,7 +1023,7 @@ do -- bug in 5.4.0: line hooks in stripped code | |||
1018 | line = l | 1023 | line = l |
1019 | end, "l") | 1024 | end, "l") |
1020 | assert(s() == 2); debug.sethook(nil) | 1025 | assert(s() == 2); debug.sethook(nil) |
1021 | assert(line == nil) -- hook called withoug debug info for 1st instruction | 1026 | assert(line == nil) -- hook called without debug info for 1st instruction |
1022 | end | 1027 | end |
1023 | 1028 | ||
1024 | do -- tests for 'source' in binary dumps | 1029 | do -- tests for 'source' in binary dumps |
diff --git a/testes/errors.lua b/testes/errors.lua index c1c40fec..4230a352 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
@@ -303,14 +303,14 @@ do | |||
303 | local f = function (a) return a + 1 end | 303 | local f = function (a) return a + 1 end |
304 | f = assert(load(string.dump(f, true))) | 304 | f = assert(load(string.dump(f, true))) |
305 | assert(f(3) == 4) | 305 | assert(f(3) == 4) |
306 | checkerr("^%?:%-1:", f, {}) | 306 | checkerr("^%?:%?:", f, {}) |
307 | 307 | ||
308 | -- code with a move to a local var ('OP_MOV A B' with A<B) | 308 | -- code with a move to a local var ('OP_MOV A B' with A<B) |
309 | f = function () local a; a = {}; return a + 2 end | 309 | f = function () local a; a = {}; return a + 2 end |
310 | -- no debug info (so that 'a' is unknown) | 310 | -- no debug info (so that 'a' is unknown) |
311 | f = assert(load(string.dump(f, true))) | 311 | f = assert(load(string.dump(f, true))) |
312 | -- symbolic execution should not get lost | 312 | -- symbolic execution should not get lost |
313 | checkerr("^%?:%-1:.*table value", f) | 313 | checkerr("^%?:%?:.*table value", f) |
314 | end | 314 | end |
315 | 315 | ||
316 | 316 | ||
@@ -489,6 +489,14 @@ if not b then | |||
489 | end | 489 | end |
490 | end]], 5) | 490 | end]], 5) |
491 | 491 | ||
492 | lineerror([[ | ||
493 | _ENV = 1 | ||
494 | global function foo () | ||
495 | local a = 10 | ||
496 | return a | ||
497 | end | ||
498 | ]], 2) | ||
499 | |||
492 | 500 | ||
493 | -- bug in 5.4.0 | 501 | -- bug in 5.4.0 |
494 | lineerror([[ | 502 | lineerror([[ |
@@ -507,7 +515,7 @@ end | |||
507 | 515 | ||
508 | 516 | ||
509 | if not _soft then | 517 | if not _soft then |
510 | -- several tests that exaust the Lua stack | 518 | -- several tests that exhaust the Lua stack |
511 | collectgarbage() | 519 | collectgarbage() |
512 | print"testing stack overflow" | 520 | print"testing stack overflow" |
513 | local C = 0 | 521 | local C = 0 |
@@ -734,7 +742,7 @@ assert(c > 255 and string.find(b, "too many upvalues") and | |||
734 | 742 | ||
735 | -- local variables | 743 | -- local variables |
736 | s = "\nfunction foo ()\n local " | 744 | s = "\nfunction foo ()\n local " |
737 | for j = 1,300 do | 745 | for j = 1,200 do |
738 | s = s.."a"..j..", " | 746 | s = s.."a"..j..", " |
739 | end | 747 | end |
740 | s = s.."b\n" | 748 | s = s.."b\n" |
diff --git a/testes/files.lua b/testes/files.lua index 05fae49b..7146ac7c 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
@@ -1,6 +1,8 @@ | |||
1 | -- $Id: testes/files.lua $ | 1 | -- $Id: testes/files.lua $ |
2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | global <const> * | ||
5 | |||
4 | local debug = require "debug" | 6 | local debug = require "debug" |
5 | 7 | ||
6 | local maxint = math.maxinteger | 8 | local maxint = math.maxinteger |
@@ -347,7 +349,7 @@ collectgarbage() | |||
347 | 349 | ||
348 | assert(io.write(' ' .. t .. ' ')) | 350 | assert(io.write(' ' .. t .. ' ')) |
349 | assert(io.write(';', 'end of file\n')) | 351 | assert(io.write(';', 'end of file\n')) |
350 | f:flush(); io.flush() | 352 | assert(f:flush()); assert(io.flush()) |
351 | f:close() | 353 | f:close() |
352 | print('+') | 354 | print('+') |
353 | 355 | ||
@@ -461,7 +463,24 @@ do -- testing closing file in line iteration | |||
461 | end | 463 | end |
462 | 464 | ||
463 | 465 | ||
464 | -- test for multipe arguments in 'lines' | 466 | do print("testing flush") |
467 | local f = io.output("/dev/null") | ||
468 | assert(f:write("abcd")) -- write to buffer | ||
469 | assert(f:flush()) -- write to device | ||
470 | assert(f:write("abcd")) -- write to buffer | ||
471 | assert(io.flush()) -- write to device | ||
472 | assert(f:close()) | ||
473 | |||
474 | local f = io.output("/dev/full") | ||
475 | assert(f:write("abcd")) -- write to buffer | ||
476 | assert(not f:flush()) -- cannot write to device | ||
477 | assert(f:write("abcd")) -- write to buffer | ||
478 | assert(not io.flush()) -- cannot write to device | ||
479 | assert(f:close()) | ||
480 | end | ||
481 | |||
482 | |||
483 | -- test for multiple arguments in 'lines' | ||
465 | io.output(file); io.write"0123456789\n":close() | 484 | io.output(file); io.write"0123456789\n":close() |
466 | for a,b in io.lines(file, 1, 1) do | 485 | for a,b in io.lines(file, 1, 1) do |
467 | if a == "\n" then assert(not b) | 486 | if a == "\n" then assert(not b) |
@@ -696,6 +715,37 @@ do | |||
696 | end | 715 | end |
697 | 716 | ||
698 | 717 | ||
718 | if T and T.nonblock and not _port then | ||
719 | print("testing failed write") | ||
720 | |||
721 | -- unable to write anything to /dev/full | ||
722 | local f = io.open("/dev/full", "w") | ||
723 | assert(f:setvbuf("no")) | ||
724 | local _, _, err, count = f:write("abcd") | ||
725 | assert(err > 0 and count == 0) | ||
726 | assert(f:close()) | ||
727 | |||
728 | -- receiver will read a "few" bytes (enough to empty a large buffer) | ||
729 | local receiver = [[ | ||
730 | lua -e 'assert(io.stdin:setvbuf("no")); assert(#io.read(1e4) == 1e4)' ]] | ||
731 | |||
732 | local f = io.popen(receiver, "w") | ||
733 | assert(f:setvbuf("no")) | ||
734 | T.nonblock(f) | ||
735 | |||
736 | -- able to write a few bytes | ||
737 | assert(f:write(string.rep("a", 1e2))) | ||
738 | |||
739 | -- Unable to write more bytes than the pipe buffer supports. | ||
740 | -- (In Linux, the pipe buffer size is 64K (2^16). Posix requires at | ||
741 | -- least 512 bytes.) | ||
742 | local _, _, err, count = f:write("abcd", string.rep("a", 2^17)) | ||
743 | assert(err > 0 and count >= 512 and count < 2^17) | ||
744 | |||
745 | assert(f:close()) | ||
746 | end | ||
747 | |||
748 | |||
699 | if not _soft then | 749 | if not _soft then |
700 | print("testing large files (> BUFSIZ)") | 750 | print("testing large files (> BUFSIZ)") |
701 | io.output(file) | 751 | io.output(file) |
@@ -790,13 +840,13 @@ assert(os.date("!\0\0") == "\0\0") | |||
790 | local x = string.rep("a", 10000) | 840 | local x = string.rep("a", 10000) |
791 | assert(os.date(x) == x) | 841 | assert(os.date(x) == x) |
792 | local t = os.time() | 842 | local t = os.time() |
793 | D = os.date("*t", t) | 843 | global D = os.date("*t", t) |
794 | assert(os.date(string.rep("%d", 1000), t) == | 844 | assert(os.date(string.rep("%d", 1000), t) == |
795 | string.rep(os.date("%d", t), 1000)) | 845 | string.rep(os.date("%d", t), 1000)) |
796 | assert(os.date(string.rep("%", 200)) == string.rep("%", 100)) | 846 | assert(os.date(string.rep("%", 200)) == string.rep("%", 100)) |
797 | 847 | ||
798 | local function checkDateTable (t) | 848 | local function checkDateTable (t) |
799 | _G.D = os.date("*t", t) | 849 | D = os.date("*t", t) |
800 | assert(os.time(D) == t) | 850 | assert(os.time(D) == t) |
801 | load(os.date([[assert(D.year==%Y and D.month==%m and D.day==%d and | 851 | load(os.date([[assert(D.year==%Y and D.month==%m and D.day==%d and |
802 | D.hour==%H and D.min==%M and D.sec==%S and | 852 | D.hour==%H and D.min==%M and D.sec==%S and |
diff --git a/testes/gc.lua b/testes/gc.lua index 0693837c..62713dac 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
@@ -288,6 +288,21 @@ x,y,z=nil | |||
288 | collectgarbage() | 288 | collectgarbage() |
289 | assert(next(a) == string.rep('$', 11)) | 289 | assert(next(a) == string.rep('$', 11)) |
290 | 290 | ||
291 | do -- invalid mode | ||
292 | local a = setmetatable({}, {__mode = 34}) | ||
293 | collectgarbage() | ||
294 | end | ||
295 | |||
296 | |||
297 | if T then -- bug since 5.3: all-weak tables are not being revisited | ||
298 | T.gcstate("propagate") | ||
299 | local t = setmetatable({}, {__mode = "kv"}) | ||
300 | T.gcstate("enteratomic") -- 't' was visited | ||
301 | setmetatable(t, {__mode = "kv"}) | ||
302 | T.gcstate("pause") -- its new metatable is not being visited | ||
303 | assert(getmetatable(t).__mode == "kv") | ||
304 | end | ||
305 | |||
291 | 306 | ||
292 | -- 'bug' in 5.1 | 307 | -- 'bug' in 5.1 |
293 | a = {} | 308 | a = {} |
@@ -446,8 +461,8 @@ do -- tests for string keys in weak tables | |||
446 | local m = collectgarbage("count") -- current memory | 461 | local m = collectgarbage("count") -- current memory |
447 | local a = setmetatable({}, {__mode = "kv"}) | 462 | local a = setmetatable({}, {__mode = "kv"}) |
448 | a[string.rep("a", 2^22)] = 25 -- long string key -> number value | 463 | a[string.rep("a", 2^22)] = 25 -- long string key -> number value |
449 | a[string.rep("b", 2^22)] = {} -- long string key -> colectable value | 464 | a[string.rep("b", 2^22)] = {} -- long string key -> collectable value |
450 | a[{}] = 14 -- colectable key | 465 | a[{}] = 14 -- collectable key |
451 | collectgarbage() | 466 | collectgarbage() |
452 | local k, v = next(a) -- string key with number value preserved | 467 | local k, v = next(a) -- string key with number value preserved |
453 | assert(k == string.rep("a", 2^22) and v == 25) | 468 | assert(k == string.rep("a", 2^22) and v == 25) |
@@ -459,7 +474,7 @@ do -- tests for string keys in weak tables | |||
459 | assert(next(a) == nil) | 474 | assert(next(a) == nil) |
460 | -- make sure will not try to compare with dead key | 475 | -- make sure will not try to compare with dead key |
461 | assert(a[string.rep("b", 100)] == undef) | 476 | assert(a[string.rep("b", 100)] == undef) |
462 | assert(collectgarbage("count") <= m + 1) -- eveything collected | 477 | assert(collectgarbage("count") <= m + 1) -- everything collected |
463 | end | 478 | end |
464 | 479 | ||
465 | 480 | ||
@@ -524,7 +539,7 @@ do | |||
524 | local co = coroutine.create(f) | 539 | local co = coroutine.create(f) |
525 | assert(coroutine.resume(co, co)) | 540 | assert(coroutine.resume(co, co)) |
526 | end | 541 | end |
527 | -- Now, thread and closure are not reacheable any more. | 542 | -- Now, thread and closure are not reachable any more. |
528 | collectgarbage() | 543 | collectgarbage() |
529 | assert(collected) | 544 | assert(collected) |
530 | collectgarbage("restart") | 545 | collectgarbage("restart") |
@@ -644,7 +659,7 @@ do | |||
644 | assert(getmetatable(o) == tt) | 659 | assert(getmetatable(o) == tt) |
645 | -- create new objects during GC | 660 | -- create new objects during GC |
646 | local a = 'xuxu'..(10+3)..'joao', {} | 661 | local a = 'xuxu'..(10+3)..'joao', {} |
647 | ___Glob = o -- ressurrect object! | 662 | ___Glob = o -- resurrect object! |
648 | setmetatable({}, tt) -- creates a new one with same metatable | 663 | setmetatable({}, tt) -- creates a new one with same metatable |
649 | print(">>> closing state " .. "<<<\n") | 664 | print(">>> closing state " .. "<<<\n") |
650 | end | 665 | end |
diff --git a/testes/goto.lua b/testes/goto.lua index eca68516..3310314d 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
@@ -1,6 +1,12 @@ | |||
1 | -- $Id: testes/goto.lua $ | 1 | -- $Id: testes/goto.lua $ |
2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | global<const> require | ||
5 | global<const> print, load, assert, string, setmetatable | ||
6 | global<const> collectgarbage, error | ||
7 | |||
8 | print("testing goto and global declarations") | ||
9 | |||
4 | collectgarbage() | 10 | collectgarbage() |
5 | 11 | ||
6 | local function errmsg (code, m) | 12 | local function errmsg (code, m) |
@@ -17,15 +23,18 @@ errmsg([[ ::l1:: ::l1:: ]], "label 'l1'") | |||
17 | errmsg([[ ::l1:: do ::l1:: end]], "label 'l1'") | 23 | errmsg([[ ::l1:: do ::l1:: end]], "label 'l1'") |
18 | 24 | ||
19 | 25 | ||
20 | -- undefined label | ||
21 | errmsg([[ goto l1; local aa ::l1:: ::l2:: print(3) ]], "local 'aa'") | ||
22 | 26 | ||
23 | -- jumping over variable definition | 27 | -- jumping over variable declaration |
28 | errmsg([[ goto l1; local aa ::l1:: ::l2:: print(3) ]], "scope of 'aa'") | ||
29 | |||
30 | errmsg([[ goto l2; global *; ::l1:: ::l2:: print(3) ]], "scope of '*'") | ||
31 | |||
24 | errmsg([[ | 32 | errmsg([[ |
25 | do local bb, cc; goto l1; end | 33 | do local bb, cc; goto l1; end |
26 | local aa | 34 | local aa |
27 | ::l1:: print(3) | 35 | ::l1:: print(3) |
28 | ]], "local 'aa'") | 36 | ]], "scope of 'aa'") |
37 | |||
29 | 38 | ||
30 | -- jumping into a block | 39 | -- jumping into a block |
31 | errmsg([[ do ::l1:: end goto l1 ]], "label 'l1'") | 40 | errmsg([[ do ::l1:: end goto l1 ]], "label 'l1'") |
@@ -38,7 +47,7 @@ errmsg([[ | |||
38 | local xuxu = 10 | 47 | local xuxu = 10 |
39 | ::cont:: | 48 | ::cont:: |
40 | until xuxu < x | 49 | until xuxu < x |
41 | ]], "local 'xuxu'") | 50 | ]], "scope of 'xuxu'") |
42 | 51 | ||
43 | -- simple gotos | 52 | -- simple gotos |
44 | local x | 53 | local x |
@@ -252,6 +261,8 @@ assert(testG(5) == 10) | |||
252 | 261 | ||
253 | do -- test goto's around to-be-closed variable | 262 | do -- test goto's around to-be-closed variable |
254 | 263 | ||
264 | global * | ||
265 | |||
255 | -- set 'var' and return an object that will reset 'var' when | 266 | -- set 'var' and return an object that will reset 'var' when |
256 | -- it goes out of scope | 267 | -- it goes out of scope |
257 | local function newobj (var) | 268 | local function newobj (var) |
@@ -263,16 +274,16 @@ do -- test goto's around to-be-closed variable | |||
263 | 274 | ||
264 | goto L1 | 275 | goto L1 |
265 | 276 | ||
266 | ::L4:: assert(not X); goto L5 -- varX dead here | 277 | ::L4:: assert(not varX); goto L5 -- varX dead here |
267 | 278 | ||
268 | ::L1:: | 279 | ::L1:: |
269 | local varX <close> = newobj("X") | 280 | local varX <close> = newobj("X") |
270 | assert(X); goto L2 -- varX alive here | 281 | assert(varX); goto L2 -- varX alive here |
271 | 282 | ||
272 | ::L3:: | 283 | ::L3:: |
273 | assert(X); goto L4 -- varX alive here | 284 | assert(varX); goto L4 -- varX alive here |
274 | 285 | ||
275 | ::L2:: assert(X); goto L3 -- varX alive here | 286 | ::L2:: assert(varX); goto L3 -- varX alive here |
276 | 287 | ||
277 | ::L5:: -- return | 288 | ::L5:: -- return |
278 | end | 289 | end |
@@ -280,7 +291,146 @@ end | |||
280 | 291 | ||
281 | 292 | ||
282 | foo() | 293 | foo() |
283 | -------------------------------------------------------------------------------- | 294 | -------------------------------------------------------------------------- |
295 | |||
296 | local function checkerr (code, err) | ||
297 | local st, msg = load(code) | ||
298 | assert(not st and string.find(msg, err)) | ||
299 | end | ||
300 | |||
301 | do | ||
302 | global T<const> | ||
303 | |||
304 | -- globals must be declared, after a global declaration | ||
305 | checkerr("global none; X = 1", "variable 'X'") | ||
306 | checkerr("global none; function XX() end", "variable 'XX'") | ||
284 | 307 | ||
308 | -- global variables cannot be to-be-closed | ||
309 | checkerr("global X<close>", "cannot be") | ||
310 | checkerr("global <close> *", "cannot be") | ||
311 | |||
312 | do | ||
313 | local X = 10 | ||
314 | do global X; X = 20 end | ||
315 | assert(X == 10) -- local X | ||
316 | end | ||
317 | assert(_ENV.X == 20) -- global X | ||
318 | |||
319 | -- '_ENV' cannot be global | ||
320 | checkerr("global _ENV, a; a = 10", "variable 'a'") | ||
321 | |||
322 | -- global declarations inside functions | ||
323 | checkerr([[ | ||
324 | global none | ||
325 | local function foo () XXX = 1 end --< ERROR]], "variable 'XXX'") | ||
326 | |||
327 | if not T then -- when not in "test mode", "global" isn't reserved | ||
328 | assert(load("global = 1; return global")() == 1) | ||
329 | print " ('global' is not a reserved word)" | ||
330 | else | ||
331 | -- "global" reserved, cannot be used as a variable | ||
332 | assert(not load("global = 1; return global")) | ||
333 | end | ||
334 | |||
335 | local foo = 20 | ||
336 | do | ||
337 | global function foo (x) | ||
338 | if x == 0 then return 1 else return 2 * foo(x - 1) end | ||
339 | end | ||
340 | assert(foo == _ENV.foo and foo(4) == 16) | ||
341 | end | ||
342 | assert(_ENV.foo(4) == 16) | ||
343 | assert(foo == 20) -- local one is in context here | ||
344 | |||
345 | do | ||
346 | global foo; | ||
347 | function foo (x) return end -- Ok after declaration | ||
348 | end | ||
349 | |||
350 | checkerr([[ | ||
351 | global<const> foo; | ||
352 | function foo (x) return end -- ERROR: foo is read-only | ||
353 | ]], "assign to const variable 'foo'") | ||
354 | |||
355 | checkerr([[ | ||
356 | global foo <const>; | ||
357 | function foo (x) -- ERROR: foo is read-only | ||
358 | return | ||
359 | end | ||
360 | ]], "%:2%:") -- correct line in error message | ||
361 | |||
362 | checkerr([[ | ||
363 | global<const> *; | ||
364 | print(X) -- Ok to use | ||
365 | Y = 1 -- ERROR | ||
366 | ]], "assign to const variable 'Y'") | ||
367 | |||
368 | checkerr([[ | ||
369 | global *; | ||
370 | Y = X -- Ok to use | ||
371 | global<const> *; | ||
372 | Y = 1 -- ERROR | ||
373 | ]], "assign to const variable 'Y'") | ||
374 | |||
375 | global * | ||
376 | Y = 10 | ||
377 | assert(_ENV.Y == 10) | ||
378 | global<const> * | ||
379 | local x = Y | ||
380 | global * | ||
381 | Y = x + Y | ||
382 | assert(_ENV.Y == 20) | ||
383 | Y = nil | ||
384 | end | ||
385 | |||
386 | |||
387 | do -- Ok to declare hundreds of globals | ||
388 | global table | ||
389 | local code = {} | ||
390 | for i = 1, 1000 do | ||
391 | code[#code + 1] = ";global x" .. i | ||
392 | end | ||
393 | code[#code + 1] = "; return x990" | ||
394 | code = table.concat(code) | ||
395 | _ENV.x990 = 11 | ||
396 | assert(load(code)() == 11) | ||
397 | _ENV.x990 = nil | ||
398 | end | ||
399 | |||
400 | do -- mixing lots of global/local declarations | ||
401 | global table | ||
402 | local code = {} | ||
403 | for i = 1, 200 do | ||
404 | code[#code + 1] = ";global x" .. i | ||
405 | code[#code + 1] = ";local y" .. i .. "=" .. (2*i) | ||
406 | end | ||
407 | code[#code + 1] = "; return x200 + y200" | ||
408 | code = table.concat(code) | ||
409 | _ENV.x200 = 11 | ||
410 | assert(assert(load(code))() == 2*200 + 11) | ||
411 | _ENV.x200 = nil | ||
412 | end | ||
413 | |||
414 | do print "testing initialization in global declarations" | ||
415 | global<const> a, b, c = 10, 20, 30 | ||
416 | assert(_ENV.a == 10 and b == 20 and c == 30) | ||
417 | |||
418 | global<const> a, b, c = 10 | ||
419 | assert(_ENV.a == 10 and b == nil and c == nil) | ||
420 | |||
421 | global table | ||
422 | global a, b, c, d = table.unpack{1, 2, 3, 6, 5} | ||
423 | assert(_ENV.a == 1 and b == 2 and c == 3 and d == 6) | ||
424 | |||
425 | local a, b = 100, 200 | ||
426 | do | ||
427 | global a, b = a, b | ||
428 | end | ||
429 | assert(_ENV.a == 100 and _ENV.b == 200) | ||
430 | |||
431 | |||
432 | _ENV.a, _ENV.b, _ENV.c, _ENV.d = nil -- erase these globals | ||
433 | end | ||
285 | 434 | ||
286 | print'OK' | 435 | print'OK' |
436 | |||
diff --git a/testes/libs/lib22.c b/testes/libs/lib22.c index 8e656502..b377cce5 100644 --- a/testes/libs/lib22.c +++ b/testes/libs/lib22.c | |||
@@ -1,3 +1,7 @@ | |||
1 | /* implementation for lib2-v2 */ | ||
2 | |||
3 | #include <string.h> | ||
4 | |||
1 | #include "lua.h" | 5 | #include "lua.h" |
2 | #include "lauxlib.h" | 6 | #include "lauxlib.h" |
3 | 7 | ||
@@ -8,8 +12,54 @@ static int id (lua_State *L) { | |||
8 | } | 12 | } |
9 | 13 | ||
10 | 14 | ||
15 | struct STR { | ||
16 | void *ud; | ||
17 | lua_Alloc allocf; | ||
18 | }; | ||
19 | |||
20 | |||
21 | static void *t_freestr (void *ud, void *ptr, size_t osize, size_t nsize) { | ||
22 | struct STR *blk = (struct STR*)ptr - 1; | ||
23 | blk->allocf(blk->ud, blk, sizeof(struct STR) + osize, 0); | ||
24 | return NULL; | ||
25 | } | ||
26 | |||
27 | |||
28 | static int newstr (lua_State *L) { | ||
29 | size_t len; | ||
30 | const char *str = luaL_checklstring(L, 1, &len); | ||
31 | void *ud; | ||
32 | lua_Alloc allocf = lua_getallocf(L, &ud); | ||
33 | struct STR *blk = (struct STR*)allocf(ud, NULL, 0, | ||
34 | len + 1 + sizeof(struct STR)); | ||
35 | if (blk == NULL) { /* allocation error? */ | ||
36 | lua_pushliteral(L, "not enough memory"); | ||
37 | lua_error(L); /* raise a memory error */ | ||
38 | } | ||
39 | blk->ud = ud; blk->allocf = allocf; | ||
40 | memcpy(blk + 1, str, len + 1); | ||
41 | lua_pushexternalstring(L, (char *)(blk + 1), len, t_freestr, L); | ||
42 | return 1; | ||
43 | } | ||
44 | |||
45 | |||
46 | /* | ||
47 | ** Create an external string and keep it in the registry, so that it | ||
48 | ** will test that the library code is still available (to deallocate | ||
49 | ** this string) when closing the state. | ||
50 | */ | ||
51 | static void initstr (lua_State *L) { | ||
52 | lua_pushcfunction(L, newstr); | ||
53 | lua_pushstring(L, | ||
54 | "012345678901234567890123456789012345678901234567890123456789"); | ||
55 | lua_call(L, 1, 1); /* call newstr("0123...") */ | ||
56 | luaL_ref(L, LUA_REGISTRYINDEX); /* keep string in the registry */ | ||
57 | } | ||
58 | |||
59 | |||
11 | static const struct luaL_Reg funcs[] = { | 60 | static const struct luaL_Reg funcs[] = { |
12 | {"id", id}, | 61 | {"id", id}, |
62 | {"newstr", newstr}, | ||
13 | {NULL, NULL} | 63 | {NULL, NULL} |
14 | }; | 64 | }; |
15 | 65 | ||
@@ -18,6 +68,7 @@ LUAMOD_API int luaopen_lib2 (lua_State *L) { | |||
18 | lua_settop(L, 2); | 68 | lua_settop(L, 2); |
19 | lua_setglobal(L, "y"); /* y gets 2nd parameter */ | 69 | lua_setglobal(L, "y"); /* y gets 2nd parameter */ |
20 | lua_setglobal(L, "x"); /* x gets 1st parameter */ | 70 | lua_setglobal(L, "x"); /* x gets 1st parameter */ |
71 | initstr(L); | ||
21 | luaL_newlib(L, funcs); | 72 | luaL_newlib(L, funcs); |
22 | return 1; | 73 | return 1; |
23 | } | 74 | } |
diff --git a/testes/literals.lua b/testes/literals.lua index 28995718..336ef585 100644 --- a/testes/literals.lua +++ b/testes/literals.lua | |||
@@ -3,6 +3,8 @@ | |||
3 | 3 | ||
4 | print('testing scanner') | 4 | print('testing scanner') |
5 | 5 | ||
6 | global <const> * | ||
7 | |||
6 | local debug = require "debug" | 8 | local debug = require "debug" |
7 | 9 | ||
8 | 10 | ||
diff --git a/testes/locals.lua b/testes/locals.lua index ccea0a14..02f41980 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
@@ -1,6 +1,8 @@ | |||
1 | -- $Id: testes/locals.lua $ | 1 | -- $Id: testes/locals.lua $ |
2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | global <const> * | ||
5 | |||
4 | print('testing local variables and environments') | 6 | print('testing local variables and environments') |
5 | 7 | ||
6 | local debug = require"debug" | 8 | local debug = require"debug" |
@@ -39,9 +41,11 @@ f = nil | |||
39 | local f | 41 | local f |
40 | local x = 1 | 42 | local x = 1 |
41 | 43 | ||
42 | a = nil | 44 | do |
43 | load('local a = {}')() | 45 | global a; a = nil |
44 | assert(a == nil) | 46 | load('local a = {}')() |
47 | assert(a == nil) | ||
48 | end | ||
45 | 49 | ||
46 | function f (a) | 50 | function f (a) |
47 | local _1, _2, _3, _4, _5 | 51 | local _1, _2, _3, _4, _5 |
@@ -154,7 +158,7 @@ local _ENV = (function (...) return ... end)(_G, dummy) -- { | |||
154 | do local _ENV = {assert=assert}; assert(true) end | 158 | do local _ENV = {assert=assert}; assert(true) end |
155 | local mt = {_G = _G} | 159 | local mt = {_G = _G} |
156 | local foo,x | 160 | local foo,x |
157 | A = false -- "declare" A | 161 | global A; A = false -- "declare" A |
158 | do local _ENV = mt | 162 | do local _ENV = mt |
159 | function foo (x) | 163 | function foo (x) |
160 | A = x | 164 | A = x |
@@ -177,20 +181,27 @@ assert(x==20) | |||
177 | A = nil | 181 | A = nil |
178 | 182 | ||
179 | 183 | ||
180 | do -- constants | 184 | do print("testing local constants") |
185 | global assert<const>, load, string, X | ||
186 | X = 1 -- not a constant | ||
181 | local a<const>, b, c<const> = 10, 20, 30 | 187 | local a<const>, b, c<const> = 10, 20, 30 |
182 | b = a + c + b -- 'b' is not constant | 188 | b = a + c + b -- 'b' is not constant |
183 | assert(a == 10 and b == 60 and c == 30) | 189 | assert(a == 10 and b == 60 and c == 30) |
190 | |||
184 | local function checkro (name, code) | 191 | local function checkro (name, code) |
185 | local st, msg = load(code) | 192 | local st, msg = load(code) |
186 | local gab = string.format("attempt to assign to const variable '%s'", name) | 193 | local gab = string.format("attempt to assign to const variable '%s'", name) |
187 | assert(not st and string.find(msg, gab)) | 194 | assert(not st and string.find(msg, gab)) |
188 | end | 195 | end |
196 | |||
189 | checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12") | 197 | checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12") |
190 | checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11") | 198 | checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11") |
191 | checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") | 199 | checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") |
192 | checkro("foo", "local foo <const> = 10; function foo() end") | 200 | checkro("foo", "local<const> foo = 10; function foo() end") |
193 | checkro("foo", "local foo <const> = {}; function foo() end") | 201 | checkro("foo", "local<const> foo <const> = {}; function foo() end") |
202 | checkro("foo", "global<const> foo <const>; function foo() end") | ||
203 | checkro("XX", "global XX <const>; XX = 10") | ||
204 | checkro("XX", "local _ENV; global XX <const>; XX = 10") | ||
194 | 205 | ||
195 | checkro("z", [[ | 206 | checkro("z", [[ |
196 | local a, z <const>, b = 10; | 207 | local a, z <const>, b = 10; |
@@ -201,11 +212,26 @@ do -- constants | |||
201 | local a, var1 <const> = 10; | 212 | local a, var1 <const> = 10; |
202 | function foo() a = 20; z = function () var1 = 12; end end | 213 | function foo() a = 20; z = function () var1 = 12; end end |
203 | ]]) | 214 | ]]) |
215 | |||
216 | checkro("var1", [[ | ||
217 | global a, var1 <const>, z; | ||
218 | local function foo() a = 20; z = function () var1 = 12; end end | ||
219 | ]]) | ||
204 | end | 220 | end |
205 | 221 | ||
206 | 222 | ||
223 | |||
207 | print"testing to-be-closed variables" | 224 | print"testing to-be-closed variables" |
208 | 225 | ||
226 | |||
227 | do | ||
228 | local st, msg = load("local <close> a, b") | ||
229 | assert(not st and string.find(msg, "multiple")) | ||
230 | |||
231 | local st, msg = load("local a<close>, b<close>") | ||
232 | assert(not st and string.find(msg, "multiple")) | ||
233 | end | ||
234 | |||
209 | local function stack(n) n = ((n == 0) or stack(n - 1)) end | 235 | local function stack(n) n = ((n == 0) or stack(n - 1)) end |
210 | 236 | ||
211 | local function func2close (f, x, y) | 237 | local function func2close (f, x, y) |
@@ -1162,7 +1188,7 @@ do | |||
1162 | local function open (x) | 1188 | local function open (x) |
1163 | numopen = numopen + 1 | 1189 | numopen = numopen + 1 |
1164 | return | 1190 | return |
1165 | function () -- iteraction function | 1191 | function () -- iteration function |
1166 | x = x - 1 | 1192 | x = x - 1 |
1167 | if x > 0 then return x end | 1193 | if x > 0 then return x end |
1168 | end, | 1194 | end, |
diff --git a/testes/main.lua b/testes/main.lua index bf3c898e..dc48dc48 100644 --- a/testes/main.lua +++ b/testes/main.lua | |||
@@ -90,7 +90,7 @@ prepfile[[ | |||
90 | 1, a | 90 | 1, a |
91 | ) | 91 | ) |
92 | ]] | 92 | ]] |
93 | RUN('lua - < %s > %s', prog, out) | 93 | RUN('lua - -- < %s > %s', prog, out) |
94 | checkout("1\tnil\n") | 94 | checkout("1\tnil\n") |
95 | 95 | ||
96 | RUN('echo "print(10)\nprint(2)\n" | lua > %s', out) | 96 | RUN('echo "print(10)\nprint(2)\n" | lua > %s', out) |
@@ -133,7 +133,7 @@ checkout("-h\n") | |||
133 | prepfile("print(package.path)") | 133 | prepfile("print(package.path)") |
134 | 134 | ||
135 | -- test LUA_PATH | 135 | -- test LUA_PATH |
136 | RUN('env LUA_INIT= LUA_PATH=x lua %s > %s', prog, out) | 136 | RUN('env LUA_INIT= LUA_PATH=x lua -- %s > %s', prog, out) |
137 | checkout("x\n") | 137 | checkout("x\n") |
138 | 138 | ||
139 | -- test LUA_PATH_version | 139 | -- test LUA_PATH_version |
@@ -226,7 +226,7 @@ RUN("lua -l 'str=string' '-lm=math' -e 'print(m.sin(0))' %s > %s", prog, out) | |||
226 | checkout("0.0\nALO ALO\t20\n") | 226 | checkout("0.0\nALO ALO\t20\n") |
227 | 227 | ||
228 | 228 | ||
229 | -- test module names with version sufix ("libs/lib2-v2") | 229 | -- test module names with version suffix ("libs/lib2-v2") |
230 | RUN("env LUA_CPATH='./libs/?.so' lua -l lib2-v2 -e 'print(lib2.id())' > %s", | 230 | RUN("env LUA_CPATH='./libs/?.so' lua -l lib2-v2 -e 'print(lib2.id())' > %s", |
231 | out) | 231 | out) |
232 | checkout("true\n") | 232 | checkout("true\n") |
@@ -347,7 +347,7 @@ checkout("a\n") | |||
347 | RUN([[lua "-eprint(1)" -ea=3 -e "print(a)" > %s]], out) | 347 | RUN([[lua "-eprint(1)" -ea=3 -e "print(a)" > %s]], out) |
348 | checkout("1\n3\n") | 348 | checkout("1\n3\n") |
349 | 349 | ||
350 | -- test iteractive mode | 350 | -- test interactive mode |
351 | prepfile[[ | 351 | prepfile[[ |
352 | (6*2-6) -- === | 352 | (6*2-6) -- === |
353 | a = | 353 | a = |
@@ -358,7 +358,7 @@ RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) | |||
358 | checkprogout("6\n10\n10\n\n") | 358 | checkprogout("6\n10\n10\n\n") |
359 | 359 | ||
360 | prepfile("a = [[b\nc\nd\ne]]\na") | 360 | prepfile("a = [[b\nc\nd\ne]]\na") |
361 | RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) | 361 | RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i -- < %s > %s]], prog, out) |
362 | checkprogout("b\nc\nd\ne\n\n") | 362 | checkprogout("b\nc\nd\ne\n\n") |
363 | 363 | ||
364 | -- input interrupted in continuation line | 364 | -- input interrupted in continuation line |
@@ -488,12 +488,13 @@ assert(not os.remove(out)) | |||
488 | -- invalid options | 488 | -- invalid options |
489 | NoRun("unrecognized option '-h'", "lua -h") | 489 | NoRun("unrecognized option '-h'", "lua -h") |
490 | NoRun("unrecognized option '---'", "lua ---") | 490 | NoRun("unrecognized option '---'", "lua ---") |
491 | NoRun("unrecognized option '-Ex'", "lua -Ex") | 491 | NoRun("unrecognized option '-Ex'", "lua -Ex --") |
492 | NoRun("unrecognized option '-vv'", "lua -vv") | 492 | NoRun("unrecognized option '-vv'", "lua -vv") |
493 | NoRun("unrecognized option '-iv'", "lua -iv") | 493 | NoRun("unrecognized option '-iv'", "lua -iv") |
494 | NoRun("'-e' needs argument", "lua -e") | 494 | NoRun("'-e' needs argument", "lua -e") |
495 | NoRun("syntax error", "lua -e a") | 495 | NoRun("syntax error", "lua -e a") |
496 | NoRun("'-l' needs argument", "lua -l") | 496 | NoRun("'-l' needs argument", "lua -l") |
497 | NoRun("-i", "lua -- -i") -- handles -i as a script name | ||
497 | 498 | ||
498 | 499 | ||
499 | if T then -- test library? | 500 | if T then -- test library? |
diff --git a/testes/math.lua b/testes/math.lua index bad8bc5e..0d228d09 100644 --- a/testes/math.lua +++ b/testes/math.lua | |||
@@ -3,8 +3,15 @@ | |||
3 | 3 | ||
4 | print("testing numbers and math lib") | 4 | print("testing numbers and math lib") |
5 | 5 | ||
6 | local minint <const> = math.mininteger | 6 | local math = require "math" |
7 | local maxint <const> = math.maxinteger | 7 | local string = require "string" |
8 | |||
9 | global none | ||
10 | |||
11 | global<const> print, assert, pcall, type, pairs, load | ||
12 | global<const> tonumber, tostring, select | ||
13 | |||
14 | local<const> minint, maxint = math.mininteger, math.maxinteger | ||
8 | 15 | ||
9 | local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1 | 16 | local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1 |
10 | assert((1 << intbits) == 0) | 17 | assert((1 << intbits) == 0) |
@@ -184,7 +191,7 @@ do | |||
184 | for i = -3, 3 do -- variables avoid constant folding | 191 | for i = -3, 3 do -- variables avoid constant folding |
185 | for j = -3, 3 do | 192 | for j = -3, 3 do |
186 | -- domain errors (0^(-n)) are not portable | 193 | -- domain errors (0^(-n)) are not portable |
187 | if not _port or i ~= 0 or j > 0 then | 194 | if not _ENV._port or i ~= 0 or j > 0 then |
188 | assert(eq(i^j, 1 / i^(-j))) | 195 | assert(eq(i^j, 1 / i^(-j))) |
189 | end | 196 | end |
190 | end | 197 | end |
@@ -430,7 +437,7 @@ for i = 2,36 do | |||
430 | assert(tonumber('\t10000000000\t', i) == i10) | 437 | assert(tonumber('\t10000000000\t', i) == i10) |
431 | end | 438 | end |
432 | 439 | ||
433 | if not _soft then | 440 | if not _ENV._soft then |
434 | -- tests with very long numerals | 441 | -- tests with very long numerals |
435 | assert(tonumber("0x"..string.rep("f", 13)..".0") == 2.0^(4*13) - 1) | 442 | assert(tonumber("0x"..string.rep("f", 13)..".0") == 2.0^(4*13) - 1) |
436 | assert(tonumber("0x"..string.rep("f", 150)..".0") == 2.0^(4*150) - 1) | 443 | assert(tonumber("0x"..string.rep("f", 150)..".0") == 2.0^(4*150) - 1) |
@@ -632,7 +639,7 @@ assert(maxint % -2 == -1) | |||
632 | 639 | ||
633 | -- non-portable tests because Windows C library cannot compute | 640 | -- non-portable tests because Windows C library cannot compute |
634 | -- fmod(1, huge) correctly | 641 | -- fmod(1, huge) correctly |
635 | if not _port then | 642 | if not _ENV._port then |
636 | local function anan (x) assert(isNaN(x)) end -- assert Not a Number | 643 | local function anan (x) assert(isNaN(x)) end -- assert Not a Number |
637 | anan(0.0 % 0) | 644 | anan(0.0 % 0) |
638 | anan(1.3 % 0) | 645 | anan(1.3 % 0) |
@@ -779,6 +786,7 @@ assert(a == '10' and b == '20') | |||
779 | 786 | ||
780 | do | 787 | do |
781 | print("testing -0 and NaN") | 788 | print("testing -0 and NaN") |
789 | global rawset, undef | ||
782 | local mz <const> = -0.0 | 790 | local mz <const> = -0.0 |
783 | local z <const> = 0.0 | 791 | local z <const> = 0.0 |
784 | assert(mz == z) | 792 | assert(mz == z) |
@@ -1071,9 +1079,10 @@ do | |||
1071 | assert(x == tonumber(tostring(x))) | 1079 | assert(x == tonumber(tostring(x))) |
1072 | end | 1080 | end |
1073 | 1081 | ||
1074 | -- different numbers shold print differently. | 1082 | -- different numbers should print differently. |
1075 | -- check pairs of floats with minimum detectable difference | 1083 | -- check pairs of floats with minimum detectable difference |
1076 | local p = floatbits - 1 | 1084 | local p = floatbits - 1 |
1085 | global ipairs | ||
1077 | for i = 1, maxexp - 1 do | 1086 | for i = 1, maxexp - 1 do |
1078 | for _, i in ipairs{-i, i} do | 1087 | for _, i in ipairs{-i, i} do |
1079 | local x = 2^i | 1088 | local x = 2^i |
diff --git a/testes/nextvar.lua b/testes/nextvar.lua index 031ad3fd..7e5bed56 100644 --- a/testes/nextvar.lua +++ b/testes/nextvar.lua | |||
@@ -1,6 +1,8 @@ | |||
1 | -- $Id: testes/nextvar.lua $ | 1 | -- $Id: testes/nextvar.lua $ |
2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | global <const> * | ||
5 | |||
4 | print('testing tables, next, and for') | 6 | print('testing tables, next, and for') |
5 | 7 | ||
6 | local function checkerror (msg, f, ...) | 8 | local function checkerror (msg, f, ...) |
@@ -227,7 +229,7 @@ for i = 1,lim do | |||
227 | end | 229 | end |
228 | 230 | ||
229 | 231 | ||
230 | -- insert and delete elements until a rehash occurr. Caller must ensure | 232 | -- insert and delete elements until a rehash occur. Caller must ensure |
231 | -- that a rehash will change the shape of the table. Must repeat because | 233 | -- that a rehash will change the shape of the table. Must repeat because |
232 | -- the insertion may collide with the deleted element, and then there is | 234 | -- the insertion may collide with the deleted element, and then there is |
233 | -- no rehash. | 235 | -- no rehash. |
@@ -343,13 +345,22 @@ do | |||
343 | end | 345 | end |
344 | end | 346 | end |
345 | 347 | ||
346 | local nofind = {} | ||
347 | 348 | ||
348 | a,b,c = 1,2,3 | 349 | do print("testing attack on table length") |
349 | a,b,c = nil | 350 | local t = {} |
351 | local lim = math.floor(math.log(math.maxinteger, 2)) - 1 | ||
352 | for i = lim, 0, -1 do | ||
353 | t[2^i] = true | ||
354 | end | ||
355 | assert(t[1 << lim]) | ||
356 | -- next loop should not take forever | ||
357 | for i = 1, #t do end | ||
358 | end | ||
359 | |||
360 | local nofind = {} | ||
350 | 361 | ||
351 | 362 | ||
352 | -- next uses always the same iteraction function | 363 | -- next uses always the same iteration function |
353 | assert(next{} == next{}) | 364 | assert(next{} == next{}) |
354 | 365 | ||
355 | local function find (name) | 366 | local function find (name) |
@@ -396,7 +407,7 @@ for i=0,10000 do | |||
396 | end | 407 | end |
397 | end | 408 | end |
398 | 409 | ||
399 | n = {n=0} | 410 | local n = {n=0} |
400 | for i,v in pairs(a) do | 411 | for i,v in pairs(a) do |
401 | n.n = n.n+1 | 412 | n.n = n.n+1 |
402 | assert(i and v and a[i] == v) | 413 | assert(i and v and a[i] == v) |
diff --git a/testes/pm.lua b/testes/pm.lua index 2a0cfb0b..720d2a35 100644 --- a/testes/pm.lua +++ b/testes/pm.lua | |||
@@ -6,6 +6,8 @@ | |||
6 | 6 | ||
7 | print('testing pattern matching') | 7 | print('testing pattern matching') |
8 | 8 | ||
9 | global <const> * | ||
10 | |||
9 | local function checkerror (msg, f, ...) | 11 | local function checkerror (msg, f, ...) |
10 | local s, err = pcall(f, ...) | 12 | local s, err = pcall(f, ...) |
11 | assert(not s and string.find(err, msg)) | 13 | assert(not s and string.find(err, msg)) |
@@ -23,9 +25,9 @@ a,b = string.find('alo', '') | |||
23 | assert(a == 1 and b == 0) | 25 | assert(a == 1 and b == 0) |
24 | a,b = string.find('a\0o a\0o a\0o', 'a', 1) -- first position | 26 | a,b = string.find('a\0o a\0o a\0o', 'a', 1) -- first position |
25 | assert(a == 1 and b == 1) | 27 | assert(a == 1 and b == 1) |
26 | a,b = string.find('a\0o a\0o a\0o', 'a\0o', 2) -- starts in the midle | 28 | a,b = string.find('a\0o a\0o a\0o', 'a\0o', 2) -- starts in the middle |
27 | assert(a == 5 and b == 7) | 29 | assert(a == 5 and b == 7) |
28 | a,b = string.find('a\0o a\0o a\0o', 'a\0o', 9) -- starts in the midle | 30 | a,b = string.find('a\0o a\0o a\0o', 'a\0o', 9) -- starts in the middle |
29 | assert(a == 9 and b == 11) | 31 | assert(a == 9 and b == 11) |
30 | a,b = string.find('a\0a\0a\0a\0\0ab', '\0ab', 2); -- finds at the end | 32 | a,b = string.find('a\0a\0a\0a\0\0ab', '\0ab', 2); -- finds at the end |
31 | assert(a == 9 and b == 11); | 33 | assert(a == 9 and b == 11); |
diff --git a/testes/strings.lua b/testes/strings.lua index ce28e4c5..46912d43 100644 --- a/testes/strings.lua +++ b/testes/strings.lua | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | -- ISO Latin encoding | 4 | -- ISO Latin encoding |
5 | 5 | ||
6 | global <const> * | ||
6 | 7 | ||
7 | print('testing strings and string library') | 8 | print('testing strings and string library') |
8 | 9 | ||
diff --git a/testes/tracegc.lua b/testes/tracegc.lua index 9c5c1b3f..a8c929df 100644 --- a/testes/tracegc.lua +++ b/testes/tracegc.lua | |||
@@ -6,7 +6,7 @@ local M = {} | |||
6 | local setmetatable, stderr, collectgarbage = | 6 | local setmetatable, stderr, collectgarbage = |
7 | setmetatable, io.stderr, collectgarbage | 7 | setmetatable, io.stderr, collectgarbage |
8 | 8 | ||
9 | _ENV = nil | 9 | global none |
10 | 10 | ||
11 | local active = false | 11 | local active = false |
12 | 12 | ||
diff --git a/testes/utf8.lua b/testes/utf8.lua index 0704782c..028995a4 100644 --- a/testes/utf8.lua +++ b/testes/utf8.lua | |||
@@ -3,6 +3,8 @@ | |||
3 | 3 | ||
4 | -- UTF-8 file | 4 | -- UTF-8 file |
5 | 5 | ||
6 | global <const> * | ||
7 | |||
6 | print "testing UTF-8 library" | 8 | print "testing UTF-8 library" |
7 | 9 | ||
8 | local utf8 = require'utf8' | 10 | local utf8 = require'utf8' |
@@ -134,7 +136,7 @@ do | |||
134 | errorcodes("\xbfinvalid") | 136 | errorcodes("\xbfinvalid") |
135 | errorcodes("αλφ\xBFα") | 137 | errorcodes("αλφ\xBFα") |
136 | 138 | ||
137 | -- calling interation function with invalid arguments | 139 | -- calling iteration function with invalid arguments |
138 | local f = utf8.codes("") | 140 | local f = utf8.codes("") |
139 | assert(f("", 2) == nil) | 141 | assert(f("", 2) == nil) |
140 | assert(f("", -1) == nil) | 142 | assert(f("", -1) == nil) |
@@ -150,11 +152,20 @@ checkerror("position out of bounds", utf8.offset, "", 1, -1) | |||
150 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) | 152 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) |
151 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) | 153 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) |
152 | checkerror("continuation byte", utf8.offset, "\x80", 1) | 154 | checkerror("continuation byte", utf8.offset, "\x80", 1) |
155 | checkerror("continuation byte", utf8.offset, "\x9c", -1) | ||
153 | 156 | ||
154 | -- error in indices for len | 157 | -- error in indices for len |
155 | checkerror("out of bounds", utf8.len, "abc", 0, 2) | 158 | checkerror("out of bounds", utf8.len, "abc", 0, 2) |
156 | checkerror("out of bounds", utf8.len, "abc", 1, 4) | 159 | checkerror("out of bounds", utf8.len, "abc", 1, 4) |
157 | 160 | ||
161 | do -- missing continuation bytes | ||
162 | -- get what is available | ||
163 | local p, e = utf8.offset("\xE0", 1) | ||
164 | assert(p == 1 and e == 1) | ||
165 | local p, e = utf8.offset("\xE0\x9e", -1) | ||
166 | assert(p == 1 and e == 2) | ||
167 | end | ||
168 | |||
158 | 169 | ||
159 | local s = "hello World" | 170 | local s = "hello World" |
160 | local t = {string.byte(s, 1, -1)} | 171 | local t = {string.byte(s, 1, -1)} |