Home | History | Annotate | Download | only in ADT
      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 
     19 TEST(SequenceTest, Basic) {
     20   int x = 0;
     21   for (int i : seq(0, 10)) {
     22     EXPECT_EQ(x, i);
     23     x++;
     24   }
     25   EXPECT_EQ(10, x);
     26 
     27   auto my_seq = seq(0, 4);
     28   EXPECT_EQ(4, my_seq.end() - my_seq.begin());
     29   for (int i : {0, 1, 2, 3})
     30     EXPECT_EQ(i, (int)my_seq.begin()[i]);
     31 
     32   EXPECT_TRUE(my_seq.begin() < my_seq.end());
     33 
     34   auto adjusted_begin = my_seq.begin() + 2;
     35   auto adjusted_end = my_seq.end() - 2;
     36   EXPECT_TRUE(adjusted_begin == adjusted_end);
     37   EXPECT_EQ(2, *adjusted_begin);
     38   EXPECT_EQ(2, *adjusted_end);
     39 }
     40 
     41 } // anonymous namespace
     42