test_spellfile.vim 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. " Test for commands that operate on the spellfile.
  2. source shared.vim
  3. source check.vim
  4. CheckFeature spell
  5. CheckFeature syntax
  6. func Test_spell_normal()
  7. new
  8. call append(0, ['1 good', '2 goood', '3 goood'])
  9. set spell spellfile=./Xspellfile.add spelllang=en
  10. let oldlang=v:lang
  11. lang C
  12. " Test for zg
  13. 1
  14. norm! ]s
  15. call assert_equal('2 goood', getline('.'))
  16. norm! zg
  17. 1
  18. let a=execute('unsilent :norm! ]s')
  19. call assert_equal('1 good', getline('.'))
  20. call assert_equal('search hit BOTTOM, continuing at TOP', a[1:])
  21. let cnt=readfile('./Xspellfile.add')
  22. call assert_equal('goood', cnt[0])
  23. " zg should fail in operator-pending mode
  24. call assert_beeps('norm! czg')
  25. " zg fails in visual mode when not able to get the visual text
  26. call assert_beeps('norm! ggVjzg')
  27. norm! V
  28. " zg fails for a non-identifier word
  29. call append(line('$'), '###')
  30. call assert_fails('norm! Gzg', 'E349:')
  31. $d
  32. " Test for zw
  33. 2
  34. norm! $zw
  35. 1
  36. norm! ]s
  37. call assert_equal('2 goood', getline('.'))
  38. let cnt=readfile('./Xspellfile.add')
  39. call assert_equal('#oood', cnt[0])
  40. call assert_equal('goood/!', cnt[1])
  41. " Test for :spellrare
  42. spellrare rare
  43. let cnt=readfile('./Xspellfile.add')
  44. call assert_equal(['#oood', 'goood/!', 'rare/?'], cnt)
  45. " Make sure :spellundo works for rare words.
  46. spellundo rare
  47. let cnt=readfile('./Xspellfile.add')
  48. call assert_equal(['#oood', 'goood/!', '#are/?'], cnt)
  49. " Test for zg in visual mode
  50. let a=execute('unsilent :norm! V$zg')
  51. call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
  52. 1
  53. norm! ]s
  54. call assert_equal('3 goood', getline('.'))
  55. let cnt=readfile('./Xspellfile.add')
  56. call assert_equal('2 goood', cnt[3])
  57. " Remove "2 good" from spellfile
  58. 2
  59. let a=execute('unsilent norm! V$zw')
  60. call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
  61. let cnt=readfile('./Xspellfile.add')
  62. call assert_equal('2 goood/!', cnt[4])
  63. " Test for zG
  64. let a=execute('unsilent norm! V$zG')
  65. call assert_match("Word '2 goood' added to .*", a)
  66. let fname=matchstr(a, 'to\s\+\zs\f\+$')
  67. let cnt=readfile(fname)
  68. call assert_equal('2 goood', cnt[0])
  69. " Test for zW
  70. let a=execute('unsilent norm! V$zW')
  71. call assert_match("Word '2 goood' added to .*", a)
  72. let cnt=readfile(fname)
  73. call assert_equal('# goood', cnt[0])
  74. call assert_equal('2 goood/!', cnt[1])
  75. " Test for zuW
  76. let a=execute('unsilent norm! V$zuW')
  77. call assert_match("Word '2 goood' removed from .*", a)
  78. let cnt=readfile(fname)
  79. call assert_equal('# goood', cnt[0])
  80. call assert_equal('# goood/!', cnt[1])
  81. " Test for zuG
  82. let a=execute('unsilent norm! $zG')
  83. call assert_match("Word 'goood' added to .*", a)
  84. let cnt=readfile(fname)
  85. call assert_equal('# goood', cnt[0])
  86. call assert_equal('# goood/!', cnt[1])
  87. call assert_equal('goood', cnt[2])
  88. let a=execute('unsilent norm! $zuG')
  89. let cnt=readfile(fname)
  90. call assert_match("Word 'goood' removed from .*", a)
  91. call assert_equal('# goood', cnt[0])
  92. call assert_equal('# goood/!', cnt[1])
  93. call assert_equal('#oood', cnt[2])
  94. " word not found in wordlist
  95. let a=execute('unsilent norm! V$zuG')
  96. let cnt=readfile(fname)
  97. call assert_match("", a)
  98. call assert_equal('# goood', cnt[0])
  99. call assert_equal('# goood/!', cnt[1])
  100. call assert_equal('#oood', cnt[2])
  101. " Test for zug
  102. call delete('./Xspellfile.add')
  103. 2
  104. let a=execute('unsilent norm! $zg')
  105. let cnt=readfile('./Xspellfile.add')
  106. call assert_equal('goood', cnt[0])
  107. let a=execute('unsilent norm! $zug')
  108. call assert_match("Word 'goood' removed from \./Xspellfile.add", a)
  109. let cnt=readfile('./Xspellfile.add')
  110. call assert_equal('#oood', cnt[0])
  111. " word not in wordlist
  112. let a=execute('unsilent norm! V$zug')
  113. call assert_match('', a)
  114. let cnt=readfile('./Xspellfile.add')
  115. call assert_equal('#oood', cnt[0])
  116. " Test for zuw
  117. call delete('./Xspellfile.add')
  118. 2
  119. let a=execute('unsilent norm! Vzw')
  120. let cnt=readfile('./Xspellfile.add')
  121. call assert_equal('2 goood/!', cnt[0])
  122. let a=execute('unsilent norm! Vzuw')
  123. call assert_match("Word '2 goood' removed from \./Xspellfile.add", a)
  124. let cnt=readfile('./Xspellfile.add')
  125. call assert_equal('# goood/!', cnt[0])
  126. " word not in wordlist
  127. let a=execute('unsilent norm! $zug')
  128. call assert_match('', a)
  129. let cnt=readfile('./Xspellfile.add')
  130. call assert_equal('# goood/!', cnt[0])
  131. " add second entry to spellfile setting
  132. set spellfile=./Xspellfile.add,./Xspellfile2.add
  133. call delete('./Xspellfile.add')
  134. 2
  135. let a=execute('unsilent norm! $2zg')
  136. let cnt=readfile('./Xspellfile2.add')
  137. call assert_match("Word 'goood' added to ./Xspellfile2.add", a)
  138. call assert_equal('goood', cnt[0])
  139. " Test for :spellgood!
  140. let temp = execute(':spe!0/0')
  141. call assert_match('Invalid region', temp)
  142. let spellfile = matchstr(temp, 'Invalid region nr in \zs.*\ze line \d: 0')
  143. call assert_equal(['# goood', '# goood/!', '#oood', '0/0'], readfile(spellfile))
  144. " Test for :spellrare!
  145. :spellrare! raare
  146. call assert_equal(['# goood', '# goood/!', '#oood', '0/0', 'raare/?'], readfile(spellfile))
  147. call delete(spellfile)
  148. " clean up
  149. exe "lang" oldlang
  150. call delete("./Xspellfile.add")
  151. call delete("./Xspellfile2.add")
  152. call delete("./Xspellfile.add.spl")
  153. call delete("./Xspellfile2.add.spl")
  154. " zux -> no-op
  155. 2
  156. norm! $zux
  157. call assert_equal([], glob('Xspellfile.add',0,1))
  158. call assert_equal([], glob('Xspellfile2.add',0,1))
  159. set spellfile= spell& spelllang&
  160. bw!
  161. endfunc
  162. " Spell file content test. Write 'content' to the spell file prefixed by the
  163. " spell file header and then enable spell checking. If 'emsg' is not empty,
  164. " then check for error.
  165. func Spellfile_Test(content, emsg)
  166. let splfile = './Xtest/spell/Xtest.utf-8.spl'
  167. " Add the spell file header and version (VIMspell2)
  168. let v = 0z56494D7370656C6C32 + a:content
  169. call writefile(v, splfile, 'b')
  170. " 'encoding' is set before each test to clear the previously loaded suggest
  171. " file from memory.
  172. set encoding=utf-8
  173. set runtimepath=./Xtest
  174. set spelllang=Xtest
  175. if a:emsg != ''
  176. call assert_fails('set spell', a:emsg)
  177. else
  178. " FIXME: With some invalid spellfile contents, there are no error
  179. " messages. So don't know how to check for the test result.
  180. set spell
  181. endif
  182. set nospell spelllang& rtp&
  183. endfunc
  184. " Test for spell file format errors.
  185. " The spell file format is described in spellfile.c
  186. func Test_spellfile_format_error()
  187. let save_rtp = &rtp
  188. call mkdir('Xtest/spell', 'pR')
  189. let splfile = './Xtest/spell/Xtest.utf-8.spl'
  190. " empty spell file
  191. call writefile([], splfile)
  192. set runtimepath=./Xtest
  193. set spelllang=Xtest
  194. call assert_fails('set spell', 'E757:')
  195. set nospell spelllang&
  196. " invalid file ID
  197. call writefile(0z56494D, splfile, 'b')
  198. set runtimepath=./Xtest
  199. set spelllang=Xtest
  200. call assert_fails('set spell', 'E757:')
  201. set nospell spelllang&
  202. " missing version number
  203. call writefile(0z56494D7370656C6C, splfile, 'b')
  204. set runtimepath=./Xtest
  205. set spelllang=Xtest
  206. call assert_fails('set spell', 'E771:')
  207. set nospell spelllang&
  208. " invalid version number
  209. call writefile(0z56494D7370656C6C7A, splfile, 'b')
  210. set runtimepath=./Xtest
  211. set spelllang=Xtest
  212. call assert_fails('set spell', 'E772:')
  213. set nospell spelllang&
  214. " no sections
  215. call Spellfile_Test(0z, 'E758:')
  216. " missing section length
  217. call Spellfile_Test(0z00, 'E758:')
  218. " unsupported required section
  219. call Spellfile_Test(0z7A0100000004, 'E770:')
  220. " unsupported not-required section
  221. call Spellfile_Test(0z7A0000000004, 'E758:')
  222. " SN_REGION: invalid number of region names
  223. call Spellfile_Test(0z0000000000FF, 'E759:')
  224. " SN_CHARFLAGS: missing <charflagslen> length
  225. call Spellfile_Test(0z010000000004, 'E758:')
  226. " SN_CHARFLAGS: invalid <charflagslen> length
  227. call Spellfile_Test(0z0100000000010201, '')
  228. " SN_CHARFLAGS: charflagslen == 0 and folcharslen != 0
  229. call Spellfile_Test(0z01000000000400000101, 'E759:')
  230. " SN_CHARFLAGS: missing <folcharslen> length
  231. call Spellfile_Test(0z01000000000100, 'E758:')
  232. " SN_PREFCOND: invalid prefcondcnt
  233. call Spellfile_Test(0z03000000000100, 'E759:')
  234. " SN_PREFCOND: invalid condlen
  235. call Spellfile_Test(0z0300000000020001, 'E759:')
  236. " SN_REP: invalid repcount
  237. call Spellfile_Test(0z04000000000100, 'E758:')
  238. " SN_REP: missing rep
  239. call Spellfile_Test(0z0400000000020004, 'E758:')
  240. " SN_REP: zero repfromlen
  241. call Spellfile_Test(0z040000000003000100, 'E759:')
  242. " SN_REP: invalid reptolen
  243. call Spellfile_Test(0z0400000000050001014101, '')
  244. " SN_REP: zero reptolen
  245. call Spellfile_Test(0z0400000000050001014100, 'E759:')
  246. " SN_SAL: missing salcount
  247. call Spellfile_Test(0z05000000000102, 'E758:')
  248. " SN_SAL: missing salfromlen
  249. call Spellfile_Test(0z050000000003080001, 'E758:')
  250. " SN_SAL: missing saltolen
  251. call Spellfile_Test(0z0500000000050400010161, 'E758:')
  252. " SN_WORDS: non-NUL terminated word
  253. call Spellfile_Test(0z0D000000000376696D, 'E758:')
  254. " SN_WORDS: very long word
  255. let v = eval('0z0D000000012C' .. repeat('41', 300))
  256. call Spellfile_Test(v, 'E759:')
  257. " SN_SOFO: missing sofofromlen
  258. call Spellfile_Test(0z06000000000100, 'E758:')
  259. " SN_SOFO: missing sofotolen
  260. call Spellfile_Test(0z06000000000400016100, 'E758:')
  261. " SN_SOFO: missing sofoto
  262. call Spellfile_Test(0z0600000000050001610000, 'E759:')
  263. " SN_SOFO: empty sofofrom and sofoto
  264. call Spellfile_Test(0z06000000000400000000FF000000000000000000000000, '')
  265. " SN_SOFO: multi-byte characters in sofofrom and sofoto
  266. call Spellfile_Test(0z0600000000080002CF810002CF82FF000000000000000000000000, '')
  267. " SN_COMPOUND: compmax is less than 2
  268. call Spellfile_Test(0z08000000000101, 'E759:')
  269. " SN_COMPOUND: missing compsylmax and other options
  270. call Spellfile_Test(0z0800000000020401, 'E759:')
  271. " SN_COMPOUND: missing compoptions
  272. call Spellfile_Test(0z080000000005040101, 'E758:')
  273. " SN_COMPOUND: missing comppattern
  274. call Spellfile_Test(0z08000000000704010100000001, 'E758:')
  275. " SN_COMPOUND: incorrect comppatlen
  276. call Spellfile_Test(0z080000000007040101000000020165, 'E758:')
  277. " SN_INFO: missing info
  278. call Spellfile_Test(0z0F0000000005040101, '')
  279. " SN_MIDWORD: missing midword
  280. call Spellfile_Test(0z0200000000040102, '')
  281. " SN_MAP: missing midword
  282. call Spellfile_Test(0z0700000000040102, '')
  283. " SN_MAP: empty map string
  284. call Spellfile_Test(0z070000000000FF000000000000000000000000, '')
  285. " SN_MAP: duplicate multibyte character
  286. call Spellfile_Test(0z070000000004DC81DC81, 'E783:')
  287. " SN_SYLLABLE: missing SYLLABLE item
  288. call Spellfile_Test(0z0900000000040102, '')
  289. " SN_SYLLABLE: More than SY_MAXLEN size
  290. let v = eval('0z090000000022612F' .. repeat('62', 32))
  291. call Spellfile_Test(v, '')
  292. " LWORDTREE: missing
  293. call Spellfile_Test(0zFF, 'E758:')
  294. " LWORDTREE: missing tree node
  295. call Spellfile_Test(0zFF00000004, 'E758:')
  296. " LWORDTREE: missing tree node value
  297. call Spellfile_Test(0zFF0000000402, 'E758:')
  298. " LWORDTREE: incorrect sibling node count
  299. call Spellfile_Test(0zFF00000001040000000000000000, 'E759:')
  300. " KWORDTREE: missing tree node
  301. call Spellfile_Test(0zFF0000000000000004, 'E758:')
  302. " PREFIXTREE: missing tree node
  303. call Spellfile_Test(0zFF000000000000000000000004, 'E758:')
  304. " PREFIXTREE: incorrect prefcondnr
  305. call Spellfile_Test(0zFF000000000000000000000002010200000020, 'E759:')
  306. " PREFIXTREE: invalid nodeidx
  307. call Spellfile_Test(0zFF00000000000000000000000201010000, 'E759:')
  308. let &rtp = save_rtp
  309. endfunc
  310. " Test for format errors in suggest file
  311. func Test_sugfile_format_error()
  312. let save_rtp = &rtp
  313. call mkdir('Xtest/spell', 'pR')
  314. let splfile = './Xtest/spell/Xtest.utf-8.spl'
  315. let sugfile = './Xtest/spell/Xtest.utf-8.sug'
  316. " create an empty spell file with a suggest timestamp
  317. call writefile(0z56494D7370656C6C320B00000000080000000000000044FF000000000000000000000000, splfile, 'b')
  318. " 'encoding' is set before each test to clear the previously loaded suggest
  319. " file from memory.
  320. " empty suggest file
  321. set encoding=utf-8
  322. call writefile([], sugfile)
  323. set runtimepath=./Xtest
  324. set spelllang=Xtest
  325. set spell
  326. call assert_fails("let s = spellsuggest('abc')", 'E778:')
  327. set nospell spelllang&
  328. " zero suggest version
  329. set encoding=utf-8
  330. call writefile(0z56494D73756700, sugfile)
  331. set runtimepath=./Xtest
  332. set spelllang=Xtest
  333. set spell
  334. call assert_fails("let s = spellsuggest('abc')", 'E779:')
  335. set nospell spelllang&
  336. " unsupported suggest version
  337. set encoding=utf-8
  338. call writefile(0z56494D7375671F, sugfile)
  339. set runtimepath=./Xtest
  340. set spelllang=Xtest
  341. set spell
  342. call assert_fails("let s = spellsuggest('abc')", 'E780:')
  343. set nospell spelllang&
  344. " missing suggest timestamp
  345. set encoding=utf-8
  346. call writefile(0z56494D73756701, sugfile)
  347. set runtimepath=./Xtest
  348. set spelllang=Xtest
  349. set spell
  350. call assert_fails("let s = spellsuggest('abc')", 'E781:')
  351. set nospell spelllang&
  352. " incorrect suggest timestamp
  353. set encoding=utf-8
  354. call writefile(0z56494D7375670100000000000000FF, sugfile)
  355. set runtimepath=./Xtest
  356. set spelllang=Xtest
  357. set spell
  358. call assert_fails("let s = spellsuggest('abc')", 'E781:')
  359. set nospell spelllang&
  360. " missing suggest wordtree
  361. set encoding=utf-8
  362. call writefile(0z56494D737567010000000000000044, sugfile)
  363. set runtimepath=./Xtest
  364. set spelllang=Xtest
  365. set spell
  366. call assert_fails("let s = spellsuggest('abc')", 'E782:')
  367. set nospell spelllang&
  368. " invalid suggest word count in SUGTABLE
  369. set encoding=utf-8
  370. call writefile(0z56494D7375670100000000000000440000000022, sugfile)
  371. set runtimepath=./Xtest
  372. set spelllang=Xtest
  373. set spell
  374. call assert_fails("let s = spellsuggest('abc')", 'E782:')
  375. set nospell spelllang&
  376. " missing sugline in SUGTABLE
  377. set encoding=utf-8
  378. call writefile(0z56494D7375670100000000000000440000000000000005, sugfile)
  379. set runtimepath=./Xtest
  380. set spelllang=Xtest
  381. set spell
  382. call assert_fails("let s = spellsuggest('abc')", 'E782:')
  383. set nospell spelllang&
  384. let &rtp = save_rtp
  385. endfunc
  386. " Test for using :mkspell to create a spell file from a list of words
  387. func Test_wordlist_dic()
  388. " duplicate encoding
  389. let lines =<< trim [END]
  390. # This is an example word list
  391. /encoding=latin1
  392. /encoding=latin1
  393. example
  394. [END]
  395. call writefile(lines, 'Xwordlist.dic', 'D')
  396. let output = execute('mkspell Xwordlist.spl Xwordlist.dic')
  397. call assert_match('Duplicate /encoding= line ignored in Xwordlist.dic line 4: /encoding=latin1', output)
  398. " multiple encoding for a word
  399. let lines =<< trim [END]
  400. example
  401. /encoding=latin1
  402. example
  403. [END]
  404. call writefile(lines, 'Xwordlist.dic')
  405. let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
  406. call assert_match('/encoding= line after word ignored in Xwordlist.dic line 2: /encoding=latin1', output)
  407. " unsupported encoding for a word
  408. let lines =<< trim [END]
  409. /encoding=Xtest
  410. example
  411. [END]
  412. call writefile(lines, 'Xwordlist.dic')
  413. let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
  414. call assert_match('Conversion in Xwordlist.dic not supported: from Xtest to utf-8', output)
  415. " duplicate region
  416. let lines =<< trim [END]
  417. /regions=usca
  418. /regions=usca
  419. example
  420. [END]
  421. call writefile(lines, 'Xwordlist.dic')
  422. let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
  423. call assert_match('Duplicate /regions= line ignored in Xwordlist.dic line 2: regions=usca', output)
  424. " maximum regions
  425. let lines =<< trim [END]
  426. /regions=uscauscauscauscausca
  427. example
  428. [END]
  429. call writefile(lines, 'Xwordlist.dic')
  430. let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
  431. call assert_match('Too many regions in Xwordlist.dic line 1: uscauscauscauscausca', output)
  432. " unsupported '/' value
  433. let lines =<< trim [END]
  434. /test=abc
  435. example
  436. [END]
  437. call writefile(lines, 'Xwordlist.dic')
  438. let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
  439. call assert_match('/ line ignored in Xwordlist.dic line 1: /test=abc', output)
  440. " unsupported flag
  441. let lines =<< trim [END]
  442. example/+
  443. [END]
  444. call writefile(lines, 'Xwordlist.dic')
  445. let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
  446. call assert_match('Unrecognized flags in Xwordlist.dic line 1: +', output)
  447. " non-ascii word
  448. call writefile(["ʀʀ"], 'Xwordlist.dic')
  449. let output = execute('mkspell! -ascii Xwordlist.spl Xwordlist.dic')
  450. call assert_match('Ignored 1 words with non-ASCII characters', output)
  451. " keep case of a word
  452. let lines =<< trim [END]
  453. example/=
  454. [END]
  455. call writefile(lines, 'Xwordlist.dic')
  456. let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
  457. call assert_match('Compressed keep-case:', output)
  458. call delete('Xwordlist.spl')
  459. endfunc
  460. " Test for the :mkspell command
  461. func Test_mkspell()
  462. call assert_fails('mkspell Xtest_us.spl', 'E751:')
  463. call assert_fails('mkspell Xtest.spl abc', 'E484:')
  464. call assert_fails('mkspell a b c d e f g h i j k', 'E754:')
  465. " create a .aff file but not the .dic file
  466. call writefile([], 'Xtest.aff')
  467. call assert_fails('mkspell Xtest.spl Xtest', 'E484:')
  468. call delete('Xtest.aff')
  469. call writefile([], 'Xtest.spl')
  470. call writefile([], 'Xtest.dic')
  471. call assert_fails('mkspell Xtest.spl Xtest.dic', 'E13:')
  472. call delete('Xtest.spl')
  473. call delete('Xtest.dic')
  474. call mkdir('Xtest.spl')
  475. call assert_fails('mkspell! Xtest.spl Xtest.dic', 'E17:')
  476. call delete('Xtest.spl', 'rf')
  477. " can't write the .spl file as its directory does not exist
  478. call writefile([], 'Xtest.aff')
  479. call writefile([], 'Xtest.dic')
  480. call assert_fails('mkspell DOES_NOT_EXIT/Xtest.spl Xtest.dic', 'E484:')
  481. call delete('Xtest.aff')
  482. call delete('Xtest.dic')
  483. call assert_fails('mkspell en en_US abc_xyz', 'E755:')
  484. endfunc
  485. " Tests for :mkspell with a .dic and .aff file
  486. func Test_aff_file_format_error()
  487. " FIXME: For some reason, the :mkspell command below doesn't fail on the
  488. " MS-Windows CI build. Disable this test on MS-Windows for now.
  489. CheckNotMSWindows
  490. " No word count in .dic file
  491. call writefile([], 'Xtest.dic', 'D')
  492. call writefile([], 'Xtest.aff', 'D')
  493. call assert_fails('mkspell! Xtest.spl Xtest', 'E760:')
  494. " create a .dic file for the tests below
  495. call writefile(['1', 'work'], 'Xtest.dic')
  496. " Invalid encoding in .aff file
  497. call writefile(['# comment', 'SET Xinvalidencoding'], 'Xtest.aff')
  498. let output = execute('mkspell! Xtest.spl Xtest')
  499. call assert_match('Conversion in Xtest.aff not supported: from xinvalidencoding', output)
  500. " Invalid flag in .aff file
  501. call writefile(['FLAG xxx'], 'Xtest.aff')
  502. let output = execute('mkspell! Xtest.spl Xtest')
  503. call assert_match('Invalid value for FLAG in Xtest.aff line 1: xxx', output)
  504. " set FLAGS after using flag for an affix
  505. call writefile(['SFX L Y 1', 'SFX L 0 re [^x]', 'FLAG long'], 'Xtest.aff')
  506. let output = execute('mkspell! Xtest.spl Xtest')
  507. call assert_match('FLAG after using flags in Xtest.aff line 3: long', output)
  508. " INFO in affix file
  509. let save_encoding = &encoding
  510. call mkdir('Xrtp/spell', 'p')
  511. call writefile(['1', 'work'], 'Xrtp/spell/Xtest.dic')
  512. call writefile(['NAME klingon', 'VERSION 1.4', 'AUTHOR Spock'],
  513. \ 'Xrtp/spell/Xtest.aff')
  514. silent mkspell! Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest
  515. let save_rtp = &rtp
  516. set runtimepath=./Xrtp
  517. set spelllang=Xtest
  518. set spell
  519. let output = split(execute('spellinfo'), "\n")
  520. call assert_equal("NAME klingon", output[1])
  521. call assert_equal("VERSION 1.4", output[2])
  522. call assert_equal("AUTHOR Spock", output[3])
  523. let &rtp = save_rtp
  524. call delete('Xrtp', 'rf')
  525. set spell& spelllang& spellfile&
  526. %bw!
  527. " 'encoding' must be set again to clear the spell file in memory
  528. let &encoding = save_encoding
  529. " COMPOUNDFORBIDFLAG flag after PFX in an affix file
  530. call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDFLAG c', 'COMPOUNDFORBIDFLAG x'],
  531. \ 'Xtest.aff')
  532. let output = execute('mkspell! Xtest.spl Xtest')
  533. call assert_match('Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in Xtest.aff line 4', output)
  534. " COMPOUNDPERMITFLAG flag after PFX in an affix file
  535. call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDPERMITFLAG c'],
  536. \ 'Xtest.aff')
  537. let output = execute('mkspell! Xtest.spl Xtest')
  538. call assert_match('Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in Xtest.aff line 3', output)
  539. " Wrong COMPOUNDRULES flag value in an affix file
  540. call writefile(['COMPOUNDRULES a'], 'Xtest.aff')
  541. let output = execute('mkspell! Xtest.spl Xtest')
  542. call assert_match('Wrong COMPOUNDRULES value in Xtest.aff line 1: a', output)
  543. " Wrong COMPOUNDWORDMAX flag value in an affix file
  544. call writefile(['COMPOUNDWORDMAX 0'], 'Xtest.aff')
  545. let output = execute('mkspell! Xtest.spl Xtest')
  546. call assert_match('Wrong COMPOUNDWORDMAX value in Xtest.aff line 1: 0', output)
  547. " Wrong COMPOUNDMIN flag value in an affix file
  548. call writefile(['COMPOUNDMIN 0'], 'Xtest.aff')
  549. let output = execute('mkspell! Xtest.spl Xtest')
  550. call assert_match('Wrong COMPOUNDMIN value in Xtest.aff line 1: 0', output)
  551. " Wrong COMPOUNDSYLMAX flag value in an affix file
  552. call writefile(['COMPOUNDSYLMAX 0'], 'Xtest.aff')
  553. let output = execute('mkspell! Xtest.spl Xtest')
  554. call assert_match('Wrong COMPOUNDSYLMAX value in Xtest.aff line 1: 0', output)
  555. " Wrong CHECKCOMPOUNDPATTERN flag value in an affix file
  556. call writefile(['CHECKCOMPOUNDPATTERN 0'], 'Xtest.aff')
  557. let output = execute('mkspell! Xtest.spl Xtest')
  558. call assert_match('Wrong CHECKCOMPOUNDPATTERN value in Xtest.aff line 1: 0', output)
  559. " Both compounding and NOBREAK specified
  560. call writefile(['COMPOUNDFLAG c', 'NOBREAK'], 'Xtest.aff')
  561. let output = execute('mkspell! Xtest.spl Xtest')
  562. call assert_match('Warning: both compounding and NOBREAK specified', output)
  563. " Duplicate affix entry in an affix file
  564. call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L Y 1', 'PFX L 0 re x'],
  565. \ 'Xtest.aff')
  566. let output = execute('mkspell! Xtest.spl Xtest')
  567. call assert_match('Duplicate affix in Xtest.aff line 3: L', output)
  568. " Duplicate affix entry in an affix file
  569. call writefile(['PFX L Y 1', 'PFX L Y 1'], 'Xtest.aff')
  570. let output = execute('mkspell! Xtest.spl Xtest')
  571. call assert_match('Unrecognized or duplicate item in Xtest.aff line 2: PFX', output)
  572. " Different combining flags in an affix file
  573. call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L N 1'], 'Xtest.aff')
  574. let output = execute('mkspell! Xtest.spl Xtest')
  575. call assert_match('Different combining flag in continued affix block in Xtest.aff line 3', output)
  576. " Try to reuse an affix used for BAD flag
  577. call writefile(['BAD x', 'PFX x Y 1', 'PFX x 0 re x'], 'Xtest.aff')
  578. let output = execute('mkspell! Xtest.spl Xtest')
  579. call assert_match('Affix also used for BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST in Xtest.aff line 2: x', output)
  580. " Trailing characters in an affix entry
  581. call writefile(['PFX L Y 1 Test', 'PFX L 0 re x'], 'Xtest.aff')
  582. let output = execute('mkspell! Xtest.spl Xtest')
  583. call assert_match('Trailing text in Xtest.aff line 1: Test', output)
  584. " Trailing characters in an affix entry
  585. call writefile(['PFX L Y 1', 'PFX L 0 re x Test'], 'Xtest.aff')
  586. let output = execute('mkspell! Xtest.spl Xtest')
  587. call assert_match('Trailing text in Xtest.aff line 2: Test', output)
  588. " Incorrect combine flag in an affix entry
  589. call writefile(['PFX L X 1', 'PFX L 0 re x'], 'Xtest.aff')
  590. let output = execute('mkspell! Xtest.spl Xtest')
  591. call assert_match('Expected Y or N in Xtest.aff line 1: X', output)
  592. " Invalid count for REP item
  593. call writefile(['REP a'], 'Xtest.aff')
  594. let output = execute('mkspell! Xtest.spl Xtest')
  595. call assert_match('Expected REP(SAL) count in Xtest.aff line 1', output)
  596. " Trailing characters in REP item
  597. call writefile(['REP 1', 'REP f ph test'], 'Xtest.aff')
  598. let output = execute('mkspell! Xtest.spl Xtest')
  599. call assert_match('Trailing text in Xtest.aff line 2: test', output)
  600. " Invalid count for MAP item
  601. call writefile(['MAP a'], 'Xtest.aff')
  602. let output = execute('mkspell! Xtest.spl Xtest')
  603. call assert_match('Expected MAP count in Xtest.aff line 1', output)
  604. " Duplicate character in a MAP item
  605. call writefile(['MAP 2', 'MAP xx', 'MAP yy'], 'Xtest.aff')
  606. let output = execute('mkspell! Xtest.spl Xtest')
  607. call assert_match('Duplicate character in MAP in Xtest.aff line 2', output)
  608. " Use COMPOUNDSYLMAX without SYLLABLE
  609. call writefile(['COMPOUNDSYLMAX 2'], 'Xtest.aff')
  610. let output = execute('mkspell! Xtest.spl Xtest')
  611. call assert_match('COMPOUNDSYLMAX used without SYLLABLE', output)
  612. " Missing SOFOTO
  613. call writefile(['SOFOFROM abcdef'], 'Xtest.aff')
  614. let output = execute('mkspell! Xtest.spl Xtest')
  615. call assert_match('Missing SOFOTO line in Xtest.aff', output)
  616. " Length of SOFOFROM and SOFOTO differ
  617. call writefile(['SOFOFROM abcde', 'SOFOTO ABCD'], 'Xtest.aff')
  618. call assert_fails('mkspell! Xtest.spl Xtest', 'E759:')
  619. " Both SAL and SOFOFROM/SOFOTO items
  620. call writefile(['SOFOFROM abcd', 'SOFOTO ABCD', 'SAL CIA X'], 'Xtest.aff')
  621. let output = execute('mkspell! Xtest.spl Xtest')
  622. call assert_match('Both SAL and SOFO lines in Xtest.aff', output)
  623. " use an alphabet flag when FLAG is num
  624. call writefile(['FLAG num', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff')
  625. let output = execute('mkspell! Xtest.spl Xtest')
  626. call assert_match('Flag is not a number in Xtest.aff line 2: L', output)
  627. " use number and alphabet flag when FLAG is num
  628. call writefile(['FLAG num', 'SFX 4f Y 1', 'SFX 4f 0 re [^x]'], 'Xtest.aff')
  629. let output = execute('mkspell! Xtest.spl Xtest')
  630. call assert_match('Affix name too long in Xtest.aff line 2: 4f', output)
  631. " use a single character flag when FLAG is long
  632. call writefile(['FLAG long', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff')
  633. let output = execute('mkspell! Xtest.spl Xtest')
  634. call assert_match('Illegal flag in Xtest.aff line 2: L', output)
  635. " Nvim: non-utf8 encoding not supported
  636. " " missing character in UPP entry. The character table is used only in a
  637. " " non-utf8 encoding
  638. " call writefile(['FOL abc', 'LOW abc', 'UPP A'], 'Xtest.aff')
  639. " let save_encoding = &encoding
  640. " set encoding=cp949
  641. " call assert_fails('mkspell! Xtest.spl Xtest', 'E761:')
  642. " let &encoding = save_encoding
  643. "
  644. " " character range doesn't match between FOL and LOW entries
  645. " call writefile(["FOL \u0102bc", 'LOW abc', 'UPP ABC'], 'Xtest.aff')
  646. " let save_encoding = &encoding
  647. " set encoding=cp949
  648. " call assert_fails('mkspell! Xtest.spl Xtest', 'E762:')
  649. " let &encoding = save_encoding
  650. "
  651. " " character range doesn't match between FOL and UPP entries
  652. " call writefile(["FOL \u0102bc", "LOW \u0102bc", 'UPP ABC'], 'Xtest.aff')
  653. " let save_encoding = &encoding
  654. " set encoding=cp949
  655. " call assert_fails('mkspell! Xtest.spl Xtest', 'E762:')
  656. " let &encoding = save_encoding
  657. "
  658. " " additional characters in LOW and UPP entries
  659. " call writefile(["FOL ab", "LOW abc", 'UPP ABC'], 'Xtest.aff')
  660. " let save_encoding = &encoding
  661. " set encoding=cp949
  662. " call assert_fails('mkspell! Xtest.spl Xtest', 'E761:')
  663. " let &encoding = save_encoding
  664. "
  665. " " missing UPP entry
  666. " call writefile(["FOL abc", "LOW abc"], 'Xtest.aff')
  667. " let save_encoding = &encoding
  668. " set encoding=cp949
  669. " let output = execute('mkspell! Xtest.spl Xtest')
  670. " call assert_match('Missing FOL/LOW/UPP line in Xtest.aff', output)
  671. " let &encoding = save_encoding
  672. " duplicate word in the .dic file
  673. call writefile(['2', 'good', 'good', 'good'], 'Xtest.dic')
  674. call writefile(['NAME vim'], 'Xtest.aff')
  675. let output = execute('mkspell! Xtest.spl Xtest')
  676. call assert_match('First duplicate word in Xtest.dic line 3: good', output)
  677. call assert_match('2 duplicate word(s) in Xtest.dic', output)
  678. " use multiple .aff files with different values for COMPOUNDWORDMAX and
  679. " MIDWORD (number and string)
  680. call writefile(['1', 'world'], 'Xtest_US.dic', 'D')
  681. call writefile(['1', 'world'], 'Xtest_CA.dic', 'D')
  682. call writefile(["COMPOUNDWORDMAX 3", "MIDWORD '-"], 'Xtest_US.aff', 'D')
  683. call writefile(["COMPOUNDWORDMAX 4", "MIDWORD '="], 'Xtest_CA.aff', 'D')
  684. let output = execute('mkspell! Xtest.spl Xtest_US Xtest_CA')
  685. call assert_match('COMPOUNDWORDMAX value differs from what is used in another .aff file', output)
  686. call assert_match('MIDWORD value differs from what is used in another .aff file', output)
  687. call delete('Xtest.spl')
  688. call delete('Xtest.sug')
  689. endfunc
  690. func Test_spell_add_word()
  691. set spellfile=
  692. call assert_fails('spellgood abc', 'E764:')
  693. set spellfile=Xtest.utf-8.add
  694. call assert_fails('2spellgood abc', 'E765:')
  695. edit Xtest.utf-8.add
  696. call setline(1, 'sample')
  697. call assert_fails('spellgood abc', 'E139:')
  698. set spellfile&
  699. %bw!
  700. endfunc
  701. func Test_spell_add_long_word()
  702. set spell spellfile=./Xspellfile.add spelllang=en
  703. let word = repeat('a', 9000)
  704. let v:errmsg = ''
  705. " Spell checking doesn't really work for such a long word,
  706. " but this should not cause an E1510 error.
  707. exe 'spellgood ' .. word
  708. call assert_equal('', v:errmsg)
  709. call assert_equal([word], readfile('./Xspellfile.add'))
  710. set spell& spellfile= spelllang& encoding=utf-8
  711. call delete('./Xspellfile.add')
  712. call delete('./Xspellfile.add.spl')
  713. endfunc
  714. func Test_spellfile_verbose()
  715. call writefile(['1', 'one'], 'XtestVerbose.dic', 'D')
  716. call writefile([], 'XtestVerbose.aff', 'D')
  717. mkspell! XtestVerbose-utf8.spl XtestVerbose
  718. set spell
  719. " First time: the spl file should be read.
  720. let a = execute('3verbose set spelllang=XtestVerbose-utf8.spl')
  721. call assert_match('Reading spell file "XtestVerbose-utf8.spl"', a)
  722. " Second time time: the spl file should not be read (already read).
  723. let a = execute('3verbose set spelllang=XtestVerbose-utf8.spl')
  724. call assert_notmatch('Reading spell file "XtestVerbose-utf8.spl"', a)
  725. set spell& spelllang&
  726. call delete('XtestVerbose-utf8.spl')
  727. endfunc
  728. " Test NOBREAK (see :help spell-NOBREAK)
  729. func Test_NOBREAK()
  730. call writefile(['3', 'one', 'two', 'three' ], 'XtestNOBREAK.dic', 'D')
  731. call writefile(['NOBREAK' ], 'XtestNOBREAK.aff', 'D')
  732. mkspell! XtestNOBREAK-utf8.spl XtestNOBREAK
  733. set spell spelllang=XtestNOBREAK-utf8.spl
  734. call assert_equal(['', ''], spellbadword('One two three onetwo onetwothree threetwoone'))
  735. call assert_equal(['x', 'bad'], spellbadword('x'))
  736. call assert_equal(['y', 'bad'], spellbadword('yone'))
  737. call assert_equal(['z', 'bad'], spellbadword('onez'))
  738. call assert_equal(['zero', 'bad'], spellbadword('Onetwozerothree'))
  739. new
  740. call setline(1, 'Onetwwothree')
  741. norm! fw1z=
  742. call assert_equal('Onetwothree', getline(1))
  743. call setline(1, 'Onetwothre')
  744. norm! fh1z=
  745. call assert_equal('Onetwothree', getline(1))
  746. bw!
  747. set spell& spelllang&
  748. call delete('XtestNOBREAK-utf8.spl')
  749. endfunc
  750. " Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN)
  751. func Test_spellfile_CHECKCOMPOUNDPATTERN()
  752. call writefile(['4',
  753. \ 'one/c',
  754. \ 'two/c',
  755. \ 'three/c',
  756. \ 'four'], 'XtestCHECKCOMPOUNDPATTERN.dic', 'D')
  757. " Forbid compound words where first word ends with 'wo' and second starts with 'on'.
  758. call writefile(['CHECKCOMPOUNDPATTERN 1',
  759. \ 'CHECKCOMPOUNDPATTERN wo on',
  760. \ 'COMPOUNDFLAG c'], 'XtestCHECKCOMPOUNDPATTERN.aff', 'D')
  761. mkspell! XtestCHECKCOMPOUNDPATTERN-utf8.spl XtestCHECKCOMPOUNDPATTERN
  762. set spell spelllang=XtestCHECKCOMPOUNDPATTERN-utf8.spl
  763. " Check valid words with and without valid compounds.
  764. for goodword in ['one', 'two', 'three', 'four',
  765. \ 'oneone', 'onetwo', 'onethree',
  766. \ 'twotwo', 'twothree',
  767. \ 'threeone', 'threetwo', 'threethree',
  768. \ 'onetwothree', 'onethreetwo', 'twothreeone', 'oneoneone']
  769. call assert_equal(['', ''], spellbadword(goodword), goodword)
  770. endfor
  771. " Compounds 'twoone' or 'threetwoone' should be forbidden by CHECKCOMPOUNPATTERN.
  772. " 'four' does not have the 'c' flag in *.aff file so no compound.
  773. " 'five' is not in the *.dic file.
  774. for badword in ['five', 'onetwox',
  775. \ 'twoone', 'threetwoone',
  776. \ 'fourone', 'onefour']
  777. call assert_equal([badword, 'bad'], spellbadword(badword))
  778. endfor
  779. set spell& spelllang&
  780. call delete('XtestCHECKCOMPOUNDPATTERN-utf8.spl')
  781. endfunc
  782. " Test NOCOMPOUNDSUGS (see :help spell-NOCOMPOUNDSUGS)
  783. func Test_spellfile_NOCOMPOUNDSUGS()
  784. call writefile(['3',
  785. \ 'one/c',
  786. \ 'two/c',
  787. \ 'three/c'], 'XtestNOCOMPOUNDSUGS.dic', 'D')
  788. " pass 0 tests without NOCOMPOUNDSUGS, pass 1 tests with NOCOMPOUNDSUGS
  789. for pass in [0, 1]
  790. if pass == 0
  791. call writefile(['COMPOUNDFLAG c'], 'XtestNOCOMPOUNDSUGS.aff', 'D')
  792. else
  793. call writefile(['NOCOMPOUNDSUGS',
  794. \ 'COMPOUNDFLAG c'], 'XtestNOCOMPOUNDSUGS.aff', 'D')
  795. endif
  796. mkspell! XtestNOCOMPOUNDSUGS-utf8.spl XtestNOCOMPOUNDSUGS
  797. set spell spelllang=XtestNOCOMPOUNDSUGS-utf8.spl
  798. for goodword in ['one', 'two', 'three',
  799. \ 'oneone', 'onetwo', 'onethree',
  800. \ 'twoone', 'twotwo', 'twothree',
  801. \ 'threeone', 'threetwo', 'threethree',
  802. \ 'onetwothree', 'onethreetwo', 'twothreeone', 'oneoneone']
  803. call assert_equal(['', ''], spellbadword(goodword), goodword)
  804. endfor
  805. for badword in ['four', 'onetwox', 'onexone']
  806. call assert_equal([badword, 'bad'], spellbadword(badword))
  807. endfor
  808. if pass == 0
  809. call assert_equal(['one', 'oneone'], spellsuggest('onne', 2))
  810. call assert_equal(['onethree', 'one three'], spellsuggest('onethre', 2))
  811. else
  812. call assert_equal(['one', 'one one'], spellsuggest('onne', 2))
  813. call assert_equal(['one three'], spellsuggest('onethre', 2))
  814. endif
  815. endfor
  816. set spell& spelllang&
  817. call delete('XtestNOCOMPOUNDSUGS-utf8.spl')
  818. endfunc
  819. " Test COMMON (better suggestions with common words, see :help spell-COMMON)
  820. func Test_spellfile_COMMON()
  821. call writefile(['7',
  822. \ 'and',
  823. \ 'ant',
  824. \ 'end',
  825. \ 'any',
  826. \ 'tee',
  827. \ 'the',
  828. \ 'ted'], 'XtestCOMMON.dic', 'D')
  829. call writefile(['COMMON the and'], 'XtestCOMMON.aff', 'D')
  830. mkspell! XtestCOMMON-utf8.spl XtestCOMMON
  831. set spell spelllang=XtestCOMMON-utf8.spl
  832. " COMMON words 'and' and 'the' should be the top suggestions.
  833. call assert_equal(['and', 'ant'], spellsuggest('anr', 2))
  834. call assert_equal(['and', 'end'], spellsuggest('ond', 2))
  835. call assert_equal(['the', 'ted'], spellsuggest('tha', 2))
  836. call assert_equal(['the', 'tee'], spellsuggest('dhe', 2))
  837. set spell& spelllang&
  838. call delete('XtestCOMMON-utf8.spl')
  839. endfunc
  840. " Test NOSUGGEST (see :help spell-COMMON)
  841. func Test_spellfile_NOSUGGEST()
  842. call writefile(['2', 'foo/X', 'fog'], 'XtestNOSUGGEST.dic', 'D')
  843. call writefile(['NOSUGGEST X'], 'XtestNOSUGGEST.aff', 'D')
  844. mkspell! XtestNOSUGGEST-utf8.spl XtestNOSUGGEST
  845. set spell spelllang=XtestNOSUGGEST-utf8.spl
  846. for goodword in ['foo', 'Foo', 'FOO', 'fog', 'Fog', 'FOG']
  847. call assert_equal(['', ''], spellbadword(goodword), goodword)
  848. endfor
  849. for badword in ['foO', 'fOO', 'fooo', 'foog', 'foofog', 'fogfoo']
  850. call assert_equal([badword, 'bad'], spellbadword(badword))
  851. endfor
  852. call assert_equal(['fog'], spellsuggest('fooo', 1))
  853. call assert_equal(['fog'], spellsuggest('fOo', 1))
  854. call assert_equal(['fog'], spellsuggest('foG', 1))
  855. call assert_equal(['fog'], spellsuggest('fogg', 1))
  856. set spell& spelllang&
  857. call delete('XtestNOSUGGEST-utf8.spl')
  858. endfunc
  859. " Test CIRCUMFIX (see: :help spell-CIRCUMFIX)
  860. func Test_spellfile_CIRCUMFIX()
  861. " Example taken verbatim from https://github.com/hunspell/hunspell/tree/master/tests
  862. call writefile(['1',
  863. \ 'nagy/C po:adj'], 'XtestCIRCUMFIX.dic', 'D')
  864. call writefile(['# circumfixes: ~ obligate prefix/suffix combinations',
  865. \ '# superlative in Hungarian: leg- (prefix) AND -bb (suffix)',
  866. \ '',
  867. \ 'CIRCUMFIX X',
  868. \ '',
  869. \ 'PFX A Y 1',
  870. \ 'PFX A 0 leg/X .',
  871. \ '',
  872. \ 'PFX B Y 1',
  873. \ 'PFX B 0 legesleg/X .',
  874. \ '',
  875. \ 'SFX C Y 3',
  876. \ 'SFX C 0 obb . is:COMPARATIVE',
  877. \ 'SFX C 0 obb/AX . is:SUPERLATIVE',
  878. \ 'SFX C 0 obb/BX . is:SUPERSUPERLATIVE'], 'XtestCIRCUMFIX.aff', 'D')
  879. mkspell! XtestCIRCUMFIX-utf8.spl XtestCIRCUMFIX
  880. set spell spelllang=XtestCIRCUMFIX-utf8.spl
  881. " From https://catalog.ldc.upenn.edu/docs/LDC2008T01/acta04.pdf:
  882. " Hungarian English
  883. " --------- -------
  884. " nagy great
  885. " nagyobb greater
  886. " legnagyobb greatest
  887. " legeslegnagyob most greatest
  888. call assert_equal(['', ''], spellbadword('nagy nagyobb legnagyobb legeslegnagyobb'))
  889. for badword in ['legnagy', 'legeslegnagy', 'legobb', 'legeslegobb']
  890. call assert_equal([badword, 'bad'], spellbadword(badword))
  891. endfor
  892. set spell& spelllang&
  893. call delete('XtestCIRCUMFIX-utf8.spl')
  894. endfunc
  895. " Test SFX that strips/chops characters
  896. func Test_spellfile_SFX_strip()
  897. " Simplified conjugation of Italian verbs ending in -are (first conjugation).
  898. call writefile(['SFX A Y 4',
  899. \ 'SFX A are iamo [^icg]are',
  900. \ 'SFX A are hiamo [cg]are',
  901. \ 'SFX A re mo iare',
  902. \ 'SFX A re vamo are'],
  903. \ 'XtestSFX.aff', 'D')
  904. " Examples of Italian verbs:
  905. " - cantare = to sing
  906. " - cercare = to search
  907. " - odiare = to hate
  908. call writefile(['3', 'cantare/A', 'cercare/A', 'odiare/A'], 'XtestSFX.dic', 'D')
  909. mkspell! XtestSFX-utf8.spl XtestSFX
  910. set spell spelllang=XtestSFX-utf8.spl
  911. " To sing, we're singing, we were singing.
  912. call assert_equal(['', ''], spellbadword('cantare cantiamo cantavamo'))
  913. " To search, we're searching, we were searching.
  914. call assert_equal(['', ''], spellbadword('cercare cerchiamo cercavamo'))
  915. " To hate, we hate, we were hating.
  916. call assert_equal(['', ''], spellbadword('odiare odiamo odiavamo'))
  917. for badword in ['canthiamo', 'cerciamo', 'cantarevamo', 'odiiamo']
  918. call assert_equal([badword, 'bad'], spellbadword(badword))
  919. endfor
  920. call assert_equal(['cantiamo'], spellsuggest('canthiamo', 1))
  921. call assert_equal(['cerchiamo'], spellsuggest('cerciamo', 1))
  922. call assert_equal(['cantavamo'], spellsuggest('cantarevamo', 1))
  923. call assert_equal(['odiamo'], spellsuggest('odiiamo', 1))
  924. set spell& spelllang&
  925. call delete('XtestSFX-utf8.spl')
  926. endfunc
  927. " When 'spellfile' is not set, adding a new good word will automatically set
  928. " the 'spellfile'
  929. func Test_init_spellfile()
  930. let save_rtp = &rtp
  931. let save_encoding = &encoding
  932. call mkdir('Xrtp/spell', 'pR')
  933. call writefile(['vim'], 'Xrtp/spell/Xtest.dic')
  934. silent mkspell Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest.dic
  935. set runtimepath=./Xrtp
  936. set spelllang=Xtest
  937. set spell
  938. silent spellgood abc
  939. call assert_equal('./Xrtp/spell/Xtest.utf-8.add', &spellfile)
  940. call assert_equal(['abc'], readfile('Xrtp/spell/Xtest.utf-8.add'))
  941. call assert_true(filereadable('Xrtp/spell/Xtest.utf-8.spl'))
  942. set spell& spelllang& spellfile&
  943. let &encoding = save_encoding
  944. let &rtp = save_rtp
  945. %bw!
  946. endfunc
  947. " Test for the 'mkspellmem' option
  948. func Test_mkspellmem_opt()
  949. call assert_fails('set mkspellmem=1000', 'E474:')
  950. call assert_fails('set mkspellmem=1000,', 'E474:')
  951. call assert_fails('set mkspellmem=1000,50', 'E474:')
  952. call assert_fails('set mkspellmem=1000,50,', 'E474:')
  953. call assert_fails('set mkspellmem=1000,50,10,', 'E474:')
  954. call assert_fails('set mkspellmem=1000,50,0', 'E474:')
  955. endfunc
  956. " 'spellfile' accepts '@' on top of 'isfname'.
  957. func Test_spellfile_allow_at_character()
  958. call mkdir('Xtest/the foo@bar,dir', 'p')
  959. let &spellfile = './Xtest/the foo@bar\,dir/Xspellfile.add'
  960. let &spellfile = ''
  961. call delete('Xtest', 'rf')
  962. endfunc
  963. " this was using a NULL pointer
  964. func Test_mkspell_empty_dic()
  965. call writefile(['1'], 'XtestEmpty.dic', 'D')
  966. call writefile(['SOFOFROM abcd', 'SOFOTO ABCD', 'SAL CIA X'], 'XtestEmpty.aff', 'D')
  967. mkspell! XtestEmpty.spl XtestEmpty
  968. call delete('XtestEmpty.spl')
  969. endfunc
  970. " vim: shiftwidth=2 sts=2 expandtab