spec/util_ringbuffer_spec.lua
author Kim Alvefur <zash@zash.se>
Thu, 04 Jun 2020 16:11:08 +0200
changeset 10903 8048255ae61e
parent 10902 c6465fb3c839
child 10905 5e33926f4b43
permissions -rw-r--r--
util.ringbuffer: Prevent creation of buffer with negative size Previously this would have been (unsigned)-1 which is a large positive integer.

local rb = require "util.ringbuffer";
describe("util.ringbuffer", function ()
	describe("#new", function ()
		it("has a constructor", function ()
			assert.Function(rb.new);
		end);
		it("can be created", function ()
			assert.truthy(rb.new());
		end);
		it("won't create an empty buffer", function ()
			assert.has_error(function ()
				rb.new(0);
			end);
		end);
		it("won't create a negatively sized buffer", function ()
			assert.has_error(function ()
				rb.new(-1);
			end);
		end);
	end);
	describe(":write", function ()
		local b = rb.new();
		it("works", function ()
			assert.truthy(b:write("hi"));
		end);
	end);
end);