[libcxx-commits] [libcxx] 3acf9b9 - [libc++][format] Improves tests.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 11 09:44:09 PDT 2023


Author: Mark de Wever
Date: 2023-04-11T18:44:03+02:00
New Revision: 3acf9b9c2b01d5220c50c9a9a9d3bf9932b3991d

URL: https://github.com/llvm/llvm-project/commit/3acf9b9c2b01d5220c50c9a9a9d3bf9932b3991d
DIFF: https://github.com/llvm/llvm-project/commit/3acf9b9c2b01d5220c50c9a9a9d3bf9932b3991d.diff

LOG: [libc++][format] Improves tests.

This is based on the last open review comment in D144331 and is applied
to all occurrences.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D147885

Added: 
    

Modified: 
    libcxx/test/std/containers/container.adaptors/container.adaptors.format/parse.pass.cpp
    libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/parse.pass.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/parse.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.bool.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.c_string.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char_array.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.handle.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.pointer.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.signed_integral.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.string.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.unsigned_integral.pass.cpp
    libcxx/test/std/utilities/format/format.range/format.range.fmtdef/parse.pass.cpp
    libcxx/test/std/utilities/format/format.range/format.range.fmtmap/parse.pass.cpp
    libcxx/test/std/utilities/format/format.range/format.range.fmtset/parse.pass.cpp
    libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp
    libcxx/test/std/utilities/format/format.range/format.range.formatter/parse.pass.cpp
    libcxx/test/std/utilities/format/format.tuple/parse.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/parse.pass.cpp b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/parse.pass.cpp
index 7a5f3ead39010..c8ed12342166f 100644
--- a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/parse.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/parse.pass.cpp
@@ -39,30 +39,30 @@
 #define SV(S) MAKE_STRING_VIEW(CharT, S)
 
 template <class Arg, class StringViewT>
