diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-16 14:58:02 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-16 14:58:02 -0300 |
commit | b96b0b5abbf40cbdbed7952bf35a5a27ddf75928 (patch) | |
tree | 5d9d5463cb7d3424833abab20dd87bce1f4b240f /testes | |
parent | ca13be9af784b7288d3a07d9b5bccb329086e885 (diff) | |
download | lua-b96b0b5abbf40cbdbed7952bf35a5a27ddf75928.tar.gz lua-b96b0b5abbf40cbdbed7952bf35a5a27ddf75928.tar.bz2 lua-b96b0b5abbf40cbdbed7952bf35a5a27ddf75928.zip |
Added macro 'luaL_pushfail'
The macro 'luaL_pushfail' documents all places in the standard libraries
that return nil to signal some kind of failure. It is defined as
'lua_pushnil'. The manual also got a notation (@fail) to document those
returns. The tests were changed to be agnostic regarding whether 'fail'
is 'nil' or 'false'.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/api.lua | 2 | ||||
-rw-r--r-- | testes/db.lua | 6 | ||||
-rw-r--r-- | testes/errors.lua | 10 | ||||
-rw-r--r-- | testes/files.lua | 30 | ||||
-rw-r--r-- | testes/literals.lua | 2 | ||||
-rw-r--r-- | testes/math.lua | 100 | ||||
-rw-r--r-- | testes/pm.lua | 22 | ||||
-rw-r--r-- | testes/strings.lua | 6 | ||||
-rw-r--r-- | testes/utf8.lua | 4 |
9 files changed, 91 insertions, 91 deletions
diff --git a/testes/api.lua b/testes/api.lua index 4f9d6717..b2680633 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
@@ -698,7 +698,7 @@ for k, v in ipairs(t) do | |||
698 | assert(v1 == v and p) | 698 | assert(v1 == v and p) |
699 | end | 699 | end |
700 | 700 | ||
701 | assert(debug.getuservalue(4) == nil) | 701 | assert(not debug.getuservalue(4)) |
702 | 702 | ||
703 | debug.setuservalue(b, function () return 10 end, 10) | 703 | debug.setuservalue(b, function () return 10 end, 10) |
704 | collectgarbage() -- function should not be collected | 704 | collectgarbage() -- function should not be collected |
diff --git a/testes/db.lua b/testes/db.lua index a64a1130..c43243a6 100644 --- a/testes/db.lua +++ b/testes/db.lua | |||
@@ -351,12 +351,12 @@ assert(g(0,0) == 30) | |||
351 | 351 | ||
352 | 352 | ||
353 | debug.sethook(nil); | 353 | debug.sethook(nil); |
354 | assert(debug.gethook() == nil) | 354 | assert(not debug.gethook()) |
355 | 355 | ||
356 | 356 | ||
357 | -- minimal tests for setuservalue/getuservalue | 357 | -- minimal tests for setuservalue/getuservalue |
358 | do | 358 | do |
359 | assert(debug.setuservalue(io.stdin, 10) == nil) | 359 | assert(not debug.setuservalue(io.stdin, 10)) |
360 | local a, b = debug.getuservalue(io.stdin, 10) | 360 | local a, b = debug.getuservalue(io.stdin, 10) |
361 | assert(a == nil and not b) | 361 | assert(a == nil and not b) |
362 | end | 362 | end |
@@ -414,7 +414,7 @@ end, "c") | |||
414 | a:f(1,2,3,4,5) | 414 | a:f(1,2,3,4,5) |
415 | assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil) | 415 | assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil) |
416 | assert(XX == 12) | 416 | assert(XX == 12) |
417 | assert(debug.gethook() == nil) | 417 | assert(not debug.gethook()) |
418 | 418 | ||
419 | 419 | ||
420 | -- testing access to local variables in return hook (bug in 5.2) | 420 | -- testing access to local variables in return hook (bug in 5.2) |
diff --git a/testes/errors.lua b/testes/errors.lua index 6e7b8004..f9623b1d 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
@@ -18,7 +18,7 @@ end | |||
18 | 18 | ||
19 | local function doit (s) | 19 | local function doit (s) |
20 | local f, msg = load(s) | 20 | local f, msg = load(s) |
21 | if f == nil then return msg end | 21 | if not f then return msg end |
22 | local cond, msg = pcall(f) | 22 | local cond, msg = pcall(f) |
23 | return (not cond) and msg | 23 | return (not cond) and msg |
24 | end | 24 | end |
@@ -312,8 +312,8 @@ end | |||
312 | 312 | ||
313 | local function lineerror (s, l) | 313 | local function lineerror (s, l) |
314 | local err,msg = pcall(load(s)) | 314 | local err,msg = pcall(load(s)) |
315 | local line = string.match(msg, ":(%d+):") | 315 | local line = tonumber(string.match(msg, ":(%d+):")) |
316 | assert(tonumber(line) == l) | 316 | assert(line == l or (not line and not l)) |
317 | end | 317 | end |
318 | 318 | ||
319 | lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2) | 319 | lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2) |
@@ -359,7 +359,7 @@ local p = [[ | |||
359 | g() | 359 | g() |
360 | ]] | 360 | ]] |
361 | X=3;lineerror((p), 3) | 361 | X=3;lineerror((p), 3) |
362 | X=0;lineerror((p), nil) | 362 | X=0;lineerror((p), false) |
363 | X=1;lineerror((p), 2) | 363 | X=1;lineerror((p), 2) |
364 | X=2;lineerror((p), 1) | 364 | X=2;lineerror((p), 1) |
365 | 365 | ||
@@ -510,7 +510,7 @@ checksyntax("a\1a = 1", "", "<\\1>", 1) | |||
510 | checksyntax("\255a = 1", "", "<\\255>", 1) | 510 | checksyntax("\255a = 1", "", "<\\255>", 1) |
511 | 511 | ||
512 | doit('I = load("a=9+"); a=3') | 512 | doit('I = load("a=9+"); a=3') |
513 | assert(a==3 and I == nil) | 513 | assert(a==3 and not I) |
514 | print('+') | 514 | print('+') |
515 | 515 | ||
516 | lim = 1000 | 516 | lim = 1000 |
diff --git a/testes/files.lua b/testes/files.lua index 585e5948..677c0dc2 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
@@ -184,7 +184,7 @@ three | |||
184 | local f <close> = assert(io.open(file, "r")) | 184 | local f <close> = assert(io.open(file, "r")) |
185 | -- second item failing | 185 | -- second item failing |
186 | l1, n1, n2, dummy = f:read("l", "n", "n", "l") | 186 | l1, n1, n2, dummy = f:read("l", "n", "n", "l") |
187 | assert(l1 == "a line" and n1 == nil) | 187 | assert(l1 == "a line" and not n1) |
188 | end | 188 | end |
189 | assert(os.remove(file)) | 189 | assert(os.remove(file)) |
190 | 190 | ||
@@ -228,7 +228,7 @@ assert(f:read("n") == 0Xdeadbeefdeadbeef); assert(f:read(2) == "x\n") | |||
228 | assert(f:read("n") == 0x1.13aP3); assert(f:read(1) == "e") | 228 | assert(f:read("n") == 0x1.13aP3); assert(f:read(1) == "e") |
229 | 229 | ||
230 | do -- attempt to read too long number | 230 | do -- attempt to read too long number |
231 | assert(f:read("n") == nil) -- fails | 231 | assert(not f:read("n")) -- fails |
232 | local s = f:read("L") -- read rest of line | 232 | local s = f:read("L") -- read rest of line |
233 | assert(string.find(s, "^00*\n$")) -- lots of 0's left | 233 | assert(string.find(s, "^00*\n$")) -- lots of 0's left |
234 | end | 234 | end |
@@ -314,13 +314,13 @@ assert(io.read() == "fourth_line") | |||
314 | assert(io.read() == "") -- empty line | 314 | assert(io.read() == "") -- empty line |
315 | assert(io.read('n') == 3450) | 315 | assert(io.read('n') == 3450) |
316 | assert(io.read(1) == '\n') | 316 | assert(io.read(1) == '\n') |
317 | assert(io.read(0) == nil) -- end of file | 317 | assert(not io.read(0)) -- end of file |
318 | assert(io.read(1) == nil) -- end of file | 318 | assert(not io.read(1)) -- end of file |
319 | assert(io.read(30000) == nil) -- end of file | 319 | assert(not io.read(30000)) -- end of file |
320 | assert(({io.read(1)})[2] == undef) | 320 | assert(({io.read(1)})[2] == undef) |
321 | assert(io.read() == nil) -- end of file | 321 | assert(not io.read()) -- end of file |
322 | assert(({io.read()})[2] == undef) | 322 | assert(({io.read()})[2] == undef) |
323 | assert(io.read('n') == nil) -- end of file | 323 | assert(not io.read('n')) -- end of file |
324 | assert(({io.read('n')})[2] == undef) | 324 | assert(({io.read('n')})[2] == undef) |
325 | assert(io.read('a') == '') -- end of file (OK for 'a') | 325 | assert(io.read('a') == '') -- end of file (OK for 'a') |
326 | assert(io.read('a') == '') -- end of file (OK for 'a') | 326 | assert(io.read('a') == '') -- end of file (OK for 'a') |
@@ -356,7 +356,7 @@ assert(io.read(string.len(t)) == t) | |||
356 | assert(io.read(1) == ' ') | 356 | assert(io.read(1) == ' ') |
357 | assert(io.read(0)) | 357 | assert(io.read(0)) |
358 | assert(io.read('a') == ';end of file\n') | 358 | assert(io.read('a') == ';end of file\n') |
359 | assert(io.read(0) == nil) | 359 | assert(not io.read(0)) |
360 | assert(io.close(io.input())) | 360 | assert(io.close(io.input())) |
361 | 361 | ||
362 | 362 | ||
@@ -364,7 +364,7 @@ assert(io.close(io.input())) | |||
364 | do | 364 | do |
365 | local function ismsg (m) | 365 | local function ismsg (m) |
366 | -- error message is not a code number | 366 | -- error message is not a code number |
367 | return (type(m) == "string" and tonumber(m) == nil) | 367 | return (type(m) == "string" and not tonumber(m)) |
368 | end | 368 | end |
369 | 369 | ||
370 | -- read | 370 | -- read |
@@ -393,7 +393,7 @@ assert(io.read"L" == "\n") | |||
393 | assert(io.read"L" == "\n") | 393 | assert(io.read"L" == "\n") |
394 | assert(io.read"L" == "line\n") | 394 | assert(io.read"L" == "line\n") |
395 | assert(io.read"L" == "other") | 395 | assert(io.read"L" == "other") |
396 | assert(io.read"L" == nil) | 396 | assert(not io.read"L") |
397 | io.input():close() | 397 | io.input():close() |
398 | 398 | ||
399 | local f = assert(io.open(file)) | 399 | local f = assert(io.open(file)) |
@@ -462,7 +462,7 @@ end | |||
462 | -- test for multipe arguments in 'lines' | 462 | -- test for multipe arguments in 'lines' |
463 | io.output(file); io.write"0123456789\n":close() | 463 | io.output(file); io.write"0123456789\n":close() |
464 | for a,b in io.lines(file, 1, 1) do | 464 | for a,b in io.lines(file, 1, 1) do |
465 | if a == "\n" then assert(b == nil) | 465 | if a == "\n" then assert(not b) |
466 | else assert(tonumber(a) == tonumber(b) - 1) | 466 | else assert(tonumber(a) == tonumber(b) - 1) |
467 | end | 467 | end |
468 | end | 468 | end |
@@ -473,13 +473,13 @@ end | |||
473 | 473 | ||
474 | for a,b,c in io.lines(file, "a", 0, 1) do | 474 | for a,b,c in io.lines(file, "a", 0, 1) do |
475 | if a == "" then break end | 475 | if a == "" then break end |
476 | assert(a == "0123456789\n" and b == nil and c == nil) | 476 | assert(a == "0123456789\n" and not b and not c) |
477 | end | 477 | end |
478 | collectgarbage() -- to close file in previous iteration | 478 | collectgarbage() -- to close file in previous iteration |
479 | 479 | ||
480 | io.output(file); io.write"00\n10\n20\n30\n40\n":close() | 480 | io.output(file); io.write"00\n10\n20\n30\n40\n":close() |
481 | for a, b in io.lines(file, "n", "n") do | 481 | for a, b in io.lines(file, "n", "n") do |
482 | if a == 40 then assert(b == nil) | 482 | if a == 40 then assert(not b) |
483 | else assert(a == b - 10) | 483 | else assert(a == b - 10) |
484 | end | 484 | end |
485 | end | 485 | end |
@@ -654,7 +654,7 @@ and the rest of the file | |||
654 | io.input(file) | 654 | io.input(file) |
655 | local _,a,b,c,d,e,h,__ = io.read(1, 'n', 'n', 'l', 'l', 'l', 'a', 10) | 655 | local _,a,b,c,d,e,h,__ = io.read(1, 'n', 'n', 'l', 'l', 'l', 'a', 10) |
656 | assert(io.close(io.input())) | 656 | assert(io.close(io.input())) |
657 | assert(_ == ' ' and __ == nil) | 657 | assert(_ == ' ' and not __) |
658 | assert(type(a) == 'number' and a==123.4 and b==-56e-2) | 658 | assert(type(a) == 'number' and a==123.4 and b==-56e-2) |
659 | assert(d=='second line' and e=='third line') | 659 | assert(d=='second line' and e=='third line') |
660 | assert(h==[[ | 660 | assert(h==[[ |
@@ -706,7 +706,7 @@ if not _soft then | |||
706 | io.input():seek('set', 0) | 706 | io.input():seek('set', 0) |
707 | y = io.read() -- huge line | 707 | y = io.read() -- huge line |
708 | assert(x == y..'\n'..io.read()) | 708 | assert(x == y..'\n'..io.read()) |
709 | assert(io.read() == nil) | 709 | assert(not io.read()) |
710 | io.close(io.input()) | 710 | io.close(io.input()) |
711 | assert(os.remove(file)) | 711 | assert(os.remove(file)) |
712 | x = nil; y = nil | 712 | x = nil; y = nil |
diff --git a/testes/literals.lua b/testes/literals.lua index 27f9377d..e101eabf 100644 --- a/testes/literals.lua +++ b/testes/literals.lua | |||
@@ -281,7 +281,7 @@ if os.setlocale("pt_BR") or os.setlocale("ptb") then | |||
281 | 281 | ||
282 | assert(" 0x.1 " + " 0x,1" + "-0X.1\t" == 0x0.1) | 282 | assert(" 0x.1 " + " 0x,1" + "-0X.1\t" == 0x0.1) |
283 | 283 | ||
284 | assert(tonumber"inf" == nil and tonumber"NAN" == nil) | 284 | assert(not tonumber"inf" and not tonumber"NAN") |
285 | 285 | ||
286 | assert(assert(load(string.format("return %q", 4.51)))() == 4.51) | 286 | assert(assert(load(string.format("return %q", 4.51)))() == 4.51) |
287 | 287 | ||
diff --git a/testes/math.lua b/testes/math.lua index bad43901..c7dc8285 100644 --- a/testes/math.lua +++ b/testes/math.lua | |||
@@ -39,7 +39,7 @@ do | |||
39 | end | 39 | end |
40 | 40 | ||
41 | assert(math.type(0) == "integer" and math.type(0.0) == "float" | 41 | assert(math.type(0) == "integer" and math.type(0.0) == "float" |
42 | and math.type("10") == nil) | 42 | and not math.type("10")) |
43 | 43 | ||
44 | 44 | ||
45 | local function checkerror (msg, f, ...) | 45 | local function checkerror (msg, f, ...) |
@@ -381,17 +381,17 @@ assert(tonumber(1/0) == 1/0) | |||
381 | 381 | ||
382 | -- 'tonumber' with strings | 382 | -- 'tonumber' with strings |
383 | assert(tonumber("0") == 0) | 383 | assert(tonumber("0") == 0) |
384 | assert(tonumber("") == nil) | 384 | assert(not tonumber("")) |
385 | assert(tonumber(" ") == nil) | 385 | assert(not tonumber(" ")) |
386 | assert(tonumber("-") == nil) | 386 | assert(not tonumber("-")) |
387 | assert(tonumber(" -0x ") == nil) | 387 | assert(not tonumber(" -0x ")) |
388 | assert(tonumber{} == nil) | 388 | assert(not tonumber{}) |
389 | assert(tonumber'+0.01' == 1/100 and tonumber'+.01' == 0.01 and | 389 | assert(tonumber'+0.01' == 1/100 and tonumber'+.01' == 0.01 and |
390 | tonumber'.01' == 0.01 and tonumber'-1.' == -1 and | 390 | tonumber'.01' == 0.01 and tonumber'-1.' == -1 and |
391 | tonumber'+1.' == 1) | 391 | tonumber'+1.' == 1) |
392 | assert(tonumber'+ 0.01' == nil and tonumber'+.e1' == nil and | 392 | assert(not tonumber'+ 0.01' and not tonumber'+.e1' and |
393 | tonumber'1e' == nil and tonumber'1.0e+' == nil and | 393 | not tonumber'1e' and not tonumber'1.0e+' and |
394 | tonumber'.' == nil) | 394 | not tonumber'.') |
395 | assert(tonumber('-012') == -010-2) | 395 | assert(tonumber('-012') == -010-2) |
396 | assert(tonumber('-1.2e2') == - - -120) | 396 | assert(tonumber('-1.2e2') == - - -120) |
397 | 397 | ||
@@ -445,45 +445,45 @@ local function f (...) | |||
445 | end | 445 | end |
446 | end | 446 | end |
447 | 447 | ||
448 | assert(f(tonumber('fFfa', 15)) == nil) | 448 | assert(not f(tonumber('fFfa', 15))) |
449 | assert(f(tonumber('099', 8)) == nil) | 449 | assert(not f(tonumber('099', 8))) |
450 | assert(f(tonumber('1\0', 2)) == nil) | 450 | assert(not f(tonumber('1\0', 2))) |
451 | assert(f(tonumber('', 8)) == nil) | 451 | assert(not f(tonumber('', 8))) |
452 | assert(f(tonumber(' ', 9)) == nil) | 452 | assert(not f(tonumber(' ', 9))) |
453 | assert(f(tonumber(' ', 9)) == nil) | 453 | assert(not f(tonumber(' ', 9))) |
454 | assert(f(tonumber('0xf', 10)) == nil) | 454 | assert(not f(tonumber('0xf', 10))) |
455 | 455 | ||
456 | assert(f(tonumber('inf')) == nil) | 456 | assert(not f(tonumber('inf'))) |
457 | assert(f(tonumber(' INF ')) == nil) | 457 | assert(not f(tonumber(' INF '))) |
458 | assert(f(tonumber('Nan')) == nil) | 458 | assert(not f(tonumber('Nan'))) |
459 | assert(f(tonumber('nan')) == nil) | 459 | assert(not f(tonumber('nan'))) |
460 | 460 | ||
461 | assert(f(tonumber(' ')) == nil) | 461 | assert(not f(tonumber(' '))) |
462 | assert(f(tonumber('')) == nil) | 462 | assert(not f(tonumber(''))) |
463 | assert(f(tonumber('1 a')) == nil) | 463 | assert(not f(tonumber('1 a'))) |
464 | assert(f(tonumber('1 a', 2)) == nil) | 464 | assert(not f(tonumber('1 a', 2))) |
465 | assert(f(tonumber('1\0')) == nil) | 465 | assert(not f(tonumber('1\0'))) |
466 | assert(f(tonumber('1 \0')) == nil) | 466 | assert(not f(tonumber('1 \0'))) |
467 | assert(f(tonumber('1\0 ')) == nil) | 467 | assert(not f(tonumber('1\0 '))) |
468 | assert(f(tonumber('e1')) == nil) | 468 | assert(not f(tonumber('e1'))) |
469 | assert(f(tonumber('e 1')) == nil) | 469 | assert(not f(tonumber('e 1'))) |
470 | assert(f(tonumber(' 3.4.5 ')) == nil) | 470 | assert(not f(tonumber(' 3.4.5 '))) |
471 | 471 | ||
472 | 472 | ||
473 | -- testing 'tonumber' for invalid hexadecimal formats | 473 | -- testing 'tonumber' for invalid hexadecimal formats |
474 | 474 | ||
475 | assert(tonumber('0x') == nil) | 475 | assert(not tonumber('0x')) |
476 | assert(tonumber('x') == nil) | 476 | assert(not tonumber('x')) |
477 | assert(tonumber('x3') == nil) | 477 | assert(not tonumber('x3')) |
478 | assert(tonumber('0x3.3.3') == nil) -- two decimal points | 478 | assert(not tonumber('0x3.3.3')) -- two decimal points |
479 | assert(tonumber('00x2') == nil) | 479 | assert(not tonumber('00x2')) |
480 | assert(tonumber('0x 2') == nil) | 480 | assert(not tonumber('0x 2')) |
481 | assert(tonumber('0 x2') == nil) | 481 | assert(not tonumber('0 x2')) |
482 | assert(tonumber('23x') == nil) | 482 | assert(not tonumber('23x')) |
483 | assert(tonumber('- 0xaa') == nil) | 483 | assert(not tonumber('- 0xaa')) |
484 | assert(tonumber('-0xaaP ') == nil) -- no exponent | 484 | assert(not tonumber('-0xaaP ')) -- no exponent |
485 | assert(tonumber('0x0.51p') == nil) | 485 | assert(not tonumber('0x0.51p')) |
486 | assert(tonumber('0x5p+-2') == nil) | 486 | assert(not tonumber('0x5p+-2')) |
487 | 487 | ||
488 | 488 | ||
489 | -- testing hexadecimal numerals | 489 | -- testing hexadecimal numerals |
@@ -705,19 +705,19 @@ do -- testing floor & ceil | |||
705 | assert(eqT(math.tointeger(maxint), maxint)) | 705 | assert(eqT(math.tointeger(maxint), maxint)) |
706 | assert(eqT(math.tointeger(maxint .. ""), maxint)) | 706 | assert(eqT(math.tointeger(maxint .. ""), maxint)) |
707 | assert(eqT(math.tointeger(minint + 0.0), minint)) | 707 | assert(eqT(math.tointeger(minint + 0.0), minint)) |
708 | assert(math.tointeger(0.0 - minint) == nil) | 708 | assert(not math.tointeger(0.0 - minint)) |
709 | assert(math.tointeger(math.pi) == nil) | 709 | assert(not math.tointeger(math.pi)) |
710 | assert(math.tointeger(-math.pi) == nil) | 710 | assert(not math.tointeger(-math.pi)) |
711 | assert(math.floor(math.huge) == math.huge) | 711 | assert(math.floor(math.huge) == math.huge) |
712 | assert(math.ceil(math.huge) == math.huge) | 712 | assert(math.ceil(math.huge) == math.huge) |
713 | assert(math.tointeger(math.huge) == nil) | 713 | assert(not math.tointeger(math.huge)) |
714 | assert(math.floor(-math.huge) == -math.huge) | 714 | assert(math.floor(-math.huge) == -math.huge) |
715 | assert(math.ceil(-math.huge) == -math.huge) | 715 | assert(math.ceil(-math.huge) == -math.huge) |
716 | assert(math.tointeger(-math.huge) == nil) | 716 | assert(not math.tointeger(-math.huge)) |
717 | assert(math.tointeger("34.0") == 34) | 717 | assert(math.tointeger("34.0") == 34) |
718 | assert(math.tointeger("34.3") == nil) | 718 | assert(not math.tointeger("34.3")) |
719 | assert(math.tointeger({}) == nil) | 719 | assert(not math.tointeger({})) |
720 | assert(math.tointeger(0/0) == nil) -- NaN | 720 | assert(not math.tointeger(0/0)) -- NaN |
721 | end | 721 | end |
722 | 722 | ||
723 | 723 | ||
diff --git a/testes/pm.lua b/testes/pm.lua index 4d87fad2..94bb63ca 100644 --- a/testes/pm.lua +++ b/testes/pm.lua | |||
@@ -28,10 +28,10 @@ a,b = string.find('a\0a\0a\0a\0\0ab', '\0ab', 2); -- finds at the end | |||
28 | assert(a == 9 and b == 11); | 28 | assert(a == 9 and b == 11); |
29 | a,b = string.find('a\0a\0a\0a\0\0ab', 'b') -- last position | 29 | a,b = string.find('a\0a\0a\0a\0\0ab', 'b') -- last position |
30 | assert(a == 11 and b == 11) | 30 | assert(a == 11 and b == 11) |
31 | assert(string.find('a\0a\0a\0a\0\0ab', 'b\0') == nil) -- check ending | 31 | assert(not string.find('a\0a\0a\0a\0\0ab', 'b\0')) -- check ending |
32 | assert(string.find('', '\0') == nil) | 32 | assert(not string.find('', '\0')) |
33 | assert(string.find('alo123alo', '12') == 4) | 33 | assert(string.find('alo123alo', '12') == 4) |
34 | assert(string.find('alo123alo', '^12') == nil) | 34 | assert(not string.find('alo123alo', '^12')) |
35 | 35 | ||
36 | assert(string.match("aaab", ".*b") == "aaab") | 36 | assert(string.match("aaab", ".*b") == "aaab") |
37 | assert(string.match("aaa", ".*a") == "aaa") | 37 | assert(string.match("aaa", ".*a") == "aaa") |
@@ -57,17 +57,17 @@ assert(f('aaa', 'ab*a') == 'aa') | |||
57 | assert(f('aba', 'ab*a') == 'aba') | 57 | assert(f('aba', 'ab*a') == 'aba') |
58 | assert(f('aaab', 'a+') == 'aaa') | 58 | assert(f('aaab', 'a+') == 'aaa') |
59 | assert(f('aaa', '^.+$') == 'aaa') | 59 | assert(f('aaa', '^.+$') == 'aaa') |
60 | assert(f('aaa', 'b+') == nil) | 60 | assert(not f('aaa', 'b+')) |
61 | assert(f('aaa', 'ab+a') == nil) | 61 | assert(not f('aaa', 'ab+a')) |
62 | assert(f('aba', 'ab+a') == 'aba') | 62 | assert(f('aba', 'ab+a') == 'aba') |
63 | assert(f('a$a', '.$') == 'a') | 63 | assert(f('a$a', '.$') == 'a') |
64 | assert(f('a$a', '.%$') == 'a$') | 64 | assert(f('a$a', '.%$') == 'a$') |
65 | assert(f('a$a', '.$.') == 'a$a') | 65 | assert(f('a$a', '.$.') == 'a$a') |
66 | assert(f('a$a', '$$') == nil) | 66 | assert(not f('a$a', '$$')) |
67 | assert(f('a$b', 'a$') == nil) | 67 | assert(not f('a$b', 'a$')) |
68 | assert(f('a$a', '$') == '') | 68 | assert(f('a$a', '$') == '') |
69 | assert(f('', 'b*') == '') | 69 | assert(f('', 'b*') == '') |
70 | assert(f('aaa', 'bb*') == nil) | 70 | assert(not f('aaa', 'bb*')) |
71 | assert(f('aaab', 'a-') == '') | 71 | assert(f('aaab', 'a-') == '') |
72 | assert(f('aaa', '^.-$') == 'aaa') | 72 | assert(f('aaa', '^.-$') == 'aaa') |
73 | assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab') | 73 | assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab') |
@@ -101,7 +101,7 @@ end | |||
101 | assert(f1('alo alx 123 b\0o b\0o', '(..*) %1') == "b\0o b\0o") | 101 | assert(f1('alo alx 123 b\0o b\0o', '(..*) %1') == "b\0o b\0o") |
102 | assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3') | 102 | assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3') |
103 | assert(f1('=======', '^(=*)=%1$') == '=======') | 103 | assert(f1('=======', '^(=*)=%1$') == '=======') |
104 | assert(string.match('==========', '^([=]*)=%1$') == nil) | 104 | assert(not string.match('==========', '^([=]*)=%1$')) |
105 | 105 | ||
106 | local function range (i, j) | 106 | local function range (i, j) |
107 | if i <= j then | 107 | if i <= j then |
@@ -135,7 +135,7 @@ print('+'); | |||
135 | assert(string.match("alo xyzK", "(%w+)K") == "xyz") | 135 | assert(string.match("alo xyzK", "(%w+)K") == "xyz") |
136 | assert(string.match("254 K", "(%d*)K") == "") | 136 | assert(string.match("254 K", "(%d*)K") == "") |
137 | assert(string.match("alo ", "(%w*)$") == "") | 137 | assert(string.match("alo ", "(%w*)$") == "") |
138 | assert(string.match("alo ", "(%w+)$") == nil) | 138 | assert(not string.match("alo ", "(%w+)$")) |
139 | assert(string.find("(álo)", "%(á") == 1) | 139 | assert(string.find("(álo)", "%(á") == 1) |
140 | local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$") | 140 | local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$") |
141 | assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) | 141 | assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) |
@@ -209,7 +209,7 @@ assert(s == r and t[1] == 1 and t[3] == 3 and t[7] == 4 and t[13] == 4) | |||
209 | 209 | ||
210 | 210 | ||
211 | function isbalanced (s) | 211 | function isbalanced (s) |
212 | return string.find(string.gsub(s, "%b()", ""), "[()]") == nil | 212 | return not string.find(string.gsub(s, "%b()", ""), "[()]") |
213 | end | 213 | end |
214 | 214 | ||
215 | assert(isbalanced("(9 ((8))(\0) 7) \0\0 a b ()(c)() a")) | 215 | assert(isbalanced("(9 ((8))(\0) 7) \0\0 a b ()(c)() a")) |
diff --git a/testes/strings.lua b/testes/strings.lua index 2e0e160f..97875ec0 100644 --- a/testes/strings.lua +++ b/testes/strings.lua | |||
@@ -56,13 +56,13 @@ a,b = string.find("123456789", "345") | |||
56 | assert(string.sub("123456789", a, b) == "345") | 56 | assert(string.sub("123456789", a, b) == "345") |
57 | assert(string.find("1234567890123456789", "345", 3) == 3) | 57 | assert(string.find("1234567890123456789", "345", 3) == 3) |
58 | assert(string.find("1234567890123456789", "345", 4) == 13) | 58 | assert(string.find("1234567890123456789", "345", 4) == 13) |
59 | assert(string.find("1234567890123456789", "346", 4) == nil) | 59 | assert(not string.find("1234567890123456789", "346", 4)) |
60 | assert(string.find("1234567890123456789", ".45", -9) == 13) | 60 | assert(string.find("1234567890123456789", ".45", -9) == 13) |
61 | assert(string.find("abcdefg", "\0", 5, 1) == nil) | 61 | assert(not string.find("abcdefg", "\0", 5, 1)) |
62 | assert(string.find("", "") == 1) | 62 | assert(string.find("", "") == 1) |
63 | assert(string.find("", "", 1) == 1) | 63 | assert(string.find("", "", 1) == 1) |
64 | assert(not string.find("", "", 2)) | 64 | assert(not string.find("", "", 2)) |
65 | assert(string.find('', 'aaa', 1) == nil) | 65 | assert(not string.find('', 'aaa', 1)) |
66 | assert(('alo(.)alo'):find('(.)', 1, 1) == 4) | 66 | assert(('alo(.)alo'):find('(.)', 1, 1) == 4) |
67 | 67 | ||
68 | assert(string.len("") == 0) | 68 | assert(string.len("") == 0) |
diff --git a/testes/utf8.lua b/testes/utf8.lua index acbb181d..5954f6e8 100644 --- a/testes/utf8.lua +++ b/testes/utf8.lua | |||
@@ -30,8 +30,8 @@ local function checksyntax (s, t) | |||
30 | assert(assert(load(ts))() == s) | 30 | assert(assert(load(ts))() == s) |
31 | end | 31 | end |
32 | 32 | ||
33 | assert(utf8.offset("alo", 5) == nil) | 33 | assert(not utf8.offset("alo", 5)) |
34 | assert(utf8.offset("alo", -4) == nil) | 34 | assert(not utf8.offset("alo", -4)) |
35 | 35 | ||
36 | -- 'check' makes several tests over the validity of string 's'. | 36 | -- 'check' makes several tests over the validity of string 's'. |
37 | -- 't' is the list of codepoints of 's'. | 37 | -- 't' is the list of codepoints of 's'. |