1326
|
1 Test for ":match", ":2match", ":3match", "clearmatches()", "getmatches()",
|
5979
|
2 "matchadd()", "matchaddpos", "matcharg()", "matchdelete()", and "setmatches()".
|
1326
|
3
|
|
4 STARTTEST
|
|
5 :so small.vim
|
6134
|
6 :set encoding=utf8
|
1326
|
7 :" --- Check that "matcharg()" returns the correct group and pattern if a match
|
|
8 :" --- is defined.
|
|
9 :let @r = "*** Test 1: "
|
6411
|
10 :highlight MyGroup1 term=bold ctermbg=red guibg=red
|
|
11 :highlight MyGroup2 term=italic ctermbg=green guibg=green
|
|
12 :highlight MyGroup3 term=underline ctermbg=blue guibg=blue
|
1326
|
13 :match MyGroup1 /TODO/
|
|
14 :2match MyGroup2 /FIXME/
|
|
15 :3match MyGroup3 /XXX/
|
|
16 :if matcharg(1) == ['MyGroup1', 'TODO'] && matcharg(2) == ['MyGroup2', 'FIXME'] && matcharg(3) == ['MyGroup3', 'XXX']
|
|
17 : let @r .= "OK\n"
|
|
18 :else
|
|
19 : let @r .= "FAILED\n"
|
|
20 :endif
|
|
21 :" --- Check that "matcharg()" returns an empty list if the argument is not 1,
|
|
22 :" --- 2 or 3 (only 0 and 4 are tested).
|
|
23 :let @r .= "*** Test 2: "
|
|
24 :if matcharg(0) == [] && matcharg(4) == []
|
|
25 : let @r .= "OK\n"
|
|
26 :else
|
|
27 : let @r .= "FAILED\n"
|
|
28 :endif
|
|
29 :" --- Check that "matcharg()" returns ['', ''] if a match is not defined.
|
|
30 :let @r .= "*** Test 3: "
|
|
31 :match
|
|
32 :2match
|
|
33 :3match
|
|
34 :if matcharg(1) == ['', ''] && matcharg(2) == ['', ''] && matcharg(3) == ['', '']
|
|
35 : let @r .= "OK\n"
|
|
36 :else
|
|
37 : let @r .= "FAILED\n"
|
|
38 :endif
|
|
39 :" --- Check that "matchadd()" and "getmatches()" agree on added matches and
|
|
40 :" --- that default values apply.
|
|
41 :let @r .= "*** Test 4: "
|
|
42 :let m1 = matchadd("MyGroup1", "TODO")
|
|
43 :let m2 = matchadd("MyGroup2", "FIXME", 42)
|
|
44 :let m3 = matchadd("MyGroup3", "XXX", 60, 17)
|
|
45 :if getmatches() == [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 4}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 42, 'id': 5}, {'group': 'MyGroup3', 'pattern': 'XXX', 'priority': 60, 'id': 17}]
|
|
46 : let @r .= "OK\n"
|
|
47 :else
|
|
48 : let @r .= "FAILED\n"
|
|
49 :endif
|
|
50 :" --- Check that "matchdelete()" deletes the matches defined in the previous
|
|
51 :" --- test correctly.
|
|
52 :let @r .= "*** Test 5: "
|
|
53 :call matchdelete(m1)
|
|
54 :call matchdelete(m2)
|
|
55 :call matchdelete(m3)
|
|
56 :unlet m1
|
|
57 :unlet m2
|
|
58 :unlet m3
|
|
59 :if getmatches() == []
|
|
60 : let @r .= "OK\n"
|
|
61 :else
|
|
62 : let @r .= "FAILED\n"
|
|
63 :endif
|
1405
|
64 :" --- Check that "matchdelete()" returns 0 if successful and otherwise -1.
|
1326
|
65 :let @r .= "*** Test 6: "
|
|
66 :let m = matchadd("MyGroup1", "TODO")
|
|
67 :let r1 = matchdelete(m)
|
|
68 :let r2 = matchdelete(42)
|
|
69 :if r1 == 0 && r2 == -1
|
|
70 : let @r .= "OK\n"
|
|
71 :else
|
|
72 : let @r .= "FAILED\n"
|
|
73 :endif
|
|
74 :unlet m
|
|
75 :unlet r1
|
|
76 :unlet r2
|
|
77 :" --- Check that "clearmatches()" clears all matches defined by ":match" and
|
|
78 :" --- "matchadd()".
|
|
79 :let @r .= "*** Test 7: "
|
|
80 :let m1 = matchadd("MyGroup1", "TODO")
|
|
81 :let m2 = matchadd("MyGroup2", "FIXME", 42)
|
|
82 :let m3 = matchadd("MyGroup3", "XXX", 60, 17)
|
|
83 :match MyGroup1 /COFFEE/
|
|
84 :2match MyGroup2 /HUMPPA/
|
|
85 :3match MyGroup3 /VIM/
|
|
86 :call clearmatches()
|
|
87 :if getmatches() == []
|
|
88 : let @r .= "OK\n"
|
|
89 :else
|
|
90 : let @r .= "FAILED\n"
|
|
91 :endif
|
|
92 :unlet m1
|
|
93 :unlet m2
|
|
94 :unlet m3
|
|
95 :" --- Check that "setmatches()" restores a list of matches saved by
|
|
96 :" --- "getmatches()" without changes. (Matches with equal priority must also
|
|
97 :" --- remain in the same order.)
|
|
98 :let @r .= "*** Test 8: "
|
|
99 :let m1 = matchadd("MyGroup1", "TODO")
|
|
100 :let m2 = matchadd("MyGroup2", "FIXME", 42)
|
|
101 :let m3 = matchadd("MyGroup3", "XXX", 60, 17)
|
|
102 :match MyGroup1 /COFFEE/
|
|
103 :2match MyGroup2 /HUMPPA/
|
|
104 :3match MyGroup3 /VIM/
|
|
105 :let ml = getmatches()
|
|
106 :call clearmatches()
|
|
107 :call setmatches(ml)
|
|
108 :if getmatches() == ml
|
|
109 : let @r .= "OK\n"
|
|
110 :else
|
|
111 : let @r .= "FAILED\n"
|
|
112 :endif
|
|
113 :call clearmatches()
|
|
114 :unlet m1
|
|
115 :unlet m2
|
|
116 :unlet m3
|
|
117 :unlet ml
|
|
118 :" --- Check that "setmatches()" will not add two matches with the same ID. The
|
|
119 :" --- expected behaviour (for now) is to add the first match but not the
|
|
120 :" --- second and to return 0 (even though it is a matter of debate whether
|
1405
|
121 :" --- this can be considered successful behaviour).
|
1326
|
122 :let @r .= "*** Test 9: "
|
|
123 :let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])
|
|
124 :if getmatches() == [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}] && r1 == 0
|
|
125 : let @r .= "OK\n"
|
|
126 :else
|
|
127 : let @r .= "FAILED\n"
|
|
128 :endif
|
|
129 :call clearmatches()
|
|
130 :unlet r1
|
1405
|
131 :" --- Check that "setmatches()" returns 0 if successful and otherwise -1.
|
1326
|
132 :" --- (A range of valid and invalid input values are tried out to generate the
|
|
133 :" --- return values.)
|
|
134 :let @r .= "*** Test 10: "
|
|
135 :let rs1 = setmatches([])
|
|
136 :let rs2 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}])
|
|
137 :call clearmatches()
|
|
138 :let rf1 = setmatches(0)
|
|
139 :let rf2 = setmatches([0])
|
|
140 :let rf3 = setmatches([{'wrong key': 'wrong value'}])
|
|
141 :if rs1 == 0 && rs2 == 0 && rf1 == -1 && rf2 == -1 && rf3 == -1
|
|
142 : let @r .= "OK\n"
|
|
143 :else
|
|
144 : let @r .= "FAILED\n"
|
|
145 :endif
|
|
146 :unlet rs1
|
|
147 :unlet rs2
|
|
148 :unlet rf1
|
|
149 :unlet rf2
|
|
150 :unlet rf3
|
5979
|
151 :" --- Check that "matchaddpos()" positions matches correctly
|
|
152 :let @r .= "*** Test 11:\n"
|
|
153 :set nolazyredraw
|
|
154 :call setline(1, 'abcdefghijklmnopq')
|
|
155 :call matchaddpos("MyGroup1", [[1, 5], [1, 8, 3]], 10, 3)
|
|
156 :1
|
|
157 :redraw!
|
|
158 :let v1 = screenattr(1, 1)
|
|
159 :let v5 = screenattr(1, 5)
|
|
160 :let v6 = screenattr(1, 6)
|
|
161 :let v8 = screenattr(1, 8)
|
|
162 :let v10 = screenattr(1, 10)
|
|
163 :let v11 = screenattr(1, 11)
|
|
164 :let @r .= string(getmatches())."\n"
|
|
165 :if v1 != v5 && v6 == v1 && v8 == v5 && v10 == v5 && v11 == v1
|
|
166 : let @r .= "OK\n"
|
|
167 :else
|
6134
|
168 : let @r .= "FAILED: " . v5 . "/" . v6 . "/" . v8 . "/" . v10 . "/" . v11 . "\n"
|
|
169 :endif
|
|
170 :call clearmatches()
|
|
171 :"
|
|
172 :call setline(1, 'abcdΣabcdef')
|
|
173 :call matchaddpos("MyGroup1", [[1, 4, 2], [1, 9, 2]])
|
|
174 :1
|
|
175 :redraw!
|
|
176 :let v1 = screenattr(1, 1)
|
|
177 :let v4 = screenattr(1, 4)
|
|
178 :let v5 = screenattr(1, 5)
|
|
179 :let v6 = screenattr(1, 6)
|
|
180 :let v7 = screenattr(1, 7)
|
|
181 :let v8 = screenattr(1, 8)
|
|
182 :let v9 = screenattr(1, 9)
|
|
183 :let v10 = screenattr(1, 10)
|
|
184 :let @r .= string(getmatches())."\n"
|
|
185 :if v1 != v4 && v5 == v4 && v6 == v1 && v7 == v1 && v8 == v4 && v9 == v4 && v10 == v1
|
|
186 : let @r .= "OK\n"
|
|
187 :else
|
|
188 : let @r .= "FAILED: " . v4 . "/" . v5 . "/" . v6 . "/" . v7 . "/" . v8 . "/" . v9 . "/" . v10 . "\n"
|
5979
|
189 :endif
|
6849
|
190 :" Check, that setmatches() can correctly restore the matches from matchaddpos()
|
|
191 :call matchadd('MyGroup1', '\%2lmatchadd')
|
|
192 :let m=getmatches()
|
5979
|
193 :call clearmatches()
|
6849
|
194 :call setmatches(m)
|
|
195 :let @r .= string(getmatches())."\n"
|
1326
|
196 G"rp
|
|
197 :/^Results/,$wq! test.out
|
|
198 ENDTEST
|
|
199
|
|
200 Results of test63:
|