Comparison

spec/util_queue_spec.lua @ 11120:b2331f3dfeea

Merge 0.11->trunk
author Matthew Wild <mwild1@gmail.com>
date Wed, 30 Sep 2020 09:50:33 +0100
parent 9901:c8b75239846c
comparison
equal deleted inserted replaced
11119:68df52bf08d5 11120:b2331f3dfeea
98 end 98 end
99 end 99 end
100 100
101 end); 101 end);
102 end); 102 end);
103 describe("consume()", function ()
104 it("should work", function ()
105 local q = queue.new(10);
106 for i = 1, 5 do
107 q:push(i);
108 end
109 local c = 0;
110 for i in q:consume() do
111 assert(i == c + 1);
112 assert(q:count() == (5-i));
113 c = i;
114 end
115 end);
116
117 it("should work even if items are pushed in the loop", function ()
118 local q = queue.new(10);
119 for i = 1, 5 do
120 q:push(i);
121 end
122 local c = 0;
123 for i in q:consume() do
124 assert(i == c + 1);
125 if c < 3 then
126 assert(q:count() == (5-i));
127 else
128 assert(q:count() == (6-i));
129 end
130
131 c = i;
132
133 if c == 3 then
134 q:push(6);
135 end
136 end
137 assert.equal(c, 6);
138 end);
139 end);
103 end); 140 end);