comparison src/testdir/test_regexp_latin.vim @ 25147:10b269321459 v8.2.3110

patch 8.2.3110: a pattern that matches the cursor position is complicated Commit: https://github.com/vim/vim/commit/04db26b36000a4677b95403ec94bd11f6cc73975 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 5 20:15:23 2021 +0200 patch 8.2.3110: a pattern that matches the cursor position is complicated Problem: A pattern that matches the cursor position is bit complicated. Solution: Use a dot to indicate the cursor line and column. (Christian Brabandt, closes #8497, closes #8179)
author Bram Moolenaar <Bram@vim.org>
date Mon, 05 Jul 2021 20:30:03 +0200
parents ed0fc4787392
children 9835f424bef5
comparison
equal deleted inserted replaced
25146:84fff3a2c3d3 25147:10b269321459
945 call assert_equal(matchstr("foo\nbaz\nbar", "\\%#=1\~"), "baz") 945 call assert_equal(matchstr("foo\nbaz\nbar", "\\%#=1\~"), "baz")
946 call assert_equal(matchstr("foo\nbaz\nbar", "\\%#=2\~"), "baz") 946 call assert_equal(matchstr("foo\nbaz\nbar", "\\%#=2\~"), "baz")
947 close! 947 close!
948 endfunc 948 endfunc
949 949
950 " Check patterns matching cursor position.
951 func s:curpos_test2()
952 new
953 call setline(1, ['1', '2 foobar eins zwei drei vier fünf sechse',
954 \ '3 foobar eins zwei drei vier fünf sechse',
955 \ '4 foobar eins zwei drei vier fünf sechse',
956 \ '5 foobar eins zwei drei vier fünf sechse',
957 \ '6 foobar eins zwei drei vier fünf sechse',
958 \ '7 foobar eins zwei drei vier fünf sechse'])
959 call setpos('.', [0, 2, 10, 0])
960 s/\%.c.*//g
961 call setpos('.', [0, 3, 15, 0])
962 s/\%.l.*//g
963 call setpos('.', [0, 5, 3, 0])
964 s/\%.v.*/_/g
965 call assert_equal(['1',
966 \ '2 foobar ',
967 \ '',
968 \ '4 foobar eins zwei drei vier fünf sechse',
969 \ '5 _',
970 \ '6 foobar eins zwei drei vier fünf sechse',
971 \ '7 foobar eins zwei drei vier fünf sechse'],
972 \ getline(1, '$'))
973 call assert_fails('call search("\\%.1l")', 'E1204:')
974 call assert_fails('call search("\\%.1c")', 'E1204:')
975 call assert_fails('call search("\\%.1v")', 'E1204:')
976 bwipe!
977 endfunc
978
979 " Check patterns matching before or after cursor position.
980 func s:curpos_test3()
981 new
982 call setline(1, ['1', '2 foobar eins zwei drei vier fünf sechse',
983 \ '3 foobar eins zwei drei vier fünf sechse',
984 \ '4 foobar eins zwei drei vier fünf sechse',
985 \ '5 foobar eins zwei drei vier fünf sechse',
986 \ '6 foobar eins zwei drei vier fünf sechse',
987 \ '7 foobar eins zwei drei vier fünf sechse'])
988 call setpos('.', [0, 2, 10, 0])
989 " Note: This removes all columns, except for the column directly in front of
990 " the cursor. Bug????
991 :s/^.*\%<.c//
992 call setpos('.', [0, 3, 10, 0])
993 :s/\%>.c.*$//
994 call setpos('.', [0, 5, 4, 0])
995 " Note: This removes all columns, except for the column directly in front of
996 " the cursor. Bug????
997 :s/^.*\%<.v/_/
998 call setpos('.', [0, 6, 4, 0])
999 :s/\%>.v.*$/_/
1000 call assert_equal(['1',
1001 \ ' eins zwei drei vier fünf sechse',
1002 \ '3 foobar e',
1003 \ '4 foobar eins zwei drei vier fünf sechse',
1004 \ '_foobar eins zwei drei vier fünf sechse',
1005 \ '6 fo_',
1006 \ '7 foobar eins zwei drei vier fünf sechse'],
1007 \ getline(1, '$'))
1008 sil %d
1009 call setline(1, ['1', '2 foobar eins zwei drei vier fünf sechse',
1010 \ '3 foobar eins zwei drei vier fünf sechse',
1011 \ '4 foobar eins zwei drei vier fünf sechse',
1012 \ '5 foobar eins zwei drei vier fünf sechse',
1013 \ '6 foobar eins zwei drei vier fünf sechse',
1014 \ '7 foobar eins zwei drei vier fünf sechse'])
1015 call setpos('.', [0, 4, 4, 0])
1016 %s/\%<.l.*//
1017 call setpos('.', [0, 5, 4, 0])
1018 %s/\%>.l.*//
1019 call assert_equal(['', '', '',
1020 \ '4 foobar eins zwei drei vier fünf sechse',
1021 \ '5 foobar eins zwei drei vier fünf sechse',
1022 \ '', ''],
1023 \ getline(1, '$'))
1024 bwipe!
1025 endfunc
1026
1027 " Test that matching below, at or after the
1028 " cursor position work
1029 func Test_matching_pos()
1030 for val in range(3)
1031 exe "set re=" .. val
1032 " Match at cursor position
1033 call s:curpos_test2()
1034 " Match before or after cursor position
1035 call s:curpos_test3()
1036 endfor
1037 set re&
1038 endfunc
1039
950 " vim: shiftwidth=2 sts=2 expandtab 1040 " vim: shiftwidth=2 sts=2 expandtab