annotate src/testdir/test_match.vim @ 9885:4e8b05fa12c6 v7.4.2217

commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 16 16:08:18 2016 +0200 patch 7.4.2217 Problem: When using matchaddpos() a character after the end of the line can be highlighted. Solution: Only highlight existing characters. (Hirohito Higashi)
author Christian Brabandt <cb@256bit.org>
date Tue, 16 Aug 2016 16:15:06 +0200
parents 2409d7038822
children 3ee84d270ea7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9776
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for :match, :2match, :3match, clearmatches(), getmatches(), matchadd(),
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " matchaddpos(), matcharg(), matchdelete(), matchstrpos() and setmatches().
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3
9885
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
4 function Test_match()
9776
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 highlight MyGroup1 term=bold ctermbg=red guibg=red
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 highlight MyGroup2 term=italic ctermbg=green guibg=green
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 highlight MyGroup3 term=underline ctermbg=blue guibg=blue
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 " --- Check that "matcharg()" returns the correct group and pattern if a match
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 " --- is defined.
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 match MyGroup1 /TODO/
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 2match MyGroup2 /FIXME/
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 3match MyGroup3 /XXX/
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call assert_equal(['MyGroup1', 'TODO'], matcharg(1))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal(['MyGroup2', 'FIXME'], matcharg(2))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 call assert_equal(['MyGroup3', 'XXX'], matcharg(3))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 " --- Check that "matcharg()" returns an empty list if the argument is not 1,
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 " --- 2 or 3 (only 0 and 4 are tested).
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call assert_equal([], matcharg(0))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_equal([], matcharg(4))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 " --- Check that "matcharg()" returns ['', ''] if a match is not defined.
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 match
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 2match
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 3match
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 call assert_equal(['', ''], matcharg(1))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 call assert_equal(['', ''], matcharg(2))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 call assert_equal(['', ''], matcharg(3))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 " --- Check that "matchadd()" and "getmatches()" agree on added matches and
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 " --- that default values apply.
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 let m1 = matchadd("MyGroup1", "TODO")
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 let m2 = matchadd("MyGroup2", "FIXME", 42)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 let m3 = matchadd("MyGroup3", "XXX", 60, 17)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 let ans = [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 4},
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 \ {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 42, 'id': 5},
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 \ {'group': 'MyGroup3', 'pattern': 'XXX', 'priority': 60, 'id': 17}]
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 call assert_equal(ans, getmatches())
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 " --- Check that "matchdelete()" deletes the matches defined in the previous
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 " --- test correctly.
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 call matchdelete(m1)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 call matchdelete(m2)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 call matchdelete(m3)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 call assert_equal([], getmatches())
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 " --- Check that "matchdelete()" returns 0 if successful and otherwise -1.
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 let m = matchadd("MyGroup1", "TODO")
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 call assert_equal(0, matchdelete(m))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 call assert_fails('call matchdelete(42)', 'E803:')
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 " --- Check that "clearmatches()" clears all matches defined by ":match" and
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 " --- "matchadd()".
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 let m1 = matchadd("MyGroup1", "TODO")
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 let m2 = matchadd("MyGroup2", "FIXME", 42)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 let m3 = matchadd("MyGroup3", "XXX", 60, 17)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 match MyGroup1 /COFFEE/
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 2match MyGroup2 /HUMPPA/
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 3match MyGroup3 /VIM/
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 call clearmatches()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 call assert_equal([], getmatches())
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 " --- Check that "setmatches()" restores a list of matches saved by
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 " --- "getmatches()" without changes. (Matches with equal priority must also
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 " --- remain in the same order.)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 let m1 = matchadd("MyGroup1", "TODO")
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 let m2 = matchadd("MyGroup2", "FIXME", 42)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 let m3 = matchadd("MyGroup3", "XXX", 60, 17)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 match MyGroup1 /COFFEE/
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 2match MyGroup2 /HUMPPA/
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 3match MyGroup3 /VIM/
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 let ml = getmatches()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 call clearmatches()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 call setmatches(ml)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 call assert_equal(ml, getmatches())
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 call clearmatches()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 " --- Check that "setmatches()" will not add two matches with the same ID. The
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 " --- expected behaviour (for now) is to add the first match but not the
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 " --- second and to return 0 (even though it is a matter of debate whether
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 " --- this can be considered successful behaviour).
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 let data = [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1},
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 \ {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}]
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 call assert_fails('call setmatches(data)', 'E801:')
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 call assert_equal([data[0]], getmatches())
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 call clearmatches()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 " --- Check that "setmatches()" returns 0 if successful and otherwise -1.
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 " --- (A range of valid and invalid input values are tried out to generate the
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 " --- return values.)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 call assert_equal(0, setmatches([]))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 call assert_equal(0, setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}]))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 call clearmatches()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 call assert_fails('call setmatches(0)', 'E714:')
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 call assert_fails('call setmatches([0])', 'E474:')
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 call assert_fails("call setmatches([{'wrong key': 'wrong value'}])", 'E474:')
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 call setline(1, 'abcdefghijklmnopq')
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 call matchaddpos("MyGroup1", [[1, 5], [1, 8, 3]], 10, 3)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 1
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 redraw!
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 let v1 = screenattr(1, 1)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 let v5 = screenattr(1, 5)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 let v6 = screenattr(1, 6)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 let v8 = screenattr(1, 8)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 let v10 = screenattr(1, 10)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 let v11 = screenattr(1, 11)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 call assert_notequal(v1, v5)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 call assert_equal(v6, v1)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 call assert_equal(v8, v5)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 call assert_equal(v10, v5)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 call assert_equal(v11, v1)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 call assert_equal([{'group': 'MyGroup1', 'id': 3, 'priority': 10, 'pos1': [1, 5, 1], 'pos2': [1, 8, 3]}], getmatches())
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 call clearmatches()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 "
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 if has('multi_byte')
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 call setline(1, 'abcdΣabcdef')
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120 call matchaddpos("MyGroup1", [[1, 4, 2], [1, 9, 2]])
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 1
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 redraw!
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 let v1 = screenattr(1, 1)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 let v4 = screenattr(1, 4)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 let v5 = screenattr(1, 5)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 let v6 = screenattr(1, 6)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 let v7 = screenattr(1, 7)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 let v8 = screenattr(1, 8)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129 let v9 = screenattr(1, 9)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130 let v10 = screenattr(1, 10)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 call assert_equal([{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}], getmatches())
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 call assert_notequal(v1, v4)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 call assert_equal(v5, v4)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 call assert_equal(v6, v1)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 call assert_equal(v7, v1)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 call assert_equal(v8, v4)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 call assert_equal(v9, v4)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 call assert_equal(v10, v1)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 " Check, that setmatches() can correctly restore the matches from matchaddpos()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141 call matchadd('MyGroup1', '\%2lmatchadd')
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 let m=getmatches()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143 call clearmatches()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 call setmatches(m)
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 call assert_equal([{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1,9, 2]}, {'group': 'MyGroup1', 'pattern': '\%2lmatchadd', 'priority': 10, 'id': 12}], getmatches())
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146 endif
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 highlight MyGroup1 NONE
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 highlight MyGroup2 NONE
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 highlight MyGroup3 NONE
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 endfunc
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 func Test_matchstrpos()
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing'))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
160 call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 endfunc
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164
9885
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
165 func Test_matchaddpos()
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
166 syntax on
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
167 set hlsearch
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
168
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
169 call setline(1, ['12345', 'NP'])
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
170 call matchaddpos('Error', [[1,2], [1,6], [2,2]])
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
171 redraw!
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
172 call assert_notequal(screenattr(2,2), 0)
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
173 call assert_equal(screenattr(2,2), screenattr(1,2))
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
174 call assert_notequal(screenattr(2,2), screenattr(1,6))
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
175 1
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
176 call matchadd('Search', 'N\|\n')
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
177 redraw!
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
178 call assert_notequal(screenattr(2,1), 0)
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
179 call assert_equal(screenattr(2,1), screenattr(1,6))
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
180 exec "norm! i0\<Esc>"
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
181 redraw!
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
182 call assert_equal(screenattr(2,2), screenattr(1,6))
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
183
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
184 nohl
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
185 syntax off
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
186 set hlsearch&
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
187 endfunc
4e8b05fa12c6 commit https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
Christian Brabandt <cb@256bit.org>
parents: 9776
diff changeset
188
9776
2409d7038822 commit https://github.com/vim/vim/commit/d76a0c15f8bdbc901015879177fd5076d34c7a06
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 " vim: et ts=2 sw=2