wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / vbscript / tests / regexp.vbs
blob6569b98956ec485dfc80c98b86a678394dce27a6
2 ' Copyright 2013 Piotr Caban for CodeWeavers
4 ' This library is free software; you can redistribute it and/or
5 ' modify it under the terms of the GNU Lesser General Public
6 ' License as published by the Free Software Foundation; either
7 ' version 2.1 of the License, or (at your option) any later version.
9 ' This library is distributed in the hope that it will be useful,
10 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ' Lesser General Public License for more details.
14 ' You should have received a copy of the GNU Lesser General Public
15 ' License along with this library; if not, write to the Free Software
16 ' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 Option Explicit
21 Dim x, matches, match, submatch, r
23 Set x = CreateObject("vbscript.regexp")
24 Call ok(getVT(x.Pattern) = "VT_BSTR", "getVT(RegExp.Pattern) = " & getVT(x.Pattern))
25 Call ok(x.Pattern = "", "RegExp.Pattern = " & x.Pattern)
26 Call ok(getVT(x.IgnoreCase) = "VT_BOOL", "getVT(RegExp.IgnoreCase) = " & getVT(x.IgnoreCase))
27 Call ok(x.IgnoreCase = false, "RegExp.IgnoreCase = " & x.IgnoreCase)
28 Call ok(getVT(x.Global) = "VT_BOOL", "getVT(RegExp.Global) = " & getVT(x.Global))
29 Call ok(x.Global = false, "RegExp.Global = " & x.Global)
30 Call ok(getVT(x.Multiline) = "VT_BOOL", "getVT(RegExp.Multiline) = " & getVT(x.Multiline))
31 Call ok(x.Multiline = false, "RegExp.Multiline = " & x.Multiline)
33 x.Pattern = "a+"
34 matches = x.Test(" aabaaa")
35 Call ok(matches = true, "RegExp.Test returned: " & matches)
36 Set matches = x.Execute(" aabaaa")
37 Call ok(getVT(matches.Count) = "VT_I4", "getVT(matches.Count) = " & getVT(matches.Count))
38 Call ok(matches.Count = 1, "matches.Count = " & matches.Count)
39 Set match = matches.Item(0)
40 Call ok(match.Value = "aa", "match.Value = " & match.Value)
41 Call ok(match.FirstIndex = 1, "match.FirstIndex = " & match.FirstIndex)
42 Call ok(match.Length = 2, "match.Length = " & match.Length)
43 Set submatch = match.SubMatches
44 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
46 x.Global = true
47 Set matches = x.Execute(" aabaaa")
48 Call ok(matches.Count = 2, "matches.Count = " & matches.Count)
49 Set match = matches.Item(0)
50 Call ok(match.Value = "aa", "match.Value = " & match.Value)
51 Call ok(match.FirstIndex = 1, "match.FirstIndex = " & match.FirstIndex)
52 Call ok(match.Length = 2, "match.Length = " & match.Length)
53 Set submatch = match.SubMatches
54 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
55 Set match = matches.Item(1)
56 Call ok(match.Value = "aaa", "match.Value = " & match.Value)
57 Call ok(match.FirstIndex = 4, "match.FirstIndex = " & match.FirstIndex)
58 Call ok(match.Length = 3, "match.Length = " & match.Length)
59 Set submatch = match.SubMatches
60 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
62 Set matches = x.Execute(" aabaaa")
63 Call ok(matches.Count = 2, "matches.Count = " & matches.Count)
64 Set match = matches.Item(0)
65 Call ok(match.Value = "aa", "match.Value = " & match.Value)
66 Call ok(match.FirstIndex = 1, "match.FirstIndex = " & match.FirstIndex)
67 Call ok(match.Length = 2, "match.Length = " & match.Length)
68 Set submatch = match.SubMatches
69 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
71 x.Pattern = "^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$"
72 x.Global = false
73 Set matches = x.Execute("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
74 Call ok(matches.Count = 0, "matches.Count = " & matches.Count)
75 Set submatch = match.SubMatches
76 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
78 x.Pattern = "(a|b)+|(c)"
79 Set matches = x.Execute("aa")
80 Call ok(matches.Count = 1, "matches.Count = " & matches.Count)
81 Set match = matches.Item(0)
82 Call ok(match.Value = "aa", "match.Value = " & match.Value)
83 Call ok(match.FirstIndex = 0, "match.FirstIndex = " & match.FirstIndex)
84 Call ok(match.Length = 2, "match.Length = " & match.Length)
85 Set submatch = match.SubMatches
86 Call ok(submatch.Count = 2, "submatch.Count = " & submatch.Count)
87 Call ok(getVT(submatch.Item(0)) = "VT_BSTR", "getVT(submatch.Item(0)) = " & getVT(submatch.Item(0)))
88 Call ok(submatch.Item(0) = "a", "submatch.Item(0) = " & submatch.Item(0))
89 Call ok(getVT(submatch.Item(1)) = "VT_EMPTY", "getVT(submatch.Item(1)) = " & getVT(submatch.Item(1)))
90 Call ok(submatch.Item(1) = "", "submatch.Item(0) = " & submatch.Item(1))
92 matches = x.Test(" a ")
93 Call ok(matches = true, "RegExp.Test returned: " & matches)
94 matches = x.Test(" a ")
95 Call ok(matches = true, "RegExp.Test returned: " & matches)
97 x.Pattern = "\[([^\[]+)\]"
98 x.Global = true
99 Set matches = x.Execute(" [test] ")
100 Call ok(matches.Count = 1, "matches.Count = " & matches.Count)
101 Set match = matches.Item(0)
102 Call ok(match.Value = "[test]", "match.Value = " & match.Value)
103 Call ok(match.FirstIndex = 1, "match.FirstIndex = " & match.FirstIndex)
104 Call ok(match.Length = 6, "match.Length = " & match.Length)
105 Set submatch = match.SubMatches
106 Call ok(submatch.Count = 1, "submatch.Count = " & submatch.Count)
107 Call ok(submatch.Item(0) = "test", "submatch.Item(0) = " & submatch.Item(0))
109 x.Pattern = "Ab"
110 x.IgnoreCase = true
111 Set matches = x.Execute("abcaBc")
112 Call ok(matches.Count = 2, "matches.Count = " & matches.Count)
113 Set match = matches.Item(0)
114 Call ok(match.Value = "ab", "match.Value = " & match.Value)
115 Call ok(match.FirstIndex = 0, "match.FirstIndex = " & match.FirstIndex)
116 Call ok(match.Length = 2, "match.Length = " & match.Length)
117 Set submatch = match.SubMatches
118 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
119 Set match = matches.Item(1)
120 Call ok(match.Value = "aB", "match.Value = " & match.Value)
121 Call ok(match.FirstIndex = 3, "match.FirstIndex = " & match.FirstIndex)
122 Call ok(match.Length = 2, "match.Length = " & match.Length)
123 Set submatch = match.SubMatches
124 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
126 x.Pattern = "a+b"
127 x.IgnoreCase = false
128 Set matches = x.Execute("aaabcabc")
129 Call ok(matches.Count = 2, "matches.Count = " & matches.Count)
130 Set match = matches.Item(0)
131 Call ok(match.Value = "aaab", "match.Value = " & match.Value)
132 Call ok(match.FirstIndex = 0, "match.FirstIndex = " & match.FirstIndex)
133 Call ok(match.Length = 4, "match.Length = " & match.Length)
134 Set submatch = match.SubMatches
135 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
136 Set match = matches.Item(1)
137 Call ok(match.Value = "ab", "match.Value = " & match.Value)
138 Call ok(match.FirstIndex = 5, "match.FirstIndex = " & match.FirstIndex)
139 Call ok(match.Length = 2, "match.Length = " & match.Length)
140 Set submatch = match.SubMatches
141 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
143 x.Pattern = "\\"
144 Set matches = x.Execute("aaa\\cabc")
145 Call ok(matches.Count = 2, "matches.Count = " & matches.Count)
146 Set match = matches.Item(0)
147 Call ok(match.Value = "\", "match.Value = " & match.Value)
148 Call ok(match.FirstIndex = 3, "match.FirstIndex = " & match.FirstIndex)
149 Call ok(match.Length = 1, "match.Length = " & match.Length)
150 Set submatch = match.SubMatches
151 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
152 Set match = matches.Item(1)
153 Call ok(match.Value = "\", "match.Value = " & match.Value)
154 Call ok(match.FirstIndex = 4, "match.FirstIndex = " & match.FirstIndex)
155 Call ok(match.Length = 1, "match.Length = " & match.Length)
156 Set submatch = match.SubMatches
157 Call ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
159 x.Pattern = "(a)(b)cabc"
160 Set matches = x.Execute("abcabc")
161 Call ok(matches.Count = 1, "matches.Count = " & matches.Count)
162 Set match = matches.Item(0)
163 Call ok(match.Value = "abcabc", "match.Value = " & match.Value)
164 Call ok(match.FirstIndex = 0, "match.FirstIndex = " & match.FirstIndex)
165 Call ok(match.Length = 6, "match.Length = " & match.Length)
166 Set submatch = match.SubMatches
167 Call ok(submatch.Count = 2, "submatch.Count = " & submatch.Count)
168 Call ok(submatch.Item(0) = "a", "submatch.Item(0) = " & submatch.Item(0))
169 Call ok(submatch.Item(1) = "b", "submatch.Item(0) = " & submatch.Item(1))
171 Set x = new regexp
172 Call ok(x.Pattern = "", "RegExp.Pattern = " & x.Pattern)
173 Call ok(x.IgnoreCase = false, "RegExp.IgnoreCase = " & x.IgnoreCase)
174 Call ok(x.Global = false, "RegExp.Global = " & x.Global)
175 Call ok(x.Multiline = false, "RegExp.Multiline = " & x.Multiline)
177 set matches = x.execute("test")
178 Call ok(matches.Count = 1, "matches.Count = " & matches.Count)
179 x.pattern = ""
180 set matches = x.execute("test")
181 Call ok(matches.Count = 1, "matches.Count = " & matches.Count)
182 set match = matches.item(0)
183 Call ok(match.Value = "", "match.Value = " & match.Value)
184 x.global = true
185 set matches = x.execute("test")
186 Call ok(matches.Count = 5, "matches.Count = " & matches.Count)
187 set match = matches.item(0)
188 Call ok(match.Value = "", "match.Value = " & match.Value)
189 set match = matches.item(4)
190 Call ok(match.Value = "", "match.Value = " & match.Value)
191 matches = x.test("test")
192 Call ok(matches = true, "matches = " & matches)
194 dim test_global
196 sub test_replace(pattern, string, rep, exp)
197 dim x, re
198 set re = new regexp
199 re.pattern = pattern
200 re.global = test_global
201 x = re.replace(string, rep)
202 call ok(x = exp, "replace returned " & x & " expected " & exp)
203 end sub
205 test_global = true
206 test_replace "xxx", "xxxx", "y", "yx"
207 test_replace "\[([^\[]+)\]", "- [test] -", "success", "- success -"
208 test_replace "\[([^\[]+)\]", "[test] [test]", "aa", "aa aa"
209 test_replace "(\&(\d))", "abc &1 123", "$'", "abc 123 123"
210 test_replace "(\&(\d))", "abc &1 123", "$`", "abc abc 123"
211 test_replace "(\&(\d))", "abc &1 123", "$3", "abc $3 123"
212 test_replace "\[([^\[]+)\]", "- [test] -", true, "- -1 -"
213 test_replace "\[([^\[]+)\]", "- [test] -", 6, "- 6 -"
214 test_replace "(\$(\d))", "$1,$2", "$$1-$1$2", "$1-$11,$1-$22"
215 test_replace "b", "abc", "x$&z", "axbzc"
217 test_global = false
218 test_replace "\[([^\[]+)\]", "[test] [test]", "aa", "aa [test]"
220 set r = new regexp
221 x = r.replace("xxx", "y")
222 call ok(x = "yxxx", "x = " & x)
223 r.global = true
224 x = r.replace("xxx", "y")
225 call ok(x = "yxyxyxy", "x = " & x)
227 Call reportSuccess()