test_spell_utf8.vim 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. " Test for spell checking with 'encoding' set to utf-8
  2. source check.vim
  3. CheckFeature spell
  4. scriptencoding utf-8
  5. func TearDown()
  6. set nospell
  7. call delete('Xtest.aff')
  8. call delete('Xtest.dic')
  9. call delete('Xtest.utf-8.add')
  10. call delete('Xtest.utf-8.add.spl')
  11. call delete('Xtest.utf-8.spl')
  12. call delete('Xtest.utf-8.sug')
  13. " set 'encoding' to clear the word list
  14. set encoding=utf-8
  15. endfunc
  16. let g:test_data_aff1 = [
  17. \"SET ISO8859-1",
  18. \"TRY esianrtolcdugmphbyfvkwjkqxz-ëéèêïîäàâöüû'ESIANRTOLCDUGMPHBYFVKWJKQXZ",
  19. \"",
  20. \"FOL àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ",
  21. \"LOW àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ",
  22. \"UPP ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßÿ",
  23. \"",
  24. \"SOFOFROM abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xBF",
  25. \"SOFOTO ebctefghejklnnepkrstevvkesebctefghejklnnepkrstevvkeseeeeeeeceeeeeeeedneeeeeeeeeeepseeeeeeeeceeeeeeeedneeeeeeeeeeep?",
  26. \"",
  27. \"MIDWORD\t'-",
  28. \"",
  29. \"KEP =",
  30. \"RAR ?",
  31. \"BAD !",
  32. \"",
  33. \"PFX I N 1",
  34. \"PFX I 0 in .",
  35. \"",
  36. \"PFX O Y 1",
  37. \"PFX O 0 out .",
  38. \"",
  39. \"SFX S Y 2",
  40. \"SFX S 0 s [^s]",
  41. \"SFX S 0 es s",
  42. \"",
  43. \"SFX N N 3",
  44. \"SFX N 0 en [^n]",
  45. \"SFX N 0 nen n",
  46. \"SFX N 0 n .",
  47. \"",
  48. \"REP 3",
  49. \"REP g ch",
  50. \"REP ch g",
  51. \"REP svp s.v.p.",
  52. \"",
  53. \"MAP 9",
  54. \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
  55. \"MAP e\xE8\xE9\xEA\xEB",
  56. \"MAP i\xEC\xED\xEE\xEF",
  57. \"MAP o\xF2\xF3\xF4\xF5\xF6",
  58. \"MAP u\xF9\xFA\xFB\xFC",
  59. \"MAP n\xF1",
  60. \"MAP c\xE7",
  61. \"MAP y\xFF\xFD",
  62. \"MAP s\xDF"
  63. \ ]
  64. let g:test_data_dic1 = [
  65. \"123456",
  66. \"test/NO",
  67. \"# comment",
  68. \"wrong",
  69. \"Comment",
  70. \"OK",
  71. \"uk",
  72. \"put/ISO",
  73. \"the end",
  74. \"deol",
  75. \"d\xE9\xF4r",
  76. \ ]
  77. let g:test_data_aff2 = [
  78. \"SET ISO8859-1",
  79. \"",
  80. \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
  81. \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
  82. \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF",
  83. \"",
  84. \"PFXPOSTPONE",
  85. \"",
  86. \"MIDWORD\t'-",
  87. \"",
  88. \"KEP =",
  89. \"RAR ?",
  90. \"BAD !",
  91. \"",
  92. \"PFX I N 1",
  93. \"PFX I 0 in .",
  94. \"",
  95. \"PFX O Y 1",
  96. \"PFX O 0 out [a-z]",
  97. \"",
  98. \"SFX S Y 2",
  99. \"SFX S 0 s [^s]",
  100. \"SFX S 0 es s",
  101. \"",
  102. \"SFX N N 3",
  103. \"SFX N 0 en [^n]",
  104. \"SFX N 0 nen n",
  105. \"SFX N 0 n .",
  106. \"",
  107. \"REP 3",
  108. \"REP g ch",
  109. \"REP ch g",
  110. \"REP svp s.v.p.",
  111. \"",
  112. \"MAP 9",
  113. \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
  114. \"MAP e\xE8\xE9\xEA\xEB",
  115. \"MAP i\xEC\xED\xEE\xEF",
  116. \"MAP o\xF2\xF3\xF4\xF5\xF6",
  117. \"MAP u\xF9\xFA\xFB\xFC",
  118. \"MAP n\xF1",
  119. \"MAP c\xE7",
  120. \"MAP y\xFF\xFD",
  121. \"MAP s\xDF",
  122. \ ]
  123. let g:test_data_aff3 = [
  124. \"SET ISO8859-1",
  125. \"",
  126. \"COMPOUNDMIN 3",
  127. \"COMPOUNDRULE m*",
  128. \"NEEDCOMPOUND x",
  129. \ ]
  130. let g:test_data_dic3 = [
  131. \"1234",
  132. \"foo/m",
  133. \"bar/mx",
  134. \"m\xEF/m",
  135. \"la/mx",
  136. \ ]
  137. let g:test_data_aff4 = [
  138. \"SET ISO8859-1",
  139. \"",
  140. \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
  141. \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
  142. \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF",
  143. \"",
  144. \"COMPOUNDRULE m+",
  145. \"COMPOUNDRULE sm*e",
  146. \"COMPOUNDRULE sm+",
  147. \"COMPOUNDMIN 3",
  148. \"COMPOUNDWORDMAX 3",
  149. \"COMPOUNDFORBIDFLAG t",
  150. \"",
  151. \"COMPOUNDSYLMAX 5",
  152. \"SYLLABLE a\xE1e\xE9i\xEDo\xF3\xF6\xF5u\xFA\xFC\xFBy/aa/au/ea/ee/ei/ie/oa/oe/oo/ou/uu/ui",
  153. \"",
  154. \"MAP 9",
  155. \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
  156. \"MAP e\xE8\xE9\xEA\xEB",
  157. \"MAP i\xEC\xED\xEE\xEF",
  158. \"MAP o\xF2\xF3\xF4\xF5\xF6",
  159. \"MAP u\xF9\xFA\xFB\xFC",
  160. \"MAP n\xF1",
  161. \"MAP c\xE7",
  162. \"MAP y\xFF\xFD",
  163. \"MAP s\xDF",
  164. \"",
  165. \"NEEDAFFIX x",
  166. \"",
  167. \"PFXPOSTPONE",
  168. \"",
  169. \"MIDWORD '-",
  170. \"",
  171. \"SFX q N 1",
  172. \"SFX q 0 -ok .",
  173. \"",
  174. \"SFX a Y 2",
  175. \"SFX a 0 s .",
  176. \"SFX a 0 ize/t .",
  177. \"",
  178. \"PFX p N 1",
  179. \"PFX p 0 pre .",
  180. \"",
  181. \"PFX P N 1",
  182. \"PFX P 0 nou .",
  183. \ ]
  184. let g:test_data_dic4 = [
  185. \"1234",
  186. \"word/mP",
  187. \"util/am",
  188. \"pro/xq",
  189. \"tomato/m",
  190. \"bork/mp",
  191. \"start/s",
  192. \"end/e",
  193. \ ]
  194. let g:test_data_aff5 = [
  195. \"SET ISO8859-1",
  196. \"",
  197. \"FLAG long",
  198. \"",
  199. \"NEEDAFFIX !!",
  200. \"",
  201. \"COMPOUNDRULE ssmm*ee",
  202. \"",
  203. \"NEEDCOMPOUND xx",
  204. \"COMPOUNDPERMITFLAG pp",
  205. \"",
  206. \"SFX 13 Y 1",
  207. \"SFX 13 0 bork .",
  208. \"",
  209. \"SFX a1 Y 1",
  210. \"SFX a1 0 a1 .",
  211. \"",
  212. \"SFX a\xE9 Y 1",
  213. \"SFX a\xE9 0 a\xE9 .",
  214. \"",
  215. \"PFX zz Y 1",
  216. \"PFX zz 0 pre/pp .",
  217. \"",
  218. \"PFX yy Y 1",
  219. \"PFX yy 0 nou .",
  220. \ ]
  221. let g:test_data_dic5 = [
  222. \"1234",
  223. \"foo/a1a\xE9!!",
  224. \"bar/zz13ee",
  225. \"start/ss",
  226. \"end/eeyy",
  227. \"middle/mmxx",
  228. \ ]
  229. let g:test_data_aff6 = [
  230. \"SET ISO8859-1",
  231. \"",
  232. \"FLAG caplong",
  233. \"",
  234. \"NEEDAFFIX A!",
  235. \"",
  236. \"COMPOUNDRULE sMm*Ee",
  237. \"",
  238. \"NEEDCOMPOUND Xx",
  239. \"",
  240. \"COMPOUNDPERMITFLAG p",
  241. \"",
  242. \"SFX N3 Y 1",
  243. \"SFX N3 0 bork .",
  244. \"",
  245. \"SFX A1 Y 1",
  246. \"SFX A1 0 a1 .",
  247. \"",
  248. \"SFX A\xE9 Y 1",
  249. \"SFX A\xE9 0 a\xE9 .",
  250. \"",
  251. \"PFX Zz Y 1",
  252. \"PFX Zz 0 pre/p .",
  253. \ ]
  254. let g:test_data_dic6 = [
  255. \"1234",
  256. \"mee/A1A\xE9A!",
  257. \"bar/ZzN3Ee",
  258. \"lead/s",
  259. \"end/Ee",
  260. \"middle/MmXx",
  261. \ ]
  262. let g:test_data_aff7 = [
  263. \"SET ISO8859-1",
  264. \"",
  265. \"FLAG num",
  266. \"",
  267. \"NEEDAFFIX 9999",
  268. \"",
  269. \"COMPOUNDRULE 2,77*123",
  270. \"",
  271. \"NEEDCOMPOUND 1",
  272. \"COMPOUNDPERMITFLAG 432",
  273. \"",
  274. \"SFX 61003 Y 1",
  275. \"SFX 61003 0 meat .",
  276. \"",
  277. \"SFX 0 Y 1",
  278. \"SFX 0 0 zero .",
  279. \"",
  280. \"SFX 391 Y 1",
  281. \"SFX 391 0 a1 .",
  282. \"",
  283. \"SFX 111 Y 1",
  284. \"SFX 111 0 a\xE9 .",
  285. \"",
  286. \"PFX 17 Y 1",
  287. \"PFX 17 0 pre/432 .",
  288. \ ]
  289. let g:test_data_dic7 = [
  290. \"1234",
  291. \"mee/0,391,111,9999",
  292. \"bar/17,61003,123",
  293. \"lead/2",
  294. \"tail/123",
  295. \"middle/77,1",
  296. \ ]
  297. let g:test_data_aff8 = [
  298. \"SET ISO8859-1",
  299. \"",
  300. \"NOSPLITSUGS",
  301. \ ]
  302. let g:test_data_dic8 = [
  303. \"1234",
  304. \"foo",
  305. \"bar",
  306. \"faabar",
  307. \ ]
  308. let g:test_data_aff9 = [
  309. \ ]
  310. let g:test_data_dic9 = [
  311. \"1234",
  312. \"foo",
  313. \"bar",
  314. \ ]
  315. let g:test_data_aff10 = [
  316. \"COMPOUNDRULE se",
  317. \"COMPOUNDPERMITFLAG p",
  318. \"",
  319. \"SFX A Y 1",
  320. \"SFX A 0 able/Mp .",
  321. \"",
  322. \"SFX M Y 1",
  323. \"SFX M 0 s .",
  324. \ ]
  325. let g:test_data_dic10 = [
  326. \"1234",
  327. \"drink/As",
  328. \"table/e",
  329. \ ]
  330. let g:test_data_aff_sal = [
  331. \"SET ISO8859-1",
  332. \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ",
  333. \"",
  334. \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
  335. \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF",
  336. \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF",
  337. \"",
  338. \"MIDWORD\t'-",
  339. \"",
  340. \"KEP =",
  341. \"RAR ?",
  342. \"BAD !",
  343. \"",
  344. \"PFX I N 1",
  345. \"PFX I 0 in .",
  346. \"",
  347. \"PFX O Y 1",
  348. \"PFX O 0 out .",
  349. \"",
  350. \"SFX S Y 2",
  351. \"SFX S 0 s [^s]",
  352. \"SFX S 0 es s",
  353. \"",
  354. \"SFX N N 3",
  355. \"SFX N 0 en [^n]",
  356. \"SFX N 0 nen n",
  357. \"SFX N 0 n .",
  358. \"",
  359. \"REP 3",
  360. \"REP g ch",
  361. \"REP ch g",
  362. \"REP svp s.v.p.",
  363. \"",
  364. \"MAP 9",
  365. \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5",
  366. \"MAP e\xE8\xE9\xEA\xEB",
  367. \"MAP i\xEC\xED\xEE\xEF",
  368. \"MAP o\xF2\xF3\xF4\xF5\xF6",
  369. \"MAP u\xF9\xFA\xFB\xFC",
  370. \"MAP n\xF1",
  371. \"MAP c\xE7",
  372. \"MAP y\xFF\xFD",
  373. \"MAP s\xDF",
  374. \"",
  375. \"SAL AH(AEIOUY)-^ *H",
  376. \"SAL AR(AEIOUY)-^ *R",
  377. \"SAL A(HR)^ *",
  378. \"SAL A^ *",
  379. \"SAL AH(AEIOUY)- H",
  380. \"SAL AR(AEIOUY)- R",
  381. \"SAL A(HR) _",
  382. \"SAL \xC0^ *",
  383. \"SAL \xC5^ *",
  384. \"SAL BB- _",
  385. \"SAL B B",
  386. \"SAL CQ- _",
  387. \"SAL CIA X",
  388. \"SAL CH X",
  389. \"SAL C(EIY)- S",
  390. \"SAL CK K",
  391. \"SAL COUGH^ KF",
  392. \"SAL CC< C",
  393. \"SAL C K",
  394. \"SAL DG(EIY) K",
  395. \"SAL DD- _",
  396. \"SAL D T",
  397. \"SAL \xC9< E",
  398. \"SAL EH(AEIOUY)-^ *H",
  399. \"SAL ER(AEIOUY)-^ *R",
  400. \"SAL E(HR)^ *",
  401. \"SAL ENOUGH^$ *NF",
  402. \"SAL E^ *",
  403. \"SAL EH(AEIOUY)- H",
  404. \"SAL ER(AEIOUY)- R",
  405. \"SAL E(HR) _",
  406. \"SAL FF- _",
  407. \"SAL F F",
  408. \"SAL GN^ N",
  409. \"SAL GN$ N",
  410. \"SAL GNS$ NS",
  411. \"SAL GNED$ N",
  412. \"SAL GH(AEIOUY)- K",
  413. \"SAL GH _",
  414. \"SAL GG9 K",
  415. \"SAL G K",
  416. \"SAL H H",
  417. \"SAL IH(AEIOUY)-^ *H",
  418. \"SAL IR(AEIOUY)-^ *R",
  419. \"SAL I(HR)^ *",
  420. \"SAL I^ *",
  421. \"SAL ING6 N",
  422. \"SAL IH(AEIOUY)- H",
  423. \"SAL IR(AEIOUY)- R",
  424. \"SAL I(HR) _",
  425. \"SAL J K",
  426. \"SAL KN^ N",
  427. \"SAL KK- _",
  428. \"SAL K K",
  429. \"SAL LAUGH^ LF",
  430. \"SAL LL- _",
  431. \"SAL L L",
  432. \"SAL MB$ M",
  433. \"SAL MM M",
  434. \"SAL M M",
  435. \"SAL NN- _",
  436. \"SAL N N",
  437. \"SAL OH(AEIOUY)-^ *H",
  438. \"SAL OR(AEIOUY)-^ *R",
  439. \"SAL O(HR)^ *",
  440. \"SAL O^ *",
  441. \"SAL OH(AEIOUY)- H",
  442. \"SAL OR(AEIOUY)- R",
  443. \"SAL O(HR) _",
  444. \"SAL PH F",
  445. \"SAL PN^ N",
  446. \"SAL PP- _",
  447. \"SAL P P",
  448. \"SAL Q K",
  449. \"SAL RH^ R",
  450. \"SAL ROUGH^ RF",
  451. \"SAL RR- _",
  452. \"SAL R R",
  453. \"SAL SCH(EOU)- SK",
  454. \"SAL SC(IEY)- S",
  455. \"SAL SH X",
  456. \"SAL SI(AO)- X",
  457. \"SAL SS- _",
  458. \"SAL S S",
  459. \"SAL TI(AO)- X",
  460. \"SAL TH @",
  461. \"SAL TCH-- _",
  462. \"SAL TOUGH^ TF",
  463. \"SAL TT- _",
  464. \"SAL T T",
  465. \"SAL UH(AEIOUY)-^ *H",
  466. \"SAL UR(AEIOUY)-^ *R",
  467. \"SAL U(HR)^ *",
  468. \"SAL U^ *",
  469. \"SAL UH(AEIOUY)- H",
  470. \"SAL UR(AEIOUY)- R",
  471. \"SAL U(HR) _",
  472. \"SAL V^ W",
  473. \"SAL V F",
  474. \"SAL WR^ R",
  475. \"SAL WH^ W",
  476. \"SAL W(AEIOU)- W",
  477. \"SAL X^ S",
  478. \"SAL X KS",
  479. \"SAL Y(AEIOU)- Y",
  480. \"SAL ZZ- _",
  481. \"SAL Z S",
  482. \ ]
  483. func LoadAffAndDic(aff_contents, dic_contents)
  484. set spellfile=
  485. call writefile(a:aff_contents, "Xtest.aff")
  486. call writefile(a:dic_contents, "Xtest.dic")
  487. " Generate a .spl file from a .dic and .aff file.
  488. mkspell! Xtest Xtest
  489. " use that spell file
  490. set spl=Xtest.utf-8.spl spell
  491. endfunc
  492. func ListWords()
  493. spelldump
  494. %yank
  495. quit
  496. return split(@", "\n")
  497. endfunc
  498. func TestGoodBadBase()
  499. exe '1;/^good:'
  500. normal 0f:]s
  501. let prevbad = ''
  502. let result = []
  503. while 1
  504. let [bad, a] = spellbadword()
  505. if bad == '' || bad == prevbad || bad == 'badend'
  506. break
  507. endif
  508. let prevbad = bad
  509. let lst = bad->spellsuggest(3)
  510. normal mm
  511. call add(result, [bad, lst])
  512. normal `m]s
  513. endwhile
  514. return result
  515. endfunc
  516. func RunGoodBad(good, bad, expected_words, expected_bad_words)
  517. %bwipe!
  518. call setline(1, ['', "good: ", a:good, a:bad, " badend "])
  519. let words = ListWords()
  520. call assert_equal(a:expected_words, words[1:-1])
  521. let bad_words = TestGoodBadBase()
  522. call assert_equal(a:expected_bad_words, bad_words)
  523. %bwipe!
  524. endfunc
  525. func Test_spell_basic()
  526. call LoadAffAndDic(g:test_data_aff1, g:test_data_dic1)
  527. call RunGoodBad("wrong OK puts. Test the end",
  528. \ "bad: inputs comment ok Ok. test d\u00E9\u00F4l end the",
  529. \["Comment", "deol", "d\u00E9\u00F4r", "input", "OK", "output", "outputs", "outtest", "put", "puts",
  530. \ "test", "testen", "testn", "the end", "uk", "wrong"],
  531. \[
  532. \ ["bad", ["put", "uk", "OK"]],
  533. \ ["inputs", ["input", "puts", "outputs"]],
  534. \ ["comment", ["Comment", "outtest", "the end"]],
  535. \ ["ok", ["OK", "uk", "put"]],
  536. \ ["Ok", ["OK", "Uk", "Put"]],
  537. \ ["test", ["Test", "testn", "testen"]],
  538. \ ["d\u00E9\u00F4l", ["deol", "d\u00E9\u00F4r", "test"]],
  539. \ ["end", ["put", "uk", "test"]],
  540. \ ["the", ["put", "uk", "test"]],
  541. \ ]
  542. \ )
  543. call assert_equal("gebletegek", soundfold('goobledygoook'))
  544. call assert_equal("kepereneven", 'kóopërÿnôven'->soundfold())
  545. call assert_equal("everles gesvets etele", soundfold('oeverloos gezwets edale'))
  546. endfunc
  547. " Postponed prefixes
  548. func Test_spell_prefixes()
  549. call LoadAffAndDic(g:test_data_aff2, g:test_data_dic1)
  550. call RunGoodBad("puts",
  551. \ "bad: inputs comment ok Ok end the. test d\u00E9\u00F4l",
  552. \ ["Comment", "deol", "d\u00E9\u00F4r", "OK", "put", "input", "output", "puts", "outputs", "test", "outtest", "testen", "testn", "the end", "uk", "wrong"],
  553. \ [
  554. \ ["bad", ["put", "uk", "OK"]],
  555. \ ["inputs", ["input", "puts", "outputs"]],
  556. \ ["comment", ["Comment"]],
  557. \ ["ok", ["OK", "uk", "put"]],
  558. \ ["Ok", ["OK", "Uk", "Put"]],
  559. \ ["end", ["put", "uk", "deol"]],
  560. \ ["the", ["put", "uk", "test"]],
  561. \ ["test", ["Test", "testn", "testen"]],
  562. \ ["d\u00E9\u00F4l", ["deol", "d\u00E9\u00F4r", "test"]],
  563. \ ])
  564. endfunc
  565. "Compound words
  566. func Test_spell_compound()
  567. call LoadAffAndDic(g:test_data_aff3, g:test_data_dic3)
  568. call RunGoodBad("foo m\u00EF foobar foofoobar barfoo barbarfoo",
  569. \ "bad: bar la foom\u00EF barm\u00EF m\u00EFfoo m\u00EFbar m\u00EFm\u00EF lala m\u00EFla lam\u00EF foola labar",
  570. \ ["foo", "m\u00EF"],
  571. \ [
  572. \ ["bad", ["foo", "m\u00EF"]],
  573. \ ["bar", ["barfoo", "foobar", "foo"]],
  574. \ ["la", ["m\u00EF", "foo"]],
  575. \ ["foom\u00EF", ["foo m\u00EF", "foo", "foofoo"]],
  576. \ ["barm\u00EF", ["barfoo", "m\u00EF", "barbar"]],
  577. \ ["m\u00EFfoo", ["m\u00EF foo", "foo", "foofoo"]],
  578. \ ["m\u00EFbar", ["foobar", "barbar", "m\u00EF"]],
  579. \ ["m\u00EFm\u00EF", ["m\u00EF m\u00EF", "m\u00EF"]],
  580. \ ["lala", []],
  581. \ ["m\u00EFla", ["m\u00EF", "m\u00EF m\u00EF"]],
  582. \ ["lam\u00EF", ["m\u00EF", "m\u00EF m\u00EF"]],
  583. \ ["foola", ["foo", "foobar", "foofoo"]],
  584. \ ["labar", ["barbar", "foobar"]],
  585. \ ])
  586. call LoadAffAndDic(g:test_data_aff4, g:test_data_dic4)
  587. call RunGoodBad("word util bork prebork start end wordutil wordutils pro-ok bork borkbork borkborkbork borkborkborkbork borkborkborkborkbork tomato tomatotomato startend startword startwordword startwordend startwordwordend startwordwordwordend prebork preborkbork preborkborkbork nouword",
  588. \ "bad: wordutilize pro borkborkborkborkborkbork tomatotomatotomato endstart endend startstart wordend wordstart preborkprebork preborkpreborkbork startwordwordwordwordend borkpreborkpreborkbork utilsbork startnouword",
  589. \ ["bork", "prebork", "end", "pro-ok", "start", "tomato", "util", "utilize", "utils", "word", "nouword"],
  590. \ [
  591. \ ["bad", ["end", "bork", "word"]],
  592. \ ["wordutilize", ["word utilize", "wordutils", "wordutil"]],
  593. \ ["pro", ["bork", "word", "end"]],
  594. \ ["borkborkborkborkborkbork", ["bork borkborkborkborkbork", "borkbork borkborkborkbork", "borkborkbork borkborkbork"]],
  595. \ ["tomatotomatotomato", ["tomato tomatotomato", "tomatotomato tomato", "tomato tomato tomato"]],
  596. \ ["endstart", ["end start", "start"]],
  597. \ ["endend", ["end end", "end"]],
  598. \ ["startstart", ["start start"]],
  599. \ ["wordend", ["word end", "word", "wordword"]],
  600. \ ["wordstart", ["word start", "bork start"]],
  601. \ ["preborkprebork", ["prebork prebork", "preborkbork", "preborkborkbork"]],
  602. \ ["preborkpreborkbork", ["prebork preborkbork", "preborkborkbork", "preborkborkborkbork"]],
  603. \ ["startwordwordwordwordend", ["startwordwordwordword end", "startwordwordwordword", "start wordwordwordword end"]],
  604. \ ["borkpreborkpreborkbork", ["bork preborkpreborkbork", "bork prebork preborkbork", "bork preborkprebork bork"]],
  605. \ ["utilsbork", ["utilbork", "utils bork", "util bork"]],
  606. \ ["startnouword", ["start nouword", "startword", "startborkword"]],
  607. \ ])
  608. endfunc
  609. " Test affix flags with two characters
  610. func Test_spell_affix()
  611. call LoadAffAndDic(g:test_data_aff5, g:test_data_dic5)
  612. call RunGoodBad("fooa1 fooa\u00E9 bar prebar barbork prebarbork startprebar start end startend startmiddleend nouend",
  613. \ "bad: foo fooa2 prabar probarbirk middle startmiddle middleend endstart startprobar startnouend",
  614. \ ["bar", "barbork", "end", "fooa1", "fooa\u00E9", "nouend", "prebar", "prebarbork", "start"],
  615. \ [
  616. \ ["bad", ["bar", "end", "fooa1"]],
  617. \ ["foo", ["fooa1", "bar", "end"]],
  618. \ ["fooa2", ["fooa1", "fooa\u00E9", "bar"]],
  619. \ ["prabar", ["prebar", "bar", "bar bar"]],
  620. \ ["probarbirk", ["prebarbork"]],
  621. \ ["middle", []],
  622. \ ["startmiddle", ["startmiddleend", "startmiddlebar"]],
  623. \ ["middleend", []],
  624. \ ["endstart", ["end start", "start"]],
  625. \ ["startprobar", ["startprebar", "start prebar", "startbar"]],
  626. \ ["startnouend", ["start nouend", "startend"]],
  627. \ ])
  628. call LoadAffAndDic(g:test_data_aff6, g:test_data_dic6)
  629. call RunGoodBad("meea1 meea\u00E9 bar prebar barbork prebarbork leadprebar lead end leadend leadmiddleend",
  630. \ "bad: mee meea2 prabar probarbirk middle leadmiddle middleend endlead leadprobar",
  631. \ ["bar", "barbork", "end", "lead", "meea1", "meea\u00E9", "prebar", "prebarbork"],
  632. \ [
  633. \ ["bad", ["bar", "end", "lead"]],
  634. \ ["mee", ["meea1", "bar", "end"]],
  635. \ ["meea2", ["meea1", "meea\u00E9", "lead"]],
  636. \ ["prabar", ["prebar", "bar", "leadbar"]],
  637. \ ["probarbirk", ["prebarbork"]],
  638. \ ["middle", []],
  639. \ ["leadmiddle", ["leadmiddleend", "leadmiddlebar"]],
  640. \ ["middleend", []],
  641. \ ["endlead", ["end lead", "lead", "end end"]],
  642. \ ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]],
  643. \ ])
  644. call LoadAffAndDic(g:test_data_aff7, g:test_data_dic7)
  645. call RunGoodBad("meea1 meezero meea\u00E9 bar prebar barmeat prebarmeat leadprebar lead tail leadtail leadmiddletail",
  646. \ "bad: mee meea2 prabar probarmaat middle leadmiddle middletail taillead leadprobar",
  647. \ ["bar", "barmeat", "lead", "meea1", "meea\u00E9", "meezero", "prebar", "prebarmeat", "tail"],
  648. \ [
  649. \ ["bad", ["bar", "lead", "tail"]],
  650. \ ["mee", ["meea1", "bar", "lead"]],
  651. \ ["meea2", ["meea1", "meea\u00E9", "lead"]],
  652. \ ["prabar", ["prebar", "bar", "leadbar"]],
  653. \ ["probarmaat", ["prebarmeat"]],
  654. \ ["middle", []],
  655. \ ["leadmiddle", ["leadmiddlebar"]],
  656. \ ["middletail", []],
  657. \ ["taillead", ["tail lead", "tail"]],
  658. \ ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]],
  659. \ ])
  660. endfunc
  661. func Test_spell_NOSLITSUGS()
  662. call LoadAffAndDic(g:test_data_aff8, g:test_data_dic8)
  663. call RunGoodBad("foo bar faabar", "bad: foobar barfoo",
  664. \ ["bar", "faabar", "foo"],
  665. \ [
  666. \ ["bad", ["bar", "foo"]],
  667. \ ["foobar", ["faabar", "foo bar", "bar"]],
  668. \ ["barfoo", ["bar foo", "bar", "foo"]],
  669. \ ])
  670. endfunc
  671. " Numbers
  672. func Test_spell_Numbers()
  673. call LoadAffAndDic(g:test_data_aff9, g:test_data_dic9)
  674. call RunGoodBad("0b1011 0777 1234 0x01ff", "",
  675. \ ["bar", "foo"],
  676. \ [
  677. \ ])
  678. endfunc
  679. " Affix flags
  680. func Test_spell_affix_flags()
  681. call LoadAffAndDic(g:test_data_aff10, g:test_data_dic10)
  682. call RunGoodBad("drink drinkable drinkables drinktable drinkabletable",
  683. \ "bad: drinks drinkstable drinkablestable",
  684. \ ["drink", "drinkable", "drinkables", "table"],
  685. \ [['bad', []],
  686. \ ['drinks', ['drink']],
  687. \ ['drinkstable', ['drinktable', 'drinkable', 'drink table']],
  688. \ ['drinkablestable', ['drinkabletable', 'drinkables table', 'drinkable table']],
  689. \ ])
  690. endfunc
  691. function FirstSpellWord()
  692. call feedkeys("/^start:\n", 'tx')
  693. normal ]smm
  694. let [str, a] = spellbadword()
  695. return str
  696. endfunc
  697. function SecondSpellWord()
  698. normal `m]s
  699. let [str, a] = spellbadword()
  700. return str
  701. endfunc
  702. " Test with SAL instead of SOFO items; test automatic reloading
  703. func Test_spell_sal_and_addition()
  704. set spellfile=
  705. call writefile(g:test_data_dic1, "Xtest.dic", 'D')
  706. call writefile(g:test_data_aff_sal, "Xtest.aff", 'D')
  707. mkspell! Xtest Xtest
  708. set spl=Xtest.utf-8.spl spell
  709. call assert_equal('kbltykk', soundfold('goobledygoook'))
  710. call assert_equal('kprnfn', soundfold('kóopërÿnôven'))
  711. call assert_equal('*fls kswts tl', soundfold('oeverloos gezwets edale'))
  712. "also use an addition file
  713. call writefile(["/regions=usgbnz", "elequint/2", "elekwint/3"], "Xtest.utf-8.add", 'D')
  714. mkspell! Xtest.utf-8.add.spl Xtest.utf-8.add
  715. bwipe!
  716. call setline(1, ["start: elequint test elekwint test elekwent asdf"])
  717. set spellfile=Xtest.utf-8.add
  718. call assert_equal("elekwent", FirstSpellWord())
  719. set spl=Xtest_us.utf-8.spl
  720. call assert_equal("elequint", FirstSpellWord())
  721. call assert_equal("elekwint", SecondSpellWord())
  722. set spl=Xtest_gb.utf-8.spl
  723. call assert_equal("elekwint", FirstSpellWord())
  724. call assert_equal("elekwent", SecondSpellWord())
  725. set spl=Xtest_nz.utf-8.spl
  726. call assert_equal("elequint", FirstSpellWord())
  727. call assert_equal("elekwent", SecondSpellWord())
  728. set spl=Xtest_ca.utf-8.spl
  729. call assert_equal("elequint", FirstSpellWord())
  730. call assert_equal("elekwint", SecondSpellWord())
  731. bwipe!
  732. set spellfile=
  733. set spl&
  734. endfunc
  735. func Test_spellfile_value()
  736. set spellfile=Xdir/Xtest.utf-8.add
  737. set spellfile=Xdir/Xtest.utf-8.add,Xtest_other.add
  738. set spellfile=
  739. endfunc
  740. func Test_no_crash_with_weird_text()
  741. new
  742. let lines =<< trim END
  743. r<sfile>
  744. €
  745. €
  746. END
  747. call setline(1, lines)
  748. try
  749. exe "%norm \<C-v>ez=>\<C-v>wzG"
  750. catch /E1280:/
  751. let caught = 'yes'
  752. endtry
  753. call assert_equal('yes', caught)
  754. bwipe!
  755. endfunc
  756. " Invalid bytes may cause trouble when creating the word list.
  757. func Test_check_for_valid_word()
  758. call assert_fails("spellgood! 0\xac", 'E1280:')
  759. endfunc
  760. " This was going over the end of the word
  761. func Test_word_index()
  762. new
  763. norm R0
  764. spellgood! fl0
  765. sil norm z=
  766. bwipe!
  767. call delete('Xtmpfile')
  768. endfunc
  769. func Test_check_empty_line()
  770. " This was using freed memory
  771. enew
  772. spellgood! fl
  773. norm z=
  774. norm yy
  775. sil! norm P]svc
  776. norm P]s
  777. bwipe!
  778. endfunc
  779. func Test_spell_suggest_too_long()
  780. " this was creating a word longer than MAXWLEN
  781. new
  782. call setline(1, 'a' .. repeat("\u0333", 150))
  783. norm! z=
  784. bwipe!
  785. endfunc
  786. " vim: shiftwidth=2 sts=2 expandtab