Mercurial > vim
comparison src/testdir/test_textformat.vim @ 20990:55b3849ded11 v8.2.1046
patch 8.2.1046: insufficient tests for src/buffer.c
Commit: https://github.com/vim/vim/commit/b7e2483655d9b68df0c7349918027d800051a28a
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jun 24 13:37:35 2020 +0200
patch 8.2.1046: insufficient tests for src/buffer.c
Problem: Insufficient tests for src/buffer.c.
Solution: Add more tests. Move comments related tests to a separate file.
(Yegappan Lakshmanan, closes #6325)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 24 Jun 2020 13:45:06 +0200 |
parents | 505d97ea54da |
children | 87acfcf65a2e |
comparison
equal
deleted
inserted
replaced
20989:c27f8e4ea9d7 | 20990:55b3849ded11 |
---|---|
782 | 782 |
783 set tw& fo& ai& | 783 set tw& fo& ai& |
784 bwipe! | 784 bwipe! |
785 endfunc | 785 endfunc |
786 | 786 |
787 func Test_tw_2_fo_cqm_com() | |
788 new | |
789 let t =<< trim END | |
790 { | |
791 X | |
792 Xa | |
793 XaY | |
794 XY | |
795 XYZ | |
796 X Y | |
797 X YZ | |
798 XX | |
799 XXa | |
800 XXY | |
801 } | |
802 END | |
803 call setline(1, t) | |
804 call cursor(2, 1) | |
805 | |
806 set tw=2 fo=cqm comments=n:X | |
807 exe "normal gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgq" | |
808 let t =<< trim END | |
809 X | |
810 Xa | |
811 XaY | |
812 XY | |
813 XYZ | |
814 X Y | |
815 X YZ | |
816 XX | |
817 XXa | |
818 XXY | |
819 END | |
820 exe "normal o\n" . join(t, "\n") | |
821 | |
822 let expected =<< trim END | |
823 { | |
824 X | |
825 Xa | |
826 Xa | |
827 XY | |
828 XY | |
829 XY | |
830 XZ | |
831 X Y | |
832 X Y | |
833 X Z | |
834 XX | |
835 XXa | |
836 XXY | |
837 | |
838 X | |
839 Xa | |
840 Xa | |
841 XY | |
842 XY | |
843 XY | |
844 XZ | |
845 X Y | |
846 X Y | |
847 X Z | |
848 XX | |
849 XXa | |
850 XXY | |
851 } | |
852 END | |
853 call assert_equal(expected, getline(1, '$')) | |
854 | |
855 set tw& fo& comments& | |
856 bwipe! | |
857 endfunc | |
858 | |
859 func Test_tw_2_fo_tm_replace() | 787 func Test_tw_2_fo_tm_replace() |
860 new | 788 new |
861 let t =<< trim END | 789 let t =<< trim END |
862 { | 790 { |
863 | 791 |
973 call assert_equal(expected, getline(1, '$')) | 901 call assert_equal(expected, getline(1, '$')) |
974 | 902 |
975 bwipe! | 903 bwipe! |
976 endfunc | 904 endfunc |
977 | 905 |
978 " Test for automatically adding comment leaders in insert mode | |
979 func Test_threepiece_comment() | |
980 new | |
981 setlocal expandtab | |
982 call setline(1, ["\t/*"]) | |
983 setlocal formatoptions=croql | |
984 call cursor(1, 3) | |
985 call feedkeys("A\<cr>\<cr>/", 'tnix') | |
986 call assert_equal(["\t/*", " *", " */"], getline(1, '$')) | |
987 | |
988 " If a comment ends in a single line, then don't add it in the next line | |
989 %d | |
990 call setline(1, '/* line1 */') | |
991 call feedkeys("A\<CR>next line", 'xt') | |
992 call assert_equal(['/* line1 */', 'next line'], getline(1, '$')) | |
993 | |
994 %d | |
995 " Copy the trailing indentation from the leader comment to a new line | |
996 setlocal autoindent noexpandtab | |
997 call feedkeys("a\t/*\tone\ntwo\n/", 'xt') | |
998 call assert_equal(["\t/*\tone", "\t *\ttwo", "\t */"], getline(1, '$')) | |
999 close! | |
1000 endfunc | |
1001 | |
1002 " Test for the 'f' flag in 'comments' (only the first line has the comment | |
1003 " string) | |
1004 func Test_firstline_comment() | |
1005 new | |
1006 setlocal comments=f:- fo+=ro | |
1007 exe "normal i- B\nD\<C-C>ggoC\<C-C>ggOA\<C-C>" | |
1008 call assert_equal(['A', '- B', ' C', ' D'], getline(1, '$')) | |
1009 %d | |
1010 setlocal comments=:- | |
1011 exe "normal i- B\nD\<C-C>ggoC\<C-C>ggOA\<C-C>" | |
1012 call assert_equal(['- A', '- B', '- C', '- D'], getline(1, '$')) | |
1013 %bw! | |
1014 endfunc | |
1015 | |
1016 " Test for the 'r' flag in 'comments' (right align comment) | |
1017 func Test_comment_rightalign() | |
1018 new | |
1019 setlocal comments=sr:/***,m:**,ex-2:******/ fo+=ro | |
1020 exe "normal i=\<C-C>o\t /***\nD\n/" | |
1021 exe "normal 2GOA\<C-C>joB\<C-C>jOC\<C-C>joE\<C-C>GOF\<C-C>joG" | |
1022 let expected =<< trim END | |
1023 = | |
1024 A | |
1025 /*** | |
1026 ** B | |
1027 ** C | |
1028 ** D | |
1029 ** E | |
1030 ** F | |
1031 ******/ | |
1032 G | |
1033 END | |
1034 call assert_equal(expected, getline(1, '$')) | |
1035 %bw! | |
1036 endfunc | |
1037 | |
1038 " Test for the 'b' flag in 'comments' | |
1039 func Test_comment_blank() | |
1040 new | |
1041 setlocal comments=b:* fo+=ro | |
1042 exe "normal i* E\nF\n\<BS>G\nH\<C-C>ggOC\<C-C>O\<BS>B\<C-C>OA\<C-C>2joD" | |
1043 let expected =<< trim END | |
1044 A | |
1045 *B | |
1046 * C | |
1047 * D | |
1048 * E | |
1049 * F | |
1050 *G | |
1051 H | |
1052 END | |
1053 call assert_equal(expected, getline(1, '$')) | |
1054 %bw! | |
1055 endfunc | |
1056 | |
1057 " Test for the 'n' flag in comments | |
1058 func Test_comment_nested() | |
1059 new | |
1060 setlocal comments=n:> fo+=ro | |
1061 exe "normal i> B\nD\<C-C>ggOA\<C-C>joC\<C-C>Go\<BS>>>> F\nH" | |
1062 exe "normal 5GOE\<C-C>6GoG" | |
1063 let expected =<< trim END | |
1064 > A | |
1065 > B | |
1066 > C | |
1067 > D | |
1068 >>>> E | |
1069 >>>> F | |
1070 >>>> G | |
1071 >>>> H | |
1072 END | |
1073 call assert_equal(expected, getline(1, '$')) | |
1074 %bw! | |
1075 endfunc | |
1076 | |
1077 " Test for a space character in 'comments' setting | |
1078 func Test_comment_space() | |
1079 new | |
1080 setlocal comments=b:\ > fo+=ro | |
1081 exe "normal i> B\nD\<C-C>ggOA\<C-C>joC" | |
1082 exe "normal Go > F\nH\<C-C>kOE\<C-C>joG" | |
1083 let expected =<< trim END | |
1084 A | |
1085 > B | |
1086 C | |
1087 D | |
1088 > E | |
1089 > F | |
1090 > G | |
1091 > H | |
1092 END | |
1093 call assert_equal(expected, getline(1, '$')) | |
1094 %bw! | |
1095 endfunc | |
1096 | |
1097 " Test for the 'O' flag in 'comments' | |
1098 func Test_comment_O() | |
1099 new | |
1100 setlocal comments=Ob:* fo+=ro | |
1101 exe "normal i* B\nD\<C-C>kOA\<C-C>joC" | |
1102 let expected =<< trim END | |
1103 A | |
1104 * B | |
1105 * C | |
1106 * D | |
1107 END | |
1108 call assert_equal(expected, getline(1, '$')) | |
1109 %bw! | |
1110 endfunc | |
1111 | |
1112 " Test for 'a' and 'w' flags in 'formatoptions' | 906 " Test for 'a' and 'w' flags in 'formatoptions' |
1113 func Test_fo_a_w() | 907 func Test_fo_a_w() |
1114 new | 908 new |
1115 setlocal fo+=aw tw=10 | 909 setlocal fo+=aw tw=10 |
1116 call feedkeys("iabc abc a abc\<Esc>k0weade", 'xt') | 910 call feedkeys("iabc abc a abc\<Esc>k0weade", 'xt') |
1138 normal 72ig | 932 normal 72ig |
1139 call feedkeys('a uu uu uu', 'xt') | 933 call feedkeys('a uu uu uu', 'xt') |
1140 call assert_equal('g uu uu ', getline(1)[-8:]) | 934 call assert_equal('g uu uu ', getline(1)[-8:]) |
1141 call assert_equal(['uu. foo'], getline(2, '$')) | 935 call assert_equal(['uu. foo'], getline(2, '$')) |
1142 | 936 |
1143 %bw! | |
1144 endfunc | |
1145 | |
1146 " Test for 'j' flag in 'formatoptions' | |
1147 func Test_fo_j() | |
1148 new | |
1149 setlocal fo+=j comments=:// | |
1150 call setline(1, ['i++; // comment1', ' // comment2']) | |
1151 normal J | |
1152 call assert_equal('i++; // comment1 comment2', getline(1)) | |
1153 setlocal fo-=j | |
1154 call setline(1, ['i++; // comment1', ' // comment2']) | |
1155 normal J | |
1156 call assert_equal('i++; // comment1 // comment2', getline(1)) | |
1157 " Test with nested comments | |
1158 setlocal fo+=j comments=n:>,n:) | |
1159 call setline(1, ['i++; > ) > ) comment1', ' > ) comment2']) | |
1160 normal J | |
1161 call assert_equal('i++; > ) > ) comment1 comment2', getline(1)) | |
1162 %bw! | 937 %bw! |
1163 endfunc | 938 endfunc |
1164 | 939 |
1165 " Test for formatting lines using gq in visual mode | 940 " Test for formatting lines using gq in visual mode |
1166 func Test_visual_gq_format() | 941 func Test_visual_gq_format() |
1294 \ "paragraph. second line of the", | 1069 \ "paragraph. second line of the", |
1295 \ "same paragraph. third line."], getline(1, '$')) | 1070 \ "same paragraph. third line."], getline(1, '$')) |
1296 close! | 1071 close! |
1297 endfunc | 1072 endfunc |
1298 | 1073 |
1299 " Test for formatting lines where only the first line has a comment. | |
1300 func Test_fo_gq_with_firstline_comment() | |
1301 new | |
1302 setlocal formatoptions=tcq | |
1303 call setline(1, ['- one two', 'three']) | |
1304 normal gggqG | |
1305 call assert_equal(['- one two three'], getline(1, '$')) | |
1306 | |
1307 %d | |
1308 call setline(1, ['- one', '- two']) | |
1309 normal gggqG | |
1310 call assert_equal(['- one', '- two'], getline(1, '$')) | |
1311 close! | |
1312 endfunc | |
1313 | |
1314 " Test for trying to join a comment line with a non-comment line | |
1315 func Test_join_comments() | |
1316 new | |
1317 call setline(1, ['one', '/* two */', 'three']) | |
1318 normal gggqG | |
1319 call assert_equal(['one', '/* two */', 'three'], getline(1, '$')) | |
1320 close! | |
1321 endfunc | |
1322 | |
1323 " Test for using 'a' in 'formatoptions' with comments | |
1324 func Test_autoformat_comments() | |
1325 new | |
1326 setlocal formatoptions+=a | |
1327 call feedkeys("a- one\n- two\n", 'xt') | |
1328 call assert_equal(['- one', '- two', ''], getline(1, '$')) | |
1329 | |
1330 %d | |
1331 call feedkeys("a\none\n", 'xt') | |
1332 call assert_equal(['', 'one', ''], getline(1, '$')) | |
1333 | |
1334 setlocal formatoptions+=aw | |
1335 %d | |
1336 call feedkeys("aone \ntwo\n", 'xt') | |
1337 call assert_equal(['one two', ''], getline(1, '$')) | |
1338 | |
1339 %d | |
1340 call feedkeys("aone\ntwo\n", 'xt') | |
1341 call assert_equal(['one', 'two', ''], getline(1, '$')) | |
1342 | |
1343 close! | |
1344 endfunc | |
1345 | |
1346 " vim: shiftwidth=2 sts=2 expandtab | 1074 " vim: shiftwidth=2 sts=2 expandtab |