2017-04-09 10:55:48 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
|
|
|
local eq = helpers.eq
|
|
|
|
local clear = helpers.clear
|
|
|
|
local meths = helpers.meths
|
|
|
|
local exc_exec = helpers.exc_exec
|
2017-04-10 10:12:56 -07:00
|
|
|
local rmdir = helpers.rmdir
|
2017-04-09 10:55:48 -07:00
|
|
|
local write_file = helpers.write_file
|
2023-04-04 12:59:06 -07:00
|
|
|
local mkdir = helpers.mkdir
|
2017-04-09 10:55:48 -07:00
|
|
|
|
|
|
|
local testdir = 'Xtest-functional-spell-spellfile.d'
|
|
|
|
|
|
|
|
describe('spellfile', function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
2017-04-10 10:12:56 -07:00
|
|
|
rmdir(testdir)
|
2023-04-04 12:59:06 -07:00
|
|
|
mkdir(testdir)
|
|
|
|
mkdir(testdir .. '/spell')
|
2017-04-09 10:55:48 -07:00
|
|
|
end)
|
|
|
|
after_each(function()
|
2017-04-10 10:12:56 -07:00
|
|
|
rmdir(testdir)
|
2017-04-09 10:55:48 -07:00
|
|
|
end)
|
|
|
|
-- ┌ Magic string (#VIMSPELLMAGIC)
|
|
|
|
-- │ ┌ Spell file version (#VIMSPELLVERSION)
|
|
|
|
local spellheader = 'VIMspell\050'
|
|
|
|
it('errors out when prefcond section is truncated', function()
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('runtimepath', testdir, {})
|
2017-04-09 10:55:48 -07:00
|
|
|
write_file(testdir .. '/spell/en.ascii.spl',
|
|
|
|
-- ┌ Section identifier (#SN_PREFCOND)
|
|
|
|
-- │ ┌ Section flags (#SNF_REQUIRED or zero)
|
|
|
|
-- │ │ ┌ Section length (4 bytes, MSB first)
|
|
|
|
spellheader .. '\003\001\000\000\000\003'
|
|
|
|
-- ┌ Number of regexes in section (2 bytes, MSB first)
|
|
|
|
-- │ ┌ Condition length (1 byte)
|
|
|
|
-- │ │ ┌ Condition regex (missing!)
|
|
|
|
.. '\000\001\001')
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('spelllang', 'en', {})
|
2017-04-09 11:47:45 -07:00
|
|
|
eq('Vim(set):E758: Truncated spell file',
|
2017-04-09 10:55:48 -07:00
|
|
|
exc_exec('set spell'))
|
|
|
|
end)
|
|
|
|
it('errors out when prefcond regexp contains NUL byte', function()
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('runtimepath', testdir, {})
|
2017-04-09 10:55:48 -07:00
|
|
|
write_file(testdir .. '/spell/en.ascii.spl',
|
|
|
|
-- ┌ Section identifier (#SN_PREFCOND)
|
|
|
|
-- │ ┌ Section flags (#SNF_REQUIRED or zero)
|
|
|
|
-- │ │ ┌ Section length (4 bytes, MSB first)
|
|
|
|
spellheader .. '\003\001\000\000\000\008'
|
|
|
|
-- ┌ Number of regexes in section (2 bytes, MSB first)
|
|
|
|
-- │ ┌ Condition length (1 byte)
|
|
|
|
-- │ │ ┌ Condition regex
|
|
|
|
-- │ │ │ ┌ End of sections marker
|
|
|
|
.. '\000\001\005ab\000cd\255'
|
|
|
|
-- ┌ LWORDTREE tree length (4 bytes)
|
|
|
|
-- │ ┌ KWORDTREE tree length (4 bytes)
|
|
|
|
-- │ │ ┌ PREFIXTREE tree length
|
|
|
|
.. '\000\000\000\000\000\000\000\000\000\000\000\000')
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('spelllang', 'en', {})
|
2017-04-09 10:55:48 -07:00
|
|
|
eq('Vim(set):E759: Format error in spell file',
|
|
|
|
exc_exec('set spell'))
|
|
|
|
end)
|
2017-04-09 12:02:26 -07:00
|
|
|
it('errors out when region contains NUL byte', function()
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('runtimepath', testdir, {})
|
2017-04-09 12:02:26 -07:00
|
|
|
write_file(testdir .. '/spell/en.ascii.spl',
|
|
|
|
-- ┌ Section identifier (#SN_REGION)
|
|
|
|
-- │ ┌ Section flags (#SNF_REQUIRED or zero)
|
|
|
|
-- │ │ ┌ Section length (4 bytes, MSB first)
|
|
|
|
spellheader .. '\000\001\000\000\000\008'
|
|
|
|
-- ┌ Regions ┌ End of sections marker
|
|
|
|
.. '01234\00067\255'
|
|
|
|
-- ┌ LWORDTREE tree length (4 bytes)
|
|
|
|
-- │ ┌ KWORDTREE tree length (4 bytes)
|
|
|
|
-- │ │ ┌ PREFIXTREE tree length
|
|
|
|
.. '\000\000\000\000\000\000\000\000\000\000\000\000')
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('spelllang', 'en', {})
|
2017-04-09 12:02:26 -07:00
|
|
|
eq('Vim(set):E759: Format error in spell file',
|
|
|
|
exc_exec('set spell'))
|
|
|
|
end)
|
2017-04-09 12:16:26 -07:00
|
|
|
it('errors out when SAL section contains NUL byte', function()
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('runtimepath', testdir, {})
|
2017-04-09 12:16:26 -07:00
|
|
|
write_file(testdir .. '/spell/en.ascii.spl',
|
|
|
|
-- ┌ Section identifier (#SN_SAL)
|
|
|
|
-- │ ┌ Section flags (#SNF_REQUIRED or zero)
|
|
|
|
-- │ │ ┌ Section length (4 bytes, MSB first)
|
|
|
|
spellheader .. '\005\001\000\000\000\008'
|
|
|
|
-- ┌ salflags
|
|
|
|
-- │ ┌ salcount (2 bytes, MSB first)
|
|
|
|
-- │ │ ┌ salfromlen (1 byte)
|
|
|
|
-- │ │ │ ┌ Special character
|
|
|
|
-- │ │ │ │┌ salfrom (should not contain NUL)
|
|
|
|
-- │ │ │ ││ ┌ saltolen
|
|
|
|
-- │ │ │ ││ │ ┌ salto
|
|
|
|
-- │ │ │ ││ │ │┌ End of sections marker
|
|
|
|
.. '\000\000\001\0024\000\0017\255'
|
|
|
|
-- ┌ LWORDTREE tree length (4 bytes)
|
|
|
|
-- │ ┌ KWORDTREE tree length (4 bytes)
|
|
|
|
-- │ │ ┌ PREFIXTREE tree length
|
|
|
|
.. '\000\000\000\000\000\000\000\000\000\000\000\000')
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('spelllang', 'en', {})
|
2017-04-09 12:16:26 -07:00
|
|
|
eq('Vim(set):E759: Format error in spell file',
|
|
|
|
exc_exec('set spell'))
|
|
|
|
end)
|
2017-04-09 12:30:48 -07:00
|
|
|
it('errors out when spell header contains NUL bytes', function()
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('runtimepath', testdir, {})
|
2017-04-09 12:30:48 -07:00
|
|
|
write_file(testdir .. '/spell/en.ascii.spl',
|
|
|
|
spellheader:sub(1, -3) .. '\000\000')
|
2022-12-19 09:37:45 -07:00
|
|
|
meths.set_option_value('spelllang', 'en', {})
|
2017-04-09 12:30:48 -07:00
|
|
|
eq('Vim(set):E757: This does not look like a spell file',
|
|
|
|
exc_exec('set spell'))
|
|
|
|
end)
|
2017-04-09 10:55:48 -07:00
|
|
|
end)
|