diff options
Diffstat (limited to 'testes/nextvar.lua')
-rw-r--r-- | testes/nextvar.lua | 23 |
1 files changed, 17 insertions, 6 deletions
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) |