aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_queue_spec.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2017-09-16 10:16:08 +0100
committerMatthew Wild <mwild1@gmail.com>2017-09-16 10:16:08 +0100
commit1a74016edf9c9f97b2b5a95cd5529b287ed83eb4 (patch)
tree29eea92f3b090413589f861b32485aad194522dc /spec/util_queue_spec.lua
parent44e570d5fe149991f5da715462d8d7d1aaf07b89 (diff)
downloadprosody-1a74016edf9c9f97b2b5a95cd5529b287ed83eb4.tar.gz
prosody-1a74016edf9c9f97b2b5a95cd5529b287ed83eb4.zip
spec/util_queue: Add iterator and peek tests for 100% line coverage
Diffstat (limited to 'spec/util_queue_spec.lua')
-rw-r--r--spec/util_queue_spec.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/util_queue_spec.lua b/spec/util_queue_spec.lua
index fc1278d4..7cd3d695 100644
--- a/spec/util_queue_spec.lua
+++ b/spec/util_queue_spec.lua
@@ -37,6 +37,11 @@ describe("util.queue", function()
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 @@ describe("util.queue", function()
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 @@ describe("util.queue", function()
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);