File: test_string_replace.bas

package info (click to toggle)
libreoffice 4%3A26.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,837,456 kB
  • sloc: cpp: 4,397,406; xml: 499,109; java: 254,438; python: 81,844; ansic: 33,825; perl: 30,297; javascript: 19,722; sh: 12,050; makefile: 10,852; cs: 8,865; yacc: 8,549; objc: 2,131; lex: 1,385; asm: 1,231; awk: 996; pascal: 914; csh: 20; sed: 5
file content (46 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
' This file is part of the LibreOffice project.
'
' This Source Code Form is subject to the terms of the Mozilla Public
' License, v. 2.0. If a copy of the MPL was not distributed with this
' file, You can obtain one at http://mozilla.org/MPL/2.0/.
'

Option VBASupport 0
Option Explicit

Function doUnitTest() As String
    TestUtil.TestInit
    verify_stringReplace
    doUnitTest = TestUtil.GetResult()
End Function

Sub verify_stringReplace()
    On Error GoTo errorHandler
    ' tdf#132389 - case-insensitive operation for non-ASCII characters
    Dim retStr
    retStr = Replace("ABCabc", "b", "*")
    TestUtil.AssertEqual(retStr, "A*Ca*c", "case-insensitive ASCII: " & retStr)
    retStr = Replace("АБВабв", "б", "*")
    TestUtil.AssertEqual(retStr, "А*Ва*в", "case-insensitive non-ASCII: " & retStr)

    ' tdf#141045 - different length of search and replace string. It is important
    ' that the search string starts with the original string in order to test the error.
    ' Without the fix in place, the string index calculations result in a crash.
    retStr = Replace("a", "abc", "ab")
    TestUtil.AssertEqual(retStr, "a", "different length of search and replace string: " & retStr)

    ' tdf#143081 - Without the fix in place, this test would have crashed here
    retStr = Replace("""Straße""", """", """)
    TestUtil.AssertEqual(retStr, ""Straße"", "replace doesn't crash: " & retStr)
    
    ' tdf#142487 - replace of special unicode characters.
    ' Without the fix in place, this test would have failed with:
    ' - Expected: Straßen
    ' - Actual  : Straßeen
    retStr = Replace("Straße", "e", "en")
    TestUtil.AssertEqual(retStr, "Straßen", "special unicode character: " & retStr)

    Exit Sub
errorHandler:
    TestUtil.ReportErrorHandler("verify_stringReplace", Err, Error$, Erl)
End Sub