mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-29 18:27:40 +02:00
Move detail::truncating_iterator to fmt/compile.h
This commit is contained in:
@ -19,6 +19,43 @@
|
||||
#include "gtest-extra.h"
|
||||
#include "util.h"
|
||||
|
||||
TEST(IteratorTest, TruncatingIterator) {
|
||||
char* p = nullptr;
|
||||
fmt::detail::truncating_iterator<char*> it(p, 3);
|
||||
auto prev = it++;
|
||||
EXPECT_EQ(prev.base(), p);
|
||||
EXPECT_EQ(it.base(), p + 1);
|
||||
}
|
||||
|
||||
|
||||
TEST(IteratorTest, TruncatingIteratorDefaultConstruct) {
|
||||
static_assert(
|
||||
std::is_default_constructible<fmt::detail::truncating_iterator<char*>>::value,
|
||||
"");
|
||||
|
||||
fmt::detail::truncating_iterator<char*> it;
|
||||
EXPECT_EQ(nullptr, it.base());
|
||||
EXPECT_EQ(std::size_t{0}, it.count());
|
||||
}
|
||||
|
||||
#ifdef __cpp_lib_ranges
|
||||
TEST(IteratorTest, TruncatingIteratorOutputIterator) {
|
||||
static_assert(std::output_iterator<fmt::detail::truncating_iterator<char*>,
|
||||
char>);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(IteratorTest, TruncatingBackInserter) {
|
||||
std::string buffer;
|
||||
auto bi = std::back_inserter(buffer);
|
||||
fmt::detail::truncating_iterator<decltype(bi)> it(bi, 2);
|
||||
*it++ = '4';
|
||||
*it++ = '2';
|
||||
*it++ = '1';
|
||||
EXPECT_EQ(buffer.size(), 2);
|
||||
EXPECT_EQ(buffer, "42");
|
||||
}
|
||||
|
||||
// compiletime_prepared_parts_type_provider is useful only with relaxed
|
||||
// constexpr.
|
||||
#if FMT_USE_CONSTEXPR
|
||||
|
Reference in New Issue
Block a user