aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_queue_spec.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-09-30 09:50:33 +0100
committerMatthew Wild <mwild1@gmail.com>2020-09-30 09:50:33 +0100
commitbf6c2db68257e8ac3a35e2c4e7c18b55313a5bf7 (patch)
tree3a37db7b805b1555d08cc61c7938cf512ff35ce0 /spec/util_queue_spec.lua
parent2940b9c66f4a053dbe2ca038468a3a8791beccd5 (diff)
parentbd3bd2179be360f86c7db3fcd400dbb168fa8be5 (diff)
downloadprosody-bf6c2db68257e8ac3a35e2c4e7c18b55313a5bf7.tar.gz
prosody-bf6c2db68257e8ac3a35e2c4e7c18b55313a5bf7.zip
Merge 0.11->trunk
Diffstat (limited to 'spec/util_queue_spec.lua')
-rw-r--r--spec/util_queue_spec.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/util_queue_spec.lua b/spec/util_queue_spec.lua
index 7cd3d695..d73f523d 100644
--- a/spec/util_queue_spec.lua
+++ b/spec/util_queue_spec.lua
@@ -100,4 +100,41 @@ describe("util.queue", function()
end);
end);
+ describe("consume()", function ()
+ it("should work", function ()
+ local q = queue.new(10);
+ for i = 1, 5 do
+ q:push(i);
+ end
+ local c = 0;
+ for i in q:consume() do
+ assert(i == c + 1);
+ assert(q:count() == (5-i));
+ c = i;
+ end
+ end);
+
+ it("should work even if items are pushed in the loop", function ()
+ local q = queue.new(10);
+ for i = 1, 5 do
+ q:push(i);
+ end
+ local c = 0;
+ for i in q:consume() do
+ assert(i == c + 1);
+ if c < 3 then
+ assert(q:count() == (5-i));
+ else
+ assert(q:count() == (6-i));
+ end
+
+ c = i;
+
+ if c == 3 then
+ q:push(6);
+ end
+ end
+ assert.equal(c, 6);
+ end);
+ end);
end);