Skip to content

Commit e80340d

Browse files
Unit test for ranget drop
This tests that these operations behave as expected and gives examples on how to use them.
1 parent b81bbcb commit e80340d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

unit/util/range.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,45 @@ SCENARIO("range tests", "[core][util][range]")
5757
++it;
5858
REQUIRE(it == filtered_range.end());
5959
}
60+
61+
THEN("Drop first 2 elements")
62+
{
63+
auto range = make_range(list);
64+
auto drop_range = range.drop(2);
65+
auto it = drop_range.begin();
66+
REQUIRE(*it == "acdef");
67+
drop_range = std::move(drop_range).drop(1);
68+
REQUIRE(drop_range.empty());
69+
// Check the original is unmodified
70+
REQUIRE(!range.empty());
71+
REQUIRE(*range.begin() == "abc");
72+
}
73+
THEN("Drop first 5 elements")
74+
{
75+
auto range = make_range(list);
76+
auto skip_range = range.drop(5);
77+
REQUIRE(skip_range.empty());
78+
// Check the original is unmodified
79+
REQUIRE(!range.empty());
80+
REQUIRE(*range.begin() == "abc");
81+
}
82+
THEN("Drop first 2 elements, move version")
83+
{
84+
auto range = make_range(list);
85+
range = std::move(range).drop(2);
86+
REQUIRE(!range.empty());
87+
auto it = range.begin();
88+
REQUIRE(*it == "acdef");
89+
range = std::move(range).drop(1);
90+
REQUIRE(range.empty());
91+
}
92+
THEN("Drop first 5 elements, move version")
93+
{
94+
auto range = make_range(list);
95+
range = std::move(range).drop(5);
96+
REQUIRE(range.empty());
97+
}
98+
6099
THEN(
61100
"A const instance of a `filter_iteratort` can mutate the input "
62101
"collection.")

0 commit comments

Comments
 (0)