From 044eb2f6afba375a914ac9d8024f8f5142bb912e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 18 Dec 2017 20:10:56 +0000 Subject: Vendor import of llvm trunk r321017: https://llvm.org/svn/llvm-project/llvm/trunk@321017 --- unittests/Support/FormatVariadicTest.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'unittests/Support/FormatVariadicTest.cpp') diff --git a/unittests/Support/FormatVariadicTest.cpp b/unittests/Support/FormatVariadicTest.cpp index bfbe556b31a7e..ddecffdeed1db 100644 --- a/unittests/Support/FormatVariadicTest.cpp +++ b/unittests/Support/FormatVariadicTest.cpp @@ -578,3 +578,34 @@ TEST(FormatVariadicTest, FormatAdapter) { // const Format cvar(1); // EXPECT_EQ("Format", formatv("{0}", cvar).str()); } + +TEST(FormatVariadicTest, FormatFormatvObject) { + EXPECT_EQ("Format", formatv("F{0}t", formatv("o{0}a", "rm")).str()); + EXPECT_EQ("[ ! ]", formatv("[{0,+5}]", formatv("{0,-2}", "!")).str()); +} + +namespace { +struct Recorder { + int Copied = 0, Moved = 0; + Recorder() = default; + Recorder(const Recorder &Copy) : Copied(1 + Copy.Copied), Moved(Copy.Moved) {} + Recorder(const Recorder &&Move) + : Copied(Move.Copied), Moved(1 + Move.Moved) {} +}; +} // namespace +namespace llvm { +template <> struct format_provider { + static void format(const Recorder &R, raw_ostream &OS, StringRef style) { + OS << R.Copied << "C " << R.Moved << "M"; + } +}; +} // namespace + +TEST(FormatVariadicTest, CopiesAndMoves) { + Recorder R; + EXPECT_EQ("0C 0M", formatv("{0}", R).str()); + EXPECT_EQ("0C 3M", formatv("{0}", std::move(R)).str()); + EXPECT_EQ("0C 3M", formatv("{0}", Recorder()).str()); + EXPECT_EQ(0, R.Copied); + EXPECT_EQ(0, R.Moved); +} -- cgit v1.2.3