comparison spec/util_ringbuffer_spec.lua @ 14186:d975d280baec

Merge 13.0->trunk
author Matthew Wild <mwild1@gmail.com>
date Mon, 25 May 2026 19:01:23 +0100
parents 67b68147ed1d
children
comparison
equal deleted inserted replaced
14168:4f4c346e4f39 14186:d975d280baec
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);
51 end);
52
53 it("works across wraps", function ()
54 local b = rb.new(5);
55 assert.truthy(b:write("12345"));
56 assert.equal("123", b:read(3));
57 assert.truthy(b:write("678"));
58 test_find(b, "45678", 1);
59 test_find(b, "567", 2);
60 test_find(b, "56", 2);
61 test_find(b, "5", 2);
62 test_find(b, "6", 3);
63 test_find(b, "7", 4);
64 test_find(b, "8", 5);
65 test_find(b, "9", nil);
66 end);
67
68 it("no match when the needle is larger than the buffer", function ()
69 for i = 5, 11 do
70 local b = rb.new(i);
71 assert.truthy(b:write("hello"));
72 test_find(b, "hello world", nil);
73 end
74 end);
75
76 it("no match when the needle is an empty string", function ()
77 local b = rb.new(5);
78 assert.truthy(b:write("hello"));
79 test_find(b, "", nil);
35 end); 80 end);
36 end); 81 end);
37 82
38 describe(":sub", function () 83 describe(":sub", function ()
39 -- Helper function to compare buffer:sub() with string:sub() 84 -- Helper function to compare buffer:sub() with string:sub()