Skip to content

Commit

Permalink
Add tests for table indexing (inspired by snabbco#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
corsix committed Oct 19, 2016
1 parent 73139f8 commit 14c132e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/lang/index
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ length.lua
modulo.lua
concat.lua
self.lua
table.lua
upvalue
coroutine.lua
tail_recursion.lua
Expand Down
32 changes: 32 additions & 0 deletions test/lang/table.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
do --- tables as keys in tables
local fwd, bck = {}, {}
for i = 1,100 do
local v = {}
fwd[i] = v
bck[v] = i
end
for i = 1,100 do
local v = fwd[i]
assert(type(v) == "table")
assert(bck[v] == i)
end
end

do --- some tables as keys in tables
local fwd, bck = {}, {}
for i = 1,100 do
local v = {}
fwd[i] = v
if i > 90 then
bck[v] = i
end
end
local n = 0
for i = 1, 100 do
local v = fwd[i]
if bck[v] then
n = n + 1
end
end
assert(n == 10)
end

0 comments on commit 14c132e

Please sign in to comment.