Software / code / prosody
Comparison
tests/test_utf8.lua @ 6594:fa6eb6fb4a80
tests: Add UTF-8 validity tests
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 23 Mar 2015 17:16:54 +0000 |
| child | 7515:9e48299799d8 |
comparison
equal
deleted
inserted
replaced
| 6593:828f9f3bdbcf | 6594:fa6eb6fb4a80 |
|---|---|
| 1 package.cpath = "../?.so" | |
| 2 package.path = "../?.lua"; | |
| 3 | |
| 4 function valid() | |
| 5 local encodings = require "util.encodings"; | |
| 6 local utf8 = assert(encodings.utf8, "no encodings.utf8 module"); | |
| 7 | |
| 8 for line in io.lines("utf8_sequences.txt") do | |
| 9 local data = line:match(":%s*([^#]+)"):gsub("%s+", ""):gsub("..", function (c) return string.char(tonumber(c, 16)); end) | |
| 10 local expect = line:match("(%S+):"); | |
| 11 if expect ~= "pass" and expect ~= "fail" then | |
| 12 error("unknown expectation: "..line:match("^[^:]+")); | |
| 13 end | |
| 14 local prefix, style = " ", valid_style; | |
| 15 local valid = utf8.valid(data); | |
| 16 assert_equal(valid, utf8.valid(data.." ")); | |
| 17 assert_equal(valid, expect == "pass", line); | |
| 18 end | |
| 19 end |