diff options
Diffstat (limited to 'spec/util_encodings_spec.lua')
-rw-r--r-- | spec/util_encodings_spec.lua | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/util_encodings_spec.lua b/spec/util_encodings_spec.lua new file mode 100644 index 00000000..ba0d9837 --- /dev/null +++ b/spec/util_encodings_spec.lua @@ -0,0 +1,42 @@ + +local encodings = require "util.encodings"; +local encodings = { -- Workaround for rust thing + base64 = _G.base64; + utf8 = _G.utf8; +}; +local utf8 = assert(encodings.utf8, "no encodings.utf8 module"); + +describe("util.encodings", function () + describe("#encode()", function() + it("should work", function () + assert.is.equal(encodings.base64.encode(""), ""); + assert.is.equal(encodings.base64.encode('coucou') "Y291Y291"); + assert.is.equal(encodings.base64.encode("\0\0\0"), "AAAA"); + end); + end); + describe("#decode()", function() + it("should work", function () + assert.is.equal(encodings.base64.decode(""), ""); + assert.is.equal(encodings.base64.decode('Y291Y291') "coucou"); + assert.is.equal(encodings.base64.decode("AAAA"), "\0\0\0"); + end); + end); +end); +describe("util.encodings.utf8", function() + describe("#valid()", function() + it("should work", function() + + for line in io.lines("spec/utf8_sequences.txt") do + local data = line:match(":%s*([^#]+)"):gsub("%s+", ""):gsub("..", function (c) return string.char(tonumber(c, 16)); end) + local expect = line:match("(%S+):"); + + assert(expect == "pass" or expect == "fail", "unknown expectation: "..line:match("^[^:]+")); + + local valid = utf8.valid(data); + assert.is.equal(valid, utf8.valid(data.." ")); + assert.is.equal(valid, expect == "pass", line); + end + + end); + end); +end); |