mirror of
https://github.com/fmtlib/fmt.git
synced 2026-09-13 14:22:26 +08:00
Simplify calendar_padding test
This commit is contained in:
parent
2012961e3e
commit
1da57c78d4
@ -994,55 +994,18 @@ TEST(chrono_test, out_of_range) {
|
||||
EXPECT_THROW((void)fmt::format("{:%j}", fd), fmt::format_error);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void check_calendar_padding(T value, const char* expected,
|
||||
const char* chrono_format) {
|
||||
EXPECT_EQ(expected, fmt::format("{}", value));
|
||||
EXPECT_EQ(expected, fmt::format("{:}", value));
|
||||
EXPECT_EQ(fmt::format("{:15}", expected), fmt::format("{:15}", value));
|
||||
EXPECT_EQ(fmt::format("{:<15}", expected), fmt::format("{:<15}", value));
|
||||
EXPECT_EQ(fmt::format("{:>15}", expected), fmt::format("{:>15}", value));
|
||||
EXPECT_EQ(fmt::format("{:*^15}", expected), fmt::format("{:*^15}", value));
|
||||
EXPECT_EQ(fmt::format("{:%>15}", expected), fmt::format("{:%>15}", value));
|
||||
EXPECT_EQ(fmt::format("{:L>15}", expected), fmt::format("{:L>15}", value));
|
||||
EXPECT_EQ(fmt::format("{:>15}", expected), fmt::format("{:>{}}", value, 15));
|
||||
EXPECT_EQ(expected, fmt::format("{:1}", value));
|
||||
auto explicit_format = fmt::format("{{:*^15{}}}", chrono_format);
|
||||
auto unpadded_format = fmt::format("{{:{}}}", chrono_format);
|
||||
EXPECT_EQ(fmt::format("{:*^15}",
|
||||
fmt::format(runtime(unpadded_format), value)),
|
||||
fmt::format(runtime(explicit_format), value));
|
||||
EXPECT_THROW((void)fmt::format(runtime("{:>{}}"), value, -1),
|
||||
fmt::format_error);
|
||||
}
|
||||
|
||||
TEST(chrono_test, calendar_padding) {
|
||||
check_calendar_padding(fmt::day(5), "05", "%d");
|
||||
check_calendar_padding(fmt::month(1), "Jan", "%B");
|
||||
check_calendar_padding(fmt::year(2024), "2024", "%y");
|
||||
check_calendar_padding(fmt::weekday(6), "Sat", "%A");
|
||||
check_calendar_padding(
|
||||
fmt::year_month_day(fmt::year(2024), fmt::month(1), fmt::day(5)),
|
||||
"2024-01-05", "%Y/%m/%d");
|
||||
}
|
||||
EXPECT_EQ("05 ", fmt::format("{:5}", fmt::day(5)));
|
||||
EXPECT_EQ(" Jan", fmt::format("{:>5}", fmt::month(1)));
|
||||
EXPECT_EQ("2024 ", fmt::format("{:5}", fmt::year(2024)));
|
||||
EXPECT_EQ(" Sat", fmt::format("{:>5}", fmt::weekday(6)));
|
||||
EXPECT_EQ(" 2024-01-05",
|
||||
fmt::format("{:>11}",
|
||||
fmt::year_month_day(fmt::year(2024), fmt::month(1),
|
||||
fmt::day(5))));
|
||||
|
||||
template <typename T> void check_localized_calendar_padding(T value) {
|
||||
auto loc = get_locale("es_ES.UTF-8");
|
||||
auto expected = fmt::format(loc, "{:L}", value);
|
||||
EXPECT_EQ(fmt::format("{:*>15}", expected),
|
||||
fmt::format(loc, "{:*>15L}", value));
|
||||
EXPECT_EQ(fmt::format("{:>15}", expected),
|
||||
fmt::format(loc, "{:>{}L}", value, 15));
|
||||
}
|
||||
|
||||
TEST(chrono_test, localized_calendar_padding) {
|
||||
check_localized_calendar_padding(fmt::month(1));
|
||||
check_localized_calendar_padding(fmt::weekday(6));
|
||||
auto loc = get_locale("es_ES.UTF-8");
|
||||
EXPECT_EQ(fmt::format("{:>15}", fmt::format(loc, "{:L%B}", fmt::month(1))),
|
||||
fmt::format(loc, "{:>15L%B}", fmt::month(1)));
|
||||
EXPECT_EQ(fmt::format("{:>15}", fmt::format(loc, "{:L%A}", fmt::weekday(6))),
|
||||
fmt::format(loc, "{:>15L%A}", fmt::weekday(6)));
|
||||
// An explicit chrono format still overrides the default.
|
||||
EXPECT_EQ("January", fmt::format("{:%B}", fmt::month(1)));
|
||||
}
|
||||
|
||||
TEST(chrono_test, year_month_day) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user