1 //===- llvm/unittest/ADT/ArrayRefTest.cpp - ArrayRef unit tests -----------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/ADT/ArrayRef.h" 11 #include "llvm/Support/Allocator.h" 12 #include "llvm/Support/raw_ostream.h" 13 #include "gtest/gtest.h" 14 using namespace llvm; 15 16 namespace llvm { 17 18 TEST(ArrayRefTest, AllocatorCopy) { 19 BumpPtrAllocator Alloc; 20 static const uint16_t Words1[] = { 1, 4, 200, 37 }; 21 ArrayRef<uint16_t> Array1 = makeArrayRef(Words1, 4); 22 static const uint16_t Words2[] = { 11, 4003, 67, 64000, 13 }; 23 ArrayRef<uint16_t> Array2 = makeArrayRef(Words2, 5); 24 ArrayRef<uint16_t> Array1c = Array1.copy(Alloc); 25 ArrayRef<uint16_t> Array2c = Array2.copy(Alloc);; 26 EXPECT_TRUE(Array1.equals(Array1c)); 27 EXPECT_NE(Array1.data(), Array1c.data()); 28 EXPECT_TRUE(Array2.equals(Array2c)); 29 EXPECT_NE(Array2.data(), Array2c.data()); 30 } 31 32 TEST(ArrayRefTest, DropBack) { 33 static const int TheNumbers[] = {4, 8, 15, 16, 23, 42}; 34 ArrayRef<int> AR1(TheNumbers); 35 ArrayRef<int> AR2(TheNumbers, AR1.size() - 1); 36 EXPECT_TRUE(AR1.drop_back().equals(AR2)); 37 } 38 39 40 } // end anonymous namespace 41