Comparison

spec/util_ringbuffer_spec.lua @ 10954:fc310727adfb

util.ringbuffer: Add some additional asserts to tests
author Matthew Wild <mwild1@gmail.com>
date Wed, 24 Jun 2020 13:00:11 +0100
parent 10953:c3b3ac63f4c3
child 10960:f84e0e2faae2
comparison
equal deleted inserted replaced
10953:c3b3ac63f4c3 10954:fc310727adfb
43 assert.equals(string_result, buffer_result, ("buffer:sub(%d, %s) does not match string:sub()"):format(x, y and ("%d"):format(y) or "nil")); 43 assert.equals(string_result, buffer_result, ("buffer:sub(%d, %s) does not match string:sub()"):format(x, y and ("%d"):format(y) or "nil"));
44 end 44 end
45 45
46 it("works", function () 46 it("works", function ()
47 local b = rb.new(); 47 local b = rb.new();
48 b:write("hello world"); 48 assert.truthy(b:write("hello world"));
49 assert.equals("hello", b:sub(1, 5)); 49 assert.equals("hello", b:sub(1, 5));
50 end); 50 end);
51 51
52 it("supports optional end parameter", function () 52 it("supports optional end parameter", function ()
53 local b = rb.new(); 53 local b = rb.new();
54 b:write("hello world"); 54 assert.truthy(b:write("hello world"));
55 assert.equals("hello world", b:sub(1)); 55 assert.equals("hello world", b:sub(1));
56 assert.equals("world", b:sub(-5)); 56 assert.equals("world", b:sub(-5));
57 end); 57 end);
58 58
59 it("is equivalent to string:sub", function () 59 it("is equivalent to string:sub", function ()
60 local b = rb.new(6); 60 local b = rb.new(6);
61 b:write("foobar"); 61 assert.truthy(b:write("foobar"));
62 b:read(3); 62 b:read(3);
63 b:write("foo"); 63 b:write("foo");
64 for i = -13, 13 do 64 for i = -13, 13 do
65 for j = -13, 13 do 65 for j = -13, 13 do
66 test_sub(b, i, j); 66 test_sub(b, i, j);
77 assert.same(string_result, buffer_result, ("buffer:byte(%d, %s) does not match string:byte()"):format(x, y and ("%d"):format(y) or "nil")); 77 assert.same(string_result, buffer_result, ("buffer:byte(%d, %s) does not match string:byte()"):format(x, y and ("%d"):format(y) or "nil"));
78 end 78 end
79 79
80 it("is equivalent to string:byte", function () 80 it("is equivalent to string:byte", function ()
81 local b = rb.new(6); 81 local b = rb.new(6);
82 b:write("foobar"); 82 assert.truthy(b:write("foo"..string.char(0, 140).."obar"));
83 b:read(3); 83 b:read(3);
84 b:write("foo"); 84 b:write("foo");
85 test_byte(b, 1); 85 test_byte(b, 1);
86 test_byte(b, 3); 86 test_byte(b, 3);
87 test_byte(b, -1); 87 test_byte(b, -1);