Mercurial > prosody-hg
comparison spec/util_dbuffer_spec.lua @ 11637:19cddf92fcc2
util.dbuffer: Fix bugs, remove multi-char support (more complex than first thought)
Character sequences could be split across chunk boundaries. Would require a bunch
of code to make that work reliably.
Only apply front_consumed on first chunk, and adjust buffer_pos accordingly.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 29 Jun 2021 14:25:57 +0100 |
| parents | 11e0a0a08da3 |
| children | bf6d2f9fad4d |
comparison
equal
deleted
inserted
replaced
| 11636:11e0a0a08da3 | 11637:19cddf92fcc2 |
|---|---|
| 53 assert.equal("\n", b:read_until("\n")); | 53 assert.equal("\n", b:read_until("\n")); |
| 54 assert.equal("\n", b:read_until("\n")); | 54 assert.equal("\n", b:read_until("\n")); |
| 55 assert.equal("stu", b:read(3)); | 55 assert.equal("stu", b:read(3)); |
| 56 assert.equal("ffmore\n", b:read_until("\n")); | 56 assert.equal("ffmore\n", b:read_until("\n")); |
| 57 assert.equal(nil, b:read_until("\n")); | 57 assert.equal(nil, b:read_until("\n")); |
| 58 assert.equal("and more", b:read_chunk()); | |
| 59 end); | |
| 60 | |
| 61 it("works with multi-character sequences", function () | |
| 62 local b = dbuffer.new(); | |
| 63 b:write("hello\r\n"); | |
| 64 b:write("world"); | |
| 65 b:write("\r\n"); | |
| 66 b:write("\r\n\r\n"); | |
| 67 b:write("stuff"); | |
| 68 b:write("more\r\nand more"); | |
| 69 | |
| 70 assert.equal(nil, b:read_until(".")); | |
| 71 assert.equal(nil, b:read_until("%")); | |
| 72 assert.equal("hello\r\n", b:read_until("\r\n")); | |
| 73 assert.equal("world\r\n", b:read_until("\r\n")); | |
| 74 assert.equal("\r\n", b:read_until("\r\n")); | |
| 75 assert.equal("\r\n", b:read_until("\r\n")); | |
| 76 assert.equal("stu", b:read(3)); | |
| 77 assert.equal("ffmore\r\n", b:read_until("\r\n")); | |
| 78 assert.equal(nil, b:read_until("\r\n")); | |
| 79 assert.equal("and more", b:read_chunk()); | 58 assert.equal("and more", b:read_chunk()); |
| 80 end); | 59 end); |
| 81 end); | 60 end); |
| 82 | 61 |
| 83 describe(":discard", function () | 62 describe(":discard", function () |
