120
|
1 //===- SequenceTest.cpp - Unit tests for a sequence abstraciton -----------===//
|
|
2 //
|
147
|
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
4 // See https://llvm.org/LICENSE.txt for license information.
|
|
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
120
|
6 //
|
|
7 //===----------------------------------------------------------------------===//
|
|
8
|
|
9 #include "llvm/ADT/Sequence.h"
|
|
10 #include "gtest/gtest.h"
|
|
11
|
|
12 #include <list>
|
|
13
|
|
14 using namespace llvm;
|
|
15
|
|
16 namespace {
|
|
17
|
|
18 TEST(SequenceTest, Basic) {
|
|
19 int x = 0;
|
|
20 for (int i : seq(0, 10)) {
|
|
21 EXPECT_EQ(x, i);
|
|
22 x++;
|
|
23 }
|
|
24 EXPECT_EQ(10, x);
|
|
25
|
|
26 auto my_seq = seq(0, 4);
|
|
27 EXPECT_EQ(4, my_seq.end() - my_seq.begin());
|
|
28 for (int i : {0, 1, 2, 3})
|
|
29 EXPECT_EQ(i, (int)my_seq.begin()[i]);
|
|
30
|
|
31 EXPECT_TRUE(my_seq.begin() < my_seq.end());
|
|
32
|
|
33 auto adjusted_begin = my_seq.begin() + 2;
|
|
34 auto adjusted_end = my_seq.end() - 2;
|
|
35 EXPECT_TRUE(adjusted_begin == adjusted_end);
|
|
36 EXPECT_EQ(2, *adjusted_begin);
|
|
37 EXPECT_EQ(2, *adjusted_end);
|
|
38 }
|
|
39
|
|
40 } // anonymous namespace
|