Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / basic / qa / vba_tests / instrrev.vb
blob3849d60c5f7e836e199feefcaf8a9a3bc239e89a
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_testInStrRev
15 doUnitTest = TestUtil.GetResult()
16 End Function
18 Sub verify_testInStrRev()
19 On Error GoTo errorHandler
21 TestUtil.AssertEqual(InStrRev("somemoretext", "more", -1), 5, "InStrRev(""somemoretext"", ""more"", -1)")
22 TestUtil.AssertEqual(InStrRev("somemoretext", "more"), 5, "InStrRev(""somemoretext"", ""more"")")
23 TestUtil.AssertEqual(InStrRev("somemoretext", "somemoretext"), 1, "InStrRev(""somemoretext"", ""somemoretext"")")
24 TestUtil.AssertEqual(InStrRev("somemoretext", "nothing"), 0, "InStrRev(""somemoretext"", ""nothing"")")
26 Dim SearchString, SearchChar
27 SearchString = "XXpXXpXXPXXP" ' String to search in.
28 SearchChar = "P" ' Search for "P".
29 TestUtil.AssertEqual(InStrRev(SearchString, SearchChar, 4, 1), 3, "InStrRev(SearchString, SearchChar, 4, 1)")
30 TestUtil.AssertEqual(InStrRev(SearchString, SearchChar, -1, 0), 12, "InStrRev(SearchString, SearchChar, -1, 0)")
31 TestUtil.AssertEqual(InStrRev(SearchString, "W", 1), 0, "InStrRev(SearchString, ""W"", 1)")
33 ' tdf#143332 - case-insensitive operation for non-ASCII characters
34 TestUtil.AssertEqual(InStrRev("α", "Α", -1, 1), 1, "InStrRev(""α"", ""Α"", -1, 1)")
35 TestUtil.AssertEqual(InStrRev("abc", "d", -1, 1), 0, "InStrRev(""abc"", ""d"", -1, 1)")
36 ' tdf#143332 - German Eszett is uppercased to a two-character 'SS'.
37 ' This test should fail after tdf#110003 has been fixed.
38 TestUtil.AssertEqual(InStrRev("Straße", "s", -1, 1), 5, "InStrRev(""Straße"", ""s"", -1, 1)")
40 ' tdf#141474 keyword names need to match that of VBA
41 Const vbBinaryCompare = 0, vbTextCompare = 1
42 TestUtil.AssertEqual(InStrRev(stringMatch:="Star", stringCheck:="LibreOffice"), 0, "InStrRev(stringMatch:=""Star"", stringCheck:=""LibreOffice"")")
43 TestUtil.AssertEqual(InStrRev(Start:=-1, stringMatch:="Libre", stringCheck:="LibreOfficeLibre"), 12, "InStrRev(Start:=-1, stringMatch:=""Libre"", stringCheck:=""LibreOfficeLibre"")")
44 TestUtil.AssertEqual(InStrRev(Start:=12, stringMatch:="Libre", stringCheck:="LibreOfficeLibre"), 1, "InStrRev(Start:=12, stringMatch:=""Libre"", stringCheck:=""LibreOfficeLibre"")")
45 TestUtil.AssertEqual(InStrRev(Compare:=vbBinaryCompare, Start:=12, stringMatch:="Libre", stringCheck:="LibreOfficeLibre"), 1, "InStrRev(Compare:=vbBinaryCompare, Start:=12, stringMatch:=""Libre"", stringCheck:=""LibreOfficeLibre"")")
47 Exit Sub
48 errorHandler:
49 TestUtil.ReportErrorHandler("verify_testInStrRev", Err, Error$, Erl)
50 End Sub