brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 8555ebd Raw
66 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010// UNSUPPORTED: no-threads11 12// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME13 14// TODO FMT This test should not require std::to_chars(floating-point)15// XFAIL: availability-fp_to_chars-missing16 17// <thread>18 19// template<class charT>20// struct formatter<thread::id, charT>;21 22// string vformat(string_view fmt, format_args args);23// wstring vformat(wstring_view fmt, wformat_args args);24 25#include <format>26#include <cassert>27 28#include "assert_macros.h"29#include "concat_macros.h"30#include "format.functions.tests.h"31#include "test_macros.h"32 33auto test = []<class CharT, class... Args>(34                std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt, Args&&... args) {35  std::basic_string<CharT> out = std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));36  TEST_REQUIRE(out == expected,37               TEST_WRITE_CONCATENATED(38                   "\nFormat string   ", fmt, "\nExpected output ", expected, "\nActual output   ", out, '\n'));39};40 41auto test_exception =42    []<class CharT, class... Args>(43        [[maybe_unused]] std::string_view what,44        [[maybe_unused]] std::basic_string_view<CharT> fmt,45        [[maybe_unused]] Args&&... args) {46      TEST_VALIDATE_EXCEPTION(47          std::format_error,48          [&]([[maybe_unused]] const std::format_error& e) {49            TEST_LIBCPP_REQUIRE(50                e.what() == what,51                TEST_WRITE_CONCATENATED(52                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));53          },54          TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));55    };56 57int main(int, char**) {58  format_tests<char>(test, test_exception);59 60#ifndef TEST_HAS_NO_WIDE_CHARACTERS61  format_tests<wchar_t>(test, test_exception);62#endif63 64  return 0;65}66