| 1 |
' |
| 2 |
' This file is part of the LibreOffice project. |
| 3 |
' |
| 4 |
' This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
' License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
' file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
' |
| 8 |
|
| 9 |
Option Explicit |
| 10 |
|
| 11 |
Function doUnitTest() As String |
| 12 |
TestUtil.TestInit |
| 13 |
verify_testLike |
| 14 |
doUnitTest = TestUtil.GetResult() |
| 15 |
End Function |
| 16 |
|
| 17 |
Sub verify_testLike() |
| 18 |
On Error GoTo errorHandler |
| 19 |
' Negation test |
| 20 |
TestUtil.AssertEqual("!" Like "[.!?]", True, "Negation1") |
| 21 |
TestUtil.AssertEqual("a" Like "[!abc]", False, "Negation2") |
| 22 |
TestUtil.AssertEqual("!" Like "[!!?]", False, "Negation3") |
| 23 |
TestUtil.AssertEqual("^" Like "[.!?]", False, "Negation4") |
| 24 |
TestUtil.AssertEqual("^" Like "[.^?]", True, "Negation5") |
| 25 |
' Like test from microsoft vba |
| 26 |
TestUtil.AssertEqual("aBBBa" Like "a*a", True, "Like1") |
| 27 |
TestUtil.AssertEqual("F" Like "[A-Z]", True, "Like2") |
| 28 |
TestUtil.AssertEqual("F" Like "[!A-Z]", False, "Like3") |
| 29 |
TestUtil.AssertEqual("a2a" Like "a#a", True, "Like4") |
| 30 |
TestUtil.AssertEqual("aM5b" Like "a[L-P]#[!c-e]", True, "Like5") |
| 31 |
TestUtil.AssertEqual("BAT123khg" Like "B?T*", True, "Like6") |
| 32 |
TestUtil.AssertEqual("CAT123khg" Like "B?T*", False, "Like7") |
| 33 |
TestUtil.AssertEqual("ab" Like "a*b", True, "Like8") |
| 34 |
TestUtil.AssertEqual("a*b" Like "a [*]b", False, "Like9") |
| 35 |
TestUtil.AssertEqual("axxxxxb" Like "a [*]b", False, "Like10") |
| 36 |
TestUtil.AssertEqual("a [xyz" Like "a [[]*", True, "Like11") |
| 37 |
TestUtil.AssertEqual("ab" + Chr(10) + "cd" Like "a*", True, "tdf#160478") |
| 38 |
' Invalid pattern |
| 39 |
Dim caughtError As Integer |
| 40 |
On Error GoTo expectedErrorHandler |
| 41 |
TestUtil.AssertEqual("a [xyz" Like "a [*", 42, "") ' Like must fail, will not reach AssertEqual |
| 42 |
TestUtil.AssertEqual(caughtError, 93, "tdf#169147") ' Invalid string pattern |
| 43 |
|
| 44 |
Exit Sub |
| 45 |
|
| 46 |
expectedErrorHandler: |
| 47 |
caughtError = Err |
| 48 |
Resume Next |
| 49 |
|
| 50 |
errorHandler: |
| 51 |
TestUtil.ReportErrorHandler("verify_testLike", Err, Error$, Erl) |
| 52 |
End Sub |