# HG changeset patch # User Matthew Wild # Date 1779716466 -3600 # Node ID 2bcabbeac9b074780527a4b49a8911cf90cd3111 # Parent 721823e085ecb7c8d8b477c48a9e408ff85f6ff6 util.ringbuffer: Fix incorrect returned position from :find() for #needle~=1 And add a test for :find() diff -r 721823e085ec -r 2bcabbeac9b0 spec/util_ringbuffer_spec.lua --- a/spec/util_ringbuffer_spec.lua Mon May 25 13:29:28 2026 +0100 +++ b/spec/util_ringbuffer_spec.lua Mon May 25 14:41:06 2026 +0100 @@ -35,6 +35,22 @@ end); end); + describe(":find", function () + local function test_find(b, str, expected) + if expected ~= nil then + assert.equal(expected, b:find(str)); + else + assert.is_nil(b:find(str)); + end + end + + it("works", function () + local b = rb.new(); + assert.truthy(b:write("hello world")); + test_find(b, "world", 7); + end); + end); + describe(":sub", function () -- Helper function to compare buffer:sub() with string:sub() local function test_sub(b, x, y) diff -r 721823e085ec -r 2bcabbeac9b0 util-src/ringbuffer.c --- a/util-src/ringbuffer.c Mon May 25 13:29:28 2026 +0100 +++ b/util-src/ringbuffer.c Mon May 25 14:41:06 2026 +0100 @@ -99,7 +99,7 @@ } if(m) { - return i + l; + return i + 1; } } }