Comparison

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
comparison
equal deleted inserted replaced
11027:8ed6c5bdbb21 11028:d7a403060946
41 it("works", function () 41 it("works", function ()
42 assert.truthy(b:write("hello world")); 42 assert.truthy(b:write("hello world"));
43 assert.truthy(b:discard(6)); 43 assert.truthy(b:discard(6));
44 assert.equal(5, b:length()); 44 assert.equal(5, b:length());
45 assert.equal("world", b:read(5)); 45 assert.equal("world", b:read(5));
46 end);
47 end);
48
49 describe(":collapse()", function ()
50 it("works on an empty buffer", function ()
51 local b = dbuffer.new();
52 b:collapse();
46 end); 53 end);
47 end); 54 end);
48 55
49 describe(":sub", function () 56 describe(":sub", function ()
50 -- Helper function to compare buffer:sub() with string:sub() 57 -- Helper function to compare buffer:sub() with string:sub()
104 local b = dbuffer.new(); 111 local b = dbuffer.new();
105 b:write(string.char(0, 140)); 112 b:write(string.char(0, 140));
106 local r = { b:byte(1, 2) }; 113 local r = { b:byte(1, 2) };
107 assert.same({ 0, 140 }, r); 114 assert.same({ 0, 140 }, r);
108 end); 115 end);
116
117 it("works on an empty buffer", function ()
118 local b = dbuffer.new();
119 assert.equal("", b:sub(1,1));
120 end);
109 end); 121 end);
110 end); 122 end);