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()
18 Sub verify_testInStr()
19 On Error GoTo errorHandler
21 TestUtil
.AssertEqual(InStr(1, "somemoretext", "more"), 5, "InStr(1, ""somemoretext"", ""more"")")
22 TestUtil
.AssertEqual(InStr("somemoretext", "more"), 5, "InStr(""somemoretext"", ""more"")")
23 TestUtil
.AssertEqual(InStr("somemoretext", "somemoretext"), 1, "InStr(""somemoretext"", ""somemoretext"")")
24 TestUtil
.AssertEqual(InStr("somemoretext", "nothing"), 0, "InStr(""somemoretext"", ""nothing"")")
26 Dim SearchString
, SearchChar
27 SearchString
= "XXpXXpXXPXXP" ' String to search in.
28 SearchChar
= "P" ' Search for "P".
29 TestUtil
.AssertEqual(InStr(4, SearchString
, SearchChar
, 1), 6, "InStr(4, SearchString, SearchChar, 1)")
30 TestUtil
.AssertEqual(InStr(1, SearchString
, SearchChar
, 0), 9, "InStr(1, SearchString, SearchChar, 0)")
31 TestUtil
.AssertEqual(InStr(1, SearchString
, "W"), 0, "InStr(1, SearchString, ""W"")")
33 ' tdf#139840 - case-insensitive operation for non-ASCII characters
34 TestUtil
.AssertEqual(InStr(1, "α", "Α", 1), 1, "InStr(1, ""α"", ""Α"", 1)")
35 ' tdf#139840 - German Eszett is uppercased to a two-character 'SS'.
36 ' This test should fail after tdf#110003 has been fixed.
37 TestUtil
.AssertEqual(InStr(2, "Straße", "s", 1), 5, "InStr(2, ""Straße"", ""s"", 1)")
39 ' Start position is greater than the length of the string being searched.
40 TestUtil
.AssertEqual(InStr(2, "α", "Α", 1), 0, "InStr(2, ""α"", ""Α"", 1)")
44 TestUtil
.ReportErrorHandler("verify_testInStr", Err
, Error$, Erl
)