@@ -510,6 +510,207 @@ func Test_mkspell()
510510 call assert_fails (' mkspell en en_US abc_xyz' , ' E755:' )
511511endfunc
512512
513+ " Tests for :mkspell with a .dic and .aff file
514+ func Test_aff_file_format_error ()
515+ " No word count in .dic file
516+ call writefile ([], ' Xtest.dic' )
517+ call writefile ([], ' Xtest.aff' )
518+ call assert_fails (' mkspell! Xtest.spl Xtest' , ' E760:' )
519+
520+ " Invalid encoding in .aff file
521+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
522+ call writefile ([' # comment' , ' SET Xinvalidencoding' ], ' Xtest.aff' )
523+ let output = execute (' mkspell! Xtest.spl Xtest' )
524+ call assert_match (' Conversion in Xtest.aff not supported: from xinvalidencoding' , output)
525+
526+ " Invalid flag in .aff file
527+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
528+ call writefile ([' FLAG xxx' ], ' Xtest.aff' )
529+ let output = execute (' mkspell! Xtest.spl Xtest' )
530+ call assert_match (' Invalid value for FLAG in Xtest.aff line 1: xxx' , output)
531+
532+ " set FLAGS after using flag for an affix
533+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
534+ call writefile ([' SFX L Y 1' , ' SFX L 0 re [^x]' , ' FLAG long' ], ' Xtest.aff' )
535+ let output = execute (' mkspell! Xtest.spl Xtest' )
536+ call assert_match (' FLAG after using flags in Xtest.aff line 3: long' , output)
537+
538+ " INFO in affix file
539+ let save_encoding = &encoding
540+ call mkdir (' Xrtp/spell' , ' p' )
541+ call writefile ([' 1' , ' work' ], ' Xrtp/spell/Xtest.dic' )
542+ call writefile ([' NAME klingon' , ' VERSION 1.4' , ' AUTHOR Spock' ],
543+ \ ' Xrtp/spell/Xtest.aff' )
544+ silent mkspell ! Xrtp/spell/ Xtest.utf- 8 .spl Xrtp/spell/ Xtest
545+ let save_rtp = &rtp
546+ set runtimepath = ./Xrtp
547+ set spelllang = Xtest
548+ set spell
549+ let output = split (execute (' spellinfo' ), " \n " )
550+ call assert_equal (" NAME klingon" , output[1 ])
551+ call assert_equal (" VERSION 1.4" , output[2 ])
552+ call assert_equal (" AUTHOR Spock" , output[3 ])
553+ let &rtp = save_rtp
554+ call delete (' Xrtp' , ' rf' )
555+ set spell & spelllang & spellfile &
556+ % bw !
557+ " 'encoding' must be set again to clear the spell file in memory
558+ let &encoding = save_encoding
559+
560+ " COMPOUNDFORBIDFLAG flag after PFX in an affix file
561+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
562+ call writefile ([' PFX L Y 1' , ' PFX L 0 re x' , ' COMPOUNDFLAG c' , ' COMPOUNDFORBIDFLAG x' ],
563+ \ ' Xtest.aff' )
564+ let output = execute (' mkspell! Xtest.spl Xtest' )
565+ call assert_match (' Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in Xtest.aff line 4' , output)
566+
567+ " COMPOUNDPERMITFLAG flag after PFX in an affix file
568+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
569+ call writefile ([' PFX L Y 1' , ' PFX L 0 re x' , ' COMPOUNDPERMITFLAG c' ],
570+ \ ' Xtest.aff' )
571+ let output = execute (' mkspell! Xtest.spl Xtest' )
572+ call assert_match (' Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in Xtest.aff line 3' , output)
573+
574+ " Wrong COMPOUNDRULES flag value in an affix file
575+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
576+ call writefile ([' COMPOUNDRULES a' ], ' Xtest.aff' )
577+ let output = execute (' mkspell! Xtest.spl Xtest' )
578+ call assert_match (' Wrong COMPOUNDRULES value in Xtest.aff line 1: a' , output)
579+
580+ " Wrong COMPOUNDWORDMAX flag value in an affix file
581+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
582+ call writefile ([' COMPOUNDWORDMAX 0' ], ' Xtest.aff' )
583+ let output = execute (' mkspell! Xtest.spl Xtest' )
584+ call assert_match (' Wrong COMPOUNDWORDMAX value in Xtest.aff line 1: 0' , output)
585+
586+ " Wrong COMPOUNDMIN flag value in an affix file
587+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
588+ call writefile ([' COMPOUNDMIN 0' ], ' Xtest.aff' )
589+ let output = execute (' mkspell! Xtest.spl Xtest' )
590+ call assert_match (' Wrong COMPOUNDMIN value in Xtest.aff line 1: 0' , output)
591+
592+ " Wrong COMPOUNDSYLMAX flag value in an affix file
593+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
594+ call writefile ([' COMPOUNDSYLMAX 0' ], ' Xtest.aff' )
595+ let output = execute (' mkspell! Xtest.spl Xtest' )
596+ call assert_match (' Wrong COMPOUNDSYLMAX value in Xtest.aff line 1: 0' , output)
597+
598+ " Wrong CHECKCOMPOUNDPATTERN flag value in an affix file
599+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
600+ call writefile ([' CHECKCOMPOUNDPATTERN 0' ], ' Xtest.aff' )
601+ let output = execute (' mkspell! Xtest.spl Xtest' )
602+ call assert_match (' Wrong CHECKCOMPOUNDPATTERN value in Xtest.aff line 1: 0' , output)
603+
604+ " Duplicate affix entry in an affix file
605+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
606+ call writefile ([' PFX L Y 1' , ' PFX L 0 re x' , ' PFX L Y 1' , ' PFX L 0 re x' ],
607+ \ ' Xtest.aff' )
608+ let output = execute (' mkspell! Xtest.spl Xtest' )
609+ call assert_match (' Duplicate affix in Xtest.aff line 3: L' , output)
610+
611+ " Duplicate affix entry in an affix file
612+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
613+ call writefile ([' PFX L Y 1' , ' PFX L Y 1' ], ' Xtest.aff' )
614+ let output = execute (' mkspell! Xtest.spl Xtest' )
615+ call assert_match (' Unrecognized or duplicate item in Xtest.aff line 2: PFX' , output)
616+
617+ " Different combining flags in an affix file
618+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
619+ call writefile ([' PFX L Y 1' , ' PFX L 0 re x' , ' PFX L N 1' ], ' Xtest.aff' )
620+ let output = execute (' mkspell! Xtest.spl Xtest' )
621+ call assert_match (' Different combining flag in continued affix block in Xtest.aff line 3' , output)
622+
623+ " Try to reuse a affix used for BAD flag
624+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
625+ call writefile ([' BAD x' , ' PFX x Y 1' , ' PFX x 0 re x' ], ' Xtest.aff' )
626+ let output = execute (' mkspell! Xtest.spl Xtest' )
627+ call assert_match (' Affix also used for BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST in Xtest.aff line 2: x' , output)
628+
629+ " Trailing characters in an affix entry
630+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
631+ call writefile ([' PFX L Y 1 Test' , ' PFX L 0 re x' ], ' Xtest.aff' )
632+ let output = execute (' mkspell! Xtest.spl Xtest' )
633+ call assert_match (' Trailing text in Xtest.aff line 1: Test' , output)
634+
635+ " Trailing characters in an affix entry
636+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
637+ call writefile ([' PFX L Y 1' , ' PFX L 0 re x Test' ], ' Xtest.aff' )
638+ let output = execute (' mkspell! Xtest.spl Xtest' )
639+ call assert_match (' Trailing text in Xtest.aff line 2: Test' , output)
640+
641+ " Incorrect combine flag in an affix entry
642+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
643+ call writefile ([' PFX L X 1' , ' PFX L 0 re x' ], ' Xtest.aff' )
644+ let output = execute (' mkspell! Xtest.spl Xtest' )
645+ call assert_match (' Expected Y or N in Xtest.aff line 1: X' , output)
646+
647+ " Invalid count for REP item
648+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
649+ call writefile ([' REP a' ], ' Xtest.aff' )
650+ let output = execute (' mkspell! Xtest.spl Xtest' )
651+ call assert_match (' Expected REP(SAL) count in Xtest.aff line 1' , output)
652+
653+ " Trailing characters in REP item
654+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
655+ call writefile ([' REP 1' , ' REP f ph test' ], ' Xtest.aff' )
656+ let output = execute (' mkspell! Xtest.spl Xtest' )
657+ call assert_match (' Trailing text in Xtest.aff line 2: test' , output)
658+
659+ " Invalid count for MAP item
660+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
661+ call writefile ([' MAP a' ], ' Xtest.aff' )
662+ let output = execute (' mkspell! Xtest.spl Xtest' )
663+ call assert_match (' Expected MAP count in Xtest.aff line 1' , output)
664+
665+ " Duplicate character in a MAP item
666+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
667+ call writefile ([' MAP 2' , ' MAP xx' , ' MAP yy' ], ' Xtest.aff' )
668+ let output = execute (' mkspell! Xtest.spl Xtest' )
669+ call assert_match (' Duplicate character in MAP in Xtest.aff line 2' , output)
670+
671+ " Use COMPOUNDSYLMAX without SYLLABLE
672+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
673+ call writefile ([' COMPOUNDSYLMAX 2' ], ' Xtest.aff' )
674+ let output = execute (' mkspell! Xtest.spl Xtest' )
675+ call assert_match (' COMPOUNDSYLMAX used without SYLLABLE' , output)
676+
677+ " Missing SOFOTO
678+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
679+ call writefile ([' SOFOFROM abcdef' ], ' Xtest.aff' )
680+ let output = execute (' mkspell! Xtest.spl Xtest' )
681+ call assert_match (' Missing SOFOTO line in Xtest.aff' , output)
682+
683+ " FIXME: The following test causes a heap overflow with the ASAN build
684+ " " Both SAL and SOFOFROM/SOFOTO items
685+ " call writefile(['1', 'work'], 'Xtest.dic')
686+ " call writefile(['SOFOFROM abcd', 'SOFOTO ABCD', 'SAL CIA X'], 'Xtest.aff')
687+ " let output = execute('mkspell! Xtest.spl Xtest')
688+ " call assert_match('Both SAL and SOFO lines in Xtest.aff', output)
689+
690+ " use an alphabet flag when FLAG is num
691+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
692+ call writefile ([' FLAG num' , ' SFX L Y 1' , ' SFX L 0 re [^x]' ], ' Xtest.aff' )
693+ let output = execute (' mkspell! Xtest.spl Xtest' )
694+ call assert_match (' Flag is not a number in Xtest.aff line 2: L' , output)
695+
696+ " use number and alphabet flag when FLAG is num
697+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
698+ call writefile ([' FLAG num' , ' SFX 4f Y 1' , ' SFX 4f 0 re [^x]' ], ' Xtest.aff' )
699+ let output = execute (' mkspell! Xtest.spl Xtest' )
700+ call assert_match (' Affix name too long in Xtest.aff line 2: 4f' , output)
701+
702+ " use a single character flag when FLAG is long
703+ call writefile ([' 1' , ' work' ], ' Xtest.dic' )
704+ call writefile ([' FLAG long' , ' SFX L Y 1' , ' SFX L 0 re [^x]' ], ' Xtest.aff' )
705+ let output = execute (' mkspell! Xtest.spl Xtest' )
706+ call assert_match (' Illegal flag in Xtest.aff line 2: L' , output)
707+
708+ call delete (' Xtest.dic' )
709+ call delete (' Xtest.aff' )
710+ call delete (' Xtest.spl' )
711+ call delete (' Xtest.sug' )
712+ endfunc
713+
513714func Test_spell_add_word ()
514715 set spellfile =
515716 call assert_fails (' spellgood abc' , ' E764:' )
@@ -524,4 +725,26 @@ func Test_spell_add_word()
524725 % bw !
525726endfunc
526727
728+ " When 'spellfile' is not set, adding a new good word will automatically set
729+ " the 'spellfile'
730+ func Test_init_spellfile ()
731+ let save_rtp = &rtp
732+ let save_encoding = &encoding
733+ call mkdir (' Xrtp/spell' , ' p' )
734+ call writefile ([' vim' ], ' Xrtp/spell/Xtest.dic' )
735+ silent mkspell Xrtp/spell/ Xtest.utf- 8 .spl Xrtp/spell/ Xtest.dic
736+ set runtimepath = ./Xrtp
737+ set spelllang = Xtest
738+ set spell
739+ silent spellgood abc
740+ call assert_equal (' ./Xrtp/spell/Xtest.utf-8.add' , &spellfile )
741+ call assert_equal ([' abc' ], readfile (' Xrtp/spell/Xtest.utf-8.add' ))
742+ call assert_true (filereadable (' Xrtp/spell/Xtest.utf-8.spl' ))
743+ set spell & spelllang & spellfile &
744+ call delete (' Xrtp' , ' rf' )
745+ let &encoding = save_encoding
746+ let &rtp = save_rtp
747+ % bw !
748+ endfunc
749+
527750" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments