fix ranges

This commit is contained in:
Walter Gray 2020-11-30 12:49:15 -08:00
parent 3b6d21be15
commit aa65e99969
2 changed files with 11 additions and 20 deletions

View File

@ -291,10 +291,10 @@ struct formatter<TupleT, Char, enable_if_t<fmt::is_tuple_like<TupleT>::value>> {
} }
out = detail::copy(formatting.delimiter, out); out = detail::copy(formatting.delimiter, out);
} }
out = format_to(out, out = vformat_to(out,
detail::format_str_quoted( detail::format_str_quoted(
(formatting.add_delimiter_spaces && i > 0), v), (formatting.add_delimiter_spaces && i > 0), v),
v); make_format_args(v));
++i; ++i;
} }
@ -366,12 +366,12 @@ struct formatter<
if (formatting.add_prepostfix_space) *out++ = ' '; if (formatting.add_prepostfix_space) *out++ = ' ';
out = detail::copy(formatting.delimiter, out); out = detail::copy(formatting.delimiter, out);
} }
out = format_to(out, out = vformat_to(out,
detail::format_str_quoted( detail::format_str_quoted(
(formatting.add_delimiter_spaces && i > 0), *it), (formatting.add_delimiter_spaces && i > 0), *it),
*it); make_format_args(*it));
if (++i > formatting.range_length_limit) { if (++i > formatting.range_length_limit) {
out = format_to(out, " ... <other elements>"); out = format_to(out, FMT_STRING(" ... <other elements>"));
break; break;
} }
} }

View File

@ -316,7 +316,7 @@ TEST(ChronoTest, FormatFullSpecs) {
TEST(ChronoTest, FormatSimpleQq) { TEST(ChronoTest, FormatSimpleQq) {
typedef std::chrono::duration<float> fs; typedef std::chrono::duration<float> fs;
// EXPECT_EQ("1.234 s", fmt::format(FMT_STRING("{:%Q %q}"), fs(1.234))); EXPECT_EQ("1.234 s", fmt::format(FMT_STRING("{:%Q %q}"), fs(1.234)));
typedef std::chrono::duration<float, std::milli> fms; typedef std::chrono::duration<float, std::milli> fms;
EXPECT_EQ("1.234 ms", fmt::format(FMT_STRING("{:%Q %q}"), fms(1.234))); EXPECT_EQ("1.234 ms", fmt::format(FMT_STRING("{:%Q %q}"), fms(1.234)));
typedef std::chrono::duration<double> ds; typedef std::chrono::duration<double> ds;
@ -404,13 +404,6 @@ TEST(ColorsTest, FormatToOutAcceptsTextStyle) {
"\x1b[38;2;255;020;030mrgb(255,20,30)123\x1b[0m"); "\x1b[38;2;255;020;030mrgb(255,20,30)123\x1b[0m");
} }
// Formatting library for C++ - std::ostream support tests
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.
struct test {}; struct test {};
// Test that there is no issues with specializations when fmt/ostream.h is // Test that there is no issues with specializations when fmt/ostream.h is
@ -637,12 +630,11 @@ struct zstring {
zstring_sentinel end() const { return {}; } zstring_sentinel end() const { return {}; }
}; };
// TODO: Fix using zstrings with FMT_STRING
TEST(RangesTest, JoinSentinel) { TEST(RangesTest, JoinSentinel) {
zstring hello{"hello"}; zstring hello{"hello"};
// EXPECT_EQ("{'h', 'e', 'l', 'l', 'o'}", fmt::format(FMT_STRING("{}"), EXPECT_EQ("{'h', 'e', 'l', 'l', 'o'}", fmt::format(FMT_STRING("{}"),
// hello)); EXPECT_EQ("h_e_l_l_o", fmt::format(FMT_STRING("{}"), hello)); EXPECT_EQ("h_e_l_l_o", fmt::format(FMT_STRING("{}"),
// fmt::join(hello, "_"))); fmt::join(hello, "_")));
} }
// A range that provides non-const only begin()/end() to test fmt::join handles // A range that provides non-const only begin()/end() to test fmt::join handles
@ -683,10 +675,9 @@ template <typename T> class noncopyable_range {
const_iterator end() const { return vec.end(); } const_iterator end() const { return vec.end(); }
}; };
// TODO: Fixme
TEST(RangesTest, Range) { TEST(RangesTest, Range) {
noncopyable_range<int> w(3u, 0); noncopyable_range<int> w(3u, 0);
/*EXPECT_EQ("{0, 0, 0}", fmt::format(FMT_STRING("{}"), w)); EXPECT_EQ("{0, 0, 0}", fmt::format(FMT_STRING("{}"), w));
EXPECT_EQ("{0, 0, 0}", fmt::format(FMT_STRING("{}"), EXPECT_EQ("{0, 0, 0}", fmt::format(FMT_STRING("{}"),
noncopyable_range<int>(3u, 0))); noncopyable_range<int>(3u, 0)));
@ -701,7 +692,7 @@ TEST(RangesTest, Range) {
0))); 0)));
const std::vector<int> z(3u, 0); const std::vector<int> z(3u, 0);
EXPECT_EQ("{0, 0, 0}", fmt::format(FMT_STRING("{}"), z));*/ EXPECT_EQ("{0, 0, 0}", fmt::format(FMT_STRING("{}"), z));
} }
#if !FMT_MSC_VER || FMT_MSC_VER >= 1927 #if !FMT_MSC_VER || FMT_MSC_VER >= 1927