aboutsummaryrefslogtreecommitdiff
path: root/testes/nextvar.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/nextvar.lua')
-rw-r--r--testes/nextvar.lua23
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
4global <const> *
5
4print('testing tables, next, and for') 6print('testing tables, next, and for')
5 7
6local function checkerror (msg, f, ...) 8local function checkerror (msg, f, ...)
@@ -227,7 +229,7 @@ for i = 1,lim do
227end 229end
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
344end 346end
345 347
346local nofind = {}
347 348
348a,b,c = 1,2,3 349do print("testing attack on table length")
349a,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
358end
359
360local nofind = {}
350 361
351 362
352-- next uses always the same iteraction function 363-- next uses always the same iteration function
353assert(next{} == next{}) 364assert(next{} == next{})
354 365
355local function find (name) 366local function find (name)
@@ -396,7 +407,7 @@ for i=0,10000 do
396 end 407 end
397end 408end
398 409
399n = {n=0} 410local n = {n=0}
400for i,v in pairs(a) do 411for 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)