diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/errhangtest.lua | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/tests/errhangtest.lua b/tests/errhangtest.lua index 5b3f0c0..819bc10 100644 --- a/tests/errhangtest.lua +++ b/tests/errhangtest.lua | |||
@@ -42,19 +42,23 @@ if true then | |||
42 | print "OK" | 42 | print "OK" |
43 | end | 43 | end |
44 | 44 | ||
45 | -- send a table that contains a function | 45 | -- ================================================================================================= |
46 | -- send a table that contains a function, both as key and value | ||
47 | -- ================================================================================================= | ||
48 | |||
46 | if true then | 49 | if true then |
47 | print "\n#### send table with a function" | 50 | print "\n#### send table with a function" |
48 | local fun = function() print "function test ok" end | 51 | local fun = function() print "function test ok" return 42 end |
49 | local t_in = { [fun] = fun, fun = fun } | 52 | local t_in = { [fun] = fun, ["fun"] = fun } |
50 | print(pcall(linda.send, linda, 'test', t_in)) | 53 | print(pcall(linda.send, linda, 'test', t_in)) |
51 | local k,t_out = linda:receive('test') -- read the contents successfully sent | 54 | local k, t_out = linda:receive('test') -- read the contents successfully sent |
52 | t_out.fun() | 55 | -- t_out should contain two entries, just like t_in |
53 | -- t_out should contain a single entry, as [fun] = fun should have been discarded because functions are not acceptable keys | ||
54 | local count = 0 | 56 | local count = 0 |
55 | for k,v in pairs(t_out) do count = count + 1 end | 57 | for k,v in pairs(t_out) do count = count + 1 end |
56 | assert(count == 1) | 58 | assert(count == 2) |
57 | print "OK" | 59 | assert(t_out["fun"] == t_out[t_out.fun]) -- t_out[t_out.fun] should be identical to t_out["fun"] |
60 | assert(t_out["fun"] ~= fun) -- even if the function is not the original one but a copy | ||
61 | assert(t_out["fun"]() == t_out[t_out.fun]() and t_out["fun"]() == fun()) -- all functions should return the same value, since they are the same | ||
58 | end | 62 | end |
59 | 63 | ||
60 | -- send a string | 64 | -- send a string |