Skip to content

Commit 3bf8e67

Browse files
authored
[libc++][format] Add tests for flat_(|multi)map formatting (#124418)
These types should be formattable out-of-the-box. This patch validates that is true.
1 parent c24e5f9 commit 3bf8e67

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <concepts>
2525
#include <deque>
2626
#include <filesystem>
27+
#include <flat_map>
2728
#include <format>
2829
#include <forward_list>
2930
#include <list>
@@ -242,6 +243,13 @@ void test_P2286() {
242243
assert_is_formattable<std::multiset<int>, CharT>();
243244
assert_is_formattable<std::multimap<int, int>, CharT>();
244245

246+
#if TEST_STD_VER >= 23
247+
// assert_is_formattable<std::flat_set<int>, CharT>();
248+
assert_is_formattable<std::flat_map<int, int>, CharT>();
249+
// assert_is_formattable<std::flat_multiset<int>, CharT>();
250+
assert_is_formattable<std::flat_multimap<int, int>, CharT>();
251+
#endif // TEST_STD_VER >= 2
252+
245253
assert_is_formattable<std::unordered_set<int>, CharT>();
246254
assert_is_formattable<std::unordered_map<int, int>, CharT>();
247255
assert_is_formattable<std::unordered_multiset<int>, CharT>();

libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.tests.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#define TEST_STD_UTILITIES_FORMAT_FORMAT_RANGE_FORMAT_RANGE_FMTMAP_FORMAT_FUNCTIONS_TESTS_H
1111

1212
#include <algorithm>
13+
#include <deque>
14+
#include <flat_map>
1315
#include <format>
1416
#include <map>
1517
#include <unordered_map>
@@ -241,10 +243,7 @@ void test_char_to_wchar(TestFunction check, ExceptionTest check_exception) {
241243
// Bool
242244
//
243245
template <class CharT, class TestFunction, class ExceptionTest>
244-
void test_bool(TestFunction check, ExceptionTest check_exception) {
245-
// duplicates are stored in order of insertion
246-
std::multimap<bool, int> input{{true, 42}, {false, 0}, {true, 1}};
247-
246+
void test_bool(TestFunction check, ExceptionTest check_exception, auto&& input) {
248247
check(SV("{false: 0, true: 42, true: 1}"), SV("{}"), input);
249248
check(SV("{false: 0, true: 42, true: 1}^42"), SV("{}^42"), input);
250249
check(SV("{false: 0, true: 42, true: 1}^42"), SV("{:}^42"), input);
@@ -339,6 +338,17 @@ void test_bool(TestFunction check, ExceptionTest check_exception) {
339338
"The argument index value is too large for the number of arguments supplied", SV("{:^^{}:#>{}}"), input, 41);
340339
}
341340

341+
template <class CharT, class TestFunction, class ExceptionTest>
342+
void test_bool(TestFunction check, ExceptionTest check_exception) {
343+
// duplicates are stored in order of insertion
344+
test_bool<CharT>(check, check_exception, std::multimap<bool, int>{{true, 42}, {false, 0}, {true, 1}});
345+
#if TEST_STD_VER >= 23
346+
test_bool<CharT>(check,
347+
check_exception,
348+
std::flat_multimap<bool, int, std::less<bool>, std::deque<bool>>{{true, 42}, {false, 0}, {true, 1}});
349+
#endif
350+
}
351+
342352
//
343353
// Integral
344354
//
@@ -442,6 +452,9 @@ void test_int(TestFunction check, ExceptionTest check_exception, auto&& input) {
442452
template <class CharT, class TestFunction, class ExceptionTest>
443453
void test_int(TestFunction check, ExceptionTest check_exception) {
444454
test_int<CharT>(check, check_exception, std::map<int, int>{{1, -1}, {42, -42}, {-42, 42}});
455+
#if TEST_STD_VER >= 23
456+
test_int<CharT>(check, check_exception, std::flat_map<int, int>{{1, -1}, {42, -42}, {-42, 42}});
457+
#endif
445458
}
446459

447460
//

0 commit comments

Comments
 (0)