-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecate _format UDL in code using FMT_DEPRECATED
- Loading branch information
1 parent
3a951a6
commit fe302bf
Showing
4 changed files
with
46 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Formatting library for C++ - formatting library tests | ||
// | ||
// Copyright (c) 2012 - present, Victor Zverovich | ||
// All rights reserved. | ||
// | ||
// For the license information refer to format.h. | ||
|
||
// clang-format off | ||
#include "fmt/format.h" | ||
// clang-format on | ||
|
||
#include "gmock/gmock.h" | ||
#include "util.h" | ||
|
||
FMT_BEGIN_NAMESPACE | ||
template <> struct formatter<date> { | ||
template <typename ParseContext> | ||
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { | ||
auto it = ctx.begin(); | ||
if (it != ctx.end() && *it == 'd') ++it; | ||
return it; | ||
} | ||
|
||
auto format(const date& d, format_context& ctx) -> decltype(ctx.out()) { | ||
format_to(ctx.out(), "{}-{}-{}", d.year(), d.month(), d.day()); | ||
return ctx.out(); | ||
} | ||
}; | ||
FMT_END_NAMESPACE | ||
|
||
#if FMT_USE_USER_DEFINED_LITERALS | ||
|
||
using namespace fmt::literals; | ||
|
||
TEST(format_test, format_udl) { | ||
EXPECT_EQ("{}c{}"_format("ab", 1), fmt::format("{}c{}", "ab", 1)); | ||
EXPECT_EQ("foo"_format(), "foo"); | ||
EXPECT_EQ("{0:10}"_format(42), " 42"); | ||
EXPECT_EQ("{}"_format(date(2015, 10, 21)), "2015-10-21"); | ||
} | ||
#endif // FMT_USE_USER_DEFINED_LITERALS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters