mirror of
https://github.com/intel/llvm.git
synced 2026-01-24 08:30:34 +08:00
[NFC][libc++][format] Improves tests.
This is mainly to improve the readability of the tests. As a side effects the tests run faster too, Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D135288
This commit is contained in:
@@ -28,18 +28,20 @@
|
||||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
#include "test_format_string.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
std::basic_string<CharT> out = std::format(std::locale(), fmt.template sv<CharT>(), args...);
|
||||
if constexpr (std::same_as<CharT, char>)
|
||||
if (out != expected)
|
||||
std::cerr << "\nFormat string " << fmt.template sv<char>() << "\nExpected output " << expected
|
||||
<< "\nActual output " << out << '\n';
|
||||
assert(out == expected);
|
||||
};
|
||||
auto test =
|
||||
[]<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr {
|
||||
std::basic_string<CharT> out = std::format(std::locale(), fmt, std::forward<Args>(args)...);
|
||||
if constexpr (std::same_as<CharT, char>)
|
||||
if (out != expected)
|
||||
std::cerr << "\nFormat string " << fmt.get() << "\nExpected output " << expected << "\nActual output "
|
||||
<< out << '\n';
|
||||
assert(out == expected);
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, const Args&...) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
|
||||
// After P2216 most exceptions thrown by std::format become ill-formed.
|
||||
// Therefore this tests does nothing.
|
||||
// A basic ill-formed test is done in format.locale.verify.cpp
|
||||
|
||||
@@ -30,25 +30,27 @@
|
||||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
#include "test_format_string.h"
|
||||
|
||||
#ifndef TEST_HAS_NO_LOCALIZATION
|
||||
# include <iostream>
|
||||
# include <type_traits>
|
||||
#endif
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
std::basic_string<CharT> out = std::format(fmt.template sv<CharT>(), args...);
|
||||
auto test =
|
||||
[]<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr {
|
||||
std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...);
|
||||
#ifndef TEST_HAS_NO_LOCALIZATION
|
||||
if constexpr (std::same_as<CharT, char>)
|
||||
if (out != expected)
|
||||
std::cerr << "\nFormat string " << fmt.template sv<char>() << "\nExpected output " << expected
|
||||
<< "\nActual output " << out << '\n';
|
||||
if constexpr (std::same_as<CharT, char>)
|
||||
if (out != expected)
|
||||
std::cerr << "\nFormat string " << fmt.get() << "\nExpected output " << expected << "\nActual output "
|
||||
<< out << '\n';
|
||||
#endif
|
||||
assert(out == expected);
|
||||
};
|
||||
assert(out == expected);
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, const Args&...) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
|
||||
// After P2216 most exceptions thrown by std::format become ill-formed.
|
||||
// Therefore this tests does nothing.
|
||||
// A basic ill-formed test is done in format.verify.cpp
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -31,36 +31,38 @@
|
||||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
#include "test_format_string.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
auto it = std::format_to(out.begin(), std::locale(), fmt.template sv<CharT>(), args...);
|
||||
assert(it == out.end());
|
||||
assert(out == expected);
|
||||
}
|
||||
{
|
||||
std::list<CharT> out;
|
||||
std::format_to(std::back_inserter(out), std::locale(), fmt.template sv<CharT>(), args...);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
std::vector<CharT> out;
|
||||
std::format_to(std::back_inserter(out), std::locale(), fmt.template sv<CharT>(), args...);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
assert(expected.size() < 4096 && "Update the size of the buffer.");
|
||||
CharT out[4096];
|
||||
CharT* it = std::format_to(out, std::locale(), fmt.template sv<CharT>(), args...);
|
||||
assert(std::distance(out, it) == int(expected.size()));
|
||||
// Convert to std::string since output contains '\0' for boolean tests.
|
||||
assert(std::basic_string<CharT>(out, it) == expected);
|
||||
}
|
||||
};
|
||||
auto test =
|
||||
[]<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
auto it = std::format_to(out.begin(), std::locale(), fmt, std::forward<Args>(args)...);
|
||||
assert(it == out.end());
|
||||
assert(out == expected);
|
||||
}
|
||||
{
|
||||
std::list<CharT> out;
|
||||
std::format_to(std::back_inserter(out), std::locale(), fmt, std::forward<Args>(args)...);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
std::vector<CharT> out;
|
||||
std::format_to(std::back_inserter(out), std::locale(), fmt, std::forward<Args>(args)...);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
assert(expected.size() < 4096 && "Update the size of the buffer.");
|
||||
CharT out[4096];
|
||||
CharT* it = std::format_to(out, std::locale(), fmt, std::forward<Args>(args)...);
|
||||
assert(std::distance(out, it) == int(expected.size()));
|
||||
// Convert to std::string since output contains '\0' for boolean tests.
|
||||
assert(std::basic_string<CharT>(out, it) == expected);
|
||||
}
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, const Args&...) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
|
||||
// After P2216 most exceptions thrown by std::format_to become ill-formed.
|
||||
// Therefore this tests does nothing.
|
||||
// A basic ill-formed test is done in format_to.locale.verify.cpp
|
||||
|
||||
@@ -28,36 +28,38 @@
|
||||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
#include "test_format_string.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
auto it = std::format_to(out.begin(), fmt.template sv<CharT>(), args...);
|
||||
assert(it == out.end());
|
||||
assert(out == expected);
|
||||
}
|
||||
{
|
||||
std::list<CharT> out;
|
||||
std::format_to(std::back_inserter(out), fmt.template sv<CharT>(), args...);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
std::vector<CharT> out;
|
||||
std::format_to(std::back_inserter(out), fmt.template sv<CharT>(), args...);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
assert(expected.size() < 4096 && "Update the size of the buffer.");
|
||||
CharT out[4096];
|
||||
CharT* it = std::format_to(out, fmt.template sv<CharT>(), args...);
|
||||
assert(std::distance(out, it) == int(expected.size()));
|
||||
// Convert to std::string since output contains '\0' for boolean tests.
|
||||
assert(std::basic_string<CharT>(out, it) == expected);
|
||||
}
|
||||
};
|
||||
auto test =
|
||||
[]<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
auto it = std::format_to(out.begin(), fmt, std::forward<Args>(args)...);
|
||||
assert(it == out.end());
|
||||
assert(out == expected);
|
||||
}
|
||||
{
|
||||
std::list<CharT> out;
|
||||
std::format_to(std::back_inserter(out), fmt, std::forward<Args>(args)...);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
std::vector<CharT> out;
|
||||
std::format_to(std::back_inserter(out), fmt, std::forward<Args>(args)...);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
assert(expected.size() < 4096 && "Update the size of the buffer.");
|
||||
CharT out[4096];
|
||||
CharT* it = std::format_to(out, fmt, std::forward<Args>(args)...);
|
||||
assert(std::distance(out, it) == int(expected.size()));
|
||||
// Convert to std::string since output contains '\0' for boolean tests.
|
||||
assert(std::basic_string<CharT>(out, it) == expected);
|
||||
}
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, const Args&...) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
|
||||
// After P2216 most exceptions thrown by std::format become ill-formed.
|
||||
// Therefore this tests does nothing.
|
||||
// A basic ill-formed test is done in format.verify.cpp
|
||||
|
||||
@@ -33,72 +33,74 @@
|
||||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
#include "test_format_string.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
{
|
||||
std::list<CharT> out;
|
||||
std::format_to_n_result result =
|
||||
std::format_to_n(std::back_inserter(out), 0, std::locale(), fmt.template sv<CharT>(), args...);
|
||||
// To avoid signedness warnings make sure formatted_size uses the same type
|
||||
// as result.size.
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt.template sv<CharT>(), args...);
|
||||
auto test =
|
||||
[]<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr {
|
||||
{
|
||||
std::list<CharT> out;
|
||||
std::format_to_n_result result =
|
||||
std::format_to_n(std::back_inserter(out), 0, std::locale(), fmt, std::forward<Args>(args)...);
|
||||
// To avoid signedness warnings make sure formatted_size uses the same type
|
||||
// as result.size.
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt, std::forward<Args>(args)...);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
assert(out.empty());
|
||||
}
|
||||
{
|
||||
std::vector<CharT> out;
|
||||
std::format_to_n_result result =
|
||||
std::format_to_n(std::back_inserter(out), 5, std::locale(), fmt.template sv<CharT>(), args...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt.template sv<CharT>(), args...);
|
||||
diff_type size = std::min<diff_type>(5, formatted_size);
|
||||
assert(result.size == formatted_size);
|
||||
assert(out.empty());
|
||||
}
|
||||
{
|
||||
std::vector<CharT> out;
|
||||
std::format_to_n_result result =
|
||||
std::format_to_n(std::back_inserter(out), 5, std::locale(), fmt, std::forward<Args>(args)...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt, std::forward<Args>(args)...);
|
||||
diff_type size = std::min<diff_type>(5, formatted_size);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.begin() + size));
|
||||
}
|
||||
{
|
||||
std::basic_string<CharT> out;
|
||||
std::format_to_n_result result =
|
||||
std::format_to_n(std::back_inserter(out), 1000, std::locale(), fmt.template sv<CharT>(), args...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt.template sv<CharT>(), args...);
|
||||
diff_type size = std::min<diff_type>(1000, formatted_size);
|
||||
assert(result.size == formatted_size);
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.begin() + size));
|
||||
}
|
||||
{
|
||||
std::basic_string<CharT> out;
|
||||
std::format_to_n_result result =
|
||||
std::format_to_n(std::back_inserter(out), 1000, std::locale(), fmt, std::forward<Args>(args)...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt, std::forward<Args>(args)...);
|
||||
diff_type size = std::min<diff_type>(1000, formatted_size);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
assert(out == expected.substr(0, size));
|
||||
}
|
||||
{
|
||||
// Test the returned iterator.
|
||||
std::basic_string<CharT> out(10, CharT(' '));
|
||||
std::format_to_n_result result =
|
||||
std::format_to_n(out.begin(), 10, std::locale(), fmt.template sv<CharT>(), args...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt.template sv<CharT>(), args...);
|
||||
diff_type size = std::min<diff_type>(10, formatted_size);
|
||||
assert(result.size == formatted_size);
|
||||
assert(out == expected.substr(0, size));
|
||||
}
|
||||
{
|
||||
// Test the returned iterator.
|
||||
std::basic_string<CharT> out(10, CharT(' '));
|
||||
std::format_to_n_result result =
|
||||
std::format_to_n(out.begin(), 10, std::locale(), fmt, std::forward<Args>(args)...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt, std::forward<Args>(args)...);
|
||||
diff_type size = std::min<diff_type>(10, formatted_size);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
assert(result.out == out.begin() + size);
|
||||
assert(out.substr(0, size) == expected.substr(0, size));
|
||||
}
|
||||
{
|
||||
static_assert(std::is_signed_v<std::iter_difference_t<CharT*>>,
|
||||
"If the difference type isn't negative the test will fail "
|
||||
"due to using a large positive value.");
|
||||
CharT buffer[1] = {CharT(0)};
|
||||
std::format_to_n_result result = std::format_to_n(buffer, -1, std::locale(), fmt.template sv<CharT>(), args...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt.template sv<CharT>(), args...);
|
||||
assert(result.size == formatted_size);
|
||||
assert(result.out == out.begin() + size);
|
||||
assert(out.substr(0, size) == expected.substr(0, size));
|
||||
}
|
||||
{
|
||||
static_assert(std::is_signed_v<std::iter_difference_t<CharT*>>,
|
||||
"If the difference type isn't negative the test will fail "
|
||||
"due to using a large positive value.");
|
||||
CharT buffer[1] = {CharT(0)};
|
||||
std::format_to_n_result result = std::format_to_n(buffer, -1, std::locale(), fmt, std::forward<Args>(args)...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(std::locale(), fmt, std::forward<Args>(args)...);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
assert(result.out == buffer);
|
||||
assert(buffer[0] == CharT(0));
|
||||
}
|
||||
};
|
||||
assert(result.size == formatted_size);
|
||||
assert(result.out == buffer);
|
||||
assert(buffer[0] == CharT(0));
|
||||
}
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, const Args&...) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
|
||||
// After P2216 most exceptions thrown by std::format_to_n become ill-formed.
|
||||
// Therefore this tests does nothing.
|
||||
// A basic ill-formed test is done in format_to_n.locale.verify.cpp
|
||||
|
||||
@@ -30,25 +30,28 @@
|
||||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
#include "test_format_string.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
auto test = []<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected,
|
||||
test_format_string<CharT, Args...> fmt,
|
||||
Args&&... args) constexpr {
|
||||
{
|
||||
std::list<CharT> out;
|
||||
std::format_to_n_result result = std::format_to_n(std::back_inserter(out), 0, fmt.template sv<CharT>(), args...);
|
||||
std::format_to_n_result result = std::format_to_n(std::back_inserter(out), 0, fmt, std::forward<Args>(args)...);
|
||||
// To avoid signedness warnings make sure formatted_size uses the same type
|
||||
// as result.size.
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(fmt.template sv<CharT>(), args...);
|
||||
diff_type formatted_size = std::formatted_size(fmt, std::forward<Args>(args)...);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
assert(out.empty());
|
||||
}
|
||||
{
|
||||
std::vector<CharT> out;
|
||||
std::format_to_n_result result = std::format_to_n(std::back_inserter(out), 5, fmt.template sv<CharT>(), args...);
|
||||
std::format_to_n_result result = std::format_to_n(std::back_inserter(out), 5, fmt, std::forward<Args>(args)...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(fmt.template sv<CharT>(), args...);
|
||||
diff_type formatted_size = std::formatted_size(fmt, std::forward<Args>(args)...);
|
||||
diff_type size = std::min<diff_type>(5, formatted_size);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
@@ -56,9 +59,9 @@ auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string
|
||||
}
|
||||
{
|
||||
std::basic_string<CharT> out;
|
||||
std::format_to_n_result result = std::format_to_n(std::back_inserter(out), 1000, fmt.template sv<CharT>(), args...);
|
||||
std::format_to_n_result result = std::format_to_n(std::back_inserter(out), 1000, fmt, std::forward<Args>(args)...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(fmt.template sv<CharT>(), args...);
|
||||
diff_type formatted_size = std::formatted_size(fmt, std::forward<Args>(args)...);
|
||||
diff_type size = std::min<diff_type>(1000, formatted_size);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
@@ -67,9 +70,9 @@ auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string
|
||||
{
|
||||
// Test the returned iterator.
|
||||
std::basic_string<CharT> out(10, CharT(' '));
|
||||
std::format_to_n_result result = std::format_to_n(out.begin(), 10, fmt.template sv<CharT>(), args...);
|
||||
std::format_to_n_result result = std::format_to_n(out.begin(), 10, fmt, std::forward<Args>(args)...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(fmt.template sv<CharT>(), args...);
|
||||
diff_type formatted_size = std::formatted_size(fmt, std::forward<Args>(args)...);
|
||||
diff_type size = std::min<diff_type>(10, formatted_size);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
@@ -81,9 +84,9 @@ auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string
|
||||
"If the difference type isn't negative the test will fail "
|
||||
"due to using a large positive value.");
|
||||
CharT buffer[1] = {CharT(0)};
|
||||
std::format_to_n_result result = std::format_to_n(buffer, -1, fmt.template sv<CharT>(), args...);
|
||||
std::format_to_n_result result = std::format_to_n(buffer, -1, fmt, std::forward<Args>(args)...);
|
||||
using diff_type = decltype(result.size);
|
||||
diff_type formatted_size = std::formatted_size(fmt.template sv<CharT>(), args...);
|
||||
diff_type formatted_size = std::formatted_size(fmt, std::forward<Args>(args)...);
|
||||
|
||||
assert(result.size == formatted_size);
|
||||
assert(result.out == buffer);
|
||||
@@ -91,7 +94,7 @@ auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string
|
||||
}
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, const Args&...) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
|
||||
// After P2216 most exceptions thrown by std::format_to_n become ill-formed.
|
||||
// Therefore this tests does nothing.
|
||||
// A basic ill-formed test is done in format_to_n.verify.cpp
|
||||
|
||||
@@ -29,14 +29,16 @@
|
||||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
#include "test_format_string.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
size_t size = std::formatted_size(std::locale(), fmt.template sv<CharT>(), args...);
|
||||
assert(size == expected.size());
|
||||
};
|
||||
auto test =
|
||||
[]<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr {
|
||||
size_t size = std::formatted_size(std::locale(), fmt, std::forward<Args>(args)...);
|
||||
assert(size == expected.size());
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, const Args&...) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
|
||||
// After P2216 most exceptions thrown by std::formatted_siz3 become ill-formed.
|
||||
// Therefore this tests does nothing.
|
||||
// A basic ill-formed test is done in formatted_size.locale.verify.cpp
|
||||
|
||||
@@ -26,14 +26,16 @@
|
||||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
#include "test_format_string.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
size_t size = std::formatted_size(fmt.template sv<CharT>(), args...);
|
||||
assert(size == expected.size());
|
||||
};
|
||||
auto test =
|
||||
[]<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr {
|
||||
size_t size = std::formatted_size(fmt, std::forward<Args>(args)...);
|
||||
assert(size == expected.size());
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, const Args&...) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
|
||||
// After P2216 most exceptions thrown by std::formatted_siz3 become ill-formed.
|
||||
// Therefore this tests does nothing.
|
||||
// A basic ill-formed test is done in formatted_size.verify.cpp
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,7 @@
|
||||
#include "make_string.h"
|
||||
#include "test_macros.h"
|
||||
#include "string_literal.h"
|
||||
#include "test_format_string.h"
|
||||
|
||||
#ifndef TEST_HAS_NO_LOCALIZATION
|
||||
# include <iostream>
|
||||
@@ -37,14 +38,14 @@
|
||||
|
||||
#define SV(S) MAKE_STRING_VIEW(CharT, S)
|
||||
|
||||
auto check = []<string_literal fmt, class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, const Args&... args) constexpr {
|
||||
std::basic_string<CharT> out = std::format(fmt.template sv<CharT>(), args...);
|
||||
template < class CharT, class... Args>
|
||||
void check(std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) {
|
||||
std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...);
|
||||
#ifndef TEST_HAS_NO_LOCALIZATION
|
||||
if constexpr (std::same_as<CharT, char>)
|
||||
if (out != expected)
|
||||
std::cerr << "\nFormat string " << fmt.template sv<char>() << "\nExpected output " << expected
|
||||
<< "\nActual output " << out << '\n';
|
||||
std::cerr << "\nFormat string " << fmt.get() << "\nExpected output " << expected << "\nActual output " << out
|
||||
<< '\n';
|
||||
#endif
|
||||
assert(out == expected);
|
||||
};
|
||||
@@ -52,62 +53,61 @@ auto check = []<string_literal fmt, class CharT, class... Args>(
|
||||
template <class CharT>
|
||||
static void test_single_code_point_fill() {
|
||||
//*** 1-byte code points ***
|
||||
check.template operator()<"{:*^3}">(SV("* *"), SV(" "));
|
||||
check.template operator()<"{:*^3}">(SV("*~*"), SV("~"));
|
||||
check(SV("* *"), SV("{:*^3}"), SV(" "));
|
||||
check(SV("*~*"), SV("{:*^3}"), SV("~"));
|
||||
|
||||
//*** 2-byte code points ***
|
||||
check.template operator()<"{:*^3}">(SV("*\u00a1*"), SV("\u00a1")); // INVERTED EXCLAMATION MARK
|
||||
check.template operator()<"{:*^3}">(SV("*\u07ff*"), SV("\u07ff")); // NKO TAMAN SIGN
|
||||
check(SV("*\u00a1*"), SV("{:*^3}"), SV("\u00a1")); // INVERTED EXCLAMATION MARK
|
||||
check(SV("*\u07ff*"), SV("{:*^3}"), SV("\u07ff")); // NKO TAMAN SIGN
|
||||
|
||||
//*** 3-byte code points ***
|
||||
check.template operator()<"{:*^3}">(SV("*\u0800*"), SV("\u0800")); // SAMARITAN LETTER ALAF
|
||||
check.template operator()<"{:*^3}">(SV("*\ufffd*"), SV("\ufffd")); // REPLACEMENT CHARACTER
|
||||
check(SV("*\u0800*"), SV("{:*^3}"), SV("\u0800")); // SAMARITAN LETTER ALAF
|
||||
check(SV("*\ufffd*"), SV("{:*^3}"), SV("\ufffd")); // REPLACEMENT CHARACTER
|
||||
|
||||
// 2 column ranges
|
||||
check.template operator()<"{:*^4}">(SV("*\u1100*"), SV("\u1100")); // HANGUL CHOSEONG KIYEOK
|
||||
check.template operator()<"{:*^4}">(SV("*\u115f*"), SV("\u115f")); // HANGUL CHOSEONG FILLER
|
||||
check(SV("*\u1100*"), SV("{:*^4}"), SV("\u1100")); // HANGUL CHOSEONG KIYEOK
|
||||
check(SV("*\u115f*"), SV("{:*^4}"), SV("\u115f")); // HANGUL CHOSEONG FILLER
|
||||
|
||||
check.template operator()<"{:*^4}">(SV("*\u2329*"), SV("\u2329")); // LEFT-POINTING ANGLE BRACKET
|
||||
check.template operator()<"{:*^4}">(SV("*\u232a*"), SV("\u232a")); // RIGHT-POINTING ANGLE BRACKET
|
||||
check(SV("*\u2329*"), SV("{:*^4}"), SV("\u2329")); // LEFT-POINTING ANGLE BRACKET
|
||||
check(SV("*\u232a*"), SV("{:*^4}"), SV("\u232a")); // RIGHT-POINTING ANGLE BRACKET
|
||||
|
||||
check.template operator()<"{:*^4}">(SV("*\u2e80*"), SV("\u2e80")); // CJK RADICAL REPEAT
|
||||
check.template operator()<"{:*^4}">(SV("*\u303e*"), SV("\u303e")); // IDEOGRAPHIC VARIATION INDICATOR
|
||||
check(SV("*\u2e80*"), SV("{:*^4}"), SV("\u2e80")); // CJK RADICAL REPEAT
|
||||
check(SV("*\u303e*"), SV("{:*^4}"), SV("\u303e")); // IDEOGRAPHIC VARIATION INDICATOR
|
||||
|
||||
check.template operator()<"{:*^4}">(SV("*\u3040*"), SV("\u3040")); // U+3041 HIRAGANA LETTER SMALL A
|
||||
check.template operator()<"{:*^4}">(SV("*\ua4cf*"), SV("\ua4cf")); // U+A4D0 LISU LETTER BA
|
||||
check(SV("*\u3040*"), SV("{:*^4}"), SV("\u3040")); // U+3041 HIRAGANA LETTER SMALL A
|
||||
check(SV("*\ua4cf*"), SV("{:*^4}"), SV("\ua4cf")); // U+A4D0 LISU LETTER BA
|
||||
|
||||
check.template operator()<"{:*^4}">(SV("*\uac00*"), SV("\uac00")); // <Hangul Syllable, First>
|
||||
check.template operator()<"{:*^4}">(SV("*\ud7a3*"), SV("\ud7a3")); // Hangul Syllable Hih
|
||||
check(SV("*\uac00*"), SV("{:*^4}"), SV("\uac00")); // <Hangul Syllable, First>
|
||||
check(SV("*\ud7a3*"), SV("{:*^4}"), SV("\ud7a3")); // Hangul Syllable Hih
|
||||
|
||||
check.template operator()<"{:*^4}">(SV("*\uf900*"), SV("\uf900")); // CJK COMPATIBILITY IDEOGRAPH-F900
|
||||
check.template operator()<"{:*^4}">(SV("*\ufaff*"), SV("\ufaff")); // U+FB00 LATIN SMALL LIGATURE FF
|
||||
check(SV("*\uf900*"), SV("{:*^4}"), SV("\uf900")); // CJK COMPATIBILITY IDEOGRAPH-F900
|
||||
check(SV("*\ufaff*"), SV("{:*^4}"), SV("\ufaff")); // U+FB00 LATIN SMALL LIGATURE FF
|
||||
|
||||
check.template operator()<"{:*^4}">(SV("*\ufe10*"), SV("\ufe10")); // PRESENTATION FORM FOR VERTICAL COMMA
|
||||
check.template
|
||||
operator()<"{:*^4}">(SV("*\ufe19*"), SV("\ufe19")); // PRESENTATION FORM FOR VERTICAL HORIZONTAL ELLIPSIS
|
||||
check(SV("*\ufe10*"), SV("{:*^4}"), SV("\ufe10")); // PRESENTATION FORM FOR VERTICAL COMMA
|
||||
check(SV("*\ufe19*"), SV("{:*^4}"), SV("\ufe19")); // PRESENTATION FORM FOR VERTICAL HORIZONTAL ELLIPSIS
|
||||
|
||||
check.template operator()<"{:*^4}">(SV("*\ufe30*"), SV("\ufe30")); // PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
|
||||
check.template operator()<"{:*^4}">(SV("*\ufe6f*"), SV("\ufe6f")); // U+FE70 ARABIC FATHATAN ISOLATED FORM
|
||||
check(SV("*\ufe30*"), SV("{:*^4}"), SV("\ufe30")); // PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
|
||||
check(SV("*\ufe6f*"), SV("{:*^4}"), SV("\ufe6f")); // U+FE70 ARABIC FATHATAN ISOLATED FORM
|
||||
|
||||
check.template operator()<"{:*^4}">(SV("*\uff00*"), SV("\uff00")); // U+FF01 FULLWIDTH EXCLAMATION MARK
|
||||
check.template operator()<"{:*^4}">(SV("*\uff60*"), SV("\uff60")); // FULLWIDTH RIGHT WHITE PARENTHESIS
|
||||
check(SV("*\uff00*"), SV("{:*^4}"), SV("\uff00")); // U+FF01 FULLWIDTH EXCLAMATION MARK
|
||||
check(SV("*\uff60*"), SV("{:*^4}"), SV("\uff60")); // FULLWIDTH RIGHT WHITE PARENTHESIS
|
||||
|
||||
check.template operator()<"{:*^4}">(SV("*\uffe0*"), SV("\uffe0")); // FULLWIDTH CENT SIGN
|
||||
check.template operator()<"{:*^4}">(SV("*\uffe6*"), SV("\uffe6")); // FULLWIDTH WON SIGN
|
||||
check(SV("*\uffe0*"), SV("{:*^4}"), SV("\uffe0")); // FULLWIDTH CENT SIGN
|
||||
check(SV("*\uffe6*"), SV("{:*^4}"), SV("\uffe6")); // FULLWIDTH WON SIGN
|
||||
|
||||
//*** 4-byte code points ***
|
||||
check.template operator()<"{:*^3}">(SV("*\U00010000*"), SV("\U00010000")); // LINEAR B SYLLABLE B008 A
|
||||
check.template operator()<"{:*^3}">(SV("*\U0010FFFF*"), SV("\U0010FFFF")); // Undefined Character
|
||||
check(SV("*\U00010000*"), SV("{:*^3}"), SV("\U00010000")); // LINEAR B SYLLABLE B008 A
|
||||
check(SV("*\U0010FFFF*"), SV("{:*^3}"), SV("\U0010FFFF")); // Undefined Character
|
||||
|
||||
// 2 column ranges
|
||||
check.template operator()<"{:*^4}">(SV("*\U0001f300*"), SV("\U0001f300")); // CYCLONE
|
||||
check.template operator()<"{:*^4}">(SV("*\U0001f64f*"), SV("\U0001f64f")); // PERSON WITH FOLDED HANDS
|
||||
check.template operator()<"{:*^4}">(SV("*\U0001f900*"), SV("\U0001f900")); // CIRCLED CROSS FORMEE WITH FOUR DOTS
|
||||
check.template operator()<"{:*^4}">(SV("*\U0001f9ff*"), SV("\U0001f9ff")); // NAZAR AMULET
|
||||
check.template operator()<"{:*^4}">(SV("*\U00020000*"), SV("\U00020000")); // <CJK Ideograph Extension B, First>
|
||||
check.template operator()<"{:*^4}">(SV("*\U0002fffd*"), SV("\U0002fffd")); // Undefined Character
|
||||
check.template operator()<"{:*^4}">(SV("*\U00030000*"), SV("\U00030000")); // <CJK Ideograph Extension G, First>
|
||||
check.template operator()<"{:*^4}">(SV("*\U0003fffd*"), SV("\U0003fffd")); // Undefined Character
|
||||
check(SV("*\U0001f300*"), SV("{:*^4}"), SV("\U0001f300")); // CYCLONE
|
||||
check(SV("*\U0001f64f*"), SV("{:*^4}"), SV("\U0001f64f")); // PERSON WITH FOLDED HANDS
|
||||
check(SV("*\U0001f900*"), SV("{:*^4}"), SV("\U0001f900")); // CIRCLED CROSS FORMEE WITH FOUR DOTS
|
||||
check(SV("*\U0001f9ff*"), SV("{:*^4}"), SV("\U0001f9ff")); // NAZAR AMULET
|
||||
check(SV("*\U00020000*"), SV("{:*^4}"), SV("\U00020000")); // <CJK Ideograph Extension B, First>
|
||||
check(SV("*\U0002fffd*"), SV("{:*^4}"), SV("\U0002fffd")); // Undefined Character
|
||||
check(SV("*\U00030000*"), SV("{:*^4}"), SV("\U00030000")); // <CJK Ideograph Extension G, First>
|
||||
check(SV("*\U0003fffd*"), SV("{:*^4}"), SV("\U0003fffd")); // Undefined Character
|
||||
}
|
||||
|
||||
// One column output is unaffected.
|
||||
@@ -115,122 +115,122 @@ static void test_single_code_point_fill() {
|
||||
template <class CharT>
|
||||
static void test_single_code_point_truncate() {
|
||||
//*** 1-byte code points ***
|
||||
check.template operator()<"{:*^3.1}">(SV("* *"), SV(" "));
|
||||
check.template operator()<"{:*^3.1}">(SV("*~*"), SV("~"));
|
||||
check(SV("* *"), SV("{:*^3.1}"), SV(" "));
|
||||
check(SV("*~*"), SV("{:*^3.1}"), SV("~"));
|
||||
|
||||
//*** 2-byte code points ***
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u00a1*"), SV("\u00a1")); // INVERTED EXCLAMATION MARK
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u07ff*"), SV("\u07ff")); // NKO TAMAN SIGN
|
||||
check(SV("*\u00a1*"), SV("{:*^3.1}"), SV("\u00a1")); // INVERTED EXCLAMATION MARK
|
||||
check(SV("*\u07ff*"), SV("{:*^3.1}"), SV("\u07ff")); // NKO TAMAN SIGN
|
||||
|
||||
//*** 3.1-byte code points ***
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u0800*"), SV("\u0800")); // SAMARITAN LETTER ALAF
|
||||
check.template operator()<"{:*^3.1}">(SV("*\ufffd*"), SV("\ufffd")); // REPLACEMENT CHARACTER
|
||||
check(SV("*\u0800*"), SV("{:*^3.1}"), SV("\u0800")); // SAMARITAN LETTER ALAF
|
||||
check(SV("*\ufffd*"), SV("{:*^3.1}"), SV("\ufffd")); // REPLACEMENT CHARACTER
|
||||
|
||||
// 2 column ranges
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\u1100")); // HANGUL CHOSEONG KIYEOK
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\u115f")); // HANGUL CHOSEONG FILLER
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\u1100")); // HANGUL CHOSEONG KIYEOK
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\u115f")); // HANGUL CHOSEONG FILLER
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\u2329")); // LEFT-POINTING ANGLE BRACKET
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\u232a")); // RIGHT-POINTING ANGLE BRACKET
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\u2329")); // LEFT-POINTING ANGLE BRACKET
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\u232a")); // RIGHT-POINTING ANGLE BRACKET
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\u2e80")); // CJK RADICAL REPEAT
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\u303e")); // IDEOGRAPHIC VARIATION INDICATOR
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\u2e80")); // CJK RADICAL REPEAT
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\u303e")); // IDEOGRAPHIC VARIATION INDICATOR
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\u3040")); // U+3041 HIRAGANA LETTER SMALL A
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\ua4cf")); // U+A4D0 LISU LETTER BA
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\u3040")); // U+3041 HIRAGANA LETTER SMALL A
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\ua4cf")); // U+A4D0 LISU LETTER BA
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\uac00")); // <Hangul Syllable, First>
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\ud7a3")); // Hangul Syllable Hih
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\uac00")); // <Hangul Syllable, First>
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\ud7a3")); // Hangul Syllable Hih
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\uf900")); // CJK COMPATIBILITY IDEOGRAPH-F900
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\ufaff")); // U+FB00 LATIN SMALL LIGATURE FF
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\uf900")); // CJK COMPATIBILITY IDEOGRAPH-F900
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\ufaff")); // U+FB00 LATIN SMALL LIGATURE FF
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\ufe10")); // PRESENTATION FORM FOR VERTICAL COMMA
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\ufe19")); // PRESENTATION FORM FOR VERTICAL HORIZONTAL ELLIPSIS
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\ufe10")); // PRESENTATION FORM FOR VERTICAL COMMA
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\ufe19")); // PRESENTATION FORM FOR VERTICAL HORIZONTAL ELLIPSIS
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\ufe30")); // PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\ufe6f")); // U+FE70 ARABIC FATHATAN ISOLATED FORM
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\ufe30")); // PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\ufe6f")); // U+FE70 ARABIC FATHATAN ISOLATED FORM
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\uff00")); // U+FF01 FULLWIDTH EXCLAMATION MARK
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\uff60")); // FULLWIDTH RIGHT WHITE PARENTHESIS
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\uff00")); // U+FF01 FULLWIDTH EXCLAMATION MARK
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\uff60")); // FULLWIDTH RIGHT WHITE PARENTHESIS
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\uffe0")); // FULLWIDTH CENT SIGN
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\uffe6")); // FULLWIDTH WON SIGN
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\uffe0")); // FULLWIDTH CENT SIGN
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\uffe6")); // FULLWIDTH WON SIGN
|
||||
|
||||
//*** 3.1-byte code points ***
|
||||
check.template operator()<"{:*^3.1}">(SV("*\U00010000*"), SV("\U00010000")); // LINEAR B SYLLABLE B008 A
|
||||
check.template operator()<"{:*^3.1}">(SV("*\U0010FFFF*"), SV("\U0010FFFF")); // Undefined Character
|
||||
check(SV("*\U00010000*"), SV("{:*^3.1}"), SV("\U00010000")); // LINEAR B SYLLABLE B008 A
|
||||
check(SV("*\U0010FFFF*"), SV("{:*^3.1}"), SV("\U0010FFFF")); // Undefined Character
|
||||
|
||||
// 2 column ranges
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\U0001f300")); // CYCLONE
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\U0001f64f")); // PERSON WITH FOLDED HANDS
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\U0001f900")); // CIRCLED CROSS FORMEE WITH FOUR DOTS
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\U0001f9ff")); // NAZAR AMULET
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\U00020000")); // <CJK Ideograph Extension B, First>
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\U0002fffd")); // Undefined Character
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\U00030000")); // <CJK Ideograph Extension G, First>
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\U0003fffd")); // Undefined Character
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\U0001f300")); // CYCLONE
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\U0001f64f")); // PERSON WITH FOLDED HANDS
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\U0001f900")); // CIRCLED CROSS FORMEE WITH FOUR DOTS
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\U0001f9ff")); // NAZAR AMULET
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\U00020000")); // <CJK Ideograph Extension B, First>
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\U0002fffd")); // Undefined Character
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\U00030000")); // <CJK Ideograph Extension G, First>
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\U0003fffd")); // Undefined Character
|
||||
}
|
||||
|
||||
// The examples used in that paper.
|
||||
template <class CharT>
|
||||
static void test_P1868() {
|
||||
// Fill
|
||||
check.template operator()<"{:*^3}">(SV("*\u0041*"), SV("\u0041")); // { LATIN CAPITAL LETTER A }
|
||||
check.template operator()<"{:*^3}">(SV("*\u00c1*"), SV("\u00c1")); // { LATIN CAPITAL LETTER A WITH ACUTE }
|
||||
check.template operator()<"{:*^3}">(
|
||||
SV("*\u0041\u0301*"),
|
||||
SV("\u0041\u0301")); // { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT }
|
||||
check.template operator()<"{:*^3}">(SV("*\u0132*"), SV("\u0132")); // { LATIN CAPITAL LIGATURE IJ }
|
||||
check.template operator()<"{:*^3}">(SV("*\u0394*"), SV("\u0394")); // { GREEK CAPITAL LETTER DELTA }
|
||||
check(SV("*\u0041*"), SV("{:*^3}"), SV("\u0041")); // { LATIN CAPITAL LETTER A }
|
||||
check(SV("*\u00c1*"), SV("{:*^3}"), SV("\u00c1")); // { LATIN CAPITAL LETTER A WITH ACUTE }
|
||||
check(SV("*\u0041\u0301*"),
|
||||
SV("{:*^3}"),
|
||||
SV("\u0041\u0301")); // { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT }
|
||||
check(SV("*\u0132*"), SV("{:*^3}"), SV("\u0132")); // { LATIN CAPITAL LIGATURE IJ }
|
||||
check(SV("*\u0394*"), SV("{:*^3}"), SV("\u0394")); // { GREEK CAPITAL LETTER DELTA }
|
||||
|
||||
check.template operator()<"{:*^3}">(SV("*\u0429*"), SV("\u0429")); // { CYRILLIC CAPITAL LETTER SHCHA }
|
||||
check.template operator()<"{:*^3}">(SV("*\u05d0*"), SV("\u05d0")); // { HEBREW LETTER ALEF }
|
||||
check.template operator()<"{:*^3}">(SV("*\u0634*"), SV("\u0634")); // { ARABIC LETTER SHEEN }
|
||||
check.template operator()<"{:*^4}">(SV("*\u3009*"), SV("\u3009")); // { RIGHT-POINTING ANGLE BRACKET }
|
||||
check.template operator()<"{:*^4}">(SV("*\u754c*"), SV("\u754c")); // { CJK Unified Ideograph-754C }
|
||||
check.template operator()<"{:*^4}">(SV("*\U0001f921*"), SV("\U0001f921")); // { UNICORN FACE }
|
||||
check.template operator()<"{:*^4}">(
|
||||
SV("*\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466*"),
|
||||
SV("\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466")); // { Family: Man, Woman, Girl, Boy }
|
||||
check(SV("*\u0429*"), SV("{:*^3}"), SV("\u0429")); // { CYRILLIC CAPITAL LETTER SHCHA }
|
||||
check(SV("*\u05d0*"), SV("{:*^3}"), SV("\u05d0")); // { HEBREW LETTER ALEF }
|
||||
check(SV("*\u0634*"), SV("{:*^3}"), SV("\u0634")); // { ARABIC LETTER SHEEN }
|
||||
check(SV("*\u3009*"), SV("{:*^4}"), SV("\u3009")); // { RIGHT-POINTING ANGLE BRACKET }
|
||||
check(SV("*\u754c*"), SV("{:*^4}"), SV("\u754c")); // { CJK Unified Ideograph-754C }
|
||||
check(SV("*\U0001f921*"), SV("{:*^4}"), SV("\U0001f921")); // { UNICORN FACE }
|
||||
check(SV("*\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466*"),
|
||||
SV("{:*^4}"),
|
||||
SV("\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466")); // { Family: Man, Woman, Girl, Boy }
|
||||
|
||||
// Truncate to 1 column: 1 column grapheme clusters are kept together.
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u0041*"), SV("\u0041")); // { LATIN CAPITAL LETTER A }
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u00c1*"), SV("\u00c1")); // { LATIN CAPITAL LETTER A WITH ACUTE }
|
||||
check.template operator()<"{:*^3.1}">(
|
||||
SV("*\u0041\u0301*"),
|
||||
SV("\u0041\u0301")); // { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT }
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u0132*"), SV("\u0132")); // { LATIN CAPITAL LIGATURE IJ }
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u0394*"), SV("\u0394")); // { GREEK CAPITAL LETTER DELTA }
|
||||
check(SV("*\u0041*"), SV("{:*^3.1}"), SV("\u0041")); // { LATIN CAPITAL LETTER A }
|
||||
check(SV("*\u00c1*"), SV("{:*^3.1}"), SV("\u00c1")); // { LATIN CAPITAL LETTER A WITH ACUTE }
|
||||
check(SV("*\u0041\u0301*"),
|
||||
SV("{:*^3.1}"),
|
||||
SV("\u0041\u0301")); // { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT }
|
||||
check(SV("*\u0132*"), SV("{:*^3.1}"), SV("\u0132")); // { LATIN CAPITAL LIGATURE IJ }
|
||||
check(SV("*\u0394*"), SV("{:*^3.1}"), SV("\u0394")); // { GREEK CAPITAL LETTER DELTA }
|
||||
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u0429*"), SV("\u0429")); // { CYRILLIC CAPITAL LETTER SHCHA }
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u05d0*"), SV("\u05d0")); // { HEBREW LETTER ALEF }
|
||||
check.template operator()<"{:*^3.1}">(SV("*\u0634*"), SV("\u0634")); // { ARABIC LETTER SHEEN }
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\u3009")); // { RIGHT-POINTING ANGLE BRACKET }
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\u754c")); // { CJK Unified Ideograph-754C }
|
||||
check.template operator()<"{:*^3.1}">(SV("***"), SV("\U0001f921")); // { UNICORN FACE }
|
||||
check.template operator()<"{:*^3.1}">(
|
||||
SV("***"),
|
||||
SV("\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466")); // { Family: Man, Woman, Girl, Boy }
|
||||
check(SV("*\u0429*"), SV("{:*^3.1}"), SV("\u0429")); // { CYRILLIC CAPITAL LETTER SHCHA }
|
||||
check(SV("*\u05d0*"), SV("{:*^3.1}"), SV("\u05d0")); // { HEBREW LETTER ALEF }
|
||||
check(SV("*\u0634*"), SV("{:*^3.1}"), SV("\u0634")); // { ARABIC LETTER SHEEN }
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\u3009")); // { RIGHT-POINTING ANGLE BRACKET }
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\u754c")); // { CJK Unified Ideograph-754C }
|
||||
check(SV("***"), SV("{:*^3.1}"), SV("\U0001f921")); // { UNICORN FACE }
|
||||
check(SV("***"),
|
||||
SV("{:*^3.1}"),
|
||||
SV("\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466")); // { Family: Man, Woman, Girl, Boy }
|
||||
|
||||
// Truncate to 2 column: 2 column grapheme clusters are kept together.
|
||||
check.template operator()<"{:*^3.2}">(SV("*\u0041*"), SV("\u0041")); // { LATIN CAPITAL LETTER A }
|
||||
check.template operator()<"{:*^3.2}">(SV("*\u00c1*"), SV("\u00c1")); // { LATIN CAPITAL LETTER A WITH ACUTE }
|
||||
check.template operator()<"{:*^3.2}">(
|
||||
SV("*\u0041\u0301*"),
|
||||
SV("\u0041\u0301")); // { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT }
|
||||
check.template operator()<"{:*^3.2}">(SV("*\u0132*"), SV("\u0132")); // { LATIN CAPITAL LIGATURE IJ }
|
||||
check.template operator()<"{:*^3.2}">(SV("*\u0394*"), SV("\u0394")); // { GREEK CAPITAL LETTER DELTA }
|
||||
check(SV("*\u0041*"), SV("{:*^3.2}"), SV("\u0041")); // { LATIN CAPITAL LETTER A }
|
||||
check(SV("*\u00c1*"), SV("{:*^3.2}"), SV("\u00c1")); // { LATIN CAPITAL LETTER A WITH ACUTE }
|
||||
check(SV("*\u0041\u0301*"),
|
||||
SV("{:*^3.2}"),
|
||||
SV("\u0041\u0301")); // { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT }
|
||||
check(SV("*\u0132*"), SV("{:*^3.2}"), SV("\u0132")); // { LATIN CAPITAL LIGATURE IJ }
|
||||
check(SV("*\u0394*"), SV("{:*^3.2}"), SV("\u0394")); // { GREEK CAPITAL LETTER DELTA }
|
||||
|
||||
check.template operator()<"{:*^3.2}">(SV("*\u0429*"), SV("\u0429")); // { CYRILLIC CAPITAL LETTER SHCHA }
|
||||
check.template operator()<"{:*^3.2}">(SV("*\u05d0*"), SV("\u05d0")); // { HEBREW LETTER ALEF }
|
||||
check.template operator()<"{:*^3.2}">(SV("*\u0634*"), SV("\u0634")); // { ARABIC LETTER SHEEN }
|
||||
check.template operator()<"{:*^4.2}">(SV("*\u3009*"), SV("\u3009")); // { RIGHT-POINTING ANGLE BRACKET }
|
||||
check.template operator()<"{:*^4.2}">(SV("*\u754c*"), SV("\u754c")); // { CJK Unified Ideograph-754C }
|
||||
check.template operator()<"{:*^4.2}">(SV("*\U0001f921*"), SV("\U0001f921")); // { UNICORN FACE }
|
||||
check.template operator()<"{:*^4.2}">(
|
||||
SV("*\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466*"),
|
||||
SV("\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466")); // { Family: Man, Woman, Girl, Boy }
|
||||
check(SV("*\u0429*"), SV("{:*^3.2}"), SV("\u0429")); // { CYRILLIC CAPITAL LETTER SHCHA }
|
||||
check(SV("*\u05d0*"), SV("{:*^3.2}"), SV("\u05d0")); // { HEBREW LETTER ALEF }
|
||||
check(SV("*\u0634*"), SV("{:*^3.2}"), SV("\u0634")); // { ARABIC LETTER SHEEN }
|
||||
check(SV("*\u3009*"), SV("{:*^4.2}"), SV("\u3009")); // { RIGHT-POINTING ANGLE BRACKET }
|
||||
check(SV("*\u754c*"), SV("{:*^4.2}"), SV("\u754c")); // { CJK Unified Ideograph-754C }
|
||||
check(SV("*\U0001f921*"), SV("{:*^4.2}"), SV("\U0001f921")); // { UNICORN FACE }
|
||||
check(SV("*\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466*"),
|
||||
SV("{:*^4.2}"),
|
||||
SV("\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466")); // { Family: Man, Woman, Girl, Boy }
|
||||
}
|
||||
|
||||
#ifdef _LIBCPP_VERSION
|
||||
@@ -240,37 +240,37 @@ template <class CharT>
|
||||
static void test_malformed_code_point() {
|
||||
if constexpr (sizeof(CharT) == 1) {
|
||||
// Malformed at end.
|
||||
check.template operator()<"{:*^7}">(SV("*ZZZZ\x8f*"), SV("ZZZZ\x8f"));
|
||||
check.template operator()<"{:*^7}">(SV("*ZZZZ\xcf*"), SV("ZZZZ\xcf"));
|
||||
check.template operator()<"{:*^7}">(SV("*ZZZZ\xef*"), SV("ZZZZ\xef"));
|
||||
check.template operator()<"{:*^7}">(SV("*ZZZZ\xff*"), SV("ZZZZ\xff"));
|
||||
check(SV("*ZZZZ\x8f*"), SV("{:*^7}"), SV("ZZZZ\x8f"));
|
||||
check(SV("*ZZZZ\xcf*"), SV("{:*^7}"), SV("ZZZZ\xcf"));
|
||||
check(SV("*ZZZZ\xef*"), SV("{:*^7}"), SV("ZZZZ\xef"));
|
||||
check(SV("*ZZZZ\xff*"), SV("{:*^7}"), SV("ZZZZ\xff"));
|
||||
|
||||
// Malformed in middle, no continuation
|
||||
check.template operator()<"{:*^8}">(SV("*ZZZZ\x8fZ*"), SV("ZZZZ\x8fZ"));
|
||||
check.template operator()<"{:*^8}">(SV("*ZZZZ\xcfZ*"), SV("ZZZZ\xcfZ"));
|
||||
check.template operator()<"{:*^8}">(SV("*ZZZZ\xefZ*"), SV("ZZZZ\xefZ"));
|
||||
check.template operator()<"{:*^8}">(SV("*ZZZZ\xffZ*"), SV("ZZZZ\xffZ"));
|
||||
check(SV("*ZZZZ\x8fZ*"), SV("{:*^8}"), SV("ZZZZ\x8fZ"));
|
||||
check(SV("*ZZZZ\xcfZ*"), SV("{:*^8}"), SV("ZZZZ\xcfZ"));
|
||||
check(SV("*ZZZZ\xefZ*"), SV("{:*^8}"), SV("ZZZZ\xefZ"));
|
||||
check(SV("*ZZZZ\xffZ*"), SV("{:*^8}"), SV("ZZZZ\xffZ"));
|
||||
|
||||
check.template operator()<"{:*^9}">(SV("*ZZZZ\x8fZZ*"), SV("ZZZZ\x8fZZ"));
|
||||
check.template operator()<"{:*^9}">(SV("*ZZZZ\xcfZZ*"), SV("ZZZZ\xcfZZ"));
|
||||
check.template operator()<"{:*^9}">(SV("*ZZZZ\xefZZ*"), SV("ZZZZ\xefZZ"));
|
||||
check.template operator()<"{:*^9}">(SV("*ZZZZ\xffZZ*"), SV("ZZZZ\xffZZ"));
|
||||
check(SV("*ZZZZ\x8fZZ*"), SV("{:*^9}"), SV("ZZZZ\x8fZZ"));
|
||||
check(SV("*ZZZZ\xcfZZ*"), SV("{:*^9}"), SV("ZZZZ\xcfZZ"));
|
||||
check(SV("*ZZZZ\xefZZ*"), SV("{:*^9}"), SV("ZZZZ\xefZZ"));
|
||||
check(SV("*ZZZZ\xffZZ*"), SV("{:*^9}"), SV("ZZZZ\xffZZ"));
|
||||
|
||||
check.template operator()<"{:*^10}">(SV("*ZZZZ\x8fZZZ*"), SV("ZZZZ\x8fZZZ"));
|
||||
check.template operator()<"{:*^10}">(SV("*ZZZZ\xcfZZZ*"), SV("ZZZZ\xcfZZZ"));
|
||||
check.template operator()<"{:*^10}">(SV("*ZZZZ\xefZZZ*"), SV("ZZZZ\xefZZZ"));
|
||||
check.template operator()<"{:*^10}">(SV("*ZZZZ\xffZZZ*"), SV("ZZZZ\xffZZZ"));
|
||||
check(SV("*ZZZZ\x8fZZZ*"), SV("{:*^10}"), SV("ZZZZ\x8fZZZ"));
|
||||
check(SV("*ZZZZ\xcfZZZ*"), SV("{:*^10}"), SV("ZZZZ\xcfZZZ"));
|
||||
check(SV("*ZZZZ\xefZZZ*"), SV("{:*^10}"), SV("ZZZZ\xefZZZ"));
|
||||
check(SV("*ZZZZ\xffZZZ*"), SV("{:*^10}"), SV("ZZZZ\xffZZZ"));
|
||||
|
||||
check.template operator()<"{:*^11}">(SV("*ZZZZ\x8fZZZZ*"), SV("ZZZZ\x8fZZZZ"));
|
||||
check.template operator()<"{:*^11}">(SV("*ZZZZ\xcfZZZZ*"), SV("ZZZZ\xcfZZZZ"));
|
||||
check.template operator()<"{:*^11}">(SV("*ZZZZ\xefZZZZ*"), SV("ZZZZ\xefZZZZ"));
|
||||
check.template operator()<"{:*^11}">(SV("*ZZZZ\xffZZZZ*"), SV("ZZZZ\xffZZZZ"));
|
||||
check(SV("*ZZZZ\x8fZZZZ*"), SV("{:*^11}"), SV("ZZZZ\x8fZZZZ"));
|
||||
check(SV("*ZZZZ\xcfZZZZ*"), SV("{:*^11}"), SV("ZZZZ\xcfZZZZ"));
|
||||
check(SV("*ZZZZ\xefZZZZ*"), SV("{:*^11}"), SV("ZZZZ\xefZZZZ"));
|
||||
check(SV("*ZZZZ\xffZZZZ*"), SV("{:*^11}"), SV("ZZZZ\xffZZZZ"));
|
||||
|
||||
// Premature end.
|
||||
check.template operator()<"{:*^8}">(SV("*ZZZZ\xef\xf5*"), SV("ZZZZ\xef\xf5"));
|
||||
check.template operator()<"{:*^12}">(SV("*ZZZZ\xef\xf5ZZZZ*"), SV("ZZZZ\xef\xf5ZZZZ"));
|
||||
check.template operator()<"{:*^9}">(SV("*ZZZZ\xff\xf5\xf5*"), SV("ZZZZ\xff\xf5\xf5"));
|
||||
check.template operator()<"{:*^13}">(SV("*ZZZZ\xff\xf5\xf5ZZZZ*"), SV("ZZZZ\xff\xf5\xf5ZZZZ"));
|
||||
check(SV("*ZZZZ\xef\xf5*"), SV("{:*^8}"), SV("ZZZZ\xef\xf5"));
|
||||
check(SV("*ZZZZ\xef\xf5ZZZZ*"), SV("{:*^12}"), SV("ZZZZ\xef\xf5ZZZZ"));
|
||||
check(SV("*ZZZZ\xff\xf5\xf5*"), SV("{:*^9}"), SV("ZZZZ\xff\xf5\xf5"));
|
||||
check(SV("*ZZZZ\xff\xf5\xf5ZZZZ*"), SV("{:*^13}"), SV("ZZZZ\xff\xf5\xf5ZZZZ"));
|
||||
|
||||
} else if constexpr (sizeof(CharT) == 2) {
|
||||
// TODO FMT Add these tests.
|
||||
|
||||
@@ -26,29 +26,28 @@
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
std::basic_string<CharT> out =
|
||||
std::vformat(std::locale(), fmt.template sv<CharT>(), std::make_format_args<context_t<CharT>>(args...));
|
||||
auto test = []<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt, Args&&... args) constexpr {
|
||||
std::basic_string<CharT> out = std::vformat(std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(out == expected);
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(
|
||||
[[maybe_unused]] std::string_view what,
|
||||
[[maybe_unused]] std::basic_string_view<CharT> fmt,
|
||||
[[maybe_unused]] Args&&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
(void)std::vformat(std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(false);
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
try {
|
||||
(void)std::vformat(std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(false);
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
#endif
|
||||
(void)what;
|
||||
(void)fmt;
|
||||
(void)sizeof...(args);
|
||||
};
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
format_tests<char>(test, test_exception);
|
||||
|
||||
@@ -24,30 +24,28 @@
|
||||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
std::basic_string<CharT> out =
|
||||
std::vformat(fmt.template sv<CharT>(), std::make_format_args<context_t<CharT>>(args...));
|
||||
auto test = []<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt, Args&&... args) constexpr {
|
||||
std::basic_string<CharT> out = std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(out == expected);
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(
|
||||
[[maybe_unused]] std::string_view what,
|
||||
[[maybe_unused]] std::basic_string_view<CharT> fmt,
|
||||
[[maybe_unused]] Args&&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(false);
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
try {
|
||||
TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(false);
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
#endif
|
||||
(void)what;
|
||||
(void)fmt;
|
||||
(void)sizeof...(args);
|
||||
};
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
format_tests<char>(test, test_exception);
|
||||
|
||||
@@ -32,55 +32,51 @@
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
auto test = []<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt, Args&&... args) constexpr {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
auto it = std::vformat_to(out.begin(), std::locale(), fmt.template sv<CharT>(),
|
||||
std::make_format_args<context_t<CharT>>(args...));
|
||||
auto it = std::vformat_to(out.begin(), std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(it == out.end());
|
||||
assert(out == expected);
|
||||
}
|
||||
{
|
||||
std::list<CharT> out;
|
||||
std::vformat_to(std::back_inserter(out), std::locale(), fmt.template sv<CharT>(),
|
||||
std::make_format_args<context_t<CharT>>(args...));
|
||||
std::vformat_to(std::back_inserter(out), std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
std::vector<CharT> out;
|
||||
std::vformat_to(std::back_inserter(out), std::locale(), fmt.template sv<CharT>(),
|
||||
std::make_format_args<context_t<CharT>>(args...));
|
||||
std::vformat_to(std::back_inserter(out), std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
assert(expected.size() < 4096 && "Update the size of the buffer.");
|
||||
CharT out[4096];
|
||||
CharT* it =
|
||||
std::vformat_to(out, std::locale(), fmt.template sv<CharT>(), std::make_format_args<context_t<CharT>>(args...));
|
||||
CharT* it = std::vformat_to(out, std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(std::distance(out, it) == int(expected.size()));
|
||||
// Convert to std::string since output contains '\0' for boolean tests.
|
||||
assert(std::basic_string<CharT>(out, it) == expected);
|
||||
}
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(
|
||||
[[maybe_unused]] std::string_view what,
|
||||
[[maybe_unused]] std::basic_string_view<CharT> fmt,
|
||||
[[maybe_unused]] Args&&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::basic_string<CharT> out;
|
||||
std::vformat_to(std::back_inserter(out), std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(false);
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
try {
|
||||
std::basic_string<CharT> out;
|
||||
std::vformat_to(std::back_inserter(out), std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(false);
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
#endif
|
||||
(void)what;
|
||||
(void)fmt;
|
||||
(void)sizeof...(args);
|
||||
};
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
format_tests<char>(test, test_exception);
|
||||
|
||||
@@ -29,53 +29,51 @@
|
||||
#include "format_tests.h"
|
||||
#include "string_literal.h"
|
||||
|
||||
auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected,
|
||||
const Args&... args) constexpr {
|
||||
auto test = []<class CharT, class... Args>(
|
||||
std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt, Args&&... args) constexpr {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
auto it = std::vformat_to(out.begin(), fmt.template sv<CharT>(), std::make_format_args<context_t<CharT>>(args...));
|
||||
auto it = std::vformat_to(out.begin(), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(it == out.end());
|
||||
assert(out == expected);
|
||||
}
|
||||
{
|
||||
std::list<CharT> out;
|
||||
std::vformat_to(std::back_inserter(out), fmt.template sv<CharT>(),
|
||||
std::make_format_args<context_t<CharT>>(args...));
|
||||
std::vformat_to(std::back_inserter(out), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
std::vector<CharT> out;
|
||||
std::vformat_to(std::back_inserter(out), fmt.template sv<CharT>(),
|
||||
std::make_format_args<context_t<CharT>>(args...));
|
||||
std::vformat_to(std::back_inserter(out), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(std::equal(out.begin(), out.end(), expected.begin(), expected.end()));
|
||||
}
|
||||
{
|
||||
assert(expected.size() < 4096 && "Update the size of the buffer.");
|
||||
CharT out[4096];
|
||||
CharT* it = std::vformat_to(out, fmt.template sv<CharT>(), std::make_format_args<context_t<CharT>>(args...));
|
||||
CharT* it = std::vformat_to(out, fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(std::distance(out, it) == int(expected.size()));
|
||||
// Convert to std::string since output contains '\0' for boolean tests.
|
||||
assert(std::basic_string<CharT>(out, it) == expected);
|
||||
}
|
||||
};
|
||||
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(
|
||||
[[maybe_unused]] std::string_view what,
|
||||
[[maybe_unused]] std::basic_string_view<CharT> fmt,
|
||||
[[maybe_unused]] Args&&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::basic_string<CharT> out;
|
||||
std::vformat_to(std::back_inserter(out), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(false);
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
try {
|
||||
std::basic_string<CharT> out;
|
||||
std::vformat_to(std::back_inserter(out), fmt, std::make_format_args<context_t<CharT>>(args...));
|
||||
assert(false);
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
#endif
|
||||
(void)what;
|
||||
(void)fmt;
|
||||
(void)sizeof...(args);
|
||||
};
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
format_tests<char>(test, test_exception);
|
||||
|
||||
Reference in New Issue
Block a user