proxygen
IteratorsTest.cpp File Reference
#include <map>
#include <folly/container/Array.h>
#include <folly/detail/Iterators.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Functions

 TEST (IteratorsTest, IterFacadeHasCorrectTraits)
 
 TEST (IteratorsTest, SimpleIteratorFacade)
 
 TEST (IteratorsTest, IterAdaptorHasCorrectTraits)
 
 TEST (IteratorsTest, IterAdaptorWithPointer)
 
 TEST (IteratorsTest, IterAdaptorOfOtherIter)
 
 TEST (IteratorsTest, MixedConstAndNonconstIters)
 

Function Documentation

TEST ( IteratorsTest  ,
IterFacadeHasCorrectTraits   
)

Definition at line 43 of file IteratorsTest.cpp.

References value.

43  {
44  using TR = std::iterator_traits<IntArrayIterator>;
48  static_assert(
50  "");
52 }
decltype(tr) TR
static const char *const value
Definition: Conv.cpp:50
TEST ( IteratorsTest  ,
SimpleIteratorFacade   
)

Definition at line 54 of file IteratorsTest.cpp.

References folly::test::end(), EXPECT_EQ, EXPECT_NE, folly::make_array(), and ptr.

54  {
55  static const auto kArray = folly::make_array(42, 43, 44);
56  IntArrayIterator end(kArray.data() + kArray.size());
57  IntArrayIterator iter(kArray.data());
58  EXPECT_NE(iter, end);
59  EXPECT_EQ(42, *iter);
60  ++iter;
61  EXPECT_NE(iter, end);
62  EXPECT_EQ(43, *iter);
63  ++iter;
64  EXPECT_NE(iter, end);
65  EXPECT_EQ(44, *iter);
66  ++iter;
67  EXPECT_EQ(iter, end);
68 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr array_detail::return_type< D, TList... > make_array(TList &&...t)
Definition: Array.h:56
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST ( IteratorsTest  ,
IterAdaptorHasCorrectTraits   
)

Definition at line 86 of file IteratorsTest.cpp.

References value.

86  {
87  using TR = std::iterator_traits<IntPointerIter>;
91  static_assert(
93  "");
95 }
decltype(tr) TR
static const char *const value
Definition: Conv.cpp:50
TEST ( IteratorsTest  ,
IterAdaptorWithPointer   
)

Definition at line 97 of file IteratorsTest.cpp.

References folly::gen::dereference, folly::test::end(), EXPECT_EQ, EXPECT_NE, and folly::make_array().

97  {
98  static const auto kArray = folly::make_array(42, 43, 44);
99  IntPointerIter end(kArray.data() + kArray.size());
100  IntPointerIter iter(kArray.data());
101  EXPECT_NE(iter, end);
102  EXPECT_EQ(42, *iter);
103  ++iter;
104  EXPECT_NE(iter, end);
105  EXPECT_EQ(43, *iter);
106  ++iter;
107  EXPECT_NE(iter, end);
108  EXPECT_EQ(44, *iter);
109  ++iter;
110  EXPECT_EQ(iter, end);
111 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr array_detail::return_type< D, TList... > make_array(TList &&...t)
Definition: Array.h:56
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST ( IteratorsTest  ,
IterAdaptorOfOtherIter   
)

Definition at line 150 of file IteratorsTest.cpp.

References folly::gen::dereference, EXPECT_EQ, EXPECT_NE, m, and folly::detail::rhs.

150  {
151  std::map<int, int> m{{2, 42}, {3, 43}, {4, 44}};
152 
153  IntMapKeyIter keyEnd(m.end());
154  IntMapKeyIter keyIter(m.begin());
155  EXPECT_NE(keyIter, keyEnd);
156  EXPECT_EQ(2, *keyIter);
157  ++keyIter;
158  EXPECT_NE(keyIter, keyEnd);
159  EXPECT_EQ(3, *keyIter);
160  ++keyIter;
161  EXPECT_NE(keyIter, keyEnd);
162  EXPECT_EQ(4, *keyIter);
163  ++keyIter;
164  EXPECT_EQ(keyIter, keyEnd);
165 
166  IntMapValueIter valueEnd(m.end());
167  IntMapValueIter valueIter(m.begin());
168  EXPECT_NE(valueIter, valueEnd);
169  EXPECT_EQ(42, *valueIter);
170  ++valueIter;
171  EXPECT_NE(valueIter, valueEnd);
172  EXPECT_EQ(43, *valueIter);
173  ++valueIter;
174  EXPECT_NE(valueIter, valueEnd);
175  EXPECT_EQ(44, *valueIter);
176  ++valueIter;
177  EXPECT_EQ(valueIter, valueEnd);
178 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static map< string, int > m
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST ( IteratorsTest  ,
MixedConstAndNonconstIters   
)

Definition at line 201 of file IteratorsTest.cpp.

References folly::padded::cend(), EXPECT_EQ, EXPECT_NE, and m.

201  {
202  std::map<int, int> m{{2, 42}, {3, 43}, {4, 44}};
203  IntMapValueIterConst cend(m.cend());
204  IntMapValueIter valueIter(m.begin());
205  EXPECT_NE(valueIter, cend);
206  ++valueIter;
207  ++valueIter;
208  ++valueIter;
209  EXPECT_EQ(valueIter, cend);
210 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static map< string, int > m
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
Iterator< typename Container::const_iterator > cend(const Container &c)
Definition: Padded.h:324