diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2016-01-24 18:54:14 +0100 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2016-01-24 18:54:14 +0100 |
| commit | af8c4896960770c0268ac3281d0622a0c0694dc5 (patch) | |
| tree | cc84353e67ef11fd2ae0d83a5467b3ee5e9a8604 /tests/test.lua | |
| parent | ca85188590e677edcc9290d29e69a3692187c826 (diff) | |
| download | lua-compat-5.3-af8c4896960770c0268ac3281d0622a0c0694dc5.tar.gz lua-compat-5.3-af8c4896960770c0268ac3281d0622a0c0694dc5.tar.bz2 lua-compat-5.3-af8c4896960770c0268ac3281d0622a0c0694dc5.zip | |
Add tests for utf8 backport.
Diffstat (limited to 'tests/test.lua')
| -rwxr-xr-x | tests/test.lua | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua index 0c77240..f2094b9 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
| @@ -248,6 +248,48 @@ print("math.ult", pcall(math.ult, 1, 2.1)) | |||
| 248 | ___'' | 248 | ___'' |
| 249 | 249 | ||
| 250 | 250 | ||
| 251 | if utf8.len then | ||
| 252 | local unpack = table.unpack or unpack | ||
| 253 | local function utf8rt(s) | ||
| 254 | local t = { utf8.codepoint(s, 1, #s) } | ||
| 255 | local ps, cs = {}, {} | ||
| 256 | for p,c in utf8.codes(s) do | ||
| 257 | ps[#ps+1], cs[#cs+1] = p, c | ||
| 258 | end | ||
| 259 | print("utf8.codes", unpack(ps)) | ||
| 260 | print("utf8.codes", unpack(cs)) | ||
| 261 | print("utf8.codepoint", unpack(t)) | ||
| 262 | print("utf8.len", utf8.len(s), #t, #s) | ||
| 263 | print("utf8.char", utf8.char(unpack(t))) | ||
| 264 | end | ||
| 265 | utf8rt("äöüßÄÖÜ") | ||
| 266 | utf8rt("abcdefg") | ||
| 267 | ___'' | ||
| 268 | local s = "äöüßÄÖÜ" | ||
| 269 | print("utf8.offset", utf8.offset(s, 1, 1)) | ||
| 270 | print("utf8.offset", utf8.offset(s, 2, 1)) | ||
| 271 | print("utf8.offset", utf8.offset(s, 3, 1)) | ||
| 272 | print("utf8.offset", pcall(utf8.offset, s, 3, 2)) | ||
| 273 | print("utf8.offset", utf8.offset(s, 3, 3)) | ||
| 274 | print("utf8.offset", utf8.offset(s, -1, 7)) | ||
| 275 | print("utf8.offset", utf8.offset(s, -2, 7)) | ||
| 276 | print("utf8.offset", utf8.offset(s, -3, 7)) | ||
| 277 | print("utf8.offset", utf8.offset(s, -1)) | ||
| 278 | ___'' | ||
| 279 | else | ||
| 280 | print("XXX: utf8 module not available") | ||
| 281 | end | ||
| 282 | |||
| 283 | |||
| 284 | if string.pack then | ||
| 285 | -- TODO | ||
| 286 | print("TODO: test string packing/unpacking") | ||
| 287 | ___'' | ||
| 288 | else | ||
| 289 | print("XXX: string packing not available") | ||
| 290 | end | ||
| 291 | |||
| 292 | |||
| 251 | print("testing Lua API for Lua 5.1 ...") | 293 | print("testing Lua API for Lua 5.1 ...") |
| 252 | 294 | ||
| 253 | ___'' | 295 | ___'' |
