diff --git a/api/array_view_unittest.cc b/api/array_view_unittest.cc index 6fdd516544..06394047b0 100644 --- a/api/array_view_unittest.cc +++ b/api/array_view_unittest.cc @@ -82,7 +82,7 @@ TEST(ArrayViewTest, TestConstructFromPtrAndArray) { // ArrayView n(arr + 2, 2); } -TEST(ArrayViewTest, TestCopyConstructorVariable) { +TEST(ArrayViewTest, TestCopyConstructorVariableLvalue) { char arr[] = "Arrr!"; ArrayView x = arr; EXPECT_EQ(6u, x.size()); @@ -99,6 +99,23 @@ TEST(ArrayViewTest, TestCopyConstructorVariable) { // ArrayView v = z; // Compile error, because can't drop const. } +TEST(ArrayViewTest, TestCopyConstructorVariableRvalue) { + char arr[] = "Arrr!"; + ArrayView x = arr; + EXPECT_EQ(6u, x.size()); + EXPECT_EQ(arr, x.data()); + ArrayView y = std::move(x); // Copy non-const -> non-const. + EXPECT_EQ(6u, y.size()); + EXPECT_EQ(arr, y.data()); + ArrayView z = std::move(x); // Copy non-const -> const. + EXPECT_EQ(6u, z.size()); + EXPECT_EQ(arr, z.data()); + ArrayView w = std::move(z); // Copy const -> const. + EXPECT_EQ(6u, w.size()); + EXPECT_EQ(arr, w.data()); + // ArrayView v = std::move(z); // Error, because can't drop const. +} + TEST(ArrayViewTest, TestCopyConstructorFixed) { char arr[] = "Arrr!"; ArrayView x = arr; @@ -130,7 +147,7 @@ TEST(ArrayViewTest, TestCopyConstructorFixed) { // ArrayView vv = z; // Compile error, because can't drop const. } -TEST(ArrayViewTest, TestCopyAssignmentVariable) { +TEST(ArrayViewTest, TestCopyAssignmentVariableLvalue) { char arr[] = "Arrr!"; ArrayView x(arr); EXPECT_EQ(6u, x.size()); @@ -151,6 +168,27 @@ TEST(ArrayViewTest, TestCopyAssignmentVariable) { // v = z; // Compile error, because can't drop const. } +TEST(ArrayViewTest, TestCopyAssignmentVariableRvalue) { + char arr[] = "Arrr!"; + ArrayView x(arr); + EXPECT_EQ(6u, x.size()); + EXPECT_EQ(arr, x.data()); + ArrayView y; + y = std::move(x); // Copy non-const -> non-const. + EXPECT_EQ(6u, y.size()); + EXPECT_EQ(arr, y.data()); + ArrayView z; + z = std::move(x); // Copy non-const -> const. + EXPECT_EQ(6u, z.size()); + EXPECT_EQ(arr, z.data()); + ArrayView w; + w = std::move(z); // Copy const -> const. + EXPECT_EQ(6u, w.size()); + EXPECT_EQ(arr, w.data()); + // ArrayView v; + // v = std::move(z); // Compile error, because can't drop const. +} + TEST(ArrayViewTest, TestCopyAssignmentFixed) { char arr[] = "Arrr!"; char init[] = "Init!";