Mercurial > prosody-hg
annotate tests/test_utf8.lua @ 8844:29c6d2681bad 0.9.14
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 25 May 2018 21:09:34 +0200 |
| parents | fa6eb6fb4a80 |
| children | 9e48299799d8 |
| rev | line source |
|---|---|
|
6594
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 package.cpath = "../?.so" |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 package.path = "../?.lua"; |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 function valid() |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local encodings = require "util.encodings"; |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local utf8 = assert(encodings.utf8, "no encodings.utf8 module"); |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 for line in io.lines("utf8_sequences.txt") do |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local data = line:match(":%s*([^#]+)"):gsub("%s+", ""):gsub("..", function (c) return string.char(tonumber(c, 16)); end) |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local expect = line:match("(%S+):"); |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 if expect ~= "pass" and expect ~= "fail" then |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 error("unknown expectation: "..line:match("^[^:]+")); |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local prefix, style = " ", valid_style; |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local valid = utf8.valid(data); |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 assert_equal(valid, utf8.valid(data.." ")); |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 assert_equal(valid, expect == "pass", line); |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end |
|
fa6eb6fb4a80
tests: Add UTF-8 validity tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 end |
