1 ' This file is part of the LibreOffice project.
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/.
10 Function doUnitTest() As String
13 doUnitTest
= TestUtil
.GetResult()
17 On Error GoTo errorHandler
20 TestUtil
.AssertEqual(Split( "Hello world" )(1), "world", "Split( ""Hello world"" )(1)")
22 ' tdf#123025 - split function sets the datatype of the array to empty,
23 ' preventing any subsequent assignments of values to the array and to the elements itself.
25 arr
= Split("a/b", "/")
26 TestUtil
.AssertEqual(arr(0), "a", "Split(""a/b"", ""/"")(0)")
27 TestUtil
.AssertEqual(arr(1), "b", "Split(""a/b"", ""/"")(1)")
29 TestUtil
.AssertEqual(arr(0), "a", "ReDim Preserve arr(1)(0)")
30 TestUtil
.AssertEqual(arr(1), "b", "ReDim Preserve arr(1)(1)")
32 TestUtil
.AssertEqual(arr(0), "", "ReDim arr(1)(0)")
33 TestUtil
.AssertEqual(arr(1), "", "ReDim arr(1)(1)")
37 TestUtil
.AssertEqual(arr(0), "a", "arr(0)")
38 TestUtil
.AssertEqual(arr(1), "b", "arr(1)")
40 TestUtil
.AssertEqual(arr(0), "a", "ReDim Preserve arr(1)(0) after assignment")
41 TestUtil
.AssertEqual(arr(1), "b", "ReDim Preserve arr(1)(1) after assignment")
43 ' tdf#144924 - allow the assignment of different data types to the individual elements
45 splitArr
= Split("a/b&&c/d", "&&")
47 For i
= 0 To UBound(splitArr
)
48 ' Without the fix in place, this assignment would have failed
49 splitArr(i
) = Split(splitArr(i
), "/")
50 ' Without the fix in place, this test would have failed with:
51 ' - Expected: 8200 (8192 for Array and 8 for String)
52 ' - Actual : 8 (8 for String)
53 TestUtil
.AssertEqual(VarType(splitArr(i
)), 8200, "VarType(splitArr(i))")
56 ' tdf#141474 keyword names need to match that of VBA
57 TestUtil
.AssertEqual(Split(expression
:="LibreOffice StarOffice")(1), "StarOffice", "Split with 1 keyword name" )
58 Dim txt
As String : txt
= "Libre_Office_Star_Office"
59 TestUtil
.AssertEqual(Split(delimiter
:="_", expression
:=txt
)(2), "Star", "Split with 2 keyword names" )
60 TestUtil
.AssertEqual(Split(limit
:=3, delimiter
:="_", expression
:=txt
)(2), "Star_Office", "Split with 3 keyword names" )
64 TestUtil
.ReportErrorHandler("verify_testSplit", Err
, Error$, Erl
)