| 1 |
' |
| 2 |
' This file is part of the LibreOffice project. |
| 3 |
' |
| 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/. |
| 7 |
' |
| 8 |
|
| 9 |
Option Explicit |
| 10 |
|
| 11 |
Function doUnitTest as String |
| 12 |
TestUtil.TestInit |
| 13 |
verify_testFormat |
| 14 |
doUnitTest = TestUtil.GetResult() |
| 15 |
End Function |
| 16 |
|
| 17 |
Sub verify_testFormat |
| 18 |
On Error GoTo errorHandler |
| 19 |
|
| 20 |
Dim d As Date |
| 21 |
d = "2024-09-16 17:03:30" |
| 22 |
TestUtil.AssertEqual(Format(d, "YYYY-MM-DD"), "2024-09-16", "Format(d, ""YYYY-MM-DD"")") |
| 23 |
TestUtil.AssertEqual(Format("2024-09-16 05:03:30 PM", "hh-mm-ss"), "17-03-30", "Format(""2024-09-16 05:03:30 PM"", ""hh-mm-ss"")") |
| 24 |
' A string that can be converted to number, with a text-format string |
| 25 |
TestUtil.AssertEqual(Format("001", "foo @ bar"), "foo 001 bar", "Format(""001"", ""foo @ bar"")") |
| 26 |
' A string that cannot be converted to number, with a text-format string |
| 27 |
TestUtil.AssertEqual(Format("baz", "foo @ bar"), "foo baz bar", "Format(""baz"", ""foo @ bar"")") |
| 28 |
' Legacy format strings |
| 29 |
' leading '!': get only the first character of the source string |
| 30 |
TestUtil.AssertEqual(Format("abc", "! @"), "a", "Format(""abc"", ""! @"")") |
| 31 |
' leading '\': get as many characters from source string, as in format string until the next '\', padding with spaces as needed |
| 32 |
TestUtil.AssertEqual(Format("abcdefgh", "\123\45"), "abcde", "Format(""abcdefgh"", ""\123\45"")") |
| 33 |
TestUtil.AssertEqual(Format("abcdefgh", "\12345"), "abcdef", "Format(""abcdefgh"", ""\12345"")") |
| 34 |
TestUtil.AssertEqual(Format("abc", "\12345\"), "abc ", "Format(""abc"", ""\12345\"")") |
| 35 |
' leading '&': get the whole source string unmodified |
| 36 |
TestUtil.AssertEqual(Format("abc", "& @"), "abc", "Format(""abc"", ""& @"")") |
| 37 |
' non-leading positions |
| 38 |
TestUtil.AssertEqual(Format("abc", "@ !"), "abc !", "Format(""abc"", ""@ !"")") |
| 39 |
TestUtil.AssertEqual(Format("abc", "1\2345"), "abc", "Format(""abc"", ""1\2345"")") |
| 40 |
TestUtil.AssertEqual(Format("abc", "@ &"), "abc &", "Format(""abc"", ""@ &"")") |
| 41 |
|
| 42 |
TestUtil.AssertEqual(Format(""), "", "Format("""")") |
| 43 |
TestUtil.AssertEqual(Format(" "), " ", "Format("" "")") |
| 44 |
TestUtil.AssertEqual(Format(" 00 "), "0", "Format("" 00 "")") |
| 45 |
TestUtil.AssertEqual(Format(CDate("2025-09-26")), "09/26/2025", "Format(CDate(""2025-09-26""))") |
| 46 |
TestUtil.AssertEqual(Format(#2025-09-26#), "09/26/2025", "Format(#2025-09-26#)") |
| 47 |
|
| 48 |
Exit Sub |
| 49 |
errorHandler: |
| 50 |
TestUtil.ReportErrorHandler("verify_testFormat", Err, Error$, Erl) |
| 51 |
End Sub |