diff options
| author | 2017-01-24 08:32:59 +0000 | |
|---|---|---|
| committer | 2017-01-24 08:32:59 +0000 | |
| commit | 53d771aafdbe5b919f264f53cba3788e2c4cffd2 (patch) | |
| tree | 7eca39498be0ff1e3a6daf583cd9ca5886bb2636 /gnu/llvm/unittests/ADT/ArrayRefTest.cpp | |
| parent | In preparation of compiling our kernels with -ffreestanding, explicitly map (diff) | |
| download | wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.tar.xz wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.zip | |
Import LLVM 4.0.0 rc1 including clang and lld to help the current
development effort on OpenBSD/arm64.
Diffstat (limited to 'gnu/llvm/unittests/ADT/ArrayRefTest.cpp')
| -rw-r--r-- | gnu/llvm/unittests/ADT/ArrayRefTest.cpp | 89 |
1 files changed, 88 insertions, 1 deletions
diff --git a/gnu/llvm/unittests/ADT/ArrayRefTest.cpp b/gnu/llvm/unittests/ADT/ArrayRefTest.cpp index b5b71f06f65..65b4cbcd668 100644 --- a/gnu/llvm/unittests/ADT/ArrayRefTest.cpp +++ b/gnu/llvm/unittests/ADT/ArrayRefTest.cpp @@ -31,6 +31,26 @@ static_assert( !std::is_convertible<ArrayRef<volatile int *>, ArrayRef<int *>>::value, "Removing volatile"); +// Check that we can't accidentally assign a temporary location to an ArrayRef. +// (Unfortunately we can't make use of the same thing with constructors.) +// +// Disable this check under MSVC; even MSVC 2015 isn't inconsistent between +// std::is_assignable and actually writing such an assignment. +#if !defined(_MSC_VER) +static_assert( + !std::is_assignable<ArrayRef<int *>, int *>::value, + "Assigning from single prvalue element"); +static_assert( + !std::is_assignable<ArrayRef<int *>, int * &&>::value, + "Assigning from single xvalue element"); +static_assert( + std::is_assignable<ArrayRef<int *>, int * &>::value, + "Assigning from single lvalue element"); +static_assert( + !std::is_assignable<ArrayRef<int *>, std::initializer_list<int *>>::value, + "Assigning from an initializer list"); +#endif + namespace { TEST(ArrayRefTest, AllocatorCopy) { @@ -82,6 +102,64 @@ TEST(ArrayRefTest, DropFront) { EXPECT_EQ(1U, AR3.drop_front(AR3.size() - 1).size()); } +TEST(ArrayRefTest, DropWhile) { + static const int TheNumbers[] = {1, 3, 5, 8, 10, 11}; + ArrayRef<int> AR1(TheNumbers); + ArrayRef<int> Expected = AR1.drop_front(3); + EXPECT_EQ(Expected, AR1.drop_while([](const int &N) { return N % 2 == 1; })); + + EXPECT_EQ(AR1, AR1.drop_while([](const int &N) { return N < 0; })); + EXPECT_EQ(ArrayRef<int>(), + AR1.drop_while([](const int &N) { return N > 0; })); +} + +TEST(ArrayRefTest, DropUntil) { + static const int TheNumbers[] = {1, 3, 5, 8, 10, 11}; + ArrayRef<int> AR1(TheNumbers); + ArrayRef<int> Expected = AR1.drop_front(3); + EXPECT_EQ(Expected, AR1.drop_until([](const int &N) { return N % 2 == 0; })); + + EXPECT_EQ(ArrayRef<int>(), + AR1.drop_until([](const int &N) { return N < 0; })); + EXPECT_EQ(AR1, AR1.drop_until([](const int &N) { return N > 0; })); +} + +TEST(ArrayRefTest, TakeBack) { + static const int TheNumbers[] = {4, 8, 15, 16, 23, 42}; + ArrayRef<int> AR1(TheNumbers); + ArrayRef<int> AR2(AR1.end() - 1, 1); + EXPECT_TRUE(AR1.take_back().equals(AR2)); +} + +TEST(ArrayRefTest, TakeFront) { + static const int TheNumbers[] = {4, 8, 15, 16, 23, 42}; + ArrayRef<int> AR1(TheNumbers); + ArrayRef<int> AR2(AR1.data(), 2); + EXPECT_TRUE(AR1.take_front(2).equals(AR2)); +} + +TEST(ArrayRefTest, TakeWhile) { + static const int TheNumbers[] = {1, 3, 5, 8, 10, 11}; + ArrayRef<int> AR1(TheNumbers); + ArrayRef<int> Expected = AR1.take_front(3); + EXPECT_EQ(Expected, AR1.take_while([](const int &N) { return N % 2 == 1; })); + + EXPECT_EQ(ArrayRef<int>(), + AR1.take_while([](const int &N) { return N < 0; })); + EXPECT_EQ(AR1, AR1.take_while([](const int &N) { return N > 0; })); +} + +TEST(ArrayRefTest, TakeUntil) { + static const int TheNumbers[] = {1, 3, 5, 8, 10, 11}; + ArrayRef<int> AR1(TheNumbers); + ArrayRef<int> Expected = AR1.take_front(3); + EXPECT_EQ(Expected, AR1.take_until([](const int &N) { return N % 2 == 0; })); + + EXPECT_EQ(AR1, AR1.take_until([](const int &N) { return N < 0; })); + EXPECT_EQ(ArrayRef<int>(), + AR1.take_until([](const int &N) { return N > 0; })); +} + TEST(ArrayRefTest, Equals) { static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8}; ArrayRef<int> AR1(A1); @@ -134,7 +212,8 @@ static void ArgTest12(ArrayRef<int> A) { } TEST(ArrayRefTest, InitializerList) { - ArrayRef<int> A = { 0, 1, 2, 3, 4 }; + std::initializer_list<int> init_list = { 0, 1, 2, 3, 4 }; + ArrayRef<int> A = init_list; for (int i = 0; i < 5; ++i) EXPECT_EQ(i, A[i]); @@ -146,6 +225,14 @@ TEST(ArrayRefTest, InitializerList) { ArgTest12({1, 2}); } +TEST(ArrayRefTest, EmptyInitializerList) { + ArrayRef<int> A = {}; + EXPECT_TRUE(A.empty()); + + A = {}; + EXPECT_TRUE(A.empty()); +} + // Test that makeArrayRef works on ArrayRef (no-op) TEST(ArrayRefTest, makeArrayRef) { static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8}; |
