Diff

spec/util_encodings_spec.lua @ 8236:4878e4159e12

Port tests to the `busted` test runner
author Waqas Hussain <waqas20@gmail.com>
date Fri, 15 Sep 2017 17:07:57 -0400
child 8367:60eb22fd21b8
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spec/util_encodings_spec.lua	Fri Sep 15 17:07:57 2017 -0400
@@ -0,0 +1,22 @@
+
+local encodings = require "util.encodings";
+local utf8 = assert(encodings.utf8, "no encodings.utf8 module");
+
+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);