Software / code / prosody
Comparison
spec/util_ringbuffer_spec.lua @ 10949:8b5b35baf370
util.ringbuffer: Add test for :discard()
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 23 Jun 2020 16:50:26 +0100 |
| parent | 10901:5e33926f4b43 |
| child | 10953:c3b3ac63f4c3 |
comparison
equal
deleted
inserted
replaced
| 10948:bebb384090b0 | 10949:8b5b35baf370 |
|---|---|
| 22 local b = rb.new(); | 22 local b = rb.new(); |
| 23 it("works", function () | 23 it("works", function () |
| 24 assert.truthy(b:write("hi")); | 24 assert.truthy(b:write("hi")); |
| 25 end); | 25 end); |
| 26 end); | 26 end); |
| 27 | |
| 28 describe(":discard", function () | |
| 29 local b = rb.new(); | |
| 30 it("works", function () | |
| 31 assert.truthy(b:write("hello world")); | |
| 32 assert.truthy(b:discard(6)); | |
| 33 assert.equal(5, #b); | |
| 34 assert.equal("world", b:read(5)); | |
| 35 end); | |
| 36 end); | |
| 37 | |
| 27 describe(":sub", function () | 38 describe(":sub", function () |
| 28 -- Helper function to compare buffer:sub() with string:sub() | 39 -- Helper function to compare buffer:sub() with string:sub() |
| 29 local function test_sub(b, x, y) | 40 local function test_sub(b, x, y) |
| 30 local s = b:read(#b, true); | 41 local s = b:read(#b, true); |
| 31 local string_result, buffer_result = s:sub(x, y), b:sub(x, y); | 42 local string_result, buffer_result = s:sub(x, y), b:sub(x, y); |