Diff

spec/util_dbuffer_spec.lua @ 11028:d7a403060946

util.dbuffer: Fix traceback when :collapse() is called on empty buffer
author Matthew Wild <mwild1@gmail.com>
date Thu, 20 Aug 2020 15:22:19 +0100
parent 10980:eaee72c7afbd
child 11044:7b720a815519
line wrap: on
line diff
--- 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);