Skip to content

Commit 51ff18e

Browse files
habamaxchrisbra
authored andcommitted
patch 9.1.1227: no tests for the comment package
Problem: no tests for the comment package Solution: add some tests (Maxim Kim). closes: #16933 Signed-off-by: Maxim Kim <habamax@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 7a5115c commit 51ff18e

3 files changed

Lines changed: 183 additions & 0 deletions

File tree

src/testdir/Make_all.mak

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ NEW_TESTS = \
239239
test_partial \
240240
test_paste \
241241
test_perl \
242+
test_plugin_comment \
242243
test_plugin_glvs \
243244
test_plugin_man \
244245
test_plugin_matchparen \
@@ -502,6 +503,7 @@ NEW_TESTS_RES = \
502503
test_partial.res \
503504
test_paste.res \
504505
test_perl.res \
506+
test_plugin_comment.res \
505507
test_plugin_glvs.res \
506508
test_plugin_man.res \
507509
test_plugin_matchparen.res \
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
source check.vim
2+
source term_util.vim
3+
4+
func Test_basic_comment()
5+
CheckScreendump
6+
let lines =<< trim END
7+
vim9script
8+
9+
def Hello()
10+
echo "Hello"
11+
enddef
12+
END
13+
14+
let input_file = "test_basic_comment_input.vim"
15+
call writefile(lines, input_file, "D")
16+
17+
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
18+
19+
call term_sendkeys(buf, "gcc")
20+
call term_sendkeys(buf, "2jgcip")
21+
let output_file = "comment_basic_test.vim"
22+
call term_sendkeys(buf, $":w {output_file}\<CR>")
23+
defer delete(output_file)
24+
25+
call StopVimInTerminal(buf)
26+
27+
let result = readfile(output_file)
28+
29+
call assert_equal(["# vim9script", "", "# def Hello()", '# echo "Hello"', "# enddef"], result)
30+
endfunc
31+
32+
33+
func Test_basic_uncomment()
34+
CheckScreendump
35+
let lines =<< trim END
36+
vim9script
37+
38+
# def Hello()
39+
# echo "Hello"
40+
# enddef
41+
END
42+
43+
let input_file = "test_basic_uncomment_input.vim"
44+
call writefile(lines, input_file, "D")
45+
46+
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
47+
48+
call term_sendkeys(buf, "gcc")
49+
call term_sendkeys(buf, "2jgcip")
50+
let output_file = "uncomment_basic_test.vim"
51+
call term_sendkeys(buf, $":w {output_file}\<CR>")
52+
defer delete(output_file)
53+
54+
call StopVimInTerminal(buf)
55+
56+
let result = readfile(output_file)
57+
58+
call assert_equal(["# vim9script", "", "def Hello()", ' echo "Hello"', "enddef"], result)
59+
endfunc
60+
61+
func Test_bothends_comment()
62+
CheckScreendump
63+
let lines =<< trim END
64+
int main() {}
65+
END
66+
67+
let input_file = "test_bothends_comment_input.c"
68+
call writefile(lines, input_file, "D")
69+
70+
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
71+
72+
call term_sendkeys(buf, "gcc")
73+
let output_file = "comment_bothends_test.c"
74+
call term_sendkeys(buf, $":w {output_file}\<CR>")
75+
defer delete(output_file)
76+
77+
call StopVimInTerminal(buf)
78+
79+
let result = readfile(output_file)
80+
81+
call assert_equal(["/* int main() {} */"], result)
82+
endfunc
83+
84+
func Test_bothends_uncomment()
85+
CheckScreendump
86+
let lines =<< trim END
87+
/* int main() { */
88+
/* return 0; */
89+
/* } */
90+
END
91+
92+
let input_file = "test_bothends_uncomment_input.c"
93+
call writefile(lines, input_file, "D")
94+
95+
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
96+
97+
call term_sendkeys(buf, "gcip")
98+
let output_file = "uncomment_bothends_test.c"
99+
call term_sendkeys(buf, $":w {output_file}\<CR>")
100+
defer delete(output_file)
101+
102+
call StopVimInTerminal(buf)
103+
104+
let result = readfile(output_file)
105+
106+
call assert_equal(["int main() {", " return 0;", "}"], result)
107+
endfunc
108+
109+
110+
func Test_mixed_comment()
111+
CheckScreendump
112+
let lines =<< trim END
113+
for x in range(10):
114+
# print(x)
115+
# print(x*x)
116+
END
117+
118+
let input_file = "test_mixed_comment_input.py"
119+
call writefile(lines, input_file, "D")
120+
121+
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
122+
123+
call term_sendkeys(buf, "gcG")
124+
let output_file = "comment_mixed_test.py"
125+
call term_sendkeys(buf, $":w {output_file}\<CR>")
126+
defer delete(output_file)
127+
128+
call StopVimInTerminal(buf)
129+
130+
let result = readfile(output_file)
131+
132+
call assert_equal(["# for x in range(10):", "# # print(x)", "# # print(x*x)"], result)
133+
endfunc
134+
135+
func Test_mixed_comment2()
136+
CheckScreendump
137+
let lines =<< trim END
138+
# for x in range(10):
139+
print(x)
140+
# print(x*x)
141+
END
142+
143+
let input_file = "test_mixed_comment_input2.py"
144+
call writefile(lines, input_file, "D")
145+
146+
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
147+
148+
call term_sendkeys(buf, "gcG")
149+
let output_file = "comment_mixed_test2.py"
150+
call term_sendkeys(buf, $":w {output_file}\<CR>")
151+
defer delete(output_file)
152+
153+
call StopVimInTerminal(buf)
154+
155+
let result = readfile(output_file)
156+
157+
call assert_equal(["# # for x in range(10):", "# print(x)", "# # print(x*x)"], result)
158+
endfunc
159+
160+
func Test_mixed_indent_comment()
161+
CheckScreendump
162+
let lines = ["int main() {", "\tif 1 {", "\t return 0;", "\t}", " return 1;", "}"]
163+
164+
let input_file = "test_mixed_indent_comment_input.c"
165+
call writefile(lines, input_file, "D")
166+
167+
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
168+
169+
call term_sendkeys(buf, "gcip")
170+
let output_file = "comment_mixed_indent_test.c"
171+
call term_sendkeys(buf, $":w {output_file}\<CR>")
172+
defer delete(output_file)
173+
174+
call StopVimInTerminal(buf)
175+
176+
let result = readfile(output_file)
177+
178+
call assert_equal(["/* int main() { */", "\t/* if 1 { */", "\t /* return 0; */", "\t/* } */", " /* return 1; */", "/* } */"], result)
179+
endfunc

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1227,
707709
/**/
708710
1226,
709711
/**/

0 commit comments

Comments
 (0)