Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195'' Copyright 2013 Piotr Caban for CodeWeavers'' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.'' This library is distributed in the hope that it will be useful,' but WITHOUT ANY WARRANTY; without even the implied warranty of' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU' Lesser General Public License for more details.'' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA'
Option Explicit
Dim x, matches, match, submatch
Set x = CreateObject("vbscript.regexp")Call ok(getVT(x.Pattern) = "VT_BSTR", "getVT(RegExp.Pattern) = " & getVT(x.Pattern))Call ok(x.Pattern = "", "RegExp.Pattern = " & x.Pattern)Call ok(getVT(x.IgnoreCase) = "VT_BOOL", "getVT(RegExp.IgnoreCase) = " & getVT(x.IgnoreCase))Call ok(x.IgnoreCase = false, "RegExp.IgnoreCase = " & x.IgnoreCase)Call ok(getVT(x.Global) = "VT_BOOL", "getVT(RegExp.Global) = " & getVT(x.Global))Call ok(x.Global = false, "RegExp.Global = " & x.Global)Call ok(getVT(x.Multiline) = "VT_BOOL", "getVT(RegExp.Multiline) = " & getVT(x.Multiline))Call ok(x.Multiline = false, "RegExp.Multiline = " & x.Multiline)
x.Pattern = "a+"matches = x.Test(" aabaaa")Call ok(matches = true, "RegExp.Test returned: " & matches)Set matches = x.Execute(" aabaaa")Call ok(getVT(matches.Count) = "VT_I4", "getVT(matches.Count) = " & getVT(matches.Count))Call ok(matches.Count = 1, "matches.Count = " & matches.Count)Set match = matches.Item(0)Call ok(match.Value = "aa", "match.Value = " & match.Value)Call ok(match.FirstIndex = 1, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 2, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
x.Global = trueSet matches = x.Execute(" aabaaa")Call ok(matches.Count = 2, "matches.Count = " & matches.Count)Set match = matches.Item(0)Call ok(match.Value = "aa", "match.Value = " & match.Value)Call ok(match.FirstIndex = 1, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 2, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)Set match = matches.Item(1)Call ok(match.Value = "aaa", "match.Value = " & match.Value)Call ok(match.FirstIndex = 4, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 3, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
Set matches = x.Execute(" aabaaa")Call ok(matches.Count = 2, "matches.Count = " & matches.Count)Set match = matches.Item(0)Call ok(match.Value = "aa", "match.Value = " & match.Value)Call ok(match.FirstIndex = 1, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 2, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
x.Pattern = "^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$"x.Global = falseSet matches = x.Execute("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")Call ok(matches.Count = 0, "matches.Count = " & matches.Count)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
x.Pattern = "(a|b)+|(c)"Set matches = x.Execute("aa")Call ok(matches.Count = 1, "matches.Count = " & matches.Count)Set match = matches.Item(0)Call ok(match.Value = "aa", "match.Value = " & match.Value)Call ok(match.FirstIndex = 0, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 2, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 2, "submatch.Count = " & submatch.Count)Call ok(getVT(submatch.Item(0)) = "VT_BSTR", "getVT(submatch.Item(0)) = " & getVT(submatch.Item(0)))Call ok(submatch.Item(0) = "a", "submatch.Item(0) = " & submatch.Item(0))Call ok(getVT(submatch.Item(1)) = "VT_EMPTY", "getVT(submatch.Item(1)) = " & getVT(submatch.Item(1)))Call ok(submatch.Item(1) = "", "submatch.Item(0) = " & submatch.Item(1))
matches = x.Test(" a ")Call ok(matches = true, "RegExp.Test returned: " & matches)matches = x.Test(" a ")Call ok(matches = true, "RegExp.Test returned: " & matches)
x.Pattern = "\[([^\[]+)\]"x.Global = trueSet matches = x.Execute(" [test] ")Call ok(matches.Count = 1, "matches.Count = " & matches.Count)Set match = matches.Item(0)Call ok(match.Value = "[test]", "match.Value = " & match.Value)Call ok(match.FirstIndex = 1, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 6, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 1, "submatch.Count = " & submatch.Count)Call ok(submatch.Item(0) = "test", "submatch.Item(0) = " & submatch.Item(0))
x.Pattern = "Ab"x.IgnoreCase = trueSet matches = x.Execute("abcaBc")Call ok(matches.Count = 2, "matches.Count = " & matches.Count)Set match = matches.Item(0)Call ok(match.Value = "ab", "match.Value = " & match.Value)Call ok(match.FirstIndex = 0, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 2, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)Set match = matches.Item(1)Call ok(match.Value = "aB", "match.Value = " & match.Value)Call ok(match.FirstIndex = 3, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 2, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
x.Pattern = "a+b"x.IgnoreCase = falseSet matches = x.Execute("aaabcabc")Call ok(matches.Count = 2, "matches.Count = " & matches.Count)Set match = matches.Item(0)Call ok(match.Value = "aaab", "match.Value = " & match.Value)Call ok(match.FirstIndex = 0, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 4, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)Set match = matches.Item(1)Call ok(match.Value = "ab", "match.Value = " & match.Value)Call ok(match.FirstIndex = 5, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 2, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
x.Pattern = "\\"Set matches = x.Execute("aaa\\cabc")Call ok(matches.Count = 2, "matches.Count = " & matches.Count)Set match = matches.Item(0)Call ok(match.Value = "\", "match.Value = " & match.Value)Call ok(match.FirstIndex = 3, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 1, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)Set match = matches.Item(1)Call ok(match.Value = "\", "match.Value = " & match.Value)Call ok(match.FirstIndex = 4, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 1, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 0, "submatch.Count = " & submatch.Count)
x.Pattern = "(a)(b)cabc"Set matches = x.Execute("abcabc")Call ok(matches.Count = 1, "matches.Count = " & matches.Count)Set match = matches.Item(0)Call ok(match.Value = "abcabc", "match.Value = " & match.Value)Call ok(match.FirstIndex = 0, "match.FirstIndex = " & match.FirstIndex)Call ok(match.Length = 6, "match.Length = " & match.Length)Set submatch = match.SubMatchesCall ok(submatch.Count = 2, "submatch.Count = " & submatch.Count)Call ok(submatch.Item(0) = "a", "submatch.Item(0) = " & submatch.Item(0))Call ok(submatch.Item(1) = "b", "submatch.Item(0) = " & submatch.Item(1))
Set x = new regexpCall ok(x.Pattern = "", "RegExp.Pattern = " & x.Pattern)Call ok(x.IgnoreCase = false, "RegExp.IgnoreCase = " & x.IgnoreCase)Call ok(x.Global = false, "RegExp.Global = " & x.Global)Call ok(x.Multiline = false, "RegExp.Multiline = " & x.Multiline)
set matches = x.execute("test")Call ok(matches.Count = 1, "matches.Count = " & matches.Count)x.pattern = ""set matches = x.execute("test")Call ok(matches.Count = 1, "matches.Count = " & matches.Count)set match = matches.item(0)Call ok(match.Value = "", "match.Value = " & match.Value)x.global = trueset matches = x.execute("test")Call ok(matches.Count = 5, "matches.Count = " & matches.Count)set match = matches.item(0)Call ok(match.Value = "", "match.Value = " & match.Value)set match = matches.item(4)Call ok(match.Value = "", "match.Value = " & match.Value)matches = x.test("test")Call ok(matches = true, "matches = " & matches)
Call reportSuccess()