spellfile_spec.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local lfs = require('lfs')
  3. local eq = helpers.eq
  4. local clear = helpers.clear
  5. local meths = helpers.meths
  6. local exc_exec = helpers.exc_exec
  7. local rmdir = helpers.rmdir
  8. local write_file = helpers.write_file
  9. local testdir = 'Xtest-functional-spell-spellfile.d'
  10. describe('spellfile', function()
  11. before_each(function()
  12. clear()
  13. rmdir(testdir)
  14. lfs.mkdir(testdir)
  15. lfs.mkdir(testdir .. '/spell')
  16. end)
  17. after_each(function()
  18. rmdir(testdir)
  19. end)
  20. -- ┌ Magic string (#VIMSPELLMAGIC)
  21. -- │ ┌ Spell file version (#VIMSPELLVERSION)
  22. local spellheader = 'VIMspell\050'
  23. it('errors out when prefcond section is truncated', function()
  24. meths.set_option('runtimepath', testdir)
  25. write_file(testdir .. '/spell/en.ascii.spl',
  26. -- ┌ Section identifier (#SN_PREFCOND)
  27. -- │ ┌ Section flags (#SNF_REQUIRED or zero)
  28. -- │ │ ┌ Section length (4 bytes, MSB first)
  29. spellheader .. '\003\001\000\000\000\003'
  30. -- ┌ Number of regexes in section (2 bytes, MSB first)
  31. -- │ ┌ Condition length (1 byte)
  32. -- │ │ ┌ Condition regex (missing!)
  33. .. '\000\001\001')
  34. meths.set_option('spelllang', 'en')
  35. eq('Vim(set):E758: Truncated spell file',
  36. exc_exec('set spell'))
  37. end)
  38. it('errors out when prefcond regexp contains NUL byte', function()
  39. meths.set_option('runtimepath', testdir)
  40. write_file(testdir .. '/spell/en.ascii.spl',
  41. -- ┌ Section identifier (#SN_PREFCOND)
  42. -- │ ┌ Section flags (#SNF_REQUIRED or zero)
  43. -- │ │ ┌ Section length (4 bytes, MSB first)
  44. spellheader .. '\003\001\000\000\000\008'
  45. -- ┌ Number of regexes in section (2 bytes, MSB first)
  46. -- │ ┌ Condition length (1 byte)
  47. -- │ │ ┌ Condition regex
  48. -- │ │ │ ┌ End of sections marker
  49. .. '\000\001\005ab\000cd\255'
  50. -- ┌ LWORDTREE tree length (4 bytes)
  51. -- │ ┌ KWORDTREE tree length (4 bytes)
  52. -- │ │ ┌ PREFIXTREE tree length
  53. .. '\000\000\000\000\000\000\000\000\000\000\000\000')
  54. meths.set_option('spelllang', 'en')
  55. eq('Vim(set):E759: Format error in spell file',
  56. exc_exec('set spell'))
  57. end)
  58. it('errors out when region contains NUL byte', function()
  59. meths.set_option('runtimepath', testdir)
  60. write_file(testdir .. '/spell/en.ascii.spl',
  61. -- ┌ Section identifier (#SN_REGION)
  62. -- │ ┌ Section flags (#SNF_REQUIRED or zero)
  63. -- │ │ ┌ Section length (4 bytes, MSB first)
  64. spellheader .. '\000\001\000\000\000\008'
  65. -- ┌ Regions ┌ End of sections marker
  66. .. '01234\00067\255'
  67. -- ┌ LWORDTREE tree length (4 bytes)
  68. -- │ ┌ KWORDTREE tree length (4 bytes)
  69. -- │ │ ┌ PREFIXTREE tree length
  70. .. '\000\000\000\000\000\000\000\000\000\000\000\000')
  71. meths.set_option('spelllang', 'en')
  72. eq('Vim(set):E759: Format error in spell file',
  73. exc_exec('set spell'))
  74. end)
  75. it('errors out when SAL section contains NUL byte', function()
  76. meths.set_option('runtimepath', testdir)
  77. write_file(testdir .. '/spell/en.ascii.spl',
  78. -- ┌ Section identifier (#SN_SAL)
  79. -- │ ┌ Section flags (#SNF_REQUIRED or zero)
  80. -- │ │ ┌ Section length (4 bytes, MSB first)
  81. spellheader .. '\005\001\000\000\000\008'
  82. -- ┌ salflags
  83. -- │ ┌ salcount (2 bytes, MSB first)
  84. -- │ │ ┌ salfromlen (1 byte)
  85. -- │ │ │ ┌ Special character
  86. -- │ │ │ │┌ salfrom (should not contain NUL)
  87. -- │ │ │ ││ ┌ saltolen
  88. -- │ │ │ ││ │ ┌ salto
  89. -- │ │ │ ││ │ │┌ End of sections marker
  90. .. '\000\000\001\0024\000\0017\255'
  91. -- ┌ LWORDTREE tree length (4 bytes)
  92. -- │ ┌ KWORDTREE tree length (4 bytes)
  93. -- │ │ ┌ PREFIXTREE tree length
  94. .. '\000\000\000\000\000\000\000\000\000\000\000\000')
  95. meths.set_option('spelllang', 'en')
  96. eq('Vim(set):E759: Format error in spell file',
  97. exc_exec('set spell'))
  98. end)
  99. it('errors out when spell header contains NUL bytes', function()
  100. meths.set_option('runtimepath', testdir)
  101. write_file(testdir .. '/spell/en.ascii.spl',
  102. spellheader:sub(1, -3) .. '\000\000')
  103. meths.set_option('spelllang', 'en')
  104. eq('Vim(set):E757: This does not look like a spell file',
  105. exc_exec('set spell'))
  106. end)
  107. end)