tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / basic / qa / basic_coverage / test_split_method.bas
blobe53dfd9705f1dd442dc1d017296ea777aaddca24
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/.
8 Option Explicit
10 Function doUnitTest() As String
11 TestUtil.TestInit
12 verify_testSplit
13 doUnitTest = TestUtil.GetResult()
14 End Function
16 Sub verify_testSplit
17 On Error GoTo errorHandler
19 ' SPLIT
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.
24 Dim arr(1) As String
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)")
28 ReDim Preserve arr(1)
29 TestUtil.AssertEqual(arr(0), "a", "ReDim Preserve arr(1)(0)")
30 TestUtil.AssertEqual(arr(1), "b", "ReDim Preserve arr(1)(1)")
31 ReDim arr(1)
32 TestUtil.AssertEqual(arr(0), "", "ReDim arr(1)(0)")
33 TestUtil.AssertEqual(arr(1), "", "ReDim arr(1)(1)")
35 arr(0) = "a"
36 arr(1) = "b"
37 TestUtil.AssertEqual(arr(0), "a", "arr(0)")
38 TestUtil.AssertEqual(arr(1), "b", "arr(1)")
39 ReDim Preserve 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
44 Dim splitArr
45 splitArr = Split("a/b&&c/d", "&&")
46 Dim i As Integer
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))")
54 Next
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" )
62 Exit Sub
63 errorHandler:
64 TestUtil.ReportErrorHandler("verify_testSplit", Err, Error$, Erl)
65 End Sub