7 function assertEqual(what
, a
, b
)
12 print('Expected:', tostring(a
))
13 print(' Actual:', tostring(b
))
18 local scriptname
= (debug
.getinfo(1, 'S').source
or ''):gsub("^@.*[/\\]", "")
19 assertEqual('script name', 'script-Ф-€-中.lua', scriptname
)
22 local code
, err
= loadfile('load-Ф-€-中.lua')
23 assertEqual('loadfile', nil, err
)
24 assertEqual('loadfile contents', 'Contents of Ф-€-中', code
and code())
27 local ok
, result
= pcall(dofile, 'load-Ф-€-中.lua')
28 assertEqual('dofile pcall', true, ok
)
29 assertEqual('dofile contents', 'Contents of Ф-€-中', result
)
32 local fr
, err
= io
.open('load-Ф-€-中.lua')
33 assertEqual('io.open (read)', nil, err
)
34 assertEqual('io.read', 'return "Contents of Ф-€-中"\n', fr
and fr
:read('*a'))
35 if fr
then fr
:close() end
38 local fw
, err
= io
.open('written-by-lua-Ф-€-中.txt', 'w')
39 assertEqual('io.open (write)', nil, err
)
41 local _
, err
= fw
:write('Feedback from Lua: Ф-€-中\n')
42 assertEqual('io.write', nil, err
)
44 if fw
then fw
:close() end
46 -- Check for Unicode in personal plugins directory path.
47 local pdir_expected
= 'unicode-Ф-€-中-testcases'
48 local pdir
= Dir
.personal_plugins_path()
49 pdir
= pdir
:gsub('.*[/\\]unicode-.*-.*-testcases[/\\].*', pdir_expected
)
50 assertEqual('Unicode in Dir.personal_plugins_path', pdir_expected
, pdir
)
53 error('Failed tests: ' .. errors
)
55 print("All tests passed!")