From 4c84eb18b69e49ffd266f49430869a259c106051 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 24 Apr 2014 08:15:32 -0700 Subject: [PATCH] Test Array's move ctor. --- format-test.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/format-test.cc b/format-test.cc index 5029f2f5..ebee78e6 100644 --- a/format-test.cc +++ b/format-test.cc @@ -207,6 +207,39 @@ TEST(ArrayTest, Ctor) { EXPECT_EQ(123u, array.capacity()); } +#if FMT_USE_RVALUE_REFERENCES + +TEST(ArrayTest, MoveCtor) { + Array array; + const char test[] = "test"; + array.append(test, test + 4); + { + Array array2(std::move(array)); + // Moving shouldn't destroy the inline content of the first array. + EXPECT_EQ(test, std::string(&array[0], array.size())); + EXPECT_EQ(test, std::string(&array2[0], array2.size())); + EXPECT_EQ(5, array2.capacity()); + } + array.push_back('a'); + { + Array array2(std::move(array)); + // Moving shouldn't destroy the inline content of the first array. + EXPECT_EQ("testa", std::string(&array[0], array.size())); + EXPECT_EQ("testa", std::string(&array2[0], array2.size())); + EXPECT_EQ(5, array2.capacity()); + } + array.push_back('b'); + { + Array array2(std::move(array)); + // Moving should rip the guts of the first array. + EXPECT_TRUE(!&array[0]); + EXPECT_EQ("testab", std::string(&array2[0], array2.size())); + EXPECT_GT(array2.capacity(), 5); + } +} + +#endif // FMT_USE_RVALUE_REFERENCES + TEST(ArrayTest, Access) { Array array; array[0] = 11;