2 ' This file is part of the LibreOffice project.
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/.
12 Function doUnitTest() As String
15 doUnitTest
= TestUtil
.GetResult()
19 On Error GoTo errorHandler
22 TestUtil
.AssertEqual(Split( "Hello world" )(1), "world", "Split( ""Hello world"" )(1)")
24 ' tdf#123025 - split function sets the datatype of the array to empty,
25 ' preventing any subsequent assignments of values to the array and to the elements itself.
27 arr
= Split("a/b", "/")
28 TestUtil
.AssertEqual(arr(0), "a", "Split(""a/b"", ""/"")(0)")
29 TestUtil
.AssertEqual(arr(1), "b", "Split(""a/b"", ""/"")(1)")
31 TestUtil
.AssertEqual(arr(0), "a", "ReDim Preserve arr(1)(0)")
32 TestUtil
.AssertEqual(arr(1), "b", "ReDim Preserve arr(1)(1)")
34 TestUtil
.AssertEqual(arr(0), "", "ReDim arr(1)(0)")
35 TestUtil
.AssertEqual(arr(1), "", "ReDim arr(1)(1)")
39 TestUtil
.AssertEqual(arr(0), "a", "arr(0)")
40 TestUtil
.AssertEqual(arr(1), "b", "arr(1)")
42 TestUtil
.AssertEqual(arr(0), "a", "ReDim Preserve arr(1)(0) after assignment")
43 TestUtil
.AssertEqual(arr(1), "b", "ReDim Preserve arr(1)(1) after assignment")
45 ' tdf#144924 - using VBASupport 1, the split function returns an array of substrings, hence no
46 ' assignment of different data types to the individual elements is possible
48 splitArr
= Split("a/b&&c/d", "&&")
49 ' Without the fix in place, this test would have failed with:
50 ' - Expected: 8 (8 for String)
51 ' - Actual : 8200 (8192 for Array and 8 for String)
52 TestUtil
.AssertEqual(VarType(splitArr(0)), 8, "VarType(splitArr(0))")
54 ' tdf#141474 keyword names need to match that of VBA
55 TestUtil
.AssertEqual(Split(expression
:="LibreOffice StarOffice")(1), "StarOffice", "Split with 1 keyword name" )
56 Dim txt
As String : txt
= "Libre_Office_Star_Office"
57 TestUtil
.AssertEqual(Split(delimiter
:="_", expression
:=txt
)(2), "Star", "Split with 2 keyword names" )
58 TestUtil
.AssertEqual(Split(limit
:=3, delimiter
:="_", expression
:=txt
)(2), "Star_Office", "Split with 3 keyword names" )
62 TestUtil
.ReportErrorHandler("verify_testSplit", Err
, Error$, Erl
)