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 // <format> 15 16 // template<class charT, formattable<charT>... Ts> 17 // struct formatter<pair-or-tuple<Ts...>, charT> 18 19 // template<class ParseContext> 20 // constexpr typename ParseContext::iterator 21 // parse(ParseContext& ctx); 22 23 // Note this tests the basics of this function. It's tested in more detail in 24 // the format functions tests. 25 26 #include <cassert> 27 #include <concepts> 28 #include <format> 29 #include <tuple> 30 #include <utility> 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 Arg, class StringViewT> 39 constexpr void test(StringViewT fmt) { 40 using CharT = typename StringViewT::value_type; 41 auto parse_ctx = std::basic_format_parse_context<CharT>(fmt); 42 std::formatter<Arg, 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() - (!fmt.empty() && fmt.back() == '}')); 47 } 48 49 template <class CharT, class Arg> 50 constexpr void test() { 51 test<Arg>(SV("")); 52 test<Arg>(SV("42")); 53 54 test<Arg>(SV("}")); 55 test<Arg>(SV("42}")); 56 } 57 58 template <class CharT> 59 constexpr void test() { 60 test<CharT, std::tuple<int>>(); 61 test<CharT, std::tuple<int, CharT>>(); 62 test<CharT, std::pair<int, CharT>>(); 63 test<CharT, std::tuple<int, CharT, bool>>(); 64 } 65 66 constexpr bool test() { 67 test<char>(); 68 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 69 test<wchar_t>(); 70 #endif 71 72 return true; 73 } 74 75 int main(int, char**) { 76 test(); 77 static_assert(test()); 78 79 return 0; 80 } 81