Add fmt::format and deprecate fmt::Format.

This commit is contained in:
Victor Zverovich
2014-06-28 14:48:42 -07:00
parent 428d114766
commit 5edda531f6
3 changed files with 66 additions and 41 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ expect_compile_error("fmt::internal::Array<char, 5> a, b(a);")
expect_compile_error("fmt::internal::Array<char, 5> a, b; b = a;")
# Writer is noncopyable.
expect_compile_error("fmt::Writer a, b(a);")
expect_compile_error("const fmt::Writer a, b(a);")
expect_compile_error("fmt::Writer a, b; b = a;")
# Formatter is not copyable from a temporary.
+6 -10
View File
@@ -1359,9 +1359,9 @@ TEST(FormatterTest, FormatExamples) {
std::string message = str(Format("The answer is {}") << 42);
EXPECT_EQ("The answer is 42", message);
EXPECT_EQ("42", str(Format("{}") << 42));
EXPECT_EQ("42", str(Format(std::string("{}")) << 42));
EXPECT_EQ("42", str(Format(Format("{{}}")) << 42));
EXPECT_EQ("42", str(format("{}", 42)));
EXPECT_EQ("42", str(format(std::string("{}"), 42)));
EXPECT_EQ("42", str(format(Format("{{}}"), 42)));
Writer writer;
writer.Format("Current point:\n");
@@ -1565,17 +1565,15 @@ TEST(FormatterTest, Examples) {
std::string path = "somefile";
ReportError("File not found: {0}") << path;
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
EXPECT_EQ("The answer is 42", str(Format("The answer is {}", 42)));
EXPECT_EQ("The answer is 42", str(format("The answer is {}", 42)));
EXPECT_THROW_MSG(
Format("The answer is {:d}", "forty-two"), FormatError,
format("The answer is {:d}", "forty-two"), FormatError,
"unknown format code 'd' for string");
EXPECT_EQ(L"Cyrillic letter \x42e",
str(Format(L"Cyrillic letter {}", L'\x42e')));
EXPECT_WRITE(stdout,
fmt::Print("{}", std::numeric_limits<double>::infinity()), "inf");
#endif
}
TEST(FormatIntTest, Data) {
@@ -1644,12 +1642,10 @@ TEST(FormatTest, PrintColored) {
#endif
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
TEST(FormatTest, Variadic) {
EXPECT_EQ("abc1", str(Format("{}c{}", "ab", 1)));
EXPECT_EQ("abc1", str(format("{}c{}", "ab", 1)));
EXPECT_EQ(L"abc1", str(Format(L"{}c{}", L"ab", 1)));
}
#endif // FMT_USE_VARIADIC_TEMPLATES
template <typename T>
std::string str(const T &value) {