aboutsummaryrefslogtreecommitdiff
path: root/testes/files.lua
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/files.lua
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/files.lua')
-rw-r--r--testes/files.lua30
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)
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