Chandler Carruth | d1ad58b | 2016-05-13 03:57:50 +0000 | [diff] [blame] | 1 | //===- SequenceTest.cpp - Unit tests for a sequence abstraciton -----------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Chandler Carruth | d1ad58b | 2016-05-13 03:57:50 +0000 | [diff] [blame] | 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; |
Justin Lebar | b17269d | 2016-07-17 18:10:30 +0000 | [diff] [blame] | 20 | for (int i : seq(0, 10)) { |
| 21 | EXPECT_EQ(x, i); |
| 22 | x++; |
| 23 | } |
Chandler Carruth | d1ad58b | 2016-05-13 03:57:50 +0000 | [diff] [blame] | 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 |