Skip to content

Commit

Permalink
Fix some test cases to pass on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Jul 21, 2020
1 parent 678a4d1 commit d680f02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion tests/io_test.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ do -- io.close for default output
assert(not ok and err == "cannot close standard file")
end

-- this test may fail on some machines with "Permission denied"
-- so we test at compile time with Lua first
## local f = io.tmpfile() if f then f:close()
do -- io.tmpfile
file = io.tmpfile()
assert(file:isopen())
assert(file:close())
assert(not file:isopen())
end
## end

do -- filestream:read, filestream:write and filestream:seek
file = io.open('test.tmp', 'w')
Expand Down Expand Up @@ -162,7 +166,8 @@ end

do -- tostring
file = io.open('LICENSE', 'r')
assert(tostring(file):sub(1,8) == 'file (0x')
assert(file:isopen())
assert(tostring(file):sub(1,6) == 'file (')
local file2 = file
file:close()
assert(not file2:isopen())
Expand Down
3 changes: 2 additions & 1 deletion tests/os_test.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ assert(os.remove('my_invalid_file') == false)
assert(os.setlocale('C') == 'C')
assert(os.setlocale('C','all') == 'C')
assert(os.time() >= 0)
assert(os.time(os_time_desc{year=2020,month=7,day=18,hour=12}) == #[os.time{year=2020,month=7,day=18,hour=12}]#)
assert(os.time(os_time_desc{year=2020,month=7,day=18,hour=12,isdst=false}) ==
#[os.time{year=2020,month=7,day=18,hour=12,isdst=false}]#)
os.exit(0)
os.exit(true)
os.exit()
Expand Down
12 changes: 6 additions & 6 deletions tests/string_test.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ do -- find
local b, e
b, e = s:find('h', 1, true) assert(b == 1 and e == 1)
b, e = s:find('he', 1, true) assert(b == 1 and e == 2)
b, e = s:find('ld', 1, true) print(b,e) assert(b == 10 and e == 11)
b, e = s:find('ld', 1, true) assert(b == 10 and e == 11)
b, e = s:find('heo', 1, true) assert(b == 0 and e == 0)
b, e = s:find('hel', 1, true) assert(b == 1 and e == 3)
b, e = s:find('d', 1, true) assert(b == 11 and e == 11)
Expand Down Expand Up @@ -265,8 +265,8 @@ do -- tostring
assert(type(tostring(nil)) == 'string')
assert(type(tostring(12)) == 'string')
local function f() end
assert(tostring(f):sub(1,12) == 'function: 0x')
assert(tostring(string.lower):sub(1,12) == 'function: 0x')
assert(tostring(f):sub(1,10) == 'function: ')
assert(tostring(string.lower):sub(1,10) == 'function: ')
assert(tostring(tostring) == 'lazyfunction')
end

Expand Down Expand Up @@ -341,15 +341,15 @@ do -- string format
assert(string.format('%X', 0xC001) == 'C001')
assert(string.format('%d', #[math.maxinteger]#) == '9223372036854775807')
assert(string.format('%i', #[math.mininteger]#) == '-9223372036854775808')
assert(string.format('%a', 2) == '0x1p+1')
assert(string.format('%A', 0.1) == '0X1.999999999999AP-4')
assert(string.format('%a', 1):find('p', 1, true))
assert(string.format('%A', 1):find('P', 1, true))
assert(string.format('%f', 0.1) == '0.100000')
assert(string.format('%e', 0.1) == '1.000000e-01')
assert(string.format('%E', 300) == '3.000000E+02')
assert(string.format('%g', 0.123) == '0.123')
assert(string.format('%G', 0.123e-20) == '1.23E-21')
assert(string.format('%p', nilptr) == '(null)')
assert(string.format('%p', (@pointer)(0xffffffff_u)) == '0xffffffff')
assert(string.format('%p', (@pointer)(0xffffffff_u)):find('ffffffff', 1, true))
assert(string.format('%s', 'asd') == 'asd')
assert(string.format('%s', string.rep('xuxu', 500)) == string.rep('xuxu', 500))
assert(string.format('a number here: %d !', 1337) == 'a number here: 1337 !')
Expand Down

0 comments on commit d680f02

Please sign in to comment.