diff options
author | Matthew Wild <mwild1@gmail.com> | 2021-06-29 13:48:14 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2021-06-29 13:48:14 +0100 |
commit | 4e56658eb3564a41d1014e5ee89cd01c8004252e (patch) | |
tree | ca4eb45e809b1aeb0a1f646add1f2f1decc8a5d2 /spec | |
parent | 08253e26710469574bb994bfe7670a008d787ba5 (diff) | |
download | prosody-4e56658eb3564a41d1014e5ee89cd01c8004252e.tar.gz prosody-4e56658eb3564a41d1014e5ee89cd01c8004252e.zip |
util.dbuffer: Add read_until() method
Diffstat (limited to 'spec')
-rw-r--r-- | spec/util_dbuffer_spec.lua | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua index 2b1af835..aa31da55 100644 --- a/spec/util_dbuffer_spec.lua +++ b/spec/util_dbuffer_spec.lua @@ -36,6 +36,50 @@ describe("util.dbuffer", function () end); end); + describe(":read_until", function () + it("works", function () + local b = dbuffer.new(); + b:write("hello\n"); + b:write("world"); + b:write("\n"); + b:write("\n\n"); + b:write("stuff"); + b:write("more\nand more"); + + assert.equal(nil, b:read_until(".")); + assert.equal(nil, b:read_until("%")); + assert.equal("hello\n", b:read_until("\n")); + assert.equal("world\n", b:read_until("\n")); + assert.equal("\n", b:read_until("\n")); + assert.equal("\n", b:read_until("\n")); + assert.equal("stu", b:read(3)); + assert.equal("ffmore\n", b:read_until("\n")); + assert.equal(nil, b:read_until("\n")); + assert.equal("and more", b:read_chunk()); + end); + + it("works with multi-character sequences", function () + local b = dbuffer.new(); + b:write("hello\r\n"); + b:write("world"); + b:write("\r\n"); + b:write("\r\n\r\n"); + b:write("stuff"); + b:write("more\r\nand more"); + + assert.equal(nil, b:read_until(".")); + assert.equal(nil, b:read_until("%")); + assert.equal("hello\r\n", b:read_until("\r\n")); + assert.equal("world\r\n", b:read_until("\r\n")); + assert.equal("\r\n", b:read_until("\r\n")); + assert.equal("\r\n", b:read_until("\r\n")); + assert.equal("stu", b:read(3)); + assert.equal("ffmore\r\n", b:read_until("\r\n")); + assert.equal(nil, b:read_until("\r\n")); + assert.equal("and more", b:read_chunk()); + end); + end); + describe(":discard", function () local b = dbuffer.new(); it("works", function () |