Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / basic / qa / vba_tests / split.vb
blob13f4d66a953941b28bc5c116696fe3184e7ace20
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/.
9 Option VBASupport 1
10 Option Explicit
12 Function doUnitTest() As String
13 TestUtil.TestInit
14 verify_testSplit
15 doUnitTest = TestUtil.GetResult()
16 End Function
18 Sub verify_testSplit
19 On Error GoTo errorHandler
21 ' SPLIT
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.
26 Dim arr(1) As String
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)")
30 ReDim Preserve arr(1)
31 TestUtil.AssertEqual(arr(0), "a", "ReDim Preserve arr(1)(0)")
32 TestUtil.AssertEqual(arr(1), "b", "ReDim Preserve arr(1)(1)")
33 ReDim arr(1)
34 TestUtil.AssertEqual(arr(0), "", "ReDim arr(1)(0)")
35 TestUtil.AssertEqual(arr(1), "", "ReDim arr(1)(1)")
37 arr(0) = "a"
38 arr(1) = "b"
39 TestUtil.AssertEqual(arr(0), "a", "arr(0)")
40 TestUtil.AssertEqual(arr(1), "b", "arr(1)")
41 ReDim Preserve 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
47 Dim splitArr
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" )
60 Exit Sub
61 errorHandler:
62 TestUtil.ReportErrorHandler("verify_testSplit", Err, Error$, Erl)
63 End Sub