Mercurial > hg > RemoteEditor > vim7
comparison src/testdir/test63.in @ 0:76efa0be13f1
Initial revision
author | atsuki |
---|---|
date | Sat, 10 Nov 2007 15:07:22 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:76efa0be13f1 |
---|---|
1 Test for ":match", ":2match", ":3match", "clearmatches()", "getmatches()", | |
2 "matchadd()", "matcharg()", "matchdelete()", and "setmatches()". | |
3 | |
4 STARTTEST | |
5 :so small.vim | |
6 :" --- Check that "matcharg()" returns the correct group and pattern if a match | |
7 :" --- is defined. | |
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'] | |
16 : let @r .= "OK\n" | |
17 :else | |
18 : let @r .= "FAILED\n" | |
19 :endif | |
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) == [] | |
24 : let @r .= "OK\n" | |
25 :else | |
26 : let @r .= "FAILED\n" | |
27 :endif | |
28 :" --- Check that "matcharg()" returns ['', ''] if a match is not defined. | |
29 :let @r .= "*** Test 3: " | |
30 :match | |
31 :2match | |
32 :3match | |
33 :if matcharg(1) == ['', ''] && matcharg(2) == ['', ''] && matcharg(3) == ['', ''] | |
34 : let @r .= "OK\n" | |
35 :else | |
36 : let @r .= "FAILED\n" | |
37 :endif | |
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}] | |
45 : let @r .= "OK\n" | |
46 :else | |
47 : let @r .= "FAILED\n" | |
48 :endif | |
49 :" --- Check that "matchdelete()" deletes the matches defined in the previous | |
50 :" --- test correctly. | |
51 :let @r .= "*** Test 5: " | |
52 :call matchdelete(m1) | |
53 :call matchdelete(m2) | |
54 :call matchdelete(m3) | |
55 :unlet m1 | |
56 :unlet m2 | |
57 :unlet m3 | |
58 :if getmatches() == [] | |
59 : let @r .= "OK\n" | |
60 :else | |
61 : let @r .= "FAILED\n" | |
62 :endif | |
63 :" --- Check that "matchdelete()" returns 0 if successful 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 | |
69 : let @r .= "OK\n" | |
70 :else | |
71 : let @r .= "FAILED\n" | |
72 :endif | |
73 :unlet m | |
74 :unlet r1 | |
75 :unlet r2 | |
76 :" --- Check that "clearmatches()" clears all matches defined by ":match" and | |
77 :" --- "matchadd()". | |
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/ | |
85 :call clearmatches() | |
86 :if getmatches() == [] | |
87 : let @r .= "OK\n" | |
88 :else | |
89 : let @r .= "FAILED\n" | |
90 :endif | |
91 :unlet m1 | |
92 :unlet m2 | |
93 :unlet m3 | |
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() | |
105 :call clearmatches() | |
106 :call setmatches(ml) | |
107 :if getmatches() == ml | |
108 : let @r .= "OK\n" | |
109 :else | |
110 : let @r .= "FAILED\n" | |
111 :endif | |
112 :call clearmatches() | |
113 :unlet m1 | |
114 :unlet m2 | |
115 :unlet m3 | |
116 :unlet ml | |
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 successful 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 | |
124 : let @r .= "OK\n" | |
125 :else | |
126 : let @r .= "FAILED\n" | |
127 :endif | |
128 :call clearmatches() | |
129 :unlet r1 | |
130 :" --- Check that "setmatches()" returns 0 if successful 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}]) | |
136 :call clearmatches() | |
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 | |
141 : let @r .= "OK\n" | |
142 :else | |
143 : let @r .= "FAILED\n" | |
144 :endif | |
145 :unlet rs1 | |
146 :unlet rs2 | |
147 :unlet rf1 | |
148 :unlet rf2 | |
149 :unlet rf3 | |
150 :highlight clear MyGroup1 | |
151 :highlight clear MyGroup2 | |
152 :highlight clear MyGroup3 | |
153 G"rp | |
154 :/^Results/,$wq! test.out | |
155 ENDTEST | |
156 | |
157 Results of test63: |