Mercurial > vim
comparison src/testdir/test_spellfile.vim @ 24727:71ace849e9f1 v8.2.2902
patch 8.2.2902: spellfile functionality not fully tested
Commit: https://github.com/vim/vim/commit/5a6cfb3ff2f2f422a3732f3855616c89dd19c19d
Author: Dominique Pelle <dominique.pelle@gmail.com>
Date: Sat May 29 17:29:33 2021 +0200
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 29 May 2021 17:30:02 +0200 |
parents | 004b1c60daa9 |
children | 857881ec1cb5 |
comparison
equal
deleted
inserted
replaced
24726:23525c2bbf6f | 24727:71ace849e9f1 |
---|---|
581 | 581 |
582 call mkdir('Xtest.spl') | 582 call mkdir('Xtest.spl') |
583 call assert_fails('mkspell! Xtest.spl Xtest.dic', 'E17:') | 583 call assert_fails('mkspell! Xtest.spl Xtest.dic', 'E17:') |
584 call delete('Xtest.spl', 'rf') | 584 call delete('Xtest.spl', 'rf') |
585 | 585 |
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 | |
586 call assert_fails('mkspell en en_US abc_xyz', 'E755:') | 593 call assert_fails('mkspell en en_US abc_xyz', 'E755:') |
587 endfunc | 594 endfunc |
588 | 595 |
589 " Tests for :mkspell with a .dic and .aff file | 596 " Tests for :mkspell with a .dic and .aff file |
590 func Test_aff_file_format_error() | 597 func Test_aff_file_format_error() |
840 call assert_fails('spellgood abc', 'E139:') | 847 call assert_fails('spellgood abc', 'E139:') |
841 set spellfile& | 848 set spellfile& |
842 %bw! | 849 %bw! |
843 endfunc | 850 endfunc |
844 | 851 |
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 | |
845 " Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN) | 893 " Test CHECKCOMPOUNDPATTERN (see :help spell-CHECKCOMPOUNDPATTERN) |
846 func Test_spellfile_CHECKCOMPOUNDPATTERN() | 894 func Test_spellfile_CHECKCOMPOUNDPATTERN() |
847 call writefile(['4', | 895 call writefile(['4', |
848 \ 'one/c', | 896 \ 'one/c', |
849 \ 'two/c', | 897 \ 'two/c', |
852 " Forbid compound words where first word ends with 'wo' and second starts with 'on'. | 900 " Forbid compound words where first word ends with 'wo' and second starts with 'on'. |
853 call writefile(['CHECKCOMPOUNDPATTERN 1', | 901 call writefile(['CHECKCOMPOUNDPATTERN 1', |
854 \ 'CHECKCOMPOUNDPATTERN wo on', | 902 \ 'CHECKCOMPOUNDPATTERN wo on', |
855 \ 'COMPOUNDFLAG c'], 'XtestCHECKCOMPOUNDPATTERN.aff') | 903 \ 'COMPOUNDFLAG c'], 'XtestCHECKCOMPOUNDPATTERN.aff') |
856 | 904 |
857 let output = execute('mkspell! XtestCHECKCOMPOUNDPATTERN-utf8.spl XtestCHECKCOMPOUNDPATTERN') | 905 mkspell! XtestCHECKCOMPOUNDPATTERN-utf8.spl XtestCHECKCOMPOUNDPATTERN |
858 set spell spelllang=XtestCHECKCOMPOUNDPATTERN-utf8.spl | 906 set spell spelllang=XtestCHECKCOMPOUNDPATTERN-utf8.spl |
859 | 907 |
860 " Check valid words with and without valid compounds. | 908 " Check valid words with and without valid compounds. |
861 for goodword in ['one', 'two', 'three', 'four', | 909 for goodword in ['one', 'two', 'three', 'four', |
862 \ 'oneone', 'onetwo', 'onethree', | 910 \ 'oneone', 'onetwo', 'onethree', |
891 \ 'tee', | 939 \ 'tee', |
892 \ 'the', | 940 \ 'the', |
893 \ 'ted'], 'XtestCOMMON.dic') | 941 \ 'ted'], 'XtestCOMMON.dic') |
894 call writefile(['COMMON the and'], 'XtestCOMMON.aff') | 942 call writefile(['COMMON the and'], 'XtestCOMMON.aff') |
895 | 943 |
896 let output = execute('mkspell! XtestCOMMON-utf8.spl XtestCOMMON') | 944 mkspell! XtestCOMMON-utf8.spl XtestCOMMON |
897 set spell spelllang=XtestCOMMON-utf8.spl | 945 set spell spelllang=XtestCOMMON-utf8.spl |
898 | 946 |
899 " COMMON words 'and' and 'the' should be the top suggestions. | 947 " COMMON words 'and' and 'the' should be the top suggestions. |
900 call assert_equal(['and', 'ant'], spellsuggest('anr', 2)) | 948 call assert_equal(['and', 'ant'], spellsuggest('anr', 2)) |
901 call assert_equal(['and', 'end'], spellsuggest('ond', 2)) | 949 call assert_equal(['and', 'end'], spellsuggest('ond', 2)) |
904 | 952 |
905 set spell& spelllang& | 953 set spell& spelllang& |
906 call delete('XtestCOMMON.dic') | 954 call delete('XtestCOMMON.dic') |
907 call delete('XtestCOMMON.aff') | 955 call delete('XtestCOMMON.aff') |
908 call delete('XtestCOMMON-utf8.spl') | 956 call delete('XtestCOMMON-utf8.spl') |
957 endfunc | |
958 | |
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') | |
909 endfunc | 1000 endfunc |
910 | 1001 |
911 " When 'spellfile' is not set, adding a new good word will automatically set | 1002 " When 'spellfile' is not set, adding a new good word will automatically set |
912 " the 'spellfile' | 1003 " the 'spellfile' |
913 func Test_init_spellfile() | 1004 func Test_init_spellfile() |