• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
9 // UNSUPPORTED: libcpp-has-no-incomplete-format
10 
11 // <format>
12 
13 // basic_format_arg<basic_format_context> arg(size_t id) const;
14 
15 #include <format>
16 #include <iterator>
17 #include <cassert>
18 
19 #include "test_basic_format_arg.h"
20 #include "test_format_context.h"
21 #include "test_macros.h"
22 #include "make_string.h"
23 
24 template <class OutIt, class CharT>
test()25 void test() {
26   std::basic_string<CharT> string = MAKE_STRING(CharT, "string");
27   auto store = std::make_format_args<std::basic_format_context<OutIt, CharT>>(
28       true, CharT('a'), 42, string);
29   std::basic_format_args args = store;
30 
31   std::basic_string<CharT> output;
32   const std::basic_format_context context = test_format_context_create(OutIt{output}, args);
33   LIBCPP_ASSERT(args.__size() == 4);
34   ASSERT_NOEXCEPT(context.arg(0));
35   for (std::size_t i = 0, e = args.__size(); i != e; ++i) {
36     assert(context.arg(i));
37   }
38   assert(!context.arg(args.__size()));
39 
40   assert(test_basic_format_arg(context.arg(0), true));
41   assert(test_basic_format_arg(context.arg(1), CharT('a')));
42   assert(test_basic_format_arg(context.arg(2), 42));
43   assert(test_basic_format_arg(context.arg(3),
44                                std::basic_string_view<CharT>(string)));
45 }
46 
main(int,char **)47 int main(int, char**) {
48   test<std::back_insert_iterator<std::basic_string<char>>, char>();
49 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
50   test<std::back_insert_iterator<std::basic_string<wchar_t>>, wchar_t>();
51 #endif
52 
53   return 0;
54 }
55