58 Commits

Author SHA1 Message Date
Alexander Grund
d56bad6d69 Add some tests for missed cases
- Date formatting for UInt64
- Error cases
- Practically unreachable cases
2025-01-16 09:11:08 +01:00
Alexander Grund
42e65d0d3d Implement support for uint64_t values in ICU backend
ICU doesn't support uint64_t directly but provides access to formatting
and parsing of decimal number strings.
Use Boost.Charconv to interface with that.

Fixes #235
2025-01-15 13:57:44 +01:00
Alexander Grund
211734c2c8 Add test for formatting large (u)int64 numbers
As reported in #235 formatting the first number which doesn't fit into
int64_t anymore fails to add the thousands separators.
I.e.:
`9223372036854775807` -> `9,223,372,036,854,775,807`
`9223372036854775808` -> `9223372036854775808`

Add a test reproducing that that for all backends.
2025-01-15 13:57:44 +01:00
Alexander Grund
ec1676280e
Raise minimum ICU version to 4.8.1
A lot of checks and a major workaround are for ICU 4.8 or earlier which
can be removed.
An annoying bug (Parsing of timezones like "GMT" in "full" format followed by unrelated text)
fixed in 4.8.1 is worth avoiding by requiring this version over 4.8.0.
2024-12-27 12:14:43 +01:00
Alexander Grund
34611eadae
Raise minimum ICU version to 4.2
StringPiece is only available in 4.2+ and is required for proper parsing
and formatting.
As this version is now "old enough", just assume 4.2+ removing many
conditionals.
2024-12-27 12:14:43 +01:00
Alexander Grund
d52908bb3c Refactor test_formatting
- Make spelling of "ICU" consistently uppercase (except at start of names)
- Move definitions related to existance of ICU together and sort by name
2024-12-27 12:13:10 +01:00
Alexander Grund
f0d95b079b
Add TEST_CONTEXT
Avoid to require manual output in anticipation of failures.
2024-12-01 19:36:58 +01:00
Alexander Grund
9f4424d7db
test: Include file in error message
Also move the error reporting to a single function
2024-12-01 19:33:38 +01:00
Alexander Grund
9a346dd5f8
Fix parsing of numbers in floating point format to integers
When parsing a string like "123.456" to an integer the ICU backend would
first parse it greedily to a floating point value and then cast/truncate
it to an integer.
Set the flag to only parse integers when parsing to an integral number.
Care must be taken not to set that when parsing e.g. a currency or date
to an integer where the truncation is intended.
2024-11-11 15:48:24 +01:00
Alexander Grund
744799aad3
Add test cases for remaining format modifiers 2023-09-20 08:33:59 +02:00
Alexander Grund
c68c5c7a2b Fix handling of escaped opening brace in format strings
When using an escaped opening brace in a format string it was output 2
times instead of one.
Fix and add test
2023-09-19 10:51:59 +02:00
Alexander Grund
51358d9394
Check Posix/classic formatting for all backends
Also include previously missed `long long` and `long double` types
2023-06-27 23:04:09 +02:00
Alexander Grund
d80b3b6ebc
Refactor format parsing for better coverage and clarity 2023-06-27 23:04:09 +02:00
Alexander Grund
9858b2e0d2
Test throwing of format class when moved with bound params
Use a helper method and comma operator to throw before moving from object
2023-06-27 23:04:08 +02:00
Alexander Grund
26469cd230
Suppress or handle missing coverage of test code
Try to achieve 100% test code coverage to find accidentally missed ones.
Especially the WinAPI tests had some wrongly uncovered lines at function
start/end which needed to be excluded.
2023-06-27 23:04:08 +02:00
Alexander Grund
c314f242e0 Add test for possible corner cases with as::posix/number
Especially the ICU backend falls back to using `std::numpunct` so need
to be sure POSIX formatting and number formatting works as expected when
changing that.
2023-06-27 13:22:31 +02:00
Alexander Grund
447f2e0f72
Fix test_formatting failure on old ICU versions
Older ICU versions didn't understand the additional comma or ' at ' in
the datetime test which was made unconditional in #184
2023-06-22 22:37:23 +02:00
Alexander Grund
219c834b57
Fix ICU time format test
ICU changed the time format again (in the CLDR) using a NBSP before AM/PM instead of a real space.
Hence query ICU directly for the expected result.
But also use a hard-coded value for parsing tests to ensure backwards compatibility.
2023-06-20 19:35:18 +02:00
Alexander Grund
6a95c82083
Simplify tests with empty_stream
Add a function to clear a string stream (i.e. make it empty)
and use it instead of `s.str(some-templated-empty-string)`
2023-05-26 19:35:36 +02:00
Alexander Grund
9b1813e757 Remove superflous braces
Make the code a bit shorter vertically, enforced formating ensures
correct indentation which provides enough readability
2023-05-16 12:04:59 +02:00
Alexander Grund
0a68c52b7f Modernize using nullptr 2023-05-07 19:01:45 +02:00
Alexander Grund
21d03989f0
Fix UB on invalid index in format string
A placeholder like `{0}` triggers an integer underflow which is UB.
Replace the `atoi` by the C++11 conversion function and check the bounds.
2023-04-08 19:13:24 +02:00
Alexander Grund
1cc2a017ab Fix some MSVC warnings
Define `_SCL_SECURE_NO_WARNINGS` for building the library to avoid "Call to 'std::copy' with parameters that may be unsafe" in `src\boost\locale\std\converter.cpp`
This also allows to remove the multiple suppressions of C4996
2022-11-22 09:15:17 +01:00
Alexander Grund
4e1cc81fdf
Make basic_format movable
Also document the possible pitfalls with it.

