2 local encodings
= require
"util.encodings";
3 local utf8
= assert(encodings
.utf8
, "no encodings.utf8 module");
5 describe("util.encodings", function ()
6 describe("#encode()", function()
7 it("should work", function ()
8 assert.is
.equal(encodings
.base64
.encode(""), "");
9 assert.is
.equal(encodings
.base64
.encode('coucou'), "Y291Y291");
10 assert.is
.equal(encodings
.base64
.encode("\0\0\0"), "AAAA");
11 assert.is
.equal(encodings
.base64
.encode("\255\255\255"), "////");
14 describe("#decode()", function()
15 it("should work", function ()
16 assert.is
.equal(encodings
.base64
.decode(""), "");
17 assert.is
.equal(encodings
.base64
.decode("="), "");
18 assert.is
.equal(encodings
.base64
.decode('Y291Y291'), "coucou");
19 assert.is
.equal(encodings
.base64
.decode("AAAA"), "\0\0\0");
20 assert.is
.equal(encodings
.base64
.decode("////"), "\255\255\255");
24 describe("util.encodings.utf8", function()
25 describe("#valid()", function()
26 it("should work", function()
28 for line
in io
.lines("spec/utf8_sequences.txt") do
29 local data
= line
:match(":%s*([^#]+)"):gsub("%s+", ""):gsub("..", function (c
) return string.char(tonumber(c
, 16)); end)
30 local expect
= line
:match("(%S+):");
32 assert(expect
== "pass" or expect
== "fail", "unknown expectation: "..line
:match("^[^:]+"));
34 local valid
= utf8
.valid(data
);
35 assert.is
.equal(valid
, utf8
.valid(data
.." "));
36 assert.is
.equal(valid
, expect
== "pass", line
);