xref: /llvm-project/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/parse.pass.cpp (revision a09b1dc1f2c534cc8b870b5b7c9bc7f7682a1ed5)
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7 
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9 // UNSUPPORTED: libcpp-has-no-incomplete-format
10 
11 // This test requires the dylib support introduced in D92214.
12 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{.+}}
13 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx11.{{.+}}
14 
15 // <vector>
16 
17 // template<class T, class charT>
18 //   requires is-vector-bool-reference<T>
19 // struct formatter<T, charT>
20 
21 // template<class ParseContext>
22 //   constexpr typename ParseContext::iterator
23 //     parse(ParseContext& ctx);
24 
25 // Note this tests the basics of this function. It's tested in more detail in
26 // the format functions test.
27 
28 #include <cassert>
29 #include <concepts>
30 #include <format>
31 #include <vector>
32 
33 #include "test_format_context.h"
34 #include "test_macros.h"
35 #include "make_string.h"
36 
37 #define SV(S) MAKE_STRING_VIEW(CharT, S)
38 
39 template <class StringViewT>
40 constexpr void test_parse(StringViewT fmt) {
41   using CharT    = typename StringViewT::value_type;
42   auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
43   std::formatter<std::vector<bool, std::allocator<bool>>::reference, CharT> formatter;
44   static_assert(std::semiregular<decltype(formatter)>);
45 
46   std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
47   assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
48 }
49 
50 template <class CharT>
51 constexpr void test_fmt() {
52   test_parse(SV(""));
53   test_parse(SV("b"));
54 
55   test_parse(SV("}"));
56   test_parse(SV("b}"));
57 }
58 
59 constexpr bool test() {
60   test_fmt<char>();
61 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
62   test_fmt<wchar_t>();
63 #endif
64 
65   return true;
66 }
67 
68 int main(int, char**) {
69   test();
70   static_assert(test());
71 
72   return 0;
73 }
74