forked from OSchip/llvm-project
[libc++][format[[nfc] Use string_view in tests.
This change is a preparation for adapting the tests for P2216 std::format improvements Reviewed By: #libc, Quuxplusone, ldionne Differential Revision: https://reviews.llvm.org/D118717
This commit is contained in:
parent
841817b1ed
commit
e885b1137b
|
@ -27,7 +27,7 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
std::basic_string<CharT> out = std::format(std::locale(), fmt, args...);
|
||||
if constexpr (std::same_as<CharT, char>)
|
||||
|
@ -37,15 +37,15 @@ auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, st
|
|||
assert(out == expected);
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::format(std::locale(), fmt, args...);
|
||||
if constexpr (std::same_as<CharT, char>)
|
||||
std::cerr << "\nFormat string " << fmt << "\nDidn't throw an exception.\n";
|
||||
assert(false);
|
||||
} catch (std::format_error& e) {
|
||||
} catch (const std::format_error& e) {
|
||||
# ifdef _LIBCPP_VERSION
|
||||
if constexpr (std::same_as<CharT, char>)
|
||||
if (e.what() != what)
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
std::basic_string<CharT> out = std::format(fmt, args...);
|
||||
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
|
||||
|
@ -44,8 +44,8 @@ auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, st
|
|||
assert(out == expected);
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::format(fmt, args...);
|
||||
|
@ -54,7 +54,7 @@ auto test_exception =
|
|||
std::cerr << "\nFormat string " << fmt << "\nDidn't throw an exception.\n";
|
||||
# endif
|
||||
assert(false);
|
||||
} catch (std::format_error& e) {
|
||||
} catch (const std::format_error& e) {
|
||||
# if defined(_LIBCPP_VERSION) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
if constexpr (std::same_as<CharT, char>)
|
||||
if (e.what() != what)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -30,7 +30,7 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
|
@ -58,14 +58,14 @@ auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, st
|
|||
}
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::basic_string<CharT> out;
|
||||
std::format_to(std::back_inserter(out), std::locale(), fmt, args...);
|
||||
assert(false);
|
||||
} catch (std::format_error& e) {
|
||||
} catch (const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
|
@ -59,14 +59,14 @@ auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, st
|
|||
}
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::basic_string<CharT> out;
|
||||
std::format_to(std::back_inserter(out), fmt, args...);
|
||||
assert(false);
|
||||
} catch (std::format_error& e) {
|
||||
} catch (const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
{
|
||||
std::list<CharT> out;
|
||||
|
@ -92,14 +92,14 @@ auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, st
|
|||
}
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::basic_string<CharT> out;
|
||||
std::format_to_n(std::back_inserter(out), 0, std::locale(), fmt, args...);
|
||||
assert(false);
|
||||
} catch (std::format_error& e) {
|
||||
} catch (const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
{
|
||||
std::list<CharT> out;
|
||||
|
@ -89,14 +89,14 @@ auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, st
|
|||
}
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::basic_string<CharT> out;
|
||||
std::format_to_n(std::back_inserter(out), 0, fmt, args...);
|
||||
assert(false);
|
||||
} catch (std::format_error& e) {
|
||||
} catch (const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -28,19 +28,19 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
size_t size = std::formatted_size(std::locale(), fmt, args...);
|
||||
assert(size == expected.size());
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::formatted_size(std::locale(), fmt, args...);
|
||||
assert(false);
|
||||
} catch (std::format_error& e) {
|
||||
} catch (const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -25,19 +25,19 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
size_t size = std::formatted_size(fmt, args...);
|
||||
assert(size == expected.size());
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
try {
|
||||
std::formatted_size(fmt, args...);
|
||||
assert(false);
|
||||
} catch (std::format_error& e) {
|
||||
} catch (const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -24,19 +24,19 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
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<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const 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]] std::format_error& e) {
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -23,19 +23,19 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
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<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const 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]] std::format_error& e) {
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
|
@ -58,14 +58,14 @@ auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, st
|
|||
}
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const 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]] std::format_error& e) {
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "test_macros.h"
|
||||
#include "format_tests.h"
|
||||
|
||||
auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, std::basic_string<CharT> fmt,
|
||||
auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
|
||||
const Args&... args) {
|
||||
{
|
||||
std::basic_string<CharT> out(expected.size(), CharT(' '));
|
||||
|
@ -59,14 +59,14 @@ auto test = []<class CharT, class... Args>(std::basic_string<CharT> expected, st
|
|||
}
|
||||
};
|
||||
|
||||
auto test_exception =
|
||||
[]<class CharT, class... Args>(std::string_view what, std::basic_string<CharT> fmt, const Args&... args) {
|
||||
auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt,
|
||||
const 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]] std::format_error& e) {
|
||||
} catch ([[maybe_unused]] const std::format_error& e) {
|
||||
LIBCPP_ASSERT(e.what() == what);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue