diff options
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/calls.lua | 2 | ||||
| -rw-r--r-- | testes/db.lua | 6 | ||||
| -rw-r--r-- | testes/errors.lua | 8 | ||||
| -rw-r--r-- | testes/files.lua | 8 | ||||
| -rw-r--r-- | testes/pm.lua | 56 | ||||
| -rw-r--r-- | testes/sort.lua | 2 | ||||
| -rw-r--r-- | testes/strings.lua | 3 | ||||
| -rw-r--r-- | testes/utf8.lua | 2 |
8 files changed, 54 insertions, 33 deletions
diff --git a/testes/calls.lua b/testes/calls.lua index 559ca935..7468d4ab 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
| @@ -342,7 +342,7 @@ do -- another bug (in 5.4.0) | |||
| 342 | end | 342 | end |
| 343 | 343 | ||
| 344 | 344 | ||
| 345 | do -- another bug (since 5.2) | 345 | if not _port then -- another bug (since 5.2) |
| 346 | -- corrupted binary dump: list of upvalue names is larger than number | 346 | -- corrupted binary dump: list of upvalue names is larger than number |
| 347 | -- of upvalues, overflowing the array of upvalues. | 347 | -- of upvalues, overflowing the array of upvalues. |
| 348 | local code = | 348 | local code = |
diff --git a/testes/db.lua b/testes/db.lua index 67b58934..d3758c41 100644 --- a/testes/db.lua +++ b/testes/db.lua | |||
| @@ -345,7 +345,7 @@ function f(a,b) | |||
| 345 | local _, y = debug.getlocal(1, 2) | 345 | local _, y = debug.getlocal(1, 2) |
| 346 | assert(x == a and y == b) | 346 | assert(x == a and y == b) |
| 347 | assert(debug.setlocal(2, 3, "pera") == "AA".."AA") | 347 | assert(debug.setlocal(2, 3, "pera") == "AA".."AA") |
| 348 | assert(debug.setlocal(2, 4, "maçã") == "B") | 348 | assert(debug.setlocal(2, 4, "manga") == "B") |
| 349 | x = debug.getinfo(2) | 349 | x = debug.getinfo(2) |
| 350 | assert(x.func == g and x.what == "Lua" and x.name == 'g' and | 350 | assert(x.func == g and x.what == "Lua" and x.name == 'g' and |
| 351 | x.nups == 2 and string.find(x.source, "^@.*db%.lua$")) | 351 | x.nups == 2 and string.find(x.source, "^@.*db%.lua$")) |
| @@ -373,9 +373,9 @@ function g (...) | |||
| 373 | local arg = {...} | 373 | local arg = {...} |
| 374 | do local a,b,c; a=math.sin(40); end | 374 | do local a,b,c; a=math.sin(40); end |
| 375 | local feijao | 375 | local feijao |
| 376 | local AAAA,B = "xuxu", "mamão" | 376 | local AAAA,B = "xuxu", "abacate" |
| 377 | f(AAAA,B) | 377 | f(AAAA,B) |
| 378 | assert(AAAA == "pera" and B == "maçã") | 378 | assert(AAAA == "pera" and B == "manga") |
| 379 | do | 379 | do |
| 380 | local B = 13 | 380 | local B = 13 |
| 381 | local x,y = debug.getlocal(1,5) | 381 | local x,y = debug.getlocal(1,5) |
diff --git a/testes/errors.lua b/testes/errors.lua index bf6f389d..b777a329 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
| @@ -392,19 +392,19 @@ lineerror("a\n=\n-\n\nprint\n;", 3) | |||
| 392 | 392 | ||
| 393 | lineerror([[ | 393 | lineerror([[ |
| 394 | a | 394 | a |
| 395 | ( | 395 | ( -- << |
| 396 | 23) | 396 | 23) |
| 397 | ]], 1) | 397 | ]], 2) |
| 398 | 398 | ||
| 399 | lineerror([[ | 399 | lineerror([[ |
| 400 | local a = {x = 13} | 400 | local a = {x = 13} |
| 401 | a | 401 | a |
| 402 | . | 402 | . |
| 403 | x | 403 | x |
| 404 | ( | 404 | ( -- << |
| 405 | 23 | 405 | 23 |
| 406 | ) | 406 | ) |
| 407 | ]], 2) | 407 | ]], 5) |
| 408 | 408 | ||
| 409 | lineerror([[ | 409 | lineerror([[ |
| 410 | local a = {x = 13} | 410 | local a = {x = 13} |
diff --git a/testes/files.lua b/testes/files.lua index 149e9c76..2582406f 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
| @@ -92,8 +92,8 @@ assert(io.output():seek("end") == string.len("alo joao")) | |||
| 92 | 92 | ||
| 93 | assert(io.output():seek("set") == 0) | 93 | assert(io.output():seek("set") == 0) |
| 94 | 94 | ||
| 95 | assert(io.write('"álo"', "{a}\n", "second line\n", "third line \n")) | 95 | assert(io.write('"alo"', "{a}\n", "second line\n", "third line \n")) |
| 96 | assert(io.write('çfourth_line')) | 96 | assert(io.write('Xfourth_line')) |
| 97 | io.output(io.stdout) | 97 | io.output(io.stdout) |
| 98 | collectgarbage() -- file should be closed by GC | 98 | collectgarbage() -- file should be closed by GC |
| 99 | assert(io.input() == io.stdin and rawequal(io.output(), io.stdout)) | 99 | assert(io.input() == io.stdin and rawequal(io.output(), io.stdout)) |
| @@ -300,14 +300,14 @@ do -- test error returns | |||
| 300 | end | 300 | end |
| 301 | checkerr("invalid format", io.read, "x") | 301 | checkerr("invalid format", io.read, "x") |
| 302 | assert(io.read(0) == "") -- not eof | 302 | assert(io.read(0) == "") -- not eof |
| 303 | assert(io.read(5, 'l') == '"álo"') | 303 | assert(io.read(5, 'l') == '"alo"') |
| 304 | assert(io.read(0) == "") | 304 | assert(io.read(0) == "") |
| 305 | assert(io.read() == "second line") | 305 | assert(io.read() == "second line") |
| 306 | local x = io.input():seek() | 306 | local x = io.input():seek() |
| 307 | assert(io.read() == "third line ") | 307 | assert(io.read() == "third line ") |
| 308 | assert(io.input():seek("set", x)) | 308 | assert(io.input():seek("set", x)) |
| 309 | assert(io.read('L') == "third line \n") | 309 | assert(io.read('L') == "third line \n") |
| 310 | assert(io.read(1) == "ç") | 310 | assert(io.read(1) == "X") |
| 311 | assert(io.read(string.len"fourth_line") == "fourth_line") | 311 | assert(io.read(string.len"fourth_line") == "fourth_line") |
| 312 | assert(io.input():seek("cur", -string.len"fourth_line")) | 312 | assert(io.input():seek("cur", -string.len"fourth_line")) |
| 313 | assert(io.read() == "fourth_line") | 313 | assert(io.read() == "fourth_line") |
diff --git a/testes/pm.lua b/testes/pm.lua index 795596d4..44454dff 100644 --- a/testes/pm.lua +++ b/testes/pm.lua | |||
| @@ -1,6 +1,9 @@ | |||
| 1 | -- $Id: testes/pm.lua $ | 1 | -- $Id: testes/pm.lua $ |
| 2 | -- See Copyright Notice in file all.lua | 2 | -- See Copyright Notice in file all.lua |
| 3 | 3 | ||
| 4 | -- UTF-8 file | ||
| 5 | |||
| 6 | |||
| 4 | print('testing pattern matching') | 7 | print('testing pattern matching') |
| 5 | 8 | ||
| 6 | local function checkerror (msg, f, ...) | 9 | local function checkerror (msg, f, ...) |
| @@ -50,6 +53,19 @@ assert(f('aLo_ALO', '%a*') == 'aLo') | |||
| 50 | 53 | ||
| 51 | assert(f(" \n\r*&\n\r xuxu \n\n", "%g%g%g+") == "xuxu") | 54 | assert(f(" \n\r*&\n\r xuxu \n\n", "%g%g%g+") == "xuxu") |
| 52 | 55 | ||
| 56 | |||
| 57 | -- Adapt a pattern to UTF-8 | ||
| 58 | local function PU (p) | ||
| 59 | -- break '?' into each individual byte of a character | ||
| 60 | p = string.gsub(p, "(" .. utf8.charpattern .. ")%?", function (c) | ||
| 61 | return string.gsub(c, ".", "%0?") | ||
| 62 | end) | ||
| 63 | -- change '.' to utf-8 character patterns | ||
| 64 | p = string.gsub(p, "%.", utf8.charpattern) | ||
| 65 | return p | ||
| 66 | end | ||
| 67 | |||
| 68 | |||
| 53 | assert(f('aaab', 'a*') == 'aaa'); | 69 | assert(f('aaab', 'a*') == 'aaa'); |
| 54 | assert(f('aaa', '^.*$') == 'aaa'); | 70 | assert(f('aaa', '^.*$') == 'aaa'); |
| 55 | assert(f('aaa', 'b*') == ''); | 71 | assert(f('aaa', 'b*') == ''); |
| @@ -73,16 +89,16 @@ assert(f('aaa', '^.-$') == 'aaa') | |||
| 73 | assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab') | 89 | assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab') |
| 74 | assert(f('aabaaabaaabaaaba', 'b.-b') == 'baaab') | 90 | assert(f('aabaaabaaabaaaba', 'b.-b') == 'baaab') |
| 75 | assert(f('alo xo', '.o$') == 'xo') | 91 | assert(f('alo xo', '.o$') == 'xo') |
| 76 | assert(f(' \n isto é assim', '%S%S*') == 'isto') | 92 | assert(f(' \n isto é assim', '%S%S*') == 'isto') |
| 77 | assert(f(' \n isto é assim', '%S*$') == 'assim') | 93 | assert(f(' \n isto é assim', '%S*$') == 'assim') |
| 78 | assert(f(' \n isto é assim', '[a-z]*$') == 'assim') | 94 | assert(f(' \n isto é assim', '[a-z]*$') == 'assim') |
| 79 | assert(f('um caracter ? extra', '[^%sa-z]') == '?') | 95 | assert(f('um caracter ? extra', '[^%sa-z]') == '?') |
| 80 | assert(f('', 'a?') == '') | 96 | assert(f('', 'a?') == '') |
| 81 | assert(f('á', 'á?') == 'á') | 97 | assert(f('á', PU'á?') == 'á') |
| 82 | assert(f('ábl', 'á?b?l?') == 'ábl') | 98 | assert(f('ábl', PU'á?b?l?') == 'ábl') |
| 83 | assert(f(' ábl', 'á?b?l?') == '') | 99 | assert(f(' ábl', PU'á?b?l?') == '') |
| 84 | assert(f('aa', '^aa?a?a') == 'aa') | 100 | assert(f('aa', '^aa?a?a') == 'aa') |
| 85 | assert(f(']]]áb', '[^]]') == 'á') | 101 | assert(f(']]]áb', '[^]]+') == 'áb') |
| 86 | assert(f("0alo alo", "%x*") == "0a") | 102 | assert(f("0alo alo", "%x*") == "0a") |
| 87 | assert(f("alo alo", "%C+") == "alo alo") | 103 | assert(f("alo alo", "%C+") == "alo alo") |
| 88 | print('+') | 104 | print('+') |
| @@ -136,28 +152,28 @@ assert(string.match("alo xyzK", "(%w+)K") == "xyz") | |||
| 136 | assert(string.match("254 K", "(%d*)K") == "") | 152 | assert(string.match("254 K", "(%d*)K") == "") |
| 137 | assert(string.match("alo ", "(%w*)$") == "") | 153 | assert(string.match("alo ", "(%w*)$") == "") |
| 138 | assert(not string.match("alo ", "(%w+)$")) | 154 | assert(not string.match("alo ", "(%w+)$")) |
| 139 | assert(string.find("(álo)", "%(á") == 1) | 155 | assert(string.find("(álo)", "%(á") == 1) |
| 140 | local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$") | 156 | local a, b, c, d, e = string.match("âlo alo", PU"^(((.).). (%w*))$") |
| 141 | assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) | 157 | assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) |
| 142 | a, b, c, d = string.match('0123456789', '(.+(.?)())') | 158 | a, b, c, d = string.match('0123456789', '(.+(.?)())') |
| 143 | assert(a == '0123456789' and b == '' and c == 11 and d == nil) | 159 | assert(a == '0123456789' and b == '' and c == 11 and d == nil) |
| 144 | print('+') | 160 | print('+') |
| 145 | 161 | ||
| 146 | assert(string.gsub('ülo ülo', 'ü', 'x') == 'xlo xlo') | 162 | assert(string.gsub('ülo ülo', 'ü', 'x') == 'xlo xlo') |
| 147 | assert(string.gsub('alo úlo ', ' +$', '') == 'alo úlo') -- trim | 163 | assert(string.gsub('alo úlo ', ' +$', '') == 'alo úlo') -- trim |
| 148 | assert(string.gsub(' alo alo ', '^%s*(.-)%s*$', '%1') == 'alo alo') -- double trim | 164 | assert(string.gsub(' alo alo ', '^%s*(.-)%s*$', '%1') == 'alo alo') -- double trim |
| 149 | assert(string.gsub('alo alo \n 123\n ', '%s+', ' ') == 'alo alo 123 ') | 165 | assert(string.gsub('alo alo \n 123\n ', '%s+', ' ') == 'alo alo 123 ') |
| 150 | local t = "abç d" | 166 | local t = "abç d" |
| 151 | a, b = string.gsub(t, '(.)', '%1@') | 167 | a, b = string.gsub(t, PU'(.)', '%1@') |
| 152 | assert('@'..a == string.gsub(t, '', '@') and b == 5) | 168 | assert(a == "a@b@ç@ @d@" and b == 5) |
| 153 | a, b = string.gsub('abçd', '(.)', '%0@', 2) | 169 | a, b = string.gsub('abçd', PU'(.)', '%0@', 2) |
| 154 | assert(a == 'a@b@çd' and b == 2) | 170 | assert(a == 'a@b@çd' and b == 2) |
| 155 | assert(string.gsub('alo alo', '()[al]', '%1') == '12o 56o') | 171 | assert(string.gsub('alo alo', '()[al]', '%1') == '12o 56o') |
| 156 | assert(string.gsub("abc=xyz", "(%w*)(%p)(%w+)", "%3%2%1-%0") == | 172 | assert(string.gsub("abc=xyz", "(%w*)(%p)(%w+)", "%3%2%1-%0") == |
| 157 | "xyz=abc-abc=xyz") | 173 | "xyz=abc-abc=xyz") |
| 158 | assert(string.gsub("abc", "%w", "%1%0") == "aabbcc") | 174 | assert(string.gsub("abc", "%w", "%1%0") == "aabbcc") |
| 159 | assert(string.gsub("abc", "%w+", "%0%1") == "abcabc") | 175 | assert(string.gsub("abc", "%w+", "%0%1") == "abcabc") |
| 160 | assert(string.gsub('áéí', '$', '\0óú') == 'áéí\0óú') | 176 | assert(string.gsub('áéÃ', '$', '\0óú') == 'áéÃ\0óú') |
| 161 | assert(string.gsub('', '^', 'r') == 'r') | 177 | assert(string.gsub('', '^', 'r') == 'r') |
| 162 | assert(string.gsub('', '$', 'r') == 'r') | 178 | assert(string.gsub('', '$', 'r') == 'r') |
| 163 | print('+') | 179 | print('+') |
| @@ -188,8 +204,8 @@ do | |||
| 188 | end | 204 | end |
| 189 | 205 | ||
| 190 | function f(a,b) return string.gsub(a,'.',b) end | 206 | function f(a,b) return string.gsub(a,'.',b) end |
| 191 | assert(string.gsub("trocar tudo em |teste|b| é |beleza|al|", "|([^|]*)|([^|]*)|", f) == | 207 | assert(string.gsub("trocar tudo em |teste|b| é |beleza|al|", "|([^|]*)|([^|]*)|", f) == |
| 192 | "trocar tudo em bbbbb é alalalalalal") | 208 | "trocar tudo em bbbbb é alalalalalal") |
| 193 | 209 | ||
| 194 | local function dostring (s) return load(s, "")() or "" end | 210 | local function dostring (s) return load(s, "")() or "" end |
| 195 | assert(string.gsub("alo $a='x'$ novamente $return a$", | 211 | assert(string.gsub("alo $a='x'$ novamente $return a$", |
diff --git a/testes/sort.lua b/testes/sort.lua index 52919b8c..40bb2d8a 100644 --- a/testes/sort.lua +++ b/testes/sort.lua | |||
| @@ -289,7 +289,7 @@ timesort(a, limit, function(x,y) return nil end, "equal") | |||
| 289 | 289 | ||
| 290 | for i,v in pairs(a) do assert(v == false) end | 290 | for i,v in pairs(a) do assert(v == false) end |
| 291 | 291 | ||
| 292 | AA = {"álo", "\0first :-)", "alo", "then this one", "45", "and a new"} | 292 | AA = {"\xE1lo", "\0first :-)", "alo", "then this one", "45", "and a new"} |
| 293 | table.sort(AA) | 293 | table.sort(AA) |
| 294 | check(AA) | 294 | check(AA) |
| 295 | 295 | ||
diff --git a/testes/strings.lua b/testes/strings.lua index b033c6ab..90983edd 100644 --- a/testes/strings.lua +++ b/testes/strings.lua | |||
| @@ -1,6 +1,9 @@ | |||
| 1 | -- $Id: testes/strings.lua $ | 1 | -- $Id: testes/strings.lua $ |
| 2 | -- See Copyright Notice in file all.lua | 2 | -- See Copyright Notice in file all.lua |
| 3 | 3 | ||
| 4 | -- ISO Latin encoding | ||
| 5 | |||
| 6 | |||
| 4 | print('testing strings and string library') | 7 | print('testing strings and string library') |
| 5 | 8 | ||
| 6 | local maxi <const> = math.maxinteger | 9 | local maxi <const> = math.maxinteger |
diff --git a/testes/utf8.lua b/testes/utf8.lua index c5a9dd3f..efadbd5c 100644 --- a/testes/utf8.lua +++ b/testes/utf8.lua | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | -- $Id: testes/utf8.lua $ | 1 | -- $Id: testes/utf8.lua $ |
| 2 | -- See Copyright Notice in file all.lua | 2 | -- See Copyright Notice in file all.lua |
| 3 | 3 | ||
| 4 | -- UTF-8 file | ||
| 5 | |||
| 4 | print "testing UTF-8 library" | 6 | print "testing UTF-8 library" |
| 5 | 7 | ||
| 6 | local utf8 = require'utf8' | 8 | local utf8 = require'utf8' |
