Diff

spec/util_dbuffer_spec.lua @ 10980:eaee72c7afbd

util.dbuffer: If no bytes parameter passed to read, return remainder of frontmost chunk
author Matthew Wild <mwild1@gmail.com>
date Mon, 29 Jun 2020 12:51:28 +0100
parent 10977:29b9b679bdbc
child 11028:d7a403060946
line wrap: on
line diff
--- a/spec/util_dbuffer_spec.lua	Sun Jun 28 15:58:47 2020 +0200
+++ b/spec/util_dbuffer_spec.lua	Mon Jun 29 12:51:28 2020 +0100
@@ -21,6 +21,21 @@
 		end);
 	end);
 
+	describe(":read", function ()
+		it("supports optional bytes parameter", function ()
+			-- should return the frontmost chunk
+			local b = dbuffer.new();
+			assert.truthy(b:write("hello"));
+			assert.truthy(b:write(" "));
+			assert.truthy(b:write("world"));
+			assert.equal("h", b:read(1));
+
+			assert.equal("ello", b:read());
+			assert.equal(" ", b:read());
+			assert.equal("world", b:read());
+		end);
+	end);
+
 	describe(":discard", function ()
 		local b = dbuffer.new();
 		it("works", function ()