1 //===- SequenceTest.cpp - Unit tests for a sequence abstraciton -----------===//
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/Sequence.h"
11 #include "gtest/gtest.h"
12
13 #include <list>
14
15 using namespace llvm;
16
17 namespace {
18
TEST(SequenceTest,Basic)19 TEST(SequenceTest, Basic) {
20 int x = 0;
21 for (int i : seq(0, 10))
22 EXPECT_EQ(x++, i);
23 EXPECT_EQ(10, x);
24
25 auto my_seq = seq(0, 4);
26 EXPECT_EQ(4, my_seq.end() - my_seq.begin());
27 for (int i : {0, 1, 2, 3})
28 EXPECT_EQ(i, (int)my_seq.begin()[i]);
29
30 EXPECT_TRUE(my_seq.begin() < my_seq.end());
31
32 auto adjusted_begin = my_seq.begin() + 2;
33 auto adjusted_end = my_seq.end() - 2;
34 EXPECT_TRUE(adjusted_begin == adjusted_end);
35 EXPECT_EQ(2, *adjusted_begin);
36 EXPECT_EQ(2, *adjusted_end);
37 }
38
39 } // anonymous namespace
40