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/files.lua | |
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/files.lua')
-rw-r--r-- | testes/files.lua | 30 |
1 files changed, 15 insertions, 15 deletions
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 |