aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-16 14:58:02 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-16 14:58:02 -0300
commitb96b0b5abbf40cbdbed7952bf35a5a27ddf75928 (patch)
tree5d9d5463cb7d3424833abab20dd87bce1f4b240f /testes
parentca13be9af784b7288d3a07d9b5bccb329086e885 (diff)
downloadlua-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.lua2
-rw-r--r--testes/db.lua6
-rw-r--r--testes/errors.lua10
-rw-r--r--testes/files.lua30
-rw-r--r--testes/literals.lua2
-rw-r--r--testes/math.lua100
-rw-r--r--testes/pm.lua22
-rw-r--r--testes/strings.lua6
-rw-r--r--testes/utf8.lua4
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)
699end 699end
700 700
701assert(debug.getuservalue(4) == nil) 701assert(not debug.getuservalue(4))
702 702
703debug.setuservalue(b, function () return 10 end, 10) 703debug.setuservalue(b, function () return 10 end, 10)
704collectgarbage() -- function should not be collected 704collectgarbage() -- 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
353debug.sethook(nil); 353debug.sethook(nil);
354assert(debug.gethook() == nil) 354assert(not debug.gethook())
355 355
356 356
357-- minimal tests for setuservalue/getuservalue 357-- minimal tests for setuservalue/getuservalue
358do 358do
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)
362end 362end
@@ -414,7 +414,7 @@ end, "c")
414a:f(1,2,3,4,5) 414a:f(1,2,3,4,5)
415assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil) 415assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil)
416assert(XX == 12) 416assert(XX == 12)
417assert(debug.gethook() == nil) 417assert(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
19local function doit (s) 19local 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
24end 24end
@@ -312,8 +312,8 @@ end
312 312
313local function lineerror (s, l) 313local 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))
317end 317end
318 318
319lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2) 319lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2)
@@ -359,7 +359,7 @@ local p = [[
359g() 359g()
360]] 360]]
361X=3;lineerror((p), 3) 361X=3;lineerror((p), 3)
362X=0;lineerror((p), nil) 362X=0;lineerror((p), false)
363X=1;lineerror((p), 2) 363X=1;lineerror((p), 2)
364X=2;lineerror((p), 1) 364X=2;lineerror((p), 1)
365 365
@@ -510,7 +510,7 @@ checksyntax("a\1a = 1", "", "<\\1>", 1)
510checksyntax("\255a = 1", "", "<\\255>", 1) 510checksyntax("\255a = 1", "", "<\\255>", 1)
511 511
512doit('I = load("a=9+"); a=3') 512doit('I = load("a=9+"); a=3')
513assert(a==3 and I == nil) 513assert(a==3 and not I)
514print('+') 514print('+')
515 515
516lim = 1000 516lim = 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)
188end 188end
189assert(os.remove(file)) 189assert(os.remove(file))
190 190
@@ -228,7 +228,7 @@ assert(f:read("n") == 0Xdeadbeefdeadbeef); assert(f:read(2) == "x\n")
228assert(f:read("n") == 0x1.13aP3); assert(f:read(1) == "e") 228assert(f:read("n") == 0x1.13aP3); assert(f:read(1) == "e")
229 229
230do -- attempt to read too long number 230do -- 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
234end 234end
@@ -314,13 +314,13 @@ assert(io.read() == "fourth_line")
314assert(io.read() == "") -- empty line 314assert(io.read() == "") -- empty line
315assert(io.read('n') == 3450) 315assert(io.read('n') == 3450)
316assert(io.read(1) == '\n') 316assert(io.read(1) == '\n')
317assert(io.read(0) == nil) -- end of file 317assert(not io.read(0)) -- end of file
318assert(io.read(1) == nil) -- end of file 318assert(not io.read(1)) -- end of file
319assert(io.read(30000) == nil) -- end of file 319assert(not io.read(30000)) -- end of file
320assert(({io.read(1)})[2] == undef) 320assert(({io.read(1)})[2] == undef)
321assert(io.read() == nil) -- end of file 321assert(not io.read()) -- end of file
322assert(({io.read()})[2] == undef) 322assert(({io.read()})[2] == undef)
323assert(io.read('n') == nil) -- end of file 323assert(not io.read('n')) -- end of file
324assert(({io.read('n')})[2] == undef) 324assert(({io.read('n')})[2] == undef)
325assert(io.read('a') == '') -- end of file (OK for 'a') 325assert(io.read('a') == '') -- end of file (OK for 'a')
326assert(io.read('a') == '') -- end of file (OK for 'a') 326assert(io.read('a') == '') -- end of file (OK for 'a')
@@ -356,7 +356,7 @@ assert(io.read(string.len(t)) == t)
356assert(io.read(1) == ' ') 356assert(io.read(1) == ' ')
357assert(io.read(0)) 357assert(io.read(0))
358assert(io.read('a') == ';end of file\n') 358assert(io.read('a') == ';end of file\n')
359assert(io.read(0) == nil) 359assert(not io.read(0))
360assert(io.close(io.input())) 360assert(io.close(io.input()))
361 361
362 362
@@ -364,7 +364,7 @@ assert(io.close(io.input()))
364do 364do
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")
393assert(io.read"L" == "\n") 393assert(io.read"L" == "\n")
394assert(io.read"L" == "line\n") 394assert(io.read"L" == "line\n")
395assert(io.read"L" == "other") 395assert(io.read"L" == "other")
396assert(io.read"L" == nil) 396assert(not io.read"L")
397io.input():close() 397io.input():close()
398 398
399local f = assert(io.open(file)) 399local f = assert(io.open(file))
@@ -462,7 +462,7 @@ end
462-- test for multipe arguments in 'lines' 462-- test for multipe arguments in 'lines'
463io.output(file); io.write"0123456789\n":close() 463io.output(file); io.write"0123456789\n":close()
464for a,b in io.lines(file, 1, 1) do 464for 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
468end 468end
@@ -473,13 +473,13 @@ end
473 473
474for a,b,c in io.lines(file, "a", 0, 1) do 474for 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)
477end 477end
478collectgarbage() -- to close file in previous iteration 478collectgarbage() -- to close file in previous iteration
479 479
480io.output(file); io.write"00\n10\n20\n30\n40\n":close() 480io.output(file); io.write"00\n10\n20\n30\n40\n":close()
481for a, b in io.lines(file, "n", "n") do 481for 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
485end 485end
@@ -654,7 +654,7 @@ and the rest of the file
654io.input(file) 654io.input(file)
655local _,a,b,c,d,e,h,__ = io.read(1, 'n', 'n', 'l', 'l', 'l', 'a', 10) 655local _,a,b,c,d,e,h,__ = io.read(1, 'n', 'n', 'l', 'l', 'l', 'a', 10)
656assert(io.close(io.input())) 656assert(io.close(io.input()))
657assert(_ == ' ' and __ == nil) 657assert(_ == ' ' and not __)
658assert(type(a) == 'number' and a==123.4 and b==-56e-2) 658assert(type(a) == 'number' and a==123.4 and b==-56e-2)
659assert(d=='second line' and e=='third line') 659assert(d=='second line' and e=='third line')
660assert(h==[[ 660assert(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
39end 39end
40 40
41assert(math.type(0) == "integer" and math.type(0.0) == "float" 41assert(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
45local function checkerror (msg, f, ...) 45local function checkerror (msg, f, ...)
@@ -381,17 +381,17 @@ assert(tonumber(1/0) == 1/0)
381 381
382-- 'tonumber' with strings 382-- 'tonumber' with strings
383assert(tonumber("0") == 0) 383assert(tonumber("0") == 0)
384assert(tonumber("") == nil) 384assert(not tonumber(""))
385assert(tonumber(" ") == nil) 385assert(not tonumber(" "))
386assert(tonumber("-") == nil) 386assert(not tonumber("-"))
387assert(tonumber(" -0x ") == nil) 387assert(not tonumber(" -0x "))
388assert(tonumber{} == nil) 388assert(not tonumber{})
389assert(tonumber'+0.01' == 1/100 and tonumber'+.01' == 0.01 and 389assert(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)
392assert(tonumber'+ 0.01' == nil and tonumber'+.e1' == nil and 392assert(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'.')
395assert(tonumber('-012') == -010-2) 395assert(tonumber('-012') == -010-2)
396assert(tonumber('-1.2e2') == - - -120) 396assert(tonumber('-1.2e2') == - - -120)
397 397
@@ -445,45 +445,45 @@ local function f (...)
445 end 445 end
446end 446end
447 447
448assert(f(tonumber('fFfa', 15)) == nil) 448assert(not f(tonumber('fFfa', 15)))
449assert(f(tonumber('099', 8)) == nil) 449assert(not f(tonumber('099', 8)))
450assert(f(tonumber('1\0', 2)) == nil) 450assert(not f(tonumber('1\0', 2)))
451assert(f(tonumber('', 8)) == nil) 451assert(not f(tonumber('', 8)))
452assert(f(tonumber(' ', 9)) == nil) 452assert(not f(tonumber(' ', 9)))
453assert(f(tonumber(' ', 9)) == nil) 453assert(not f(tonumber(' ', 9)))
454assert(f(tonumber('0xf', 10)) == nil) 454assert(not f(tonumber('0xf', 10)))
455 455
456assert(f(tonumber('inf')) == nil) 456assert(not f(tonumber('inf')))
457assert(f(tonumber(' INF ')) == nil) 457assert(not f(tonumber(' INF ')))
458assert(f(tonumber('Nan')) == nil) 458assert(not f(tonumber('Nan')))
459assert(f(tonumber('nan')) == nil) 459assert(not f(tonumber('nan')))
460 460
461assert(f(tonumber(' ')) == nil) 461assert(not f(tonumber(' ')))
462assert(f(tonumber('')) == nil) 462assert(not f(tonumber('')))
463assert(f(tonumber('1 a')) == nil) 463assert(not f(tonumber('1 a')))
464assert(f(tonumber('1 a', 2)) == nil) 464assert(not f(tonumber('1 a', 2)))
465assert(f(tonumber('1\0')) == nil) 465assert(not f(tonumber('1\0')))
466assert(f(tonumber('1 \0')) == nil) 466assert(not f(tonumber('1 \0')))
467assert(f(tonumber('1\0 ')) == nil) 467assert(not f(tonumber('1\0 ')))
468assert(f(tonumber('e1')) == nil) 468assert(not f(tonumber('e1')))
469assert(f(tonumber('e 1')) == nil) 469assert(not f(tonumber('e 1')))
470assert(f(tonumber(' 3.4.5 ')) == nil) 470assert(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
475assert(tonumber('0x') == nil) 475assert(not tonumber('0x'))
476assert(tonumber('x') == nil) 476assert(not tonumber('x'))
477assert(tonumber('x3') == nil) 477assert(not tonumber('x3'))
478assert(tonumber('0x3.3.3') == nil) -- two decimal points 478assert(not tonumber('0x3.3.3')) -- two decimal points
479assert(tonumber('00x2') == nil) 479assert(not tonumber('00x2'))
480assert(tonumber('0x 2') == nil) 480assert(not tonumber('0x 2'))
481assert(tonumber('0 x2') == nil) 481assert(not tonumber('0 x2'))
482assert(tonumber('23x') == nil) 482assert(not tonumber('23x'))
483assert(tonumber('- 0xaa') == nil) 483assert(not tonumber('- 0xaa'))
484assert(tonumber('-0xaaP ') == nil) -- no exponent 484assert(not tonumber('-0xaaP ')) -- no exponent
485assert(tonumber('0x0.51p') == nil) 485assert(not tonumber('0x0.51p'))
486assert(tonumber('0x5p+-2') == nil) 486assert(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
721end 721end
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
28assert(a == 9 and b == 11); 28assert(a == 9 and b == 11);
29a,b = string.find('a\0a\0a\0a\0\0ab', 'b') -- last position 29a,b = string.find('a\0a\0a\0a\0\0ab', 'b') -- last position
30assert(a == 11 and b == 11) 30assert(a == 11 and b == 11)
31assert(string.find('a\0a\0a\0a\0\0ab', 'b\0') == nil) -- check ending 31assert(not string.find('a\0a\0a\0a\0\0ab', 'b\0')) -- check ending
32assert(string.find('', '\0') == nil) 32assert(not string.find('', '\0'))
33assert(string.find('alo123alo', '12') == 4) 33assert(string.find('alo123alo', '12') == 4)
34assert(string.find('alo123alo', '^12') == nil) 34assert(not string.find('alo123alo', '^12'))
35 35
36assert(string.match("aaab", ".*b") == "aaab") 36assert(string.match("aaab", ".*b") == "aaab")
37assert(string.match("aaa", ".*a") == "aaa") 37assert(string.match("aaa", ".*a") == "aaa")
@@ -57,17 +57,17 @@ assert(f('aaa', 'ab*a') == 'aa')
57assert(f('aba', 'ab*a') == 'aba') 57assert(f('aba', 'ab*a') == 'aba')
58assert(f('aaab', 'a+') == 'aaa') 58assert(f('aaab', 'a+') == 'aaa')
59assert(f('aaa', '^.+$') == 'aaa') 59assert(f('aaa', '^.+$') == 'aaa')
60assert(f('aaa', 'b+') == nil) 60assert(not f('aaa', 'b+'))
61assert(f('aaa', 'ab+a') == nil) 61assert(not f('aaa', 'ab+a'))
62assert(f('aba', 'ab+a') == 'aba') 62assert(f('aba', 'ab+a') == 'aba')
63assert(f('a$a', '.$') == 'a') 63assert(f('a$a', '.$') == 'a')
64assert(f('a$a', '.%$') == 'a$') 64assert(f('a$a', '.%$') == 'a$')
65assert(f('a$a', '.$.') == 'a$a') 65assert(f('a$a', '.$.') == 'a$a')
66assert(f('a$a', '$$') == nil) 66assert(not f('a$a', '$$'))
67assert(f('a$b', 'a$') == nil) 67assert(not f('a$b', 'a$'))
68assert(f('a$a', '$') == '') 68assert(f('a$a', '$') == '')
69assert(f('', 'b*') == '') 69assert(f('', 'b*') == '')
70assert(f('aaa', 'bb*') == nil) 70assert(not f('aaa', 'bb*'))
71assert(f('aaab', 'a-') == '') 71assert(f('aaab', 'a-') == '')
72assert(f('aaa', '^.-$') == 'aaa') 72assert(f('aaa', '^.-$') == 'aaa')
73assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab') 73assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab')
@@ -101,7 +101,7 @@ end
101assert(f1('alo alx 123 b\0o b\0o', '(..*) %1') == "b\0o b\0o") 101assert(f1('alo alx 123 b\0o b\0o', '(..*) %1') == "b\0o b\0o")
102assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3') 102assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3')
103assert(f1('=======', '^(=*)=%1$') == '=======') 103assert(f1('=======', '^(=*)=%1$') == '=======')
104assert(string.match('==========', '^([=]*)=%1$') == nil) 104assert(not string.match('==========', '^([=]*)=%1$'))
105 105
106local function range (i, j) 106local function range (i, j)
107 if i <= j then 107 if i <= j then
@@ -135,7 +135,7 @@ print('+');
135assert(string.match("alo xyzK", "(%w+)K") == "xyz") 135assert(string.match("alo xyzK", "(%w+)K") == "xyz")
136assert(string.match("254 K", "(%d*)K") == "") 136assert(string.match("254 K", "(%d*)K") == "")
137assert(string.match("alo ", "(%w*)$") == "") 137assert(string.match("alo ", "(%w*)$") == "")
138assert(string.match("alo ", "(%w+)$") == nil) 138assert(not string.match("alo ", "(%w+)$"))
139assert(string.find("(álo)", "%(á") == 1) 139assert(string.find("(álo)", "%(á") == 1)
140local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$") 140local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$")
141assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) 141assert(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
211function isbalanced (s) 211function isbalanced (s)
212 return string.find(string.gsub(s, "%b()", ""), "[()]") == nil 212 return not string.find(string.gsub(s, "%b()", ""), "[()]")
213end 213end
214 214
215assert(isbalanced("(9 ((8))(\0) 7) \0\0 a b ()(c)() a")) 215assert(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")
56assert(string.sub("123456789", a, b) == "345") 56assert(string.sub("123456789", a, b) == "345")
57assert(string.find("1234567890123456789", "345", 3) == 3) 57assert(string.find("1234567890123456789", "345", 3) == 3)
58assert(string.find("1234567890123456789", "345", 4) == 13) 58assert(string.find("1234567890123456789", "345", 4) == 13)
59assert(string.find("1234567890123456789", "346", 4) == nil) 59assert(not string.find("1234567890123456789", "346", 4))
60assert(string.find("1234567890123456789", ".45", -9) == 13) 60assert(string.find("1234567890123456789", ".45", -9) == 13)
61assert(string.find("abcdefg", "\0", 5, 1) == nil) 61assert(not string.find("abcdefg", "\0", 5, 1))
62assert(string.find("", "") == 1) 62assert(string.find("", "") == 1)
63assert(string.find("", "", 1) == 1) 63assert(string.find("", "", 1) == 1)
64assert(not string.find("", "", 2)) 64assert(not string.find("", "", 2))
65assert(string.find('', 'aaa', 1) == nil) 65assert(not string.find('', 'aaa', 1))
66assert(('alo(.)alo'):find('(.)', 1, 1) == 4) 66assert(('alo(.)alo'):find('(.)', 1, 1) == 4)
67 67
68assert(string.len("") == 0) 68assert(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)
31end 31end
32 32
33assert(utf8.offset("alo", 5) == nil) 33assert(not utf8.offset("alo", 5))
34assert(utf8.offset("alo", -4) == nil) 34assert(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'.