1 Test for ":match", ":2match", ":3match", "clearmatches()", "getmatches()",
2 "matchadd()", "matcharg()", "matchdelete()", and "setmatches()".
6 :" --- Check that "matcharg()" returns the correct group and pattern if a match
8 :let @r = "*** Test 1: "
9 :highlight MyGroup1 ctermbg=red
10 :highlight MyGroup2 ctermbg=green
11 :highlight MyGroup3 ctermbg=blue
12 :match MyGroup1 /TODO/
13 :2match MyGroup2 /FIXME/
14 :3match MyGroup3 /XXX/
15 :if matcharg(1) == ['MyGroup1', 'TODO'] && matcharg(2) == ['MyGroup2', 'FIXME'] && matcharg(3) == ['MyGroup3', 'XXX']
18 : let @r .= "FAILED\n"
20 :" --- Check that "matcharg()" returns an empty list if the argument is not 1,
21 :" --- 2 or 3 (only 0 and 4 are tested).
22 :let @r .= "*** Test 2: "
23 :if matcharg(0) == [] && matcharg(4) == []
26 : let @r .= "FAILED\n"
28 :" --- Check that "matcharg()" returns ['', ''] if a match is not defined.
29 :let @r .= "*** Test 3: "
33 :if matcharg(1) == ['', ''] && matcharg(2) == ['', ''] && matcharg(3) == ['', '']
36 : let @r .= "FAILED\n"
38 :" --- Check that "matchadd()" and "getmatches()" agree on added matches and
39 :" --- that default values apply.
40 :let @r .= "*** Test 4: "
41 :let m1 = matchadd("MyGroup1", "TODO")
42 :let m2 = matchadd("MyGroup2", "FIXME", 42)
43 :let m3 = matchadd("MyGroup3", "XXX", 60, 17)
44 :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}]
47 : let @r .= "FAILED\n"
49 :" --- Check that "matchdelete()" deletes the matches defined in the previous
50 :" --- test correctly.
51 :let @r .= "*** Test 5: "
58 :if getmatches() == []
61 : let @r .= "FAILED\n"
63 :" --- Check that "matchdelete()" returns 0 if succesfull and otherwise -1.
64 :let @r .= "*** Test 6: "
65 :let m = matchadd("MyGroup1", "TODO")
66 :let r1 = matchdelete(m)
67 :let r2 = matchdelete(42)
68 :if r1 == 0 && r2 == -1
71 : let @r .= "FAILED\n"
76 :" --- Check that "clearmatches()" clears all matches defined by ":match" and
78 :let @r .= "*** Test 7: "
79 :let m1 = matchadd("MyGroup1", "TODO")
80 :let m2 = matchadd("MyGroup2", "FIXME", 42)
81 :let m3 = matchadd("MyGroup3", "XXX", 60, 17)
82 :match MyGroup1 /COFFEE/
83 :2match MyGroup2 /HUMPPA/
84 :3match MyGroup3 /VIM/
86 :if getmatches() == []
89 : let @r .= "FAILED\n"
94 :" --- Check that "setmatches()" restores a list of matches saved by
95 :" --- "getmatches()" without changes. (Matches with equal priority must also
96 :" --- remain in the same order.)
97 :let @r .= "*** Test 8: "
98 :let m1 = matchadd("MyGroup1", "TODO")
99 :let m2 = matchadd("MyGroup2", "FIXME", 42)
100 :let m3 = matchadd("MyGroup3", "XXX", 60, 17)
101 :match MyGroup1 /COFFEE/
102 :2match MyGroup2 /HUMPPA/
103 :3match MyGroup3 /VIM/
104 :let ml = getmatches()
107 :if getmatches() == ml
110 : let @r .= "FAILED\n"
117 :" --- Check that "setmatches()" will not add two matches with the same ID. The
118 :" --- expected behaviour (for now) is to add the first match but not the
119 :" --- second and to return 0 (even though it is a matter of debate whether
120 :" --- this can be considered succesfull behaviour).
121 :let @r .= "*** Test 9: "
122 :let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])
123 :if getmatches() == [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}] && r1 == 0
126 : let @r .= "FAILED\n"
130 :" --- Check that "setmatches()" returns 0 if succesfull and otherwise -1.
131 :" --- (A range of valid and invalid input values are tried out to generate the
132 :" --- return values.)
133 :let @r .= "*** Test 10: "
134 :let rs1 = setmatches([])
135 :let rs2 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}])
137 :let rf1 = setmatches(0)
138 :let rf2 = setmatches([0])
139 :let rf3 = setmatches([{'wrong key': 'wrong value'}])
140 :if rs1 == 0 && rs2 == 0 && rf1 == -1 && rf2 == -1 && rf3 == -1
143 : let @r .= "FAILED\n"
150 :highlight clear MyGroup1
151 :highlight clear MyGroup2
152 :highlight clear MyGroup3
154 :/^Results/,$wq! test.out