-constexpr void test_parse(StringViewT fmt) {
+constexpr void test_parse(StringViewT fmt, std::size_t offset) {
   using CharT    = typename StringViewT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<Arg, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 }
 
 template <class StringViewT>
-constexpr void test_parse(StringViewT fmt) {
-  test_parse<std::queue<int>>(fmt);
-  test_parse<std::priority_queue<int>>(fmt);
-  test_parse<std::stack<int>>(fmt);
+constexpr void test_parse(StringViewT fmt, std::size_t offset) {
+  test_parse<std::queue<int>>(fmt, offset);
+  test_parse<std::priority_queue<int>>(fmt, offset);
+  test_parse<std::stack<int>>(fmt, offset);
 }
 
 template <class CharT>
 constexpr void test_fmt() {
-  test_parse(SV(""));
-  test_parse(SV(":d"));
+  test_parse(SV(""), 0);
+  test_parse(SV(":d"), 0);
 
-  test_parse(SV("}"));
-  test_parse(SV(":d}"));
+  test_parse(SV("}"), 1);
+  test_parse(SV(":d}"), 1);
 }
 
 constexpr bool test() {

diff  --git a/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/parse.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/parse.pass.cpp
index c6013ce7690dc..1851b83c7acc4 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/parse.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/parse.pass.cpp
@@ -36,23 +36,23 @@
 #define SV(S) MAKE_STRING_VIEW(CharT, S)
 
 template <class StringViewT>
-constexpr void test_parse(StringViewT fmt) {
+constexpr void test_parse(StringViewT fmt, std::size_t offset) {
   using CharT    = typename StringViewT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<std::vector<bool, std::allocator<bool>>::reference, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 }
 
 template <class CharT>
 constexpr void test_fmt() {
-  test_parse(SV(""));
-  test_parse(SV("b"));
+  test_parse(SV(""), 0);
+  test_parse(SV("b"), 0);
 
-  test_parse(SV("}"));
-  test_parse(SV("b}"));
+  test_parse(SV("}"), 1);
+  test_parse(SV("b}"), 1);
 }
 
 constexpr bool test() {

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/parse.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/parse.pass.cpp
index cc5b6aec59476..e4b235e21edc8 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/parse.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/parse.pass.cpp
@@ -35,23 +35,23 @@
 #define SV(S) MAKE_STRING_VIEW(CharT, S)
 
 template <class StringViewT>
-constexpr void test_parse(StringViewT fmt) {
+constexpr void test_parse(StringViewT fmt, std::size_t offset) {
   using CharT    = typename StringViewT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<std::thread::id, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 }
 
 template <class CharT>
 constexpr void test_fmt() {
-  test_parse(SV(""));
-  test_parse(SV("1"));
+  test_parse(SV(""), 0);
+  test_parse(SV("1"), 0);
 
-  test_parse(SV("}"));
-  test_parse(SV("1}"));
+  test_parse(SV("}"), 1);
+  test_parse(SV("1}"), 1);
 }
 
 constexpr bool test() {

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.bool.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.bool.pass.cpp
index a5657f57c9d85..c3263d0cfd32e 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.bool.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.bool.pass.cpp
@@ -32,14 +32,14 @@
 #define STR(S) MAKE_STRING(CharT, S)
 
 template <class StringT, class StringViewT>
-void test(StringT expected, StringViewT fmt, bool arg) {
+void test(StringT expected, StringViewT fmt, bool arg, std::size_t offset) {
   using CharT = typename StringT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<bool, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 
   StringT result;
   auto out = std::back_inserter(result);
@@ -61,9 +61,9 @@ void test_termination_condition(StringT expected, StringT f, bool arg) {
   std::basic_string_view<CharT> fmt{f};
   assert(fmt.back() == CharT('}') && "Pre-condition failure");
 
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 1);
   fmt.remove_suffix(1);
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 0);
 }
 
 template <class CharT>

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.c_string.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.c_string.pass.cpp
index 8b31da1904409..16b9f4b7e58f7 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.c_string.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.c_string.pass.cpp
@@ -33,13 +33,13 @@
 #define CSTR(S) MAKE_CSTRING(CharT, S)
 
 template <class T, class StringT, class StringViewT, class CharT>
-void test(StringT expected, StringViewT fmt, const CharT* a) {
+void test(StringT expected, StringViewT fmt, const CharT* a, std::size_t offset) {
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<T, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 
   StringT result;
   auto out = std::back_inserter(result);
@@ -61,9 +61,9 @@ void test_termination_condition(StringT expected, StringT f, const CharT* arg) {
   std::basic_string_view<CharT> fmt{f};
   assert(fmt.back() == CharT('}') && "Pre-condition failure");
 
-  test<ArgumentT>(expected, fmt, arg);
+  test<ArgumentT>(expected, fmt, arg, 1);
   fmt.remove_suffix(1);
-  test<ArgumentT>(expected, fmt, arg);
+  test<ArgumentT>(expected, fmt, arg, 0);
 }
 
 #if TEST_STD_VER > 20

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.pass.cpp
index 25939e8c7121b..ac1dfec36ebec 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char.pass.cpp
@@ -33,14 +33,14 @@
 #define SV(S) MAKE_STRING_VIEW(CharT, S)
 
 template <class StringT, class StringViewT, class ArgumentT>
-void test(StringT expected, StringViewT fmt, ArgumentT arg) {
+void test(StringT expected, StringViewT fmt, ArgumentT arg, std::size_t offset) {
   using CharT = typename StringT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<ArgumentT, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 
   StringT result;
   auto out = std::back_inserter(result);
@@ -62,9 +62,9 @@ void test_termination_condition(StringT expected, StringT f, ArgumentT arg) {
   std::basic_string_view<CharT> fmt{f};
   assert(fmt.back() == CharT('}') && "Pre-condition failure");
 
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 1);
   fmt.remove_suffix(1);
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 0);
 }
 
 #if TEST_STD_VER > 20

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char_array.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char_array.pass.cpp
index bb3299636e623..10aaeaa97e387 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char_array.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char_array.pass.cpp
@@ -44,14 +44,15 @@ struct Tester {
   static const std::size_t size = N - 1;
 
   template <class CharT>
-  void test(const std::basic_string<CharT>& expected, const std::basic_string_view<CharT>& fmt) const {
+  void
+  test(const std::basic_string<CharT>& expected, const std::basic_string_view<CharT>& fmt, std::size_t offset) const {
     using Str = CharT[size];
     std::basic_format_parse_context<CharT> parse_ctx{fmt};
     std::formatter<Str, CharT> formatter;
     static_assert(std::semiregular<decltype(formatter)>);
 
     auto it = formatter.parse(parse_ctx);
-    assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+    assert(it == fmt.end() - offset);
 
     std::basic_string<CharT> result;
     auto out = std::back_inserter(result);
@@ -76,9 +77,9 @@ struct Tester {
     std::basic_string_view<CharT> fmt{f};
     assert(fmt.back() == CharT('}') && "Pre-condition failure");
 
-    test(expected, fmt);
+    test(expected, fmt, 1);
     fmt.remove_suffix(1);
-    test(expected, fmt);
+    test(expected, fmt, 0);
   }
 };
 

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp
index b5f33d018e552..2fde253e5855d 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp
@@ -44,13 +44,13 @@
 #define STR(S) MAKE_STRING(CharT, S)
 
 template <class CharT, class ArithmeticT>
-void test(std::basic_string_view<CharT> fmt, ArithmeticT arg, std::basic_string<CharT> expected) {
+void test(std::basic_string_view<CharT> fmt, ArithmeticT arg, std::basic_string<CharT> expected, std::size_t offset) {
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<ArithmeticT, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 
   std::basic_string<CharT> result;
   auto out = std::back_inserter(result);
@@ -78,9 +78,9 @@ void test_termination_condition(StringT f, ArithmeticT arg, StringT expected = {
   std::basic_string_view<CharT> fmt{f};
   assert(fmt.back() == CharT('}') && "Pre-condition failure");
 
-  test(fmt, arg, expected);
+  test(fmt, arg, expected, 1);
   fmt.remove_suffix(1);
-  test(fmt, arg, expected);
+  test(fmt, arg, expected, 0);
 }
 
 template <class CharT, class ArithmeticT>

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.handle.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.handle.pass.cpp
index 8758046eb5757..b9632324b0b80 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.handle.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.handle.pass.cpp
@@ -38,13 +38,13 @@ struct std::formatter<color> : std::formatter<const char*> {
   }
 };
 
-void test(std::string expected, std::string_view fmt, color arg) {
+void test(std::string expected, std::string_view fmt, color arg, std::size_t offset) {
   auto parse_ctx = std::format_parse_context(fmt);
   std::formatter<color, char> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 
   std::string result;
   auto out = std::back_inserter(result);
@@ -64,9 +64,9 @@ void test_termination_condition(std::string expected, std::string f, color arg)
   std::string_view fmt{f};
   assert(fmt.back() == '}' && "Pre-condition failure");
 
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 1);
   fmt.remove_suffix(1);
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 0);
 }
 
 int main(int, char**) {

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.pointer.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.pointer.pass.cpp
index 83a3df3d1e447..330ac0642242d 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.pointer.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.pointer.pass.cpp
@@ -37,14 +37,14 @@
 #define STR(S) MAKE_STRING(CharT, S)
 
 template <class StringT, class StringViewT, class PointerT>
-void test(StringT expected, StringViewT fmt, PointerT arg) {
+void test(StringT expected, StringViewT fmt, PointerT arg, std::size_t offset) {
   using CharT = typename StringT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<PointerT, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 
   StringT result;
   auto out = std::back_inserter(result);
@@ -74,9 +74,9 @@ void test_termination_condition(StringT expected, StringT f, PointerT arg) {
   std::basic_string_view<CharT> fmt{f};
   assert(fmt.back() == CharT('}') && "Pre-condition failure");
 
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 1);
   fmt.remove_suffix(1);
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 0);
 }
 
 template <class CharT>

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.signed_integral.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.signed_integral.pass.cpp
index 1bec16279948d..65caa6bb260b1 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.signed_integral.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.signed_integral.pass.cpp
@@ -39,14 +39,14 @@
 #define STR(S) MAKE_STRING(CharT, S)
 
 template <class StringT, class StringViewT, class ArithmeticT>
-void test(StringT expected, StringViewT fmt, ArithmeticT arg) {
+void test(StringT expected, StringViewT fmt, ArithmeticT arg, std::size_t offset) {
   using CharT = typename StringT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<ArithmeticT, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 
   StringT result;
   auto out = std::back_inserter(result);
@@ -68,9 +68,9 @@ void test_termination_condition(StringT expected, StringT f, ArithmeticT arg) {
   std::basic_string_view<CharT> fmt{f};
   assert(fmt.back() == CharT('}') && "Pre-condition failure");
 
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 1);
   fmt.remove_suffix(1);
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 0);
 }
 
 template <class Arithmetic, class CharT>

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.string.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.string.pass.cpp
index 68bb76bed6b2a..3b91834ffc822 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.string.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.string.pass.cpp
@@ -35,7 +35,7 @@
 #define CSTR(S) MAKE_CSTRING(CharT, S)
 
 template <class T, class ArgumentT, class StringT, class StringViewT>
-void test(StringT expected, StringViewT fmt, StringT a) {
+void test(StringT expected, StringViewT fmt, StringT a, std::size_t offset) {
   static_assert(
       std::same_as<typename T::value_type,
                    typename std::decay_t<ArgumentT>::value_type> &&
@@ -47,7 +47,7 @@ void test(StringT expected, StringViewT fmt, StringT a) {
   static_assert(std::semiregular<decltype(formatter)>);
 
   auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 
   StringT result;
   auto out = std::back_inserter(result);
@@ -70,9 +70,9 @@ void test_termination_condition(StringT expected, StringT f, StringT arg) {
   std::basic_string_view<CharT> fmt{f};
   assert(fmt.back() == CharT('}') && "Pre-condition failure");
 
-  test<T, ArgumentT>(expected, fmt, arg);
+  test<T, ArgumentT>(expected, fmt, arg, 1);
   fmt.remove_suffix(1);
-  test<T, ArgumentT>(expected, fmt, arg);
+  test<T, ArgumentT>(expected, fmt, arg, 0);
 }
 
 #if TEST_STD_VER > 20

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.unsigned_integral.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.unsigned_integral.pass.cpp
index accd9b464818c..c413abac25e97 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.unsigned_integral.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.unsigned_integral.pass.cpp
@@ -39,14 +39,14 @@
 #define STR(S) MAKE_STRING(CharT, S)
 
 template <class StringT, class StringViewT, class ArithmeticT>
-void test(StringT expected, StringViewT fmt, ArithmeticT arg) {
+void test(StringT expected, StringViewT fmt, ArithmeticT arg, std::size_t offset) {
   using CharT = typename StringT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<ArithmeticT, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 
   StringT result;
   auto out = std::back_inserter(result);
@@ -68,9 +68,9 @@ void test_termination_condition(StringT expected, StringT f, ArithmeticT arg) {
   std::basic_string_view<CharT> fmt{f};
   assert(fmt.back() == CharT('}') && "Pre-condition failure");
 
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 1);
   fmt.remove_suffix(1);
-  test(expected, fmt, arg);
+  test(expected, fmt, arg, 0);
 }
 
 template <class ArithmeticT, class CharT>

diff  --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/parse.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/parse.pass.cpp
index c848f4ff2fc26..f66ef7b87c241 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/parse.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/parse.pass.cpp
@@ -32,23 +32,23 @@
 #define SV(S) MAKE_STRING_VIEW(CharT, S)
 
 template <class StringViewT>
-constexpr void test_parse(StringViewT fmt) {
+constexpr void test_parse(StringViewT fmt, std::size_t offset) {
   using CharT    = typename StringViewT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<std::array<int, 2>, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 }
 
 template <class CharT>
 constexpr void test_fmt() {
-  test_parse(SV(""));
-  test_parse(SV(":5"));
+  test_parse(SV(""), 0);
+  test_parse(SV(":5"), 0);
 
-  test_parse(SV("}"));
-  test_parse(SV(":5}"));
+  test_parse(SV("}"), 1);
+  test_parse(SV(":5}"), 1);
 }
 
 constexpr bool test() {

diff  --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/parse.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/parse.pass.cpp
index be117a6de2ecf..441a71759d23a 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/parse.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/parse.pass.cpp
@@ -35,23 +35,23 @@
 #define SV(S) MAKE_STRING_VIEW(CharT, S)
 
 template <class StringViewT>
-constexpr void test_parse(StringViewT fmt) {
+constexpr void test_parse(StringViewT fmt, std::size_t offset) {
   using CharT    = typename StringViewT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<std::map<int, int>, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 }
 
 template <class CharT>
 constexpr void test_fmt() {
-  test_parse(SV(""));
-  test_parse(SV(":5"));
+  test_parse(SV(""), 0);
+  test_parse(SV(":5"), 0);
 
-  test_parse(SV("}"));
-  test_parse(SV(":5}"));
+  test_parse(SV("}"), 1);
+  test_parse(SV(":5}"), 1);
 }
 
 constexpr bool test() {

diff  --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/parse.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/parse.pass.cpp
index 88940525925fa..fede410ff6075 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/parse.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/parse.pass.cpp
@@ -35,23 +35,23 @@
 #define SV(S) MAKE_STRING_VIEW(CharT, S)
 
 template <class StringViewT>
-constexpr void test_parse(StringViewT fmt) {
+constexpr void test_parse(StringViewT fmt, std::size_t offset) {
   using CharT    = typename StringViewT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<std::set<int>, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 }
 
 template <class CharT>
 constexpr void test_fmt() {
-  test_parse(SV(""));
-  test_parse(SV(":5"));
+  test_parse(SV(""), 0);
+  test_parse(SV(":5"), 0);
 
-  test_parse(SV("}"));
-  test_parse(SV(":5}"));
+  test_parse(SV("}"), 1);
+  test_parse(SV(":5}"), 1);
 }
 
 constexpr bool test() {

diff  --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp
index 5aaeae51e1d76..64919eb427ce0 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp
@@ -33,27 +33,27 @@
 #include "test_macros.h"
 
 template <class FormatterT, class StringViewT>
-constexpr void test_parse(StringViewT fmt) {
+constexpr void test_parse(StringViewT fmt, std::size_t offset) {
   using CharT    = typename StringViewT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   FormatterT formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 }
 
 template <class StringViewT>
-constexpr void test_formatters(StringViewT fmt) {
+constexpr void test_formatters(StringViewT fmt, std::size_t offset) {
   using CharT = typename StringViewT::value_type;
-  test_parse<std::formatter<test_range_format_string<std::basic_string<CharT>>, CharT>>(fmt);
-  test_parse<std::formatter<test_range_format_debug_string<std::basic_string<CharT>>, CharT>>(fmt);
+  test_parse<std::formatter<test_range_format_string<std::basic_string<CharT>>, CharT>>(fmt, offset);
+  test_parse<std::formatter<test_range_format_debug_string<std::basic_string<CharT>>, CharT>>(fmt, offset);
 }
 
 template <class CharT>
 constexpr void test_char_type() {
-  test_formatters(SV(""));
-  test_formatters(SV("}"));
+  test_formatters(SV(""), 0);
+  test_formatters(SV("}"), 1);
 }
 
 constexpr bool test() {

diff  --git a/libcxx/test/std/utilities/format/format.range/format.range.formatter/parse.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.formatter/parse.pass.cpp
index c440b1ac2b168..9ea2ed8ce046a 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.formatter/parse.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.range/format.range.formatter/parse.pass.cpp
@@ -35,23 +35,23 @@
 #define SV(S) MAKE_STRING_VIEW(CharT, S)
 
 template <class StringViewT>
-constexpr void test_parse(StringViewT fmt) {
+constexpr void test_parse(StringViewT fmt, std::size_t offset) {
   using CharT    = typename StringViewT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::range_formatter<int, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 }
 
 template <class CharT>
 constexpr void test_fmt() {
-  test_parse(SV(""));
-  test_parse(SV(":d"));
+  test_parse(SV(""), 0);
+  test_parse(SV(":d"), 0);
 
-  test_parse(SV("}"));
-  test_parse(SV(":d}"));
+  test_parse(SV("}"), 1);
+  test_parse(SV(":d}"), 1);
 }
 
 constexpr bool test() {

diff  --git a/libcxx/test/std/utilities/format/format.tuple/parse.pass.cpp b/libcxx/test/std/utilities/format/format.tuple/parse.pass.cpp
index f38c9fad2df92..3cb699af4354e 100644
--- a/libcxx/test/std/utilities/format/format.tuple/parse.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.tuple/parse.pass.cpp
@@ -36,23 +36,23 @@
 #define SV(S) MAKE_STRING_VIEW(CharT, S)
 
 template <class Arg, class StringViewT>
-constexpr void test(StringViewT fmt) {
+constexpr void test(StringViewT fmt, std::size_t offset) {
   using CharT    = typename StringViewT::value_type;
   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
   std::formatter<Arg, CharT> formatter;
   static_assert(std::semiregular<decltype(formatter)>);
 
   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
-  assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+  assert(it == fmt.end() - offset);
 }
 
 template <class CharT, class Arg>
 constexpr void test() {
-  test<Arg>(SV(""));
-  test<Arg>(SV("42"));
+  test<Arg>(SV(""), 0);
+  test<Arg>(SV("42"), 0);
 
-  test<Arg>(SV("}"));
-  test<Arg>(SV("42}"));
+  test<Arg>(SV("}"), 1);
+  test<Arg>(SV("42}"), 1);
 }
 
 template <class CharT>


        


More information about the libcxx-commits mailing list