Maxim Kim | aa68f8a | 2025-03-28 19:17:53 +0100 | [diff] [blame] | 1 | " Test for the comment package |
| 2 | |
Maxim Kim | 51ff18e | 2025-03-19 20:54:12 +0100 | [diff] [blame] | 3 | source check.vim |
| 4 | source term_util.vim |
| 5 | |
| 6 | func Test_basic_comment() |
| 7 | CheckScreendump |
| 8 | let lines =<< trim END |
| 9 | vim9script |
| 10 | |
| 11 | def Hello() |
| 12 | echo "Hello" |
| 13 | enddef |
| 14 | END |
| 15 | |
| 16 | let input_file = "test_basic_comment_input.vim" |
| 17 | call writefile(lines, input_file, "D") |
| 18 | |
| 19 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 20 | |
| 21 | call term_sendkeys(buf, "gcc") |
| 22 | call term_sendkeys(buf, "2jgcip") |
| 23 | let output_file = "comment_basic_test.vim" |
| 24 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 25 | defer delete(output_file) |
| 26 | |
| 27 | call StopVimInTerminal(buf) |
| 28 | |
| 29 | let result = readfile(output_file) |
| 30 | |
| 31 | call assert_equal(["# vim9script", "", "# def Hello()", '# echo "Hello"', "# enddef"], result) |
| 32 | endfunc |
| 33 | |
Maxim Kim | 51ff18e | 2025-03-19 20:54:12 +0100 | [diff] [blame] | 34 | func Test_basic_uncomment() |
| 35 | CheckScreendump |
| 36 | let lines =<< trim END |
| 37 | vim9script |
| 38 | |
| 39 | # def Hello() |
| 40 | # echo "Hello" |
| 41 | # enddef |
| 42 | END |
| 43 | |
| 44 | let input_file = "test_basic_uncomment_input.vim" |
| 45 | call writefile(lines, input_file, "D") |
| 46 | |
| 47 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 48 | |
| 49 | call term_sendkeys(buf, "gcc") |
| 50 | call term_sendkeys(buf, "2jgcip") |
| 51 | let output_file = "uncomment_basic_test.vim" |
| 52 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 53 | defer delete(output_file) |
| 54 | |
| 55 | call StopVimInTerminal(buf) |
| 56 | |
| 57 | let result = readfile(output_file) |
| 58 | |
Maxim Kim | 9712a25 | 2025-03-21 18:02:56 +0100 | [diff] [blame] | 59 | call assert_equal(["# vim9script", "", "def Hello()", ' echo "Hello"', "enddef"], result) |
Maxim Kim | 51ff18e | 2025-03-19 20:54:12 +0100 | [diff] [blame] | 60 | endfunc |
| 61 | |
| 62 | func Test_bothends_comment() |
| 63 | CheckScreendump |
| 64 | let lines =<< trim END |
| 65 | int main() {} |
| 66 | END |
| 67 | |
| 68 | let input_file = "test_bothends_comment_input.c" |
| 69 | call writefile(lines, input_file, "D") |
| 70 | |
| 71 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 72 | |
| 73 | call term_sendkeys(buf, "gcc") |
| 74 | let output_file = "comment_bothends_test.c" |
| 75 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 76 | defer delete(output_file) |
| 77 | |
| 78 | call StopVimInTerminal(buf) |
| 79 | |
| 80 | let result = readfile(output_file) |
| 81 | |
| 82 | call assert_equal(["/* int main() {} */"], result) |
| 83 | endfunc |
| 84 | |
| 85 | func Test_bothends_uncomment() |
| 86 | CheckScreendump |
| 87 | let lines =<< trim END |
| 88 | /* int main() { */ |
| 89 | /* return 0; */ |
| 90 | /* } */ |
| 91 | END |
| 92 | |
| 93 | let input_file = "test_bothends_uncomment_input.c" |
| 94 | call writefile(lines, input_file, "D") |
| 95 | |
| 96 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 97 | |
| 98 | call term_sendkeys(buf, "gcip") |
| 99 | let output_file = "uncomment_bothends_test.c" |
| 100 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 101 | defer delete(output_file) |
| 102 | |
| 103 | call StopVimInTerminal(buf) |
| 104 | |
| 105 | let result = readfile(output_file) |
| 106 | |
| 107 | call assert_equal(["int main() {", " return 0;", "}"], result) |
| 108 | endfunc |
| 109 | |
Maxim Kim | 51ff18e | 2025-03-19 20:54:12 +0100 | [diff] [blame] | 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 |
Maxim Kim | 9712a25 | 2025-03-21 18:02:56 +0100 | [diff] [blame] | 180 | |
Maxim Kim | aa68f8a | 2025-03-28 19:17:53 +0100 | [diff] [blame] | 181 | func Test_buffer_first_col_comment() |
| 182 | CheckScreendump |
| 183 | let lines =<< trim END |
| 184 | def Hello(): |
| 185 | print("Hello") |
| 186 | pass |
| 187 | END |
| 188 | |
| 189 | let input_file = "test_first_col_comment_input.py" |
| 190 | call writefile(lines, input_file, "D") |
| 191 | |
| 192 | let buf = RunVimInTerminal('-c "packadd comment" -c "let b:comment_first_col=1" ' .. input_file, {}) |
| 193 | |
| 194 | call term_sendkeys(buf, "jgcc") |
| 195 | let output_file = "comment_first_col_test.py" |
| 196 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 197 | defer delete(output_file) |
| 198 | |
| 199 | call StopVimInTerminal(buf) |
| 200 | |
| 201 | let result = readfile(output_file) |
| 202 | |
| 203 | call assert_equal(["def Hello():", '# print("Hello")', " pass"], result) |
| 204 | endfunc |
| 205 | |
| 206 | func Test_global_first_col_comment() |
| 207 | CheckScreendump |
| 208 | let lines =<< trim END |
| 209 | def Hello(): |
| 210 | print("Hello") |
| 211 | pass |
| 212 | END |
| 213 | |
| 214 | let input_file = "test_first_col_comment_input.py" |
| 215 | call writefile(lines, input_file, "D") |
| 216 | |
| 217 | let buf = RunVimInTerminal('-c "packadd comment" -c "let g:comment_first_col=1" ' .. input_file, {}) |
| 218 | |
| 219 | call term_sendkeys(buf, "jgcj") |
| 220 | let output_file = "comment_first_col_test.py" |
| 221 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 222 | defer delete(output_file) |
| 223 | |
| 224 | call StopVimInTerminal(buf) |
| 225 | |
| 226 | let result = readfile(output_file) |
| 227 | |
| 228 | call assert_equal(["def Hello():", '# print("Hello")', "# pass"], result) |
| 229 | endfunc |
| 230 | |
Maxim Kim | 9712a25 | 2025-03-21 18:02:56 +0100 | [diff] [blame] | 231 | func Test_textobj_icomment() |
| 232 | CheckScreendump |
| 233 | let lines =<< trim END |
| 234 | for x in range(10): |
| 235 | print(x) # printing stuff |
| 236 | # print(x*x) |
| 237 | #print(x*x*x) |
| 238 | print(x*x*x*x) # printing stuff |
| 239 | print(x*x*x*x*x) # printing stuff |
| 240 | # print(x*x) |
| 241 | #print(x*x*x) |
| 242 | |
| 243 | print(x*x*x*x*x) |
| 244 | END |
| 245 | |
| 246 | let input_file = "test_textobj_icomment_input.py" |
| 247 | call writefile(lines, input_file, "D") |
| 248 | |
| 249 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 250 | |
| 251 | call term_sendkeys(buf, "dic..") |
| 252 | let output_file = "comment_textobj_icomment.py" |
| 253 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 254 | defer delete(output_file) |
| 255 | |
| 256 | call StopVimInTerminal(buf) |
| 257 | |
| 258 | let result = readfile(output_file) |
| 259 | |
| 260 | call assert_equal(["for x in range(10):", " print(x) ", " print(x*x*x*x) ", " print(x*x*x*x*x) ", "", " print(x*x*x*x*x)"], result) |
| 261 | endfunc |
| 262 | |
| 263 | func Test_textobj_icomment2() |
| 264 | CheckScreendump |
| 265 | let lines =<< trim END |
| 266 | #include <stdio.h> |
| 267 | |
| 268 | int main() { |
| 269 | printf("hello"); /* hello world */ printf(" world\n"); |
| 270 | /* if 1 { |
| 271 | return 1; |
| 272 | }*/ |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | END |
| 277 | |
| 278 | let input_file = "test_textobj_icomment2_input.c" |
| 279 | call writefile(lines, input_file, "D") |
| 280 | |
| 281 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 282 | |
| 283 | call term_sendkeys(buf, "dic..") |
| 284 | let output_file = "comment_textobj_icomment2.c" |
| 285 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 286 | defer delete(output_file) |
| 287 | |
| 288 | call StopVimInTerminal(buf) |
| 289 | |
| 290 | let result = readfile(output_file) |
| 291 | |
| 292 | call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\"); printf(\" world\\n\");", " ", "", " return 0;", "}"], result) |
| 293 | endfunc |
| 294 | |
| 295 | func Test_textobj_icomment3() |
| 296 | CheckScreendump |
| 297 | let lines =<< trim END |
| 298 | #include <stdio.h> |
| 299 | |
| 300 | int main() { |
| 301 | printf("hello");/*hello world*/printf(" world\n"); |
| 302 | return 0; |
| 303 | } |
| 304 | END |
| 305 | |
| 306 | let input_file = "test_textobj_icomment3_input.c" |
| 307 | call writefile(lines, input_file, "D") |
| 308 | |
| 309 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 310 | |
| 311 | call term_sendkeys(buf, "jjjdic") |
| 312 | let output_file = "comment_textobj_icomment3.c" |
| 313 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 314 | defer delete(output_file) |
| 315 | |
| 316 | call StopVimInTerminal(buf) |
| 317 | |
| 318 | let result = readfile(output_file) |
| 319 | |
| 320 | call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\");printf(\" world\\n\");", " return 0;", "}"], result) |
| 321 | endfunc |
| 322 | |
| 323 | func Test_textobj_acomment() |
| 324 | CheckScreendump |
| 325 | let lines =<< trim END |
| 326 | for x in range(10): |
| 327 | print(x) # printing stuff |
| 328 | # print(x*x) |
| 329 | #print(x*x*x) |
| 330 | print(x*x*x*x) # printing stuff |
| 331 | print(x*x*x*x*x) # printing stuff |
| 332 | # print(x*x) |
| 333 | #print(x*x*x) |
| 334 | |
| 335 | print(x*x*x*x*x) |
| 336 | END |
| 337 | |
| 338 | let input_file = "test_textobj_acomment_input.py" |
| 339 | call writefile(lines, input_file, "D") |
| 340 | |
| 341 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 342 | |
| 343 | call term_sendkeys(buf, "dac..") |
| 344 | let output_file = "comment_textobj_acomment.py" |
| 345 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 346 | defer delete(output_file) |
| 347 | |
| 348 | call StopVimInTerminal(buf) |
| 349 | |
| 350 | let result = readfile(output_file) |
| 351 | |
| 352 | call assert_equal(["for x in range(10):", " print(x)", " print(x*x*x*x)", " print(x*x*x*x*x)", "", " print(x*x*x*x*x)"], result) |
| 353 | endfunc |
| 354 | |
| 355 | func Test_textobj_acomment2() |
| 356 | CheckScreendump |
| 357 | let lines =<< trim END |
| 358 | #include <stdio.h> |
| 359 | |
| 360 | int main() { |
| 361 | printf("hello"); /* hello world */ printf(" world\n"); |
| 362 | /* if 1 { |
| 363 | return 1; |
| 364 | }*/ |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | END |
| 369 | |
| 370 | let input_file = "test_textobj_acomment2_input.c" |
| 371 | call writefile(lines, input_file, "D") |
| 372 | |
| 373 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 374 | |
| 375 | call term_sendkeys(buf, "dac.") |
| 376 | let output_file = "comment_textobj_acomment2.c" |
| 377 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 378 | defer delete(output_file) |
| 379 | |
| 380 | call StopVimInTerminal(buf) |
| 381 | |
| 382 | let result = readfile(output_file) |
| 383 | |
| 384 | call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\");printf(\" world\\n\");", " return 0;", "}"], result) |
| 385 | endfunc |
| 386 | |
| 387 | func Test_textobj_acomment3() |
| 388 | CheckScreendump |
| 389 | let lines =<< trim END |
| 390 | #include <stdio.h> |
| 391 | |
| 392 | int main() { |
| 393 | printf("hello");/*hello world*/printf(" world\n"); |
| 394 | return 0; |
| 395 | } |
| 396 | END |
| 397 | |
| 398 | let input_file = "test_textobj_acomment3_input.c" |
| 399 | call writefile(lines, input_file, "D") |
| 400 | |
| 401 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 402 | |
| 403 | call term_sendkeys(buf, "jjjdac") |
| 404 | let output_file = "comment_textobj_acomment3.c" |
| 405 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 406 | defer delete(output_file) |
| 407 | |
| 408 | call StopVimInTerminal(buf) |
| 409 | |
| 410 | let result = readfile(output_file) |
| 411 | |
| 412 | call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\");printf(\" world\\n\");", " return 0;", "}"], result) |
| 413 | endfunc |
| 414 | |
| 415 | func Test_textobj_firstline_comment() |
| 416 | CheckScreendump |
| 417 | let lines =<< trim END |
| 418 | /*#include <stdio.h>*/ |
| 419 | |
| 420 | int main() {} |
| 421 | END |
| 422 | |
| 423 | let input_file = "test_textobj_firstlinecomment_input.c" |
| 424 | call writefile(lines, input_file, "D") |
| 425 | |
| 426 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 427 | |
| 428 | call term_sendkeys(buf, "dac") |
| 429 | let output_file = "comment_textobj_firstline_comment.c" |
| 430 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 431 | defer delete(output_file) |
| 432 | |
| 433 | call StopVimInTerminal(buf) |
| 434 | |
| 435 | let result = readfile(output_file) |
| 436 | |
| 437 | call assert_equal(["int main() {}"], result) |
| 438 | endfunc |
| 439 | |
| 440 | func Test_textobj_noleading_space_comment() |
| 441 | CheckScreendump |
| 442 | let lines =<< trim END |
| 443 | int main() {// main start |
| 444 | }/* main end */ |
| 445 | END |
| 446 | |
| 447 | let input_file = "test_textobj_noleading_space_input.c" |
| 448 | call writefile(lines, input_file, "D") |
| 449 | |
| 450 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 451 | |
| 452 | call term_sendkeys(buf, "dacdic") |
| 453 | let output_file = "comment_textobj_noleading_space_comment.c" |
| 454 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 455 | defer delete(output_file) |
| 456 | |
| 457 | call StopVimInTerminal(buf) |
| 458 | |
| 459 | let result = readfile(output_file) |
| 460 | |
| 461 | call assert_equal(["int main() {", "}"], result) |
| 462 | endfunc |
| 463 | |
| 464 | func Test_textobj_noleading_space_comment2() |
| 465 | CheckScreendump |
| 466 | let lines =<< trim END |
| 467 | int main() {// main start |
| 468 | } /* main end */ |
| 469 | END |
| 470 | |
| 471 | let input_file = "test_textobj_noleading_space_input2.c" |
| 472 | call writefile(lines, input_file, "D") |
| 473 | |
| 474 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 475 | |
| 476 | call term_sendkeys(buf, "dac.") |
| 477 | let output_file = "comment_textobj_noleading_space_comment2.c" |
| 478 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 479 | defer delete(output_file) |
| 480 | |
| 481 | call StopVimInTerminal(buf) |
| 482 | |
| 483 | let result = readfile(output_file) |
| 484 | |
| 485 | call assert_equal(["int main() {", "}"], result) |
| 486 | endfunc |
| 487 | |
| 488 | func Test_textobj_cursor_on_leading_space_comment() |
| 489 | CheckScreendump |
| 490 | let lines =<< trim END |
| 491 | int main() { |
| 492 | // multilple comments |
| 493 | // cursor is between them |
| 494 | } |
| 495 | END |
| 496 | |
| 497 | let input_file = "test_textobj_cursor_on_leading_space_comment_input.c" |
| 498 | call writefile(lines, input_file, "D") |
| 499 | |
| 500 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 501 | |
| 502 | call term_sendkeys(buf, "jjdac") |
| 503 | let output_file = "comment_textobj_cursor_on_leading_space_comment.c" |
| 504 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 505 | defer delete(output_file) |
| 506 | |
| 507 | call StopVimInTerminal(buf) |
| 508 | |
| 509 | let result = readfile(output_file) |
| 510 | |
Maxim Kim | 08283b2 | 2025-03-26 19:04:20 +0100 | [diff] [blame] | 511 | call assert_equal(["int main() {", "}"], result) |
Maxim Kim | 9712a25 | 2025-03-21 18:02:56 +0100 | [diff] [blame] | 512 | endfunc |
| 513 | |
| 514 | func Test_textobj_conseq_comment() |
| 515 | CheckScreendump |
| 516 | let lines =<< trim END |
| 517 | int main() { |
| 518 | printf("hello"); // hello |
| 519 | // world |
| 520 | printf("world"); |
| 521 | } |
| 522 | END |
| 523 | |
| 524 | let input_file = "test_textobj_conseq_comment_input.c" |
| 525 | call writefile(lines, input_file, "D") |
| 526 | |
| 527 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 528 | |
| 529 | call term_sendkeys(buf, "dac") |
| 530 | let output_file = "comment_textobj_conseq_comment.c" |
| 531 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 532 | defer delete(output_file) |
| 533 | |
| 534 | call StopVimInTerminal(buf) |
| 535 | |
| 536 | let result = readfile(output_file) |
| 537 | |
| 538 | call assert_equal(["int main() {", " printf(\"hello\");", " printf(\"world\");", "}"], result) |
| 539 | endfunc |
| 540 | |
| 541 | func Test_textobj_conseq_comment2() |
| 542 | CheckScreendump |
| 543 | let lines =<< trim END |
| 544 | int main() { |
| 545 | printf("hello"); // hello |
| 546 | |
| 547 | // world |
| 548 | printf("world"); |
| 549 | } |
| 550 | END |
| 551 | |
| 552 | let input_file = "test_textobj_conseq_comment_input2.c" |
| 553 | call writefile(lines, input_file, "D") |
| 554 | |
| 555 | let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) |
| 556 | |
| 557 | call term_sendkeys(buf, "dac") |
| 558 | let output_file = "comment_textobj_conseq_comment2.c" |
| 559 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 560 | defer delete(output_file) |
| 561 | |
| 562 | call StopVimInTerminal(buf) |
| 563 | |
| 564 | let result = readfile(output_file) |
| 565 | |
| 566 | call assert_equal(["int main() {", " printf(\"hello\");", "", " // world", " printf(\"world\");", "}"], result) |
| 567 | endfunc |
Maxim Kim | 08283b2 | 2025-03-26 19:04:20 +0100 | [diff] [blame] | 568 | |
| 569 | func Test_inline_comment() |
| 570 | CheckScreendump |
| 571 | let lines =<< trim END |
| 572 | echo "Hello" This should be a comment |
| 573 | END |
| 574 | |
| 575 | let input_file = "test_inline_comment_input.vim" |
| 576 | call writefile(lines, input_file, "D") |
| 577 | |
| 578 | let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap <expr> gC comment#Toggle()..''$''" ' .. input_file, {}) |
| 579 | |
| 580 | call term_sendkeys(buf, "fTgC") |
| 581 | |
| 582 | let output_file = "comment_inline_test.vim" |
| 583 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 584 | defer delete(output_file) |
| 585 | |
| 586 | call StopVimInTerminal(buf) |
| 587 | |
| 588 | let result = readfile(output_file) |
| 589 | call assert_equal(['echo "Hello" " This should be a comment'], result) |
| 590 | endfunc |
| 591 | |
| 592 | func Test_inline_uncomment() |
| 593 | CheckScreendump |
| 594 | let lines =<< trim END |
| 595 | echo "Hello" " This should be a comment |
| 596 | END |
| 597 | |
| 598 | let input_file = "test_inline_uncomment_input.vim" |
| 599 | call writefile(lines, input_file, "D") |
| 600 | |
| 601 | let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap <expr> gC comment#Toggle()..''$''" ' .. input_file, {}) |
| 602 | |
| 603 | call term_sendkeys(buf, '$F"gC') |
| 604 | |
| 605 | let output_file = "uncomment_inline_test.vim" |
| 606 | call term_sendkeys(buf, $":w {output_file}\<CR>") |
| 607 | defer delete(output_file) |
| 608 | |
| 609 | call StopVimInTerminal(buf) |
| 610 | |
| 611 | let result = readfile(output_file) |
| 612 | call assert_equal(['echo "Hello" This should be a comment'], result) |
| 613 | endfunc |