--- a/spec/util_dbuffer_spec.lua Sun Aug 16 20:30:02 2020 +0200
+++ b/spec/util_dbuffer_spec.lua Thu Aug 20 15:22:19 2020 +0100
@@ -46,6 +46,13 @@
end);
end);
+ describe(":collapse()", function ()
+ it("works on an empty buffer", function ()
+ local b = dbuffer.new();
+ b:collapse();
+ end);
+ end);
+
describe(":sub", function ()
-- Helper function to compare buffer:sub() with string:sub()
local s = "hello world";
@@ -106,5 +113,10 @@
local r = { b:byte(1, 2) };
assert.same({ 0, 140 }, r);
end);
+
+ it("works on an empty buffer", function ()
+ local b = dbuffer.new();
+ assert.equal("", b:sub(1,1));
+ end);
end);
end);
--- a/util/dbuffer.lua Sun Aug 16 20:30:02 2020 +0200
+++ b/util/dbuffer.lua Thu Aug 20 15:22:19 2020 +0100
@@ -142,7 +142,7 @@
local front_chunk = self.items:peek();
- if #front_chunk - self.front_consumed >= bytes then
+ if not front_chunk or #front_chunk - self.front_consumed >= bytes then
return;
end