1
0

Some utf8 tests and fixing minor library issues.

This commit is contained in:
Jon Michael Aanes 2017-07-31 16:29:56 +02:00
parent f332d6bf95
commit a0008a5c5c
4 changed files with 81 additions and 12 deletions

View File

@ -642,7 +642,7 @@ library_function {
func = math.exp,
name = 'math.exp',
para = 'x',
docs = 'Returns the value ex.'
docs = 'Returns the value e^x. (Euler\'s number raised to the power of x.)'
}
library_function {
@ -663,14 +663,14 @@ library_function {
func = math.frexp,
name = 'math.frexp',
para = 'x',
docs = 'Returns m and e such that x = m2e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero).'
docs = 'Returns m and e such that x = m*2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero).'
}
library_function {
func = math.ldexp,
name = 'math.ldexp',
para = 'm, e',
docs = 'Returns m2e (e should be an integer).'
docs = 'Returns m*2^e (e should be an integer).'
}
library_function {
@ -712,7 +712,7 @@ library_function {
func = math.pow,
name = 'math.pow',
para = 'x, y',
docs = 'Returns xy. (You can also use the expression x^y to compute this value.)'
docs = 'Returns x raised to the power of y. (You can also use the expression x^y to compute this value.)'
}
library_function {

View File

@ -208,6 +208,12 @@ format_test {
expect = '{ 1/2, 1/3, 1/4, 1/5 }',
}
format_test {
name = 'Format sequences and tables with common format',
input = { 0.01, 0.02, 0.03, 0.04 },
expect = '{ 0.01, 0.02, 0.03, 0.04 }',
}
--------------------------------------------------------------------------------
return SUITE

View File

@ -241,7 +241,11 @@ format_test {
expect = '\'abc\\255def\'',
}
-- TODO: Add more malformed unicode tests: https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
SUITE:addTest('UTF8 Resilience Test', function ()
for _, str in ipairs(EXAMPLES.STRING_UTF8) do
assert_equal(str, loadstring('return '..format(str))() )
end
end)
--------------------------------------------------------------------------------

View File

@ -41,13 +41,6 @@ SUITE:addTest('Dont allow bad types in options', function ()
assert(error_msg)
end)
--------------------------------------------------------------------------------
-- Survive not loading libs
-- TODO: Find a way to test this.
--------------------------------------------------------------------------------
-- Strange standard libs
@ -94,4 +87,70 @@ end)
--------------------------------------------------------------------------------
SUITE:addTest('Proper malformed utf8 escaping (through LÖVE)', function ()
-- This test asserts that malformed unicode strings are escaped. This is
-- done by checking whether LÖVE can draw the sequence of bytes, given by
-- `pretty`. LÖVE have roboust unicode checking, and will throw an error if
-- the characters is not escaped properly.
-- The input strings are gotten from TestSuite's example strings.
local pjk_path = '/tmp/test_pjk_'..os.time()
local conf = [[
function love.conf(t)
-- Graphics Settings
t.window.width = 1
t.window.height = 1
t.window.minwidth = 1
t.window.minheight = 1
-- Modules
t.modules.audio = false
t.modules.event = true
t.modules.graphics = true
t.modules.image = false
t.modules.joystick = false
t.modules.keyboard = false
t.modules.math = false
t.modules.mouse = false
t.modules.physics = false
t.modules.sound = false
t.modules.system = false
t.modules.timer = false
t.modules.touch = false
t.modules.video = false
t.modules.window = true
t.modules.thread = false
end]]
-- Create project, main.lua and conf.lua
os.execute('mkdir '..pjk_path)
local f = io.open(pjk_path..'/conf.lua', 'w')
f:write(conf)
f:close()
local f = io.open(pjk_path..'/main.lua', 'w')
f:write''
f:close()
for i, str in ipairs(EXAMPLES.STRING_UTF8) do
-- Create project and main.lua
local f = io.open(pjk_path..'/main.lua', 'w')
f:write('love.errhand = love.event.quit love.graphics.print('..pretty(str)..') love.event.quit(0)')
f:close()
-- Run project
local status_code = os.execute('love '..pjk_path)
if status_code ~= 0 then
local l = {}
for i = 1, #str do l[i] = tostring(str:byte(i)) end
error('Could not escape following string properly: '..str..'\n\tByte-sequence: \\'..table.concat(l, '\\'))
end
end
end)
--------------------------------------------------------------------------------
return SUITE