patch 9.1.1536: tests: test_plugin_comment uses wrong :Check command

Problem:  tests: test_plugin_comment.vim uses :CheckScreenDump check but
          doesn't actually use a screen dump.
Solution: Use :CheckRunVimInTerminal instead, remove a few empty lines.

test_plugin_comment.vim uses :CheckScreenDump to test for the screen
dump feature in each single test case.

However, since we are not actually using any screen dumps, it would be
more correct to use :CheckRunVimInTerminal, since this is the actual
command that we want to run.

And instead of verifying this for each single test, let's just do it
once when sourcing the file. While doing this, also remove some white
spaces.

closes: #17711

Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt
2025-07-10 20:40:09 +02:00
parent b7b7fa04bf
commit 48d7f5b5a3
2 changed files with 3 additions and 113 deletions

View File

@ -1,7 +1,7 @@
" Test for the comment package " Test for the comment package
CheckRunVimInTerminal
func Test_basic_comment() func Test_basic_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
vim9script vim9script
@ -14,7 +14,6 @@ func Test_basic_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcc") call term_sendkeys(buf, "gcc")
call term_sendkeys(buf, "2jgcip") call term_sendkeys(buf, "2jgcip")
let output_file = "comment_basic_test.vim" let output_file = "comment_basic_test.vim"
@ -22,14 +21,11 @@ func Test_basic_comment()
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["# vim9script", "", "# def Hello()", '# echo "Hello"', "# enddef"], result) call assert_equal(["# vim9script", "", "# def Hello()", '# echo "Hello"', "# enddef"], result)
endfunc endfunc
func Test_basic_uncomment() func Test_basic_uncomment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
vim9script vim9script
@ -42,7 +38,6 @@ func Test_basic_uncomment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcc") call term_sendkeys(buf, "gcc")
call term_sendkeys(buf, "2jgcip") call term_sendkeys(buf, "2jgcip")
let output_file = "uncomment_basic_test.vim" let output_file = "uncomment_basic_test.vim"
@ -50,15 +45,12 @@ func Test_basic_uncomment()
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["# vim9script", "", "def Hello()", ' echo "Hello"', "enddef"], result) call assert_equal(["# vim9script", "", "def Hello()", ' echo "Hello"', "enddef"], result)
endfunc endfunc
func Test_backward_slash_uncomment() func Test_backward_slash_uncomment()
" Note this test depends on 'commentstring' setting in nroff ftplugin " Note this test depends on 'commentstring' setting in nroff ftplugin
CheckScreendump
let lines =<< trim END let lines =<< trim END
.\" .TL Test backward slash uncomment .\" .TL Test backward slash uncomment
END END
@ -67,21 +59,17 @@ func Test_backward_slash_uncomment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcc") call term_sendkeys(buf, "gcc")
let output_file = "backward_slash_uncomment_test.mom" let output_file = "backward_slash_uncomment_test.mom"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal([".TL Test backward slash uncomment"], result) call assert_equal([".TL Test backward slash uncomment"], result)
endfunc endfunc
func Test_caseinsensitive_uncomment() func Test_caseinsensitive_uncomment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
rem echo "Hello" rem echo "Hello"
END END
@ -90,21 +78,17 @@ func Test_caseinsensitive_uncomment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcc") call term_sendkeys(buf, "gcc")
let output_file = "comment_testinsensitive_uncomment_test.bat" let output_file = "comment_testinsensitive_uncomment_test.bat"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(['echo "Hello"'], result) call assert_equal(['echo "Hello"'], result)
endfunc endfunc
func Test_bothends_comment() func Test_bothends_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
int main() {} int main() {}
END END
@ -113,21 +97,17 @@ func Test_bothends_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcc") call term_sendkeys(buf, "gcc")
let output_file = "comment_bothends_test.c" let output_file = "comment_bothends_test.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["/* int main() {} */"], result) call assert_equal(["/* int main() {} */"], result)
endfunc endfunc
func Test_bothends_uncomment() func Test_bothends_uncomment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
/* int main() { */ /* int main() { */
/* return 0; */ /* return 0; */
@ -138,21 +118,17 @@ func Test_bothends_uncomment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcip") call term_sendkeys(buf, "gcip")
let output_file = "uncomment_bothends_test.c" let output_file = "uncomment_bothends_test.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["int main() {", " return 0;", "}"], result) call assert_equal(["int main() {", " return 0;", "}"], result)
endfunc endfunc
func Test_mixed_comment() func Test_mixed_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
for x in range(10): for x in range(10):
# print(x) # print(x)
@ -163,21 +139,17 @@ func Test_mixed_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcG") call term_sendkeys(buf, "gcG")
let output_file = "comment_mixed_test.py" let output_file = "comment_mixed_test.py"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["# for x in range(10):", "# # print(x)", "# # print(x*x)"], result) call assert_equal(["# for x in range(10):", "# # print(x)", "# # print(x*x)"], result)
endfunc endfunc
func Test_mixed_comment2() func Test_mixed_comment2()
CheckScreendump
let lines =<< trim END let lines =<< trim END
# for x in range(10): # for x in range(10):
print(x) print(x)
@ -188,42 +160,34 @@ func Test_mixed_comment2()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcG") call term_sendkeys(buf, "gcG")
let output_file = "comment_mixed_test2.py" let output_file = "comment_mixed_test2.py"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["# # for x in range(10):", "# print(x)", "# # print(x*x)"], result) call assert_equal(["# # for x in range(10):", "# print(x)", "# # print(x*x)"], result)
endfunc endfunc
func Test_mixed_indent_comment() func Test_mixed_indent_comment()
CheckScreendump
let lines = ["int main() {", "\tif 1 {", "\t return 0;", "\t}", " return 1;", "}"] let lines = ["int main() {", "\tif 1 {", "\t return 0;", "\t}", " return 1;", "}"]
let input_file = "test_mixed_indent_comment_input.c" let input_file = "test_mixed_indent_comment_input.c"
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcip") call term_sendkeys(buf, "gcip")
let output_file = "comment_mixed_indent_test.c" let output_file = "comment_mixed_indent_test.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["/* int main() { */", "\t/* if 1 { */", "\t /* return 0; */", "\t/* } */", " /* return 1; */", "/* } */"], result) call assert_equal(["/* int main() { */", "\t/* if 1 { */", "\t /* return 0; */", "\t/* } */", " /* return 1; */", "/* } */"], result)
endfunc endfunc
func Test_buffer_first_col_comment() func Test_buffer_first_col_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
def Hello(): def Hello():
print("Hello") print("Hello")
@ -234,21 +198,17 @@ func Test_buffer_first_col_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" -c "let b:comment_first_col=1" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" -c "let b:comment_first_col=1" ' .. input_file, {})
call term_sendkeys(buf, "jgcc") call term_sendkeys(buf, "jgcc")
let output_file = "comment_first_col_test.py" let output_file = "comment_first_col_test.py"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["def Hello():", '# print("Hello")', " pass"], result) call assert_equal(["def Hello():", '# print("Hello")', " pass"], result)
endfunc endfunc
func Test_global_first_col_comment() func Test_global_first_col_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
def Hello(): def Hello():
print("Hello") print("Hello")
@ -259,21 +219,17 @@ func Test_global_first_col_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" -c "let g:comment_first_col=1" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" -c "let g:comment_first_col=1" ' .. input_file, {})
call term_sendkeys(buf, "jgcj") call term_sendkeys(buf, "jgcj")
let output_file = "comment_first_col_test.py" let output_file = "comment_first_col_test.py"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["def Hello():", '# print("Hello")', "# pass"], result) call assert_equal(["def Hello():", '# print("Hello")', "# pass"], result)
endfunc endfunc
func Test_textobj_icomment() func Test_textobj_icomment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
for x in range(10): for x in range(10):
print(x) # printing stuff print(x) # printing stuff
@ -291,21 +247,17 @@ func Test_textobj_icomment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dic..") call term_sendkeys(buf, "dic..")
let output_file = "comment_textobj_icomment.py" let output_file = "comment_textobj_icomment.py"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
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) 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)
endfunc endfunc
func Test_textobj_icomment2() func Test_textobj_icomment2()
CheckScreendump
let lines =<< trim END let lines =<< trim END
#include <stdio.h> #include <stdio.h>
@ -323,21 +275,17 @@ func Test_textobj_icomment2()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dic..") call term_sendkeys(buf, "dic..")
let output_file = "comment_textobj_icomment2.c" let output_file = "comment_textobj_icomment2.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\"); printf(\" world\\n\");", " ", "", " return 0;", "}"], result) call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\"); printf(\" world\\n\");", " ", "", " return 0;", "}"], result)
endfunc endfunc
func Test_textobj_icomment3() func Test_textobj_icomment3()
CheckScreendump
let lines =<< trim END let lines =<< trim END
#include <stdio.h> #include <stdio.h>
@ -351,21 +299,17 @@ func Test_textobj_icomment3()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "jjjdic") call term_sendkeys(buf, "jjjdic")
let output_file = "comment_textobj_icomment3.c" let output_file = "comment_textobj_icomment3.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\");printf(\" world\\n\");", " return 0;", "}"], result) call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\");printf(\" world\\n\");", " return 0;", "}"], result)
endfunc endfunc
func Test_textobj_acomment() func Test_textobj_acomment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
for x in range(10): for x in range(10):
print(x) # printing stuff print(x) # printing stuff
@ -383,21 +327,17 @@ func Test_textobj_acomment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dac..") call term_sendkeys(buf, "dac..")
let output_file = "comment_textobj_acomment.py" let output_file = "comment_textobj_acomment.py"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
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) 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)
endfunc endfunc
func Test_textobj_acomment2() func Test_textobj_acomment2()
CheckScreendump
let lines =<< trim END let lines =<< trim END
#include <stdio.h> #include <stdio.h>
@ -415,21 +355,17 @@ func Test_textobj_acomment2()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dac.") call term_sendkeys(buf, "dac.")
let output_file = "comment_textobj_acomment2.c" let output_file = "comment_textobj_acomment2.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\");printf(\" world\\n\");", " return 0;", "}"], result) call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\");printf(\" world\\n\");", " return 0;", "}"], result)
endfunc endfunc
func Test_textobj_acomment3() func Test_textobj_acomment3()
CheckScreendump
let lines =<< trim END let lines =<< trim END
#include <stdio.h> #include <stdio.h>
@ -443,21 +379,17 @@ func Test_textobj_acomment3()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "jjjdac") call term_sendkeys(buf, "jjjdac")
let output_file = "comment_textobj_acomment3.c" let output_file = "comment_textobj_acomment3.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\");printf(\" world\\n\");", " return 0;", "}"], result) call assert_equal(["#include <stdio.h>", "", "int main() {", " printf(\"hello\");printf(\" world\\n\");", " return 0;", "}"], result)
endfunc endfunc
func Test_textobj_firstline_comment() func Test_textobj_firstline_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
/*#include <stdio.h>*/ /*#include <stdio.h>*/
@ -468,21 +400,17 @@ func Test_textobj_firstline_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dac") call term_sendkeys(buf, "dac")
let output_file = "comment_textobj_firstline_comment.c" let output_file = "comment_textobj_firstline_comment.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["int main() {}"], result) call assert_equal(["int main() {}"], result)
endfunc endfunc
func Test_textobj_noleading_space_comment() func Test_textobj_noleading_space_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
int main() {// main start int main() {// main start
}/* main end */ }/* main end */
@ -492,21 +420,17 @@ func Test_textobj_noleading_space_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dacdic") call term_sendkeys(buf, "dacdic")
let output_file = "comment_textobj_noleading_space_comment.c" let output_file = "comment_textobj_noleading_space_comment.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["int main() {", "}"], result) call assert_equal(["int main() {", "}"], result)
endfunc endfunc
func Test_textobj_noleading_space_comment2() func Test_textobj_noleading_space_comment2()
CheckScreendump
let lines =<< trim END let lines =<< trim END
int main() {// main start int main() {// main start
} /* main end */ } /* main end */
@ -516,63 +440,51 @@ func Test_textobj_noleading_space_comment2()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dac.") call term_sendkeys(buf, "dac.")
let output_file = "comment_textobj_noleading_space_comment2.c" let output_file = "comment_textobj_noleading_space_comment2.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["int main() {", "}"], result) call assert_equal(["int main() {", "}"], result)
endfunc endfunc
func Test_textobj_trailing_spaces_comment() func Test_textobj_trailing_spaces_comment()
CheckScreendump
let lines = ['# print("hello") ', '# print("world") ', "#", 'print("!")'] let lines = ['# print("hello") ', '# print("world") ', "#", 'print("!")']
let input_file = "test_textobj_trailing_spaces_input.py" let input_file = "test_textobj_trailing_spaces_input.py"
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "jdac") call term_sendkeys(buf, "jdac")
let output_file = "comment_textobj_trailing_spaces_comment.py" let output_file = "comment_textobj_trailing_spaces_comment.py"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(['print("!")'], result) call assert_equal(['print("!")'], result)
endfunc endfunc
func Test_textobj_trailing_spaces_last_comment() func Test_textobj_trailing_spaces_last_comment()
CheckScreendump
let lines = ['# print("hello") ', '# print("world") ', "#", '', ''] let lines = ['# print("hello") ', '# print("world") ', "#", '', '']
let input_file = "test_textobj_trailing_spaces_last_input.py" let input_file = "test_textobj_trailing_spaces_last_input.py"
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "jdac") call term_sendkeys(buf, "jdac")
let output_file = "comment_textobj_trailing_spaces_last_comment.py" let output_file = "comment_textobj_trailing_spaces_last_comment.py"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal([], result) call assert_equal([], result)
endfunc endfunc
func Test_textobj_last_line_empty_comment() func Test_textobj_last_line_empty_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
# print("hello") # print("hello")
# #
@ -583,21 +495,17 @@ func Test_textobj_last_line_empty_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dac") call term_sendkeys(buf, "dac")
let output_file = "comment_textobj_last_line_empty_comment.py" let output_file = "comment_textobj_last_line_empty_comment.py"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal([], result) call assert_equal([], result)
endfunc endfunc
func Test_textobj_cursor_on_leading_space_comment() func Test_textobj_cursor_on_leading_space_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
int main() { int main() {
// multilple comments // multilple comments
@ -609,21 +517,17 @@ func Test_textobj_cursor_on_leading_space_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "jjdac") call term_sendkeys(buf, "jjdac")
let output_file = "comment_textobj_cursor_on_leading_space_comment.c" let output_file = "comment_textobj_cursor_on_leading_space_comment.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["int main() {", "}"], result) call assert_equal(["int main() {", "}"], result)
endfunc endfunc
func Test_textobj_conseq_comment() func Test_textobj_conseq_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
int main() { int main() {
printf("hello"); // hello printf("hello"); // hello
@ -636,21 +540,17 @@ func Test_textobj_conseq_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dac") call term_sendkeys(buf, "dac")
let output_file = "comment_textobj_conseq_comment.c" let output_file = "comment_textobj_conseq_comment.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["int main() {", " printf(\"hello\");", " printf(\"world\");", "}"], result) call assert_equal(["int main() {", " printf(\"hello\");", " printf(\"world\");", "}"], result)
endfunc endfunc
func Test_textobj_conseq_comment2() func Test_textobj_conseq_comment2()
CheckScreendump
let lines =<< trim END let lines =<< trim END
int main() { int main() {
printf("hello"); // hello printf("hello"); // hello
@ -664,21 +564,17 @@ func Test_textobj_conseq_comment2()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dac") call term_sendkeys(buf, "dac")
let output_file = "comment_textobj_conseq_comment2.c" let output_file = "comment_textobj_conseq_comment2.c"
call term_sendkeys(buf, $":w {output_file}\<CR>") call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(["int main() {", " printf(\"hello\");", "", " // world", " printf(\"world\");", "}"], result) call assert_equal(["int main() {", " printf(\"hello\");", "", " // world", " printf(\"world\");", "}"], result)
endfunc endfunc
func Test_inline_comment() func Test_inline_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
echo "Hello" This should be a comment echo "Hello" This should be a comment
END END
@ -687,7 +583,6 @@ func Test_inline_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap <expr> gC comment#Toggle()..''$''" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap <expr> gC comment#Toggle()..''$''" ' .. input_file, {})
call term_sendkeys(buf, "fTgC") call term_sendkeys(buf, "fTgC")
let output_file = "comment_inline_test.vim" let output_file = "comment_inline_test.vim"
@ -695,13 +590,11 @@ func Test_inline_comment()
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(['echo "Hello" " This should be a comment'], result) call assert_equal(['echo "Hello" " This should be a comment'], result)
endfunc endfunc
func Test_inline_uncomment() func Test_inline_uncomment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
echo "Hello" " This should be a comment echo "Hello" " This should be a comment
END END
@ -710,7 +603,6 @@ func Test_inline_uncomment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap <expr> gC comment#Toggle()..''$''" ' .. input_file, {}) let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap <expr> gC comment#Toggle()..''$''" ' .. input_file, {})
call term_sendkeys(buf, '$F"gC') call term_sendkeys(buf, '$F"gC')
let output_file = "uncomment_inline_test.vim" let output_file = "uncomment_inline_test.vim"
@ -718,13 +610,11 @@ func Test_inline_uncomment()
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(['echo "Hello" This should be a comment'], result) call assert_equal(['echo "Hello" This should be a comment'], result)
endfunc endfunc
func Test_textobj_selection_exclusive_inline_comment() func Test_textobj_selection_exclusive_inline_comment()
CheckScreendump
let lines =<< trim END let lines =<< trim END
print("Hello") # selection exclusive print("Hello") # selection exclusive
END END
@ -733,7 +623,6 @@ func Test_textobj_selection_exclusive_inline_comment()
call writefile(lines, input_file, "D") call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "set selection=exclusive" -c "packadd comment" ' .. input_file, {}) let buf = RunVimInTerminal('-c "set selection=exclusive" -c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "dac") call term_sendkeys(buf, "dac")
let output_file = "test_selection_exclusive_inline_comment.py" let output_file = "test_selection_exclusive_inline_comment.py"
@ -741,7 +630,6 @@ func Test_textobj_selection_exclusive_inline_comment()
defer delete(output_file) defer delete(output_file)
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
let result = readfile(output_file) let result = readfile(output_file)
call assert_equal(['print("Hello")'], result) call assert_equal(['print("Hello")'], result)
endfunc endfunc

View File

@ -719,6 +719,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1536,
/**/ /**/
1535, 1535,
/**/ /**/