2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2017-07-03 16:22:26 -07:00
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-01-12 04:28:20 -07:00
|
|
|
local NIL = vim.NIL
|
2024-04-20 08:44:13 -07:00
|
|
|
local eval = n.eval
|
|
|
|
local clear = n.clear
|
|
|
|
local api = n.api
|
|
|
|
local fn = n.fn
|
|
|
|
local source = n.source
|
2024-04-08 02:03:20 -07:00
|
|
|
local dedent = t.dedent
|
2024-04-20 08:44:13 -07:00
|
|
|
local command = n.command
|
|
|
|
local exc_exec = n.exc_exec
|
|
|
|
local exec_capture = n.exec_capture
|
2024-04-08 02:03:20 -07:00
|
|
|
local matches = t.matches
|
2020-02-02 13:55:15 -07:00
|
|
|
|
|
|
|
describe(':echo :echon :echomsg :echoerr', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
local fn_tbl = { 'String', 'StringN', 'StringMsg', 'StringErr' }
|
2020-02-02 13:55:15 -07:00
|
|
|
local function assert_same_echo_dump(expected, input, use_eval)
|
2024-01-02 18:09:18 -07:00
|
|
|
for _, v in pairs(fn_tbl) do
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(expected, use_eval and eval(v .. '(' .. input .. ')') or fn[v](input))
|
2020-02-02 13:55:15 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
local function assert_matches_echo_dump(expected, input, use_eval)
|
2024-01-02 18:09:18 -07:00
|
|
|
for _, v in pairs(fn_tbl) do
|
2024-01-12 10:59:57 -07:00
|
|
|
matches(expected, use_eval and eval(v .. '(' .. input .. ')') or fn[v](input))
|
2020-02-02 13:55:15 -07:00
|
|
|
end
|
|
|
|
end
|
2017-07-03 16:06:04 -07:00
|
|
|
|
2017-07-03 16:22:26 -07:00
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
source([[
|
|
|
|
function String(s)
|
|
|
|
return execute('echo a:s')[1:]
|
|
|
|
endfunction
|
2020-02-02 13:55:15 -07:00
|
|
|
function StringMsg(s)
|
|
|
|
return execute('echomsg a:s')[1:]
|
|
|
|
endfunction
|
|
|
|
function StringN(s)
|
|
|
|
return execute('echon a:s')
|
|
|
|
endfunction
|
|
|
|
function StringErr(s)
|
|
|
|
try
|
|
|
|
execute 'echoerr a:s'
|
|
|
|
catch
|
|
|
|
return substitute(v:exception, '^Vim(echoerr):', '', '')
|
|
|
|
endtry
|
|
|
|
endfunction
|
2017-07-03 16:22:26 -07:00
|
|
|
]])
|
|
|
|
end)
|
2017-07-03 16:06:04 -07:00
|
|
|
|
|
|
|
describe('used to represent floating-point values', function()
|
|
|
|
it('dumps NaN values', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump("str2float('nan')", "str2float('nan')", true)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps infinite values', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump("str2float('inf')", "str2float('inf')", true)
|
|
|
|
assert_same_echo_dump("-str2float('inf')", "str2float('-inf')", true)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps regular values', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('1.5', 1.5)
|
|
|
|
assert_same_echo_dump('1.56e-20', 1.56000e-020)
|
|
|
|
assert_same_echo_dump('0.0', '0.0', true)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps special v: values', function()
|
2017-07-03 16:22:26 -07:00
|
|
|
eq('v:true', eval('String(v:true)'))
|
|
|
|
eq('v:false', eval('String(v:false)'))
|
|
|
|
eq('v:null', eval('String(v:null)'))
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('v:true', fn.String(true))
|
|
|
|
eq('v:false', fn.String(false))
|
|
|
|
eq('v:null', fn.String(NIL))
|
2020-07-20 02:01:14 -07:00
|
|
|
eq('v:true', eval('StringMsg(v:true)'))
|
|
|
|
eq('v:false', eval('StringMsg(v:false)'))
|
|
|
|
eq('v:null', eval('StringMsg(v:null)'))
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('v:true', fn.StringMsg(true))
|
|
|
|
eq('v:false', fn.StringMsg(false))
|
|
|
|
eq('v:null', fn.StringMsg(NIL))
|
2020-07-20 02:01:14 -07:00
|
|
|
eq('v:true', eval('StringErr(v:true)'))
|
|
|
|
eq('v:false', eval('StringErr(v:false)'))
|
|
|
|
eq('v:null', eval('StringErr(v:null)'))
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('v:true', fn.StringErr(true))
|
|
|
|
eq('v:false', fn.StringErr(false))
|
|
|
|
eq('v:null', fn.StringErr(NIL))
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('dumps values with at most six digits after the decimal point', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('1.234568e-20', 1.23456789123456789123456789e-020)
|
|
|
|
assert_same_echo_dump('1.234568', 1.23456789123456789123456789)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('dumps values with at most seven digits before the decimal point', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('1234567.891235', 1234567.89123456789123456789)
|
|
|
|
assert_same_echo_dump('1.234568e7', 12345678.9123456789123456789)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps negative values', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('-1.5', -1.5)
|
|
|
|
assert_same_echo_dump('-1.56e-20', -1.56000e-020)
|
|
|
|
assert_same_echo_dump('-1.234568e-20', -1.23456789123456789123456789e-020)
|
|
|
|
assert_same_echo_dump('-1.234568', -1.23456789123456789123456789)
|
|
|
|
assert_same_echo_dump('-1234567.891235', -1234567.89123456789123456789)
|
|
|
|
assert_same_echo_dump('-1.234568e7', -12345678.9123456789123456789)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('used to represent numbers', function()
|
|
|
|
it('dumps regular values', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('0', 0)
|
|
|
|
assert_same_echo_dump('-1', -1)
|
|
|
|
assert_same_echo_dump('1', 1)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps large values', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
assert_same_echo_dump('2147483647', 2 ^ 31 - 1)
|
|
|
|
assert_same_echo_dump('-2147483648', -2 ^ 31)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('used to represent strings', function()
|
|
|
|
it('dumps regular strings', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('test', 'test')
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps empty strings', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('', '')
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2020-02-02 13:55:15 -07:00
|
|
|
it("dumps strings with ' inside", function()
|
|
|
|
assert_same_echo_dump("'''", "'''")
|
|
|
|
assert_same_echo_dump("a'b''", "a'b''")
|
|
|
|
assert_same_echo_dump("'b''d", "'b''d")
|
|
|
|
assert_same_echo_dump("a'b'c'd", "a'b'c'd")
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps NULL strings', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('', '$XXX_UNEXISTENT_VAR_XXX', true)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps NULL lists', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('[]', 'v:_null_list', true)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps NULL dictionaries', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('{}', 'v:_null_dict', true)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('used to represent funcrefs', function()
|
|
|
|
before_each(function()
|
|
|
|
source([[
|
|
|
|
function Test1()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function s:Test2() dict
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function g:Test3() dict
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let g:Test2_f = function('s:Test2')
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps references to built-in functions', function()
|
2017-07-03 16:22:26 -07:00
|
|
|
eq('function', eval('String(function("function"))'))
|
2020-02-02 13:55:15 -07:00
|
|
|
eq("function('function')", eval('StringMsg(function("function"))'))
|
|
|
|
eq("function('function')", eval('StringErr(function("function"))'))
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps references to user functions', function()
|
2017-07-03 16:22:26 -07:00
|
|
|
eq('Test1', eval('String(function("Test1"))'))
|
|
|
|
eq('g:Test3', eval('String(function("g:Test3"))'))
|
2020-02-02 13:55:15 -07:00
|
|
|
eq("function('Test1')", eval("StringMsg(function('Test1'))"))
|
|
|
|
eq("function('g:Test3')", eval("StringMsg(function('g:Test3'))"))
|
|
|
|
eq("function('Test1')", eval("StringErr(function('Test1'))"))
|
|
|
|
eq("function('g:Test3')", eval("StringErr(function('g:Test3'))"))
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps references to script functions', function()
|
2022-03-27 10:25:55 -07:00
|
|
|
eq('<SNR>1_Test2', eval('String(Test2_f)'))
|
|
|
|
eq("function('<SNR>1_Test2')", eval('StringMsg(Test2_f)'))
|
|
|
|
eq("function('<SNR>1_Test2')", eval('StringErr(Test2_f)'))
|
2020-02-02 13:55:15 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dump references to lambdas', function()
|
|
|
|
assert_matches_echo_dump("function%('<lambda>%d+'%)", '{-> 1234}', true)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps partials with self referencing a partial', function()
|
|
|
|
source([[
|
|
|
|
function TestDict() dict
|
|
|
|
endfunction
|
|
|
|
let d = {}
|
|
|
|
let TestDictRef = function('TestDict', d)
|
|
|
|
let d.tdr = TestDictRef
|
|
|
|
]])
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
dedent([[
|
2017-07-03 16:22:26 -07:00
|
|
|
function('TestDict', {'tdr': function('TestDict', {...@1})})]]),
|
2024-01-02 18:09:18 -07:00
|
|
|
exec_capture('echo String(d.tdr)')
|
|
|
|
)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps automatically created partials', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump(
|
2022-03-27 10:25:55 -07:00
|
|
|
"function('<SNR>1_Test2', {'f': function('<SNR>1_Test2')})",
|
2020-02-02 13:55:15 -07:00
|
|
|
'{"f": Test2_f}.f',
|
2024-01-02 18:09:18 -07:00
|
|
|
true
|
|
|
|
)
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump(
|
2022-03-27 10:25:55 -07:00
|
|
|
"function('<SNR>1_Test2', [1], {'f': function('<SNR>1_Test2', [1])})",
|
2020-02-02 13:55:15 -07:00
|
|
|
'{"f": function(Test2_f, [1])}.f',
|
2024-01-02 18:09:18 -07:00
|
|
|
true
|
|
|
|
)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps manually created partials', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
assert_same_echo_dump("function('Test3', [1, 2], {})", "function('Test3', [1, 2], {})", true)
|
|
|
|
assert_same_echo_dump("function('Test3', [1, 2])", "function('Test3', [1, 2])", true)
|
|
|
|
assert_same_echo_dump("function('Test3', {})", "function('Test3', {})", true)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('does not crash or halt when dumping partials with reference cycles in self', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('d', { v = true })
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
dedent(
|
|
|
|
[[
|
|
|
|
{'p': function('<SNR>1_Test2', {...@0}), 'f': function('<SNR>1_Test2'), 'v': v:true}]]
|
|
|
|
),
|
|
|
|
exec_capture('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))')
|
|
|
|
)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('does not show errors when dumping partials referencing the same dictionary', function()
|
2017-07-03 16:06:04 -07:00
|
|
|
command('let d = {}')
|
|
|
|
-- Regression for “eval/typval_encode: Dump empty dictionary before
|
|
|
|
-- checking for refcycle”, results in error.
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
"[function('tr', {}), function('tr', {})]",
|
|
|
|
eval('String([function("tr", d), function("tr", d)])')
|
|
|
|
)
|
2017-07-03 16:06:04 -07:00
|
|
|
-- Regression for “eval: Work with reference cycles in partials (self)
|
|
|
|
-- properly”, results in crash.
|
|
|
|
eval('extend(d, {"a": 1})')
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
"[function('tr', {'a': 1}), function('tr', {'a': 1})]",
|
|
|
|
eval('String([function("tr", d), function("tr", d)])')
|
|
|
|
)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('does not crash or halt when dumping partials with reference cycles in arguments', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('l', {})
|
2017-07-03 16:06:04 -07:00
|
|
|
eval('add(l, l)')
|
|
|
|
-- Regression: the below line used to crash (add returns original list and
|
|
|
|
-- there was error in dumping partials). Tested explicitly in
|
2024-04-08 02:03:20 -07:00
|
|
|
-- test/unit/api/private_t_spec.lua.
|
2017-07-03 16:06:04 -07:00
|
|
|
eval('add(l, function("Test1", l))')
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
dedent(
|
|
|
|
[=[
|
|
|
|
function('Test1', [[[...@2], function('Test1', [[...@2]])], function('Test1', [[[...@4], function('Test1', [[...@4]])]])])]=]
|
|
|
|
),
|
|
|
|
exec_capture('echo String(function("Test1", l))')
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it(
|
|
|
|
'does not crash or halt when dumping partials with reference cycles in self and arguments',
|
|
|
|
function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('d', { v = true })
|
|
|
|
api.nvim_set_var('l', {})
|
2024-01-02 18:09:18 -07:00
|
|
|
eval('add(l, l)')
|
|
|
|
eval('add(l, function("Test1", l))')
|
|
|
|
eval('add(l, function("Test1", d))')
|
|
|
|
eq(
|
|
|
|
dedent(
|
|
|
|
[=[
|
|
|
|
{'p': function('<SNR>1_Test2', [[[...@3], function('Test1', [[...@3]]), function('Test1', {...@0})], function('Test1', [[[...@5], function('Test1', [[...@5]]), function('Test1', {...@0})]]), function('Test1', {...@0})], {...@0}), 'f': function('<SNR>1_Test2'), 'v': v:true}]=]
|
|
|
|
),
|
|
|
|
exec_capture(
|
|
|
|
'echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": function(g:d.f, l)}))'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('used to represent lists', function()
|
|
|
|
it('dumps empty list', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('[]', {})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps non-empty list', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
assert_same_echo_dump('[1, 2]', { 1, 2 })
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps nested lists', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
assert_same_echo_dump('[[[[[]]]]]', { { { { {} } } } })
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps nested non-empty lists', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
assert_same_echo_dump('[1, [[3, [[5], 4]], 2]]', { 1, { { 3, { { 5 }, 4 } }, 2 } })
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2017-07-03 16:22:26 -07:00
|
|
|
it('does not error when dumping recursive lists', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('l', {})
|
2017-07-03 16:06:04 -07:00
|
|
|
eval('add(l, l)')
|
2017-07-03 16:22:26 -07:00
|
|
|
eq(0, exc_exec('echo String(l)'))
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2017-07-03 16:22:26 -07:00
|
|
|
it('dumps recursive lists without error', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('l', {})
|
2017-07-03 16:06:04 -07:00
|
|
|
eval('add(l, l)')
|
2021-09-19 02:29:37 -07:00
|
|
|
eq('[[...@0]]', exec_capture('echo String(l)'))
|
|
|
|
eq('[[[...@1]]]', exec_capture('echo String([l])'))
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('used to represent dictionaries', function()
|
|
|
|
it('dumps empty dictionary', function()
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('{}', '{}', true)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps list with two same empty dictionaries, also in partials', function()
|
|
|
|
command('let d = {}')
|
2020-02-02 13:55:15 -07:00
|
|
|
assert_same_echo_dump('[{}, {}]', '[d, d]', true)
|
2024-01-02 18:09:18 -07:00
|
|
|
eq("[function('tr', {}), {}]", eval('String([function("tr", d), d])'))
|
|
|
|
eq("[{}, function('tr', {})]", eval('String([d, function("tr", d)])'))
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('dumps non-empty dictionary', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
assert_same_echo_dump("{'t''est': 1}", { ["t'est"] = 1 })
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2017-07-03 16:22:26 -07:00
|
|
|
it('does not error when dumping recursive dictionaries', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('d', { d = 1 })
|
2017-07-03 16:06:04 -07:00
|
|
|
eval('extend(d, {"d": d})')
|
2017-07-03 16:22:26 -07:00
|
|
|
eq(0, exc_exec('echo String(d)'))
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
|
2017-07-03 16:22:26 -07:00
|
|
|
it('dumps recursive dictionaries without the error', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('d', { d = 1 })
|
2017-07-03 16:06:04 -07:00
|
|
|
eval('extend(d, {"d": d})')
|
2024-01-02 18:09:18 -07:00
|
|
|
eq("{'d': {...@0}}", exec_capture('echo String(d)'))
|
|
|
|
eq("{'out': {'d': {...@1}}}", exec_capture('echo String({"out": d})'))
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|
|
|
|
end)
|
2017-07-03 16:38:30 -07:00
|
|
|
|
|
|
|
describe('used to represent special values', function()
|
2024-04-20 08:44:13 -07:00
|
|
|
local function chr(_n)
|
|
|
|
return ('%c'):format(_n)
|
2017-07-03 16:38:30 -07:00
|
|
|
end
|
|
|
|
local function ctrl(c)
|
|
|
|
return ('%c'):format(c:upper():byte() - 0x40)
|
|
|
|
end
|
|
|
|
it('displays hex as hex', function()
|
|
|
|
-- Regression: due to missing (uint8_t) cast \x80 was represented as
|
|
|
|
-- ~@<80>.
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('<80>', fn.String(chr(0x80)))
|
|
|
|
eq('<81>', fn.String(chr(0x81)))
|
|
|
|
eq('<8e>', fn.String(chr(0x8e)))
|
|
|
|
eq('<c2>', fn.String(('«'):sub(1, 1)))
|
|
|
|
eq('«', fn.String(('«'):sub(1, 2)))
|
|
|
|
|
|
|
|
eq('<80>', fn.StringMsg(chr(0x80)))
|
|
|
|
eq('<81>', fn.StringMsg(chr(0x81)))
|
|
|
|
eq('<8e>', fn.StringMsg(chr(0x8e)))
|
|
|
|
eq('<c2>', fn.StringMsg(('«'):sub(1, 1)))
|
|
|
|
eq('«', fn.StringMsg(('«'):sub(1, 2)))
|
2017-07-03 16:38:30 -07:00
|
|
|
end)
|
|
|
|
it('displays ASCII control characters using ^X notation', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('^C', fn.String(ctrl('c')))
|
|
|
|
eq('^A', fn.String(ctrl('a')))
|
|
|
|
eq('^F', fn.String(ctrl('f')))
|
|
|
|
eq('^C', fn.StringMsg(ctrl('c')))
|
|
|
|
eq('^A', fn.StringMsg(ctrl('a')))
|
|
|
|
eq('^F', fn.StringMsg(ctrl('f')))
|
2017-07-03 16:38:30 -07:00
|
|
|
end)
|
|
|
|
it('prints CR, NL and tab as-is', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('\n', fn.String('\n'))
|
|
|
|
eq('\r', fn.String('\r'))
|
|
|
|
eq('\t', fn.String('\t'))
|
2017-07-03 16:38:30 -07:00
|
|
|
end)
|
|
|
|
it('prints non-printable UTF-8 in <> notation', function()
|
|
|
|
-- SINGLE SHIFT TWO, unicode control
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('<8e>', fn.String(fn.nr2char(0x8E)))
|
|
|
|
eq('<8e>', fn.StringMsg(fn.nr2char(0x8E)))
|
2017-07-03 16:38:30 -07:00
|
|
|
-- Surrogate pair: U+1F0A0 PLAYING CARD BACK is represented in UTF-16 as
|
|
|
|
-- 0xD83C 0xDCA0. This is not valid in UTF-8.
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('<d83c>', fn.String(fn.nr2char(0xD83C)))
|
|
|
|
eq('<dca0>', fn.String(fn.nr2char(0xDCA0)))
|
|
|
|
eq('<d83c><dca0>', fn.String(fn.nr2char(0xD83C) .. fn.nr2char(0xDCA0)))
|
|
|
|
eq('<d83c>', fn.StringMsg(fn.nr2char(0xD83C)))
|
|
|
|
eq('<dca0>', fn.StringMsg(fn.nr2char(0xDCA0)))
|
|
|
|
eq('<d83c><dca0>', fn.StringMsg(fn.nr2char(0xD83C) .. fn.nr2char(0xDCA0)))
|
2017-07-03 16:38:30 -07:00
|
|
|
end)
|
|
|
|
end)
|
2017-07-03 16:06:04 -07:00
|
|
|
end)
|