From 67cf276ba2e23710c9ab2abd7e2f7b377aab1070 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 29 Jun 2020 12:51:28 +0100 Subject: util.dbuffer: If no bytes parameter passed to read, return remainder of frontmost chunk --- spec/util_dbuffer_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec/util_dbuffer_spec.lua') diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua index 1a0c2992..c4fa22b2 100644 --- a/spec/util_dbuffer_spec.lua +++ b/spec/util_dbuffer_spec.lua @@ -21,6 +21,21 @@ describe("util.dbuffer", function () 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 () -- cgit v1.2.3