Software / code / prosody
Comparison
spec/util_queue_spec.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parent | 9901:c8b75239846c |
| child | 13558:56e112b890ea |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 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); |