Skip to content

Commit aace215

Browse files
committed
patch 8.0.1269: effect of autocommands on marks is not tested
Problem: Effect of autocommands on marks is not tested. Solution: Add a couple of tests. (James McCoy, closes #2271)
1 parent 3bf8c3c commit aace215

2 files changed

Lines changed: 129 additions & 0 deletions

File tree

src/testdir/test_autocmd.vim

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,3 +997,130 @@ func Test_Cmd_Autocmds()
997997
call delete('Xxx')
998998
enew!
999999
endfunc
1000+
1001+
func SetChangeMarks(start, end)
1002+
exe a:start. 'mark ['
1003+
exe a:end. 'mark ]'
1004+
endfunc
1005+
1006+
" Verify the effects of autocmds on '[ and ']
1007+
func Test_change_mark_in_autocmds()
1008+
edit! Xtest
1009+
call feedkeys("ia\<CR>b\<CR>c\<CR>d\<C-g>u", 'xtn')
1010+
1011+
call SetChangeMarks(2, 3)
1012+
write
1013+
call assert_equal([1, 4], [line("'["), line("']")])
1014+
1015+
call SetChangeMarks(2, 3)
1016+
au BufWritePre * call assert_equal([1, 4], [line("'["), line("']")])
1017+
write
1018+
au! BufWritePre
1019+
1020+
if executable('cat')
1021+
write XtestFilter
1022+
write >> XtestFilter
1023+
1024+
call SetChangeMarks(2, 3)
1025+
" Marks are set to the entire range of the write
1026+
au FilterWritePre * call assert_equal([1, 4], [line("'["), line("']")])
1027+
" '[ is adjusted to just before the line that will receive the filtered
1028+
" data
1029+
au FilterReadPre * call assert_equal([4, 4], [line("'["), line("']")])
1030+
" The filtered data is read into the buffer, and the source lines are
1031+
" still present, so the range is after the source lines
1032+
au FilterReadPost * call assert_equal([5, 12], [line("'["), line("']")])
1033+
%!cat XtestFilter
1034+
" After the filtered data is read, the original lines are deleted
1035+
call assert_equal([1, 8], [line("'["), line("']")])
1036+
au! FilterWritePre,FilterReadPre,FilterReadPost
1037+
undo
1038+
1039+
call SetChangeMarks(1, 4)
1040+
au FilterWritePre * call assert_equal([2, 3], [line("'["), line("']")])
1041+
au FilterReadPre * call assert_equal([3, 3], [line("'["), line("']")])
1042+
au FilterReadPost * call assert_equal([4, 11], [line("'["), line("']")])
1043+
2,3!cat XtestFilter
1044+
call assert_equal([2, 9], [line("'["), line("']")])
1045+
au! FilterWritePre,FilterReadPre,FilterReadPost
1046+
undo
1047+
1048+
call delete('XtestFilter')
1049+
endif
1050+
1051+
call SetChangeMarks(1, 4)
1052+
au FileWritePre * call assert_equal([2, 3], [line("'["), line("']")])
1053+
2,3write Xtest2
1054+
au! FileWritePre
1055+
1056+
call SetChangeMarks(2, 3)
1057+
au FileAppendPre * call assert_equal([1, 4], [line("'["), line("']")])
1058+
write >> Xtest2
1059+
au! FileAppendPre
1060+
1061+
call SetChangeMarks(1, 4)
1062+
au FileAppendPre * call assert_equal([2, 3], [line("'["), line("']")])
1063+
2,3write >> Xtest2
1064+
au! FileAppendPre
1065+
1066+
call SetChangeMarks(1, 1)
1067+
au FileReadPre * call assert_equal([3, 1], [line("'["), line("']")])
1068+
au FileReadPost * call assert_equal([4, 11], [line("'["), line("']")])
1069+
3read Xtest2
1070+
au! FileReadPre,FileReadPost
1071+
undo
1072+
1073+
call SetChangeMarks(4, 4)
1074+
" When the line is 0, it's adjusted to 1
1075+
au FileReadPre * call assert_equal([1, 4], [line("'["), line("']")])
1076+
au FileReadPost * call assert_equal([1, 8], [line("'["), line("']")])
1077+
0read Xtest2
1078+
au! FileReadPre,FileReadPost
1079+
undo
1080+
1081+
call SetChangeMarks(4, 4)
1082+
" When the line is 0, it's adjusted to 1
1083+
au FileReadPre * call assert_equal([1, 4], [line("'["), line("']")])
1084+
au FileReadPost * call assert_equal([2, 9], [line("'["), line("']")])
1085+
1read Xtest2
1086+
au! FileReadPre,FileReadPost
1087+
undo
1088+
1089+
bwipe!
1090+
call delete('Xtest')
1091+
call delete('Xtest2')
1092+
endfunc
1093+
1094+
func Test_Filter_noshelltemp()
1095+
if !executable('cat')
1096+
return
1097+
endif
1098+
1099+
enew!
1100+
call setline(1, ['a', 'b', 'c', 'd'])
1101+
1102+
let shelltemp = &shelltemp
1103+
set shelltemp
1104+
1105+
let g:filter_au = 0
1106+
au FilterWritePre * let g:filter_au += 1
1107+
au FilterReadPre * let g:filter_au += 1
1108+
au FilterReadPost * let g:filter_au += 1
1109+
%!cat
1110+
call assert_equal(3, g:filter_au)
1111+
1112+
if has('filterpipe')
1113+
set noshelltemp
1114+
1115+
let g:filter_au = 0
1116+
au FilterWritePre * let g:filter_au += 1
1117+
au FilterReadPre * let g:filter_au += 1
1118+
au FilterReadPost * let g:filter_au += 1
1119+
%!cat
1120+
call assert_equal(0, g:filter_au)
1121+
endif
1122+
1123+
au! FilterWritePre,FilterReadPre,FilterReadPost
1124+
let &shelltemp = shelltemp
1125+
bwipe!
1126+
endfunc

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1269,
764766
/**/
765767
1268,
766768
/**/

0 commit comments

Comments
 (0)