Provide utilities for testing custom formatters.
Outline
Purpose
Provide utilities for testing custom formatters
Classes
- FormatterTestUtil: formatter test utilities
Description
This component provides a utility to facilitate testing of bsl::formatter partial specializations where, due to hierarchical reasons, the testing cannot be performed using bslfmt::format.
This component is for use within bslfmt only.
Usage
This section illustrates intended usage of this component.
Example: Testing an integer formatter
Suppose we want to test bsl::formatter specialization for int.
First, to test parse function, we can use testParseVFormat function, that accepts pointer to bsl::string in which to store an error message if any, a flag indicating our desire to see the result of the standard implementation and accordingly the format string itself:
bool rv = TestUtilChar::testParseVFormat<int>(&message, true, "{0:}");
Definition bslstl_string.h:1252
Since the input data is correct, we get a positive result and the error message is empty:
assert(true == rv);
bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this string has length 0, and false otherwise.
Definition bslstl_string.h:7331
Then, we try to parse invalid format string and get the expected error message at the output:
rv = TestUtilChar::testParseVFormat<int>(&message, true, "{0");
assert(false == rv);
assert(
bsl::string(
"Format string too short") == message);
void clear() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6043
Now we check format formatter's method using testEvaluateVFormat function, that in addition to the parameters already mentioned, accepts a string with the expected formatting result and a value for formatting:
rv = TestUtilChar::testEvaluateVFormat<int>(&message,
"5",
true,
"{0:}",
5);
assert(true == rv);
Finally verify that this function returns a false value if the expected and actual results do not match:
rv = TestUtilChar::testEvaluateVFormat<int>(&message,
"7",
true,
"{0:}",
5);
assert(false == rv);
assert(message.
starts_with(
"bslfmt result does not match"));
bool starts_with(basic_string_view< CHAR_TYPE, CHAR_TRAITS > characterString) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:7918
◆ BSLFMT_FORMATTER_TEST_CONSTEVAL
| #define BSLFMT_FORMATTER_TEST_CONSTEVAL |
◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING
◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_GETTER
| #define BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_GETTER |
( |
|
ARG | ) |
ARG.get() |
◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_ONE_ARG
◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_P
◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_TWO_ARGS
◆ BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING
◆ BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING_ONE_ARG
◆ BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING_P
◆ BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING_TWO_ARGS
◆ BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING
◆ BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING_ONE_ARG
◆ BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING_P
◆ BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING_TWO_ARGS