Debian Codegraph @

basic/qa/basic_coverage/test_Vbscript_RegExp.bas

raw
1 ' This file is part of the LibreOffice project.
2 '
3 ' This Source Code Form is subject to the terms of the Mozilla Public
4 ' License, v. 2.0. If a copy of the MPL was not distributed with this
5 ' file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 '
7
8 Option Explicit
9
10 Function doUnitTest() As String
11 TestUtil.TestInit
12 verify_testVbscript_RegExp
13 doUnitTest = TestUtil.GetResult()
14 End Function
15
16 Sub verify_testVbscript_RegExp()
17 On Error GoTo errorHandler
18
19 If GetGuiType() <> 1 Then ' Only testing on Windows
20 TestUtil.Assert(True) ' Mark test as succeeded
21 Exit Sub
22 End If
23
24 Dim txt, regex, matches, item1, item2
25
26 txt = "This is LibreOffice for you"
27
28 regex = CreateObject("VBScript.RegExp")
29 regex.Pattern = "(Li.+)(Of\w+)"
30
31 matches = regex.Execute(txt)
32
33 ' Test that accessing twice an indexed property (here: Item) of a COM object works
34 If matches.Count > 0 Then
35 item1 = matches.Item(0).SubMatches.Item(0)
36 ' Without the fix, the following line errored out:
37 ' Type: com.sun.star.lang.WrappedTargetRuntimeException
38 ' Message: [automation bridge] unexpected exception in IUnknownWrapper::getValue
39 item2 = matches.Item(0).SubMatches.Item(1)
40 End If
41
42 TestUtil.AssertEqual(item1, "Libre", "item1")
43 TestUtil.AssertEqual(item2, "Office", "item2")
44
45 Exit Sub
46 errorHandler:
47 TestUtil.ReportErrorHandler("verify_testVbscript_RegExp", Err, Error$, Erl)
48 End Sub