Mercurial > prosody-hg
comparison spec/util_ringbuffer_spec.lua @ 14176:2bcabbeac9b0 13.0
util.ringbuffer: Fix incorrect returned position from :find() for #needle~=1
And add a test for :find()
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 25 May 2026 14:41:06 +0100 |
| parents | f84e0e2faae2 |
| children | 67b68147ed1d |
comparison
equal
deleted
inserted
replaced
| 14175:721823e085ec | 14176:2bcabbeac9b0 |
|---|---|
| 30 it("works", function () | 30 it("works", function () |
| 31 assert.truthy(b:write("hello world")); | 31 assert.truthy(b:write("hello world")); |
| 32 assert.truthy(b:discard(6)); | 32 assert.truthy(b:discard(6)); |
| 33 assert.equal(5, #b); | 33 assert.equal(5, #b); |
| 34 assert.equal("world", b:read(5)); | 34 assert.equal("world", b:read(5)); |
| 35 end); | |
| 36 end); | |
| 37 | |
| 38 describe(":find", function () | |
| 39 local function test_find(b, str, expected) | |
| 40 if expected ~= nil then | |
| 41 assert.equal(expected, b:find(str)); | |
| 42 else | |
| 43 assert.is_nil(b:find(str)); | |
| 44 end | |
| 45 end | |
| 46 | |
| 47 it("works", function () | |
| 48 local b = rb.new(); | |
| 49 assert.truthy(b:write("hello world")); | |
| 50 test_find(b, "world", 7); | |
| 35 end); | 51 end); |
| 36 end); | 52 end); |
| 37 | 53 |
| 38 describe(":sub", function () | 54 describe(":sub", function () |
| 39 -- Helper function to compare buffer:sub() with string:sub() | 55 -- Helper function to compare buffer:sub() with string:sub() |
