diff options
author | Mark de Wever <koraq@xs4all.nl> | 2023-05-06 17:04:26 +0200 |
---|---|---|
committer | Mark de Wever <koraq@xs4all.nl> | 2023-05-13 11:21:15 +0200 |
commit | 62858636f54a688c7f5d62e12bd20427296fe686 (patch) | |
tree | 72f69597f5eb7e42b969de6d0695c6af85307f5b /libcxx | |
parent | 0418d0242bf4d060ac3e0493d9a01d449c952430 (diff) | |
download | llvm-62858636f54a688c7f5d62e12bd20427296fe686.tar.gz |
[NFC][libc++][format] Tests formatter requirements.
Like done D149543 this validates the other formatter specializations.
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D150041
Diffstat (limited to 'libcxx')
4 files changed, 229 insertions, 4 deletions
diff --git a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/types.compile.pass.cpp b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/types.compile.pass.cpp new file mode 100644 index 000000000000..a3ed6b1fa329 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/types.compile.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 +// UNSUPPORTED: libcpp-has-no-incomplete-format + +// [container.adaptors.format]/1 +// For each of queue, priority_queue, and stack, the library provides the +// following formatter specialization where adaptor-type is the name of the +// template: +// template<class charT, class T, formattable<charT> Container, class... U> +// struct formatter<adaptor-type<T, Container, U...>, charT>; +// +// Note it is unspecified in which header the adaptor formatters reside. In +// libc++ they are in <format>. However their own headers are still required for +// the declarations of these types. + +// [format.formatter.spec]/4 +// If the library provides an explicit or partial specialization of +// formatter<T, charT>, that specialization is enabled and meets the +// Formatter requirements except as noted otherwise. +// +// Tests parts of the BasicFormatter requirements. Like the formattable concept +// it uses the semiregular concept. The test does not use the formattable +// concept to be similar to tests for formatters not provided by the <format> +// header. + +#include <concepts> +#include <format> +#include <queue> +#include <stack> + +#include "test_macros.h" + +static_assert(std::semiregular<std::formatter<std::queue<int>, char>>); +static_assert(std::semiregular<std::formatter<std::priority_queue<int>, char>>); +static_assert(std::semiregular<std::formatter<std::stack<int>, char>>); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS +static_assert(std::semiregular<std::formatter<std::queue<int>, wchar_t>>); +static_assert(std::semiregular<std::formatter<std::priority_queue<int>, wchar_t>>); +static_assert(std::semiregular<std::formatter<std::stack<int>, wchar_t>>); +#endif // TEST_HAS_NO_WIDE_CHARACTERS diff --git a/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/types.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/types.compile.pass.cpp index 1b8d06c31540..3b5e69b004e9 100644 --- a/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/types.compile.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/types.compile.pass.cpp @@ -18,10 +18,10 @@ // formatter<T, charT>, that specialization is enabled and meets the // Formatter requirements except as noted otherwise. // -// Tests parts of the BasicFormatter requirements. Like the formattable concept -// it uses the semiregular concept. It test does not use the formattable -// concept since it is the intention the formatter is available without -// including the format header. +// Test parts of the BasicFormatter requirements. Like the formattable concept +// it uses the semiregular concept. This test does not use the formattable +// concept since the intent is for the formatter to be available without +// including the <format> header. // TODO FMT Evaluate what to do with [format.formatter.spec]/2 // [format.formatter.spec]/2 diff --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/types.compile.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/types.compile.pass.cpp new file mode 100644 index 000000000000..7cf8393111b5 --- /dev/null +++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/types.compile.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 +// UNSUPPORTED: libcpp-has-no-incomplete-format +// UNSUPPORTED: no-threads + +// <thread> + +// template<class charT> struct formatter<thread::id, charT>; + +// [format.formatter.spec]/4 +// If the library provides an explicit or partial specialization of +// formatter<T, charT>, that specialization is enabled and meets the +// Formatter requirements except as noted otherwise. +// +// Test parts of the BasicFormatter requirements. Like the formattable concept +// it uses the semiregular concept. This test does not use the formattable +// concept since the intent is for the formatter to be available without +// including the <format> header. + +// TODO FMT Evaluate what to do with [format.formatter.spec]/2 +// [format.formatter.spec]/2 +// Each header that declares the template formatter provides the following +// enabled specializations: +// Then there is a list of formatters, but is that really useful? +// Note this should be discussed in LEWG. + +#include <concepts> +#include <thread> + +#include "test_macros.h" + +static_assert(std::semiregular<std::formatter<std::thread::id, char>>); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS +static_assert(std::semiregular<std::formatter<std::thread::id, wchar_t>>); +#endif diff --git a/libcxx/test/std/utilities/format/types.compile.pass.cpp b/libcxx/test/std/utilities/format/types.compile.pass.cpp new file mode 100644 index 000000000000..f099fa69a16e --- /dev/null +++ b/libcxx/test/std/utilities/format/types.compile.pass.cpp @@ -0,0 +1,138 @@ +//===----------------------------------------------------------------------===// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-has-no-incomplete-format + +// <format> + +// C++20 +// ... provides the following enabled specializations: +// The debug-enabled specializations +// template<> struct formatter<char, char>; +// template<> struct formatter<char, wchar_t>; +// template<> struct formatter<wchar_t, wchar_t>; +// +// For each charT, the debug-enabled string type specializations template<> +// struct formatter<charT*, charT>; +// template<> struct formatter<const charT*, charT>; +// template<size_t N> struct formatter<charT[N], charT>; +// template<class traits, class Allocator> +// struct formatter<basic_string<charT, traits, Allocator>, charT>; +// template<class traits> +// struct formatter<basic_string_view<charT, traits>, charT>; +// +// For each charT, for each cv-unqualified arithmetic type ArithmeticT other +// than char, wchar_t, char8_t, char16_t, or char32_t, a specialization +// template<> struct formatter<ArithmeticT, charT>; +// +// For each charT, the pointer type specializations template<> struct +// formatter<nullptr_t, charT>; +// template<> struct formatter<void*, charT>; +// template<> struct formatter<const void*, charT>; + +// C++23 +// [format.range.formatter] +// template<class T, class charT = char> +// requires same_as<remove_cvref_t<T>, T> && formattable<T, charT> +// class range_formatter; +// +// [format.tuple]/1 +// For each of pair and tuple, the library provides the following formatter +// specialization where pair-or-tuple is the name of the template: +// template<class charT, formattable<charT>... Ts> +// struct formatter<pair-or-tuple<Ts...>, charT> { + +// [format.formatter.spec]/4 +// If the library provides an explicit or partial specialization of +// formatter<T, charT>, that specialization is enabled and meets the +// Formatter requirements except as noted otherwise. +// +// Test parts of the BasicFormatter requirements. Like the formattable concept +// it uses the semiregular concept. This test does not use the formattable +// concept since the intent is for the formatter to be available without +// including the <format> header. + +#include <concepts> +#include <format> + +#include "test_macros.h" + +static_assert(std::semiregular<std::formatter<char, char>>); + +static_assert(std::semiregular<std::formatter<char*, char>>); +static_assert(std::semiregular<std::formatter<const char*, char>>); +static_assert(std::semiregular<std::formatter<char[1], char>>); +static_assert(std::semiregular<std::formatter<std::string, char>>); +static_assert(std::semiregular<std::formatter<std::string_view, char>>); + +static_assert(std::semiregular<std::formatter<bool, char>>); + +static_assert(std::semiregular<std::formatter<signed char, char>>); +static_assert(std::semiregular<std::formatter<signed short, char>>); +static_assert(std::semiregular<std::formatter<signed int, char>>); +static_assert(std::semiregular<std::formatter<signed long, char>>); +static_assert(std::semiregular<std::formatter<signed long long, char>>); + +static_assert(std::semiregular<std::formatter<unsigned char, char>>); +static_assert(std::semiregular<std::formatter<unsigned short, char>>); +static_assert(std::semiregular<std::formatter<unsigned int, char>>); +static_assert(std::semiregular<std::formatter<unsigned long, char>>); +static_assert(std::semiregular<std::formatter<unsigned long long, char>>); + +static_assert(std::semiregular<std::formatter<float, char>>); +static_assert(std::semiregular<std::formatter<double, char>>); +static_assert(std::semiregular<std::formatter<long double, char>>); + +static_assert(std::semiregular<std::formatter<nullptr_t, char>>); +static_assert(std::semiregular<std::formatter<void*, char>>); +static_assert(std::semiregular<std::formatter<const void*, char>>); + +#if TEST_STD_VER > 20 +static_assert(std::semiregular<std::range_formatter<int, char>>); +static_assert(std::semiregular<std::formatter<std::tuple<int>, char>>); +static_assert(std::semiregular<std::range_formatter<std::pair<int, int>, char>>); +#endif + +#ifndef TEST_HAS_NO_WIDE_CHARACTERS +static_assert(std::semiregular<std::formatter<char, wchar_t>>); +static_assert(std::semiregular<std::formatter<wchar_t, wchar_t>>); + +static_assert(std::semiregular<std::formatter<wchar_t*, wchar_t>>); +static_assert(std::semiregular<std::formatter<const wchar_t*, wchar_t>>); +static_assert(std::semiregular<std::formatter<wchar_t[1], wchar_t>>); +static_assert(std::semiregular<std::formatter<std::wstring, wchar_t>>); +static_assert(std::semiregular<std::formatter<std::wstring_view, wchar_t>>); + +static_assert(std::semiregular<std::formatter<bool, wchar_t>>); + +static_assert(std::semiregular<std::formatter<signed char, wchar_t>>); +static_assert(std::semiregular<std::formatter<signed short, wchar_t>>); +static_assert(std::semiregular<std::formatter<signed int, wchar_t>>); +static_assert(std::semiregular<std::formatter<signed long, wchar_t>>); +static_assert(std::semiregular<std::formatter<signed long long, wchar_t>>); + +static_assert(std::semiregular<std::formatter<unsigned char, wchar_t>>); +static_assert(std::semiregular<std::formatter<unsigned short, wchar_t>>); +static_assert(std::semiregular<std::formatter<unsigned int, wchar_t>>); +static_assert(std::semiregular<std::formatter<unsigned long, wchar_t>>); +static_assert(std::semiregular<std::formatter<unsigned long long, wchar_t>>); + +static_assert(std::semiregular<std::formatter<float, wchar_t>>); +static_assert(std::semiregular<std::formatter<double, wchar_t>>); +static_assert(std::semiregular<std::formatter<long double, wchar_t>>); + +static_assert(std::semiregular<std::formatter<nullptr_t, wchar_t>>); +static_assert(std::semiregular<std::formatter<void*, wchar_t>>); +static_assert(std::semiregular<std::formatter<const void*, wchar_t>>); + +# if TEST_STD_VER > 20 +static_assert(std::semiregular<std::range_formatter<int, wchar_t>>); +static_assert(std::semiregular<std::formatter<std::tuple<int>, wchar_t>>); +static_assert(std::semiregular<std::range_formatter<std::pair<int, int>, wchar_t>>); +# endif +#endif // TEST_HAS_NO_WIDE_CHARACTERS |