LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / basic / qa / basic_coverage / test_split_method.bas
blob52ba91fe3a65befdc52485a8638051b0bb3ac1e2
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 Exit Sub
57 errorHandler:
58 TestUtil.ReportErrorHandler("verify_testSplit", Err, Error$, Erl)
59 End Sub