diff options
Diffstat (limited to 'testes/utf8.lua')
-rw-r--r-- | testes/utf8.lua | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/testes/utf8.lua b/testes/utf8.lua index 0704782c..028995a4 100644 --- a/testes/utf8.lua +++ b/testes/utf8.lua | |||
@@ -3,6 +3,8 @@ | |||
3 | 3 | ||
4 | -- UTF-8 file | 4 | -- UTF-8 file |
5 | 5 | ||
6 | global <const> * | ||
7 | |||
6 | print "testing UTF-8 library" | 8 | print "testing UTF-8 library" |
7 | 9 | ||
8 | local utf8 = require'utf8' | 10 | local utf8 = require'utf8' |
@@ -134,7 +136,7 @@ do | |||
134 | errorcodes("\xbfinvalid") | 136 | errorcodes("\xbfinvalid") |
135 | errorcodes("αλφ\xBFα") | 137 | errorcodes("αλφ\xBFα") |
136 | 138 | ||
137 | -- calling interation function with invalid arguments | 139 | -- calling iteration function with invalid arguments |
138 | local f = utf8.codes("") | 140 | local f = utf8.codes("") |
139 | assert(f("", 2) == nil) | 141 | assert(f("", 2) == nil) |
140 | assert(f("", -1) == nil) | 142 | assert(f("", -1) == nil) |
@@ -150,11 +152,20 @@ checkerror("position out of bounds", utf8.offset, "", 1, -1) | |||
150 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) | 152 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) |
151 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) | 153 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) |
152 | checkerror("continuation byte", utf8.offset, "\x80", 1) | 154 | checkerror("continuation byte", utf8.offset, "\x80", 1) |
155 | checkerror("continuation byte", utf8.offset, "\x9c", -1) | ||
153 | 156 | ||
154 | -- error in indices for len | 157 | -- error in indices for len |
155 | checkerror("out of bounds", utf8.len, "abc", 0, 2) | 158 | checkerror("out of bounds", utf8.len, "abc", 0, 2) |
156 | checkerror("out of bounds", utf8.len, "abc", 1, 4) | 159 | checkerror("out of bounds", utf8.len, "abc", 1, 4) |
157 | 160 | ||
161 | do -- missing continuation bytes | ||
162 | -- get what is available | ||
163 | local p, e = utf8.offset("\xE0", 1) | ||
164 | assert(p == 1 and e == 1) | ||
165 | local p, e = utf8.offset("\xE0\x9e", -1) | ||
166 | assert(p == 1 and e == 2) | ||
167 | end | ||
168 | |||
158 | 169 | ||
159 | local s = "hello World" | 170 | local s = "hello World" |
160 | local t = {string.byte(s, 1, -1)} | 171 | local t = {string.byte(s, 1, -1)} |