Skip to content

Commit 5a6cfb3

Browse files
dpellebrammool
authored andcommitted
patch 8.2.2902: spellfile functionality not fully tested
Problem: Spellfile functionality not fully tested. Solution: Add tests for CIRCUMFIX, NOBREAK and others. (Dominique Pellé, closes #8283)
1 parent 3e72dca commit 5a6cfb3

2 files changed

Lines changed: 95 additions & 2 deletions

File tree

src/testdir/test_spellfile.vim

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,13 @@ func Test_mkspell()
583583
call assert_fails('mkspell! Xtest.spl Xtest.dic', 'E17:')
584584
call delete('Xtest.spl', 'rf')
585585

586+
" can't write the .spl file as its directory does not exist
587+
call writefile([], 'Xtest.aff')
588+
call writefile([], 'Xtest.dic')
589+
call assert_fails('mkspell DOES_NOT_EXIT/Xtest.spl Xtest.dic', 'E484:')
590+
call delete('Xtest.aff')
591+
call delete('Xtest.dic')
592+
586593
call assert_fails('mkspell en en_US abc_xyz', 'E755:')
587594
endfunc
588595

@@ -842,6 +849,47 @@ func Test_spell_add_word()
842849
%bw!
843850
endfunc
844851

852+
func Test_spellfile_verbose()
853+
call writefile(['1', 'one'], 'XtestVerbose.dic')
854+
call writefile([], 'XtestVerbose.aff')
855+
mkspell! XtestVerbose-utf8.spl XtestVerbose
856+
set spell
857+
858+
" First time: the spl file should be read.
859+
let a = execute('3verbose set spelllang=XtestVerbose-utf8.spl')
860+
call assert_match('Reading spell file "XtestVerbose-utf8.spl"', a)
861+
862+
" Second time time: the spl file should not be read (already read).
863+
let a = execute('3verbose set spelllang=XtestVerbose-utf8.spl')
864+
call assert_notmatch('Reading spell file "XtestVerbose-utf8.spl"', a)
865+
866+
set spell& spelllang&
867+
call delete('XtestVerbose.dic')
868+
call delete('XtestVerbose.aff')
869+
call delete('XtestVerbose-utf8.spl')
870+
endfunc
871+
872+
" Test NOBREAK (see :help spell-NOBREAK)
873+
func Test_NOBREAK()
874+
call writefile(['3', 'one', 'two', 'three' ], 'XtestNOBREAK.dic')
875+
call writefile(['NOBREAK' ], 'XtestNOBREAK.aff')
876+
877+
mkspell! XtestNOBREAK-utf8.spl XtestNOBREAK
878+
set spell spelllang=XtestNOBREAK-utf8.spl
879+
880+
call assert_equal(['', ''], spellbadword('One two three onetwo onetwothree threetwoone'))
881+
882+
call assert_equal(['x', 'bad'], spellbadword('x'))
883+
call assert_equal(['y', 'bad'], spellbadword('yone'))
884+
call assert_equal(['z', 'bad'], spellbadword('onez'))
885+
call assert_equal(['zero', 'bad'], spellbadword('Onetwozerothree'))
886+
887+
set spell& spelllang&
888+
call delete('XtestNOBREAK.dic')
889+
call delete('XtestNOBREAK.aff')
890+
call delete('XtestNOBREAK-utf8.spl')
891+
endfunc
892+
845893
" Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN)
846894
func Test_spellfile_CHECKCOMPOUNDPATTERN()
847895
call writefile(['4',
@@ -854,7 +902,7 @@ func Test_spellfile_CHECKCOMPOUNDPATTERN()
854902
\ 'CHECKCOMPOUNDPATTERN wo on',
855903
\ 'COMPOUNDFLAG c'], 'XtestCHECKCOMPOUNDPATTERN.aff')
856904

857-
let output = execute('mkspell! XtestCHECKCOMPOUNDPATTERN-utf8.spl XtestCHECKCOMPOUNDPATTERN')
905+
mkspell! XtestCHECKCOMPOUNDPATTERN-utf8.spl XtestCHECKCOMPOUNDPATTERN
858906
set spell spelllang=XtestCHECKCOMPOUNDPATTERN-utf8.spl
859907

860908
" Check valid words with and without valid compounds.
@@ -893,7 +941,7 @@ func Test_spellfile_COMMON()
893941
\ 'ted'], 'XtestCOMMON.dic')
894942
call writefile(['COMMON the and'], 'XtestCOMMON.aff')
895943

896-
let output = execute('mkspell! XtestCOMMON-utf8.spl XtestCOMMON')
944+
mkspell! XtestCOMMON-utf8.spl XtestCOMMON
897945
set spell spelllang=XtestCOMMON-utf8.spl
898946

899947
" COMMON words 'and' and 'the' should be the top suggestions.
@@ -908,6 +956,49 @@ func Test_spellfile_COMMON()
908956
call delete('XtestCOMMON-utf8.spl')
909957
endfunc
910958

959+
" Test CIRCUMFIX (see: :help spell-CIRCUMFIX)
960+
func Test_spellfile_CIRCUMFIX()
961+
" Example taken verbatim from https://github.com/hunspell/hunspell/tree/master/tests
962+
call writefile(['1',
963+
\ 'nagy/C po:adj'], 'XtestCIRCUMFIX.dic')
964+
call writefile(['# circumfixes: ~ obligate prefix/suffix combinations',
965+
\ '# superlative in Hungarian: leg- (prefix) AND -bb (suffix)',
966+
\ '',
967+
\ 'CIRCUMFIX X',
968+
\ '',
969+
\ 'PFX A Y 1',
970+
\ 'PFX A 0 leg/X .',
971+
\ '',
972+
\ 'PFX B Y 1',
973+
\ 'PFX B 0 legesleg/X .',
974+
\ '',
975+
\ 'SFX C Y 3',
976+
\ 'SFX C 0 obb . is:COMPARATIVE',
977+
\ 'SFX C 0 obb/AX . is:SUPERLATIVE',
978+
\ 'SFX C 0 obb/BX . is:SUPERSUPERLATIVE'], 'XtestCIRCUMFIX.aff')
979+
980+
mkspell! XtestCIRCUMFIX-utf8.spl XtestCIRCUMFIX
981+
set spell spelllang=XtestCIRCUMFIX-utf8.spl
982+
983+
" From https://catalog.ldc.upenn.edu/docs/LDC2008T01/acta04.pdf:
984+
" Hungarian English
985+
" --------- -------
986+
" nagy great
987+
" nagyobb greater
988+
" legnagyobb greatest
989+
" legeslegnagyob most greatest
990+
call assert_equal(['', ''], spellbadword('nagy nagyobb legnagyobb legeslegnagyobb'))
991+
992+
for badword in ['legnagy', 'legeslegnagy', 'legobb', 'legeslegobb']
993+
call assert_equal([badword, 'bad'], spellbadword(badword))
994+
endfor
995+
996+
set spell& spelllang&
997+
call delete('XtestCIRCUMFIX.dic')
998+
call delete('XtestCIRCUMFIX.aff')
999+
call delete('XtestCIRCUMFIX-utf8.spl')
1000+
endfunc
1001+
9111002
" When 'spellfile' is not set, adding a new good word will automatically set
9121003
" the 'spellfile'
9131004
func Test_init_spellfile()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2902,
753755
/**/
754756
2901,
755757
/**/

0 commit comments

Comments
 (0)