changeset 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 721823e085ec
children 67b68147ed1d
files spec/util_ringbuffer_spec.lua util-src/ringbuffer.c
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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;
 			}
 		}
 	}