blob: 8e877acdb4a5065b510d3bf46547c3074dbe951a [file] [log] [blame]
Maxim Kim51ff18e2025-03-19 20:54:12 +01001source check.vim
2source term_util.vim
3
4func 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)
30endfunc
31
32
33func 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)
59endfunc
60
61func 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)
82endfunc
83
84func 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)
107endfunc
108
109
110func 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)
133endfunc
134
135func 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)
158endfunc
159
160func 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)
179endfunc