| 1 |
' This file is part of the LibreOffice project. |
| 2 |
' |
| 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/. |
| 6 |
' |
| 7 |
|
| 8 |
Option VBASupport 0 |
| 9 |
Option Explicit |
| 10 |
|
| 11 |
Function doUnitTest() As String |
| 12 |
TestUtil.TestInit |
| 13 |
verify_stringReplace |
| 14 |
doUnitTest = TestUtil.GetResult() |
| 15 |
End Function |
| 16 |
|
| 17 |
Sub verify_stringReplace() |
| 18 |
On Error GoTo errorHandler |
| 19 |
' tdf#132389 - case-insensitive operation for non-ASCII characters |
| 20 |
Dim retStr |
| 21 |
retStr = Replace("ABCabc", "b", "*") |
| 22 |
TestUtil.AssertEqual(retStr, "A*Ca*c", "case-insensitive ASCII: " & retStr) |
| 23 |
retStr = Replace("АБВабв", "б", "*") |
| 24 |
TestUtil.AssertEqual(retStr, "А*Ва*в", "case-insensitive non-ASCII: " & retStr) |
| 25 |
|
| 26 |
' tdf#141045 - different length of search and replace string. It is important |
| 27 |
' that the search string starts with the original string in order to test the error. |
| 28 |
' Without the fix in place, the string index calculations result in a crash. |
| 29 |
retStr = Replace("a", "abc", "ab") |
| 30 |
TestUtil.AssertEqual(retStr, "a", "different length of search and replace string: " & retStr) |
| 31 |
|
| 32 |
' tdf#143081 - Without the fix in place, this test would have crashed here |
| 33 |
retStr = Replace("""Straße""", """", """) |
| 34 |
TestUtil.AssertEqual(retStr, ""Straße"", "replace doesn't crash: " & retStr) |
| 35 |
|
| 36 |
' tdf#142487 - replace of special unicode characters. |
| 37 |
' Without the fix in place, this test would have failed with: |
| 38 |
' - Expected: Straßen |
| 39 |
' - Actual : Straßeen |
| 40 |
retStr = Replace("Straße", "e", "en") |
| 41 |
TestUtil.AssertEqual(retStr, "Straßen", "special unicode character: " & retStr) |
| 42 |
|
| 43 |
Exit Sub |
| 44 |
errorHandler: |
| 45 |
TestUtil.ReportErrorHandler("verify_stringReplace", Err, Error$, Erl) |
| 46 |
End Sub |