blob: 4356bb18a0cd923d749da89f5818c6d1664e5e1f [file] [log] [blame]
Chandler Carruthd1ad58b2016-05-13 03:57:50 +00001//===- SequenceTest.cpp - Unit tests for a sequence abstraciton -----------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Carruthd1ad58b2016-05-13 03:57:50 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/ADT/Sequence.h"
10#include "gtest/gtest.h"
11
12#include <list>
13
14using namespace llvm;
15
16namespace {
17
18TEST(SequenceTest, Basic) {
19 int x = 0;
Justin Lebarb17269d2016-07-17 18:10:30 +000020 for (int i : seq(0, 10)) {
21 EXPECT_EQ(x, i);
22 x++;
23 }
Chandler Carruthd1ad58b2016-05-13 03:57:50 +000024 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