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