diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic.lua | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/tests/basic.lua b/tests/basic.lua index d65728e..5a905e7 100644 --- a/tests/basic.lua +++ b/tests/basic.lua | |||
@@ -214,26 +214,27 @@ local chunk= function(linda) | |||
214 | local function receive() return linda:receive("->") end | 214 | local function receive() return linda:receive("->") end |
215 | local function send(...) linda:send("<-", ...) end | 215 | local function send(...) linda:send("<-", ...) end |
216 | 216 | ||
217 | WR("Lane starts!\n") | 217 | WR("chunk ", "Lane starts!\n") |
218 | 218 | ||
219 | local k,v | 219 | local k,v |
220 | k,v=receive(); WR(v.." received\n"); assert(v==1) | 220 | k,v=receive(); WR("chunk ", v.." received (expecting 1)\n"); assert(v==1) |
221 | k,v=receive(); WR(v.." received\n"); assert(v==2) | 221 | k,v=receive(); WR("chunk ", v.." received (expecting 2)\n"); assert(v==2) |
222 | k,v=receive(); WR(v.." received\n"); assert(v==3) | 222 | k,v=receive(); WR("chunk ", v.." received (expecting 3)\n"); assert(v==3) |
223 | k,v=receive(); WR(tostring(v).." received\n"); assert(v==nil) | 223 | k,v=receive(); WR("chunk ", tostring(v).." received (expecting nil from __lanesignore)\n"); assert(v==nil) -- a table with __lanesignore was sent |
224 | k,v=receive(); WR("chunk ", tostring(v).." received (expecting nil)\n"); assert(v==nil) | ||
224 | 225 | ||
225 | send(1,2,3); WR("1,2,3 sent\n") | 226 | send(4,5,6); WR("chunk ", "4,5,6 sent\n") |
226 | send 'a'; WR("'a' sent\n") | 227 | send 'aaa'; WR("chunk ", "'aaa' sent\n") |
227 | send(nil); WR("nil sent\n") | 228 | send(nil); WR("chunk ", "nil sent\n") |
228 | send { 'a', 'b', 'c', d=10 }; WR("{'a','b','c',d=10} sent\n") | 229 | send { 'a', 'b', 'c', d=10 }; WR("chunk ","{'a','b','c',d=10} sent\n") |
229 | 230 | ||
230 | k,v=receive(); WR(v.." received\n"); assert(v==4) | 231 | k,v=receive(); WR("chunk ", v.." received\n"); assert(v==4) |
231 | 232 | ||
232 | local subT1 = { "subT1"} | 233 | local subT1 = { "subT1"} |
233 | local subT2 = { "subT2"} | 234 | local subT2 = { "subT2"} |
234 | send { subT1, subT2, subT1, subT2}; WR("{ subT1, subT2, subT1, subT2} sent\n") | 235 | send { subT1, subT2, subT1, subT2}; WR("chunk ", "{ subT1, subT2, subT1, subT2} sent\n") |
235 | 236 | ||
236 | WR("Lane ends!\n") | 237 | WR("chunk ", "Lane ends!\n") |
237 | end | 238 | end |
238 | 239 | ||
239 | local linda = lanes_linda("communications") | 240 | local linda = lanes_linda("communications") |
@@ -248,15 +249,16 @@ local function RECEIVE() local k,v = linda:receive(1, "<-") return v end | |||
248 | 249 | ||
249 | local comms_lane = lanes_gen("io", {gc_cb = gc_cb, name = "auto"}, chunk)(linda) -- prepare & launch | 250 | local comms_lane = lanes_gen("io", {gc_cb = gc_cb, name = "auto"}, chunk)(linda) -- prepare & launch |
250 | 251 | ||
251 | SEND(1); WR("1 sent\n") | 252 | SEND(1); WR("main ", "1 sent\n") |
252 | SEND(2); WR("2 sent\n") | 253 | SEND(2); WR("main ", "2 sent\n") |
253 | SEND(3); WR("3 sent\n") | 254 | SEND(3); WR("main ", "3 sent\n") |
255 | SEND(setmetatable({"should be ignored"},{__lanesignore=true})); WR("main ", "__lanesignore table sent\n") | ||
254 | for i=1,100 do | 256 | for i=1,100 do |
255 | WR "." | 257 | WR "." |
256 | lanes.sleep(0.0001) | 258 | lanes.sleep(0.0001) |
257 | assert(PEEK() == nil) -- nothing coming in, yet | 259 | assert(PEEK() == nil) -- nothing coming in, yet |
258 | end | 260 | end |
259 | SEND(nil); WR("\nnil sent\n") | 261 | SEND(nil); WR("\nmain ", "nil sent\n") |
260 | 262 | ||
261 | local a,b,c = RECEIVE(), RECEIVE(), RECEIVE() | 263 | local a,b,c = RECEIVE(), RECEIVE(), RECEIVE() |
262 | 264 | ||
@@ -264,13 +266,13 @@ print("lane status: " .. comms_lane.status) | |||
264 | if comms_lane.status == "error" then | 266 | if comms_lane.status == "error" then |
265 | print(comms_lane:join()) | 267 | print(comms_lane:join()) |
266 | else | 268 | else |
267 | WR(a..", "..b..", "..c.." received\n") | 269 | WR("main ", tostring(a)..", "..tostring(b)..", "..tostring(c).." received\n") |
268 | end | 270 | end |
269 | 271 | ||
270 | assert(a==1 and b==2 and c==3) | 272 | assert(a==4 and b==5 and c==6) |
271 | 273 | ||
272 | local a = RECEIVE(); WR(a.." received\n") | 274 | local aaa = RECEIVE(); WR("main ", aaa.." received\n") |
273 | assert(a=='a') | 275 | assert(aaa=='aaa') |
274 | 276 | ||
275 | local null = RECEIVE(); WR(tostring(null).." received\n") | 277 | local null = RECEIVE(); WR(tostring(null).." received\n") |
276 | assert(null==nil) | 278 | assert(null==nil) |