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 // TODO FMT Fix this test using GCC, it currently times out. 12 // UNSUPPORTED: gcc-12 13 14 // <vector> 15 16 // template<class T, class charT> 17 // requires is-vector-bool-reference<T> 18 // struct formatter<T, charT> 19 20 // template<class ParseContext> 21 // constexpr typename ParseContext::iterator 22 // parse(ParseContext& ctx); 23 24 // Note this tests the basics of this function. It's tested in more detail in 25 // the format functions test. 26 27 #include <cassert> 28 #include <concepts> 29 #include <format> 30 #include <vector> 31 32 #include "test_format_context.h" 33 #include "test_macros.h" 34 #include "make_string.h" 35 36 #define SV(S) MAKE_STRING_VIEW(CharT, S) 37 38 template <class StringViewT> 39 constexpr void test_parse(StringViewT fmt, std::size_t offset) { 40 using CharT = typename StringViewT::value_type; 41 auto parse_ctx = std::basic_format_parse_context<CharT>(fmt); 42 std::formatter<std::vector<bool, std::allocator<bool>>::reference, CharT> formatter; 43 static_assert(std::semiregular<decltype(formatter)>); 44 45 std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx); 46 assert(it == fmt.end() - offset); 47 } 48 49 template <class CharT> 50 constexpr void test_fmt() { 51 test_parse(SV(""), 0); 52 test_parse(SV("b"), 0); 53 54 test_parse(SV("}"), 1); 55 test_parse(SV("b}"), 1); 56 } 57 58 constexpr bool test() { 59 test_fmt<char>(); 60 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 61 test_fmt<wchar_t>(); 62 #endif 63 64 return true; 65 } 66 67 int main(int, char**) { 68 test(); 69 static_assert(test()); 70 71 return 0; 72 } 73