1 //===- IteratorTest.cpp - Unit tests for iterator utilities ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/iterator.h"
11 #include "llvm/ADT/SmallVector.h"
12 #include "gtest/gtest.h"
18 TEST(PointeeIteratorTest, Basic) {
19 int arr[4] = { 1, 2, 3, 4 };
20 SmallVector<int *, 4> V;
26 typedef pointee_iterator<SmallVectorImpl<int *>::const_iterator> test_iterator;
28 test_iterator Begin, End;
30 End = test_iterator(V.end());
32 test_iterator I = Begin;
33 for (int i = 0; i < 4; ++i) {
36 EXPECT_EQ(I, Begin + i);
37 EXPECT_EQ(I, std::next(Begin, i));
38 test_iterator J = Begin;
41 EXPECT_EQ(*V[i], Begin[i]);
49 EXPECT_EQ(i, I - Begin);
50 EXPECT_EQ(i, std::distance(Begin, I));
51 EXPECT_EQ(Begin, I - i);
53 test_iterator K = I++;
54 EXPECT_EQ(K, std::prev(I));
59 } // anonymous namespace