# HG changeset patch # User Matthew Wild # Date 1505553368 -3600 # Node ID c803624cae3d3f7989ed5ecb9c8431a3076141d5 # Parent 20e3d5689cce062a7eb30dcdd2e75bd532f97e7f spec/util_queue: Add iterator and peek tests for 100% line coverage diff -r 20e3d5689cce -r c803624cae3d spec/util_queue_spec.lua --- a/spec/util_queue_spec.lua Sat Sep 16 10:13:39 2017 +0100 +++ b/spec/util_queue_spec.lua Sat Sep 16 10:16:08 2017 +0100 @@ -37,6 +37,11 @@ end assert.are.equal(q:count(), 0, "queue count incorrect"); + assert.are.equal(q:pop(), nil, "empty queue pops non-nil result"); + assert.are.equal(q:count(), 0, "popping empty queue affects count"); + + assert.are.equal(q:peek(), nil, "empty queue peeks non-nil result"); + assert.are.equal(q:count(), 0, "peeking empty queue affects count"); assert.is_true(q:push(1)); for i = 1, 1001 do @@ -68,6 +73,7 @@ assert.is_true(q:push(11)); assert.are.equal(q:count(), 10); assert.are.equal(q:pop(), 2); -- First item should have been purged + assert.are.equal(q:peek(), 3); for i = 12, 32 do assert.is_true(q:push(i)); @@ -77,6 +83,21 @@ assert.are.equal(q:pop(), 23); end + do + -- Test iterator + local q = queue.new(10, true); + + for i = 1, 10 do + q:push(i); + end + + local i = 0; + for item in q:items() do + i = i + 1; + assert.are.equal(item, i, "unexpected item returned by iterator") + end + end + end); end); end);