Closes #2
2022-10-17 19:48:12 +02:00
Alexander Grund
2dd0f55502
Add corner case testing for basic_format 2022-10-17 19:48:00 +02:00
Flamefire
3a24b94d18 Simplify min-max formatting test using C++11 std integer types 2022-10-14 12:59:18 +02:00
Alexander Grund
b8a3c3cb53
Refactor tests and remove/combine/handle special cases for some ICU versions in tests 2022-10-13 20:58:25 +02:00
Alexander Grund
907e62517f Always compile all test cases
Move the skip condition into `test_main` to avoid missing compile failures due to wrong/missing includes in the headers and to improve formatting due to the removed indentation level of the PP macros
2022-10-10 14:25:58 +02:00
Alexander Grund
7784f46243 Format sources
Use clang-format-14 to format source code consistently.
Closes #98
2022-10-10 14:25:58 +02:00
Flamefire
eda19c7242 Fix failures when using ICU and libc++
The `dynamic_cast` of ICU classes may fail with libc++ due to
missing/wrong RTTI and their `U_IMPORT`. I.e. it may duplicate the RTTI
for e.g. `SimpleDateFormat` making the cast fail.
Introduce `icu_cast` to handle that.
2022-10-02 13:45:46 +02:00
Alexander Grund
0823a89826 Make time format test failures easier to debug
Refactor to arrays of pairs (input, expected output) and use a range-based for to iterate over those.
This allows to easier see the pairs.
2022-10-02 13:45:46 +02:00
Alexander Grund
87e3e10408 Fix time format test failure in e.g. ICU 55.1
The long format of the GMT time zone changes between versions so get it from ICU directly.
2022-10-02 13:45:46 +02:00
Alexander Grund
6d94e4a9db Fix time format test failure in ICU 52.x
The `icu::DateFormat::kLong` format now returns "Greenwich Mean Time"
instead of "GMT" only.
2022-10-02 13:45:46 +02:00
Alexander Grund
15f8c20e1d Fix time format test failure in ICU 51.x
The timezone is output as "GMT+1" not "GMT+01:00" as it used to be
in earlier ICU versions.
2022-10-02 13:45:46 +02:00
Alexander Grund
87ad204883 Fix currency formatting test with recent ICU
The ISO currency format changes between ICU versions so add a function
to use ICU directly to format the currency and use that as the expected
value.
2022-10-02 13:45:46 +02:00
Alexander Grund
e8e5b832e5 Reduce reevaluation of values in test_formatting macros
Especially the `get_icu_currency_iso` was reevaluated multiple times for each subtest which is redundant.
So modify the macros to store the value as a `const std::string` evaluating it exactly once.
2022-09-27 21:58:45 +02:00
Alexander Grund
b50e7ed313
Refactor test_formatting
Use better names for macros and their params
2022-09-16 11:31:59 +02:00
Alexander Grund
46319fed1e
Use long long unconditionally 2022-09-14 10:15:45 +02:00
Alexander Grund
fadb2190ce
Move test headers to subfolder
Gets rid of the `test_` prefix in the filenames and avoids confusing those with the actual tests especially by renaming the test framework file from `test_locale.hpp` to `unit_test.hpp`
2022-09-13 12:50:23 +02:00
Alexander Grund
5888146aa6
Improve test_formatting
Simplify code by removing uneccessary loops.
Factor out code from macros into functions to allow easier debugging.
2022-09-13 12:50:23 +02:00
Alexander Grund
0c3eeb4c3c
Tests: Print RHS&LHS for failing TEST_EQ 2022-09-13 12:50:23 +02:00
Alexander Grund
9b2a67dd08
Suppress boostinspect warning for min/max macros
We compile with NOMINMAX to avoid such issues in general.
2022-07-12 18:35:43 +02:00
Alexander Grund
707f801c55
Remive vim markers
To be replaced by clang-format in the future.
2022-07-12 18:35:42 +02:00
Alexander Grund
595934f25e
Update license headers
Use the more concise format omitting the reference to the license file
and refer to the URL only.
2022-07-12 18:35:41 +02:00
Alexander Grund
1512f618f9 Refactor ICU src files
Introduce and use `BOOST_LOCALE_ICU_VERSION`
Make sure headers include the config header first
2022-07-07 08:58:07 +02:00
Alexander Grund
192807a27e
Fix various MSVC warnings
Mostly constant conditions and narrowing casts
2022-07-01 17:13:52 +02:00
Alexander Grund
aa30bd33aa Refactor test framework
Use a common `main` function calling into custom `test_main` functions and
move all common code into the former.
Also introduce an RAII class for a `locale_t` to avoid leaks and reduce
the code further.
Add some LCOV annotations for lines not expected to be reached.
2022-06-30 15:08:08 +02:00
Alexander Grund
8c7338cd0d Use \n instead of std::endl where appropriate
We usually don't need the flush so use \n at end of strings which
greatly shortens the code.
2022-06-30 15:08:08 +02:00
Alexander Grund
00c8e07689 Remove using std-namespace and reformat
Removes the `using namespace std` to easier differentiate between
Boost.Locale and Std stuff.
Add spaces around shift operators.
2022-06-30 15:08:08 +02:00
Alexander Grund
d1fc12426f Remove trailing spaces 2022-06-04 11:50:39 +02:00