Skip to content

Commit

Permalink
move checking unsupported iterator concepts to separate test
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed Dec 18, 2024
1 parent 0c39d23 commit 68c4dbc
Showing 1 changed file with 26 additions and 119 deletions.
145 changes: 26 additions & 119 deletions tests/unittests/std_interoperability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ TEST_CASE("Collection AllocatorAwareContainer types", "[collection][container][t
}
// TODO add tests for AllocatorAwareContainer statements and expressions

TEST_CASE("Collection and iterator concepts", "[collection][container][iterator][std]") {
#if (__cplusplus >= 202002L)
TEST_CASE("Collection and iterator concepts", "[collection][container][iterator][std]") {

SECTION("input_or_output_iterator") {
// weakly incrementable
Expand Down Expand Up @@ -495,126 +495,33 @@ TEST_CASE("Collection and iterator concepts", "[collection][container][iterator]
// const_iterator
STATIC_REQUIRE(std::input_iterator<const_iterator>);
}
}

SECTION("output_iterator") {
// indirectly_writable
// iterator
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<iterator, CollectionType::value_type>);
// STATIC_REQUIRE(std::is_same_v<std::iter_value_t<iterator>, std::decay_t<iterator::value_type>>);
// {
// auto coll = CollectionType{};
// coll.create().cellID(42);
// auto e = iterator::value_type{13, 0, 0, 0, 0};
// auto e_copy = e;
// auto o = coll.begin();
// *o = e;
// REQUIRE(*o == e_copy);
// }
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<iterator, CollectionType::value_type::mutable_type>);
// STATIC_REQUIRE(std::is_same_v<std::iter_value_t<iterator>, std::decay_t<iterator::value_type::mutable_type>>);
// {
// auto coll = CollectionType{};
// coll.create().cellID(42);
// auto e = iterator::value_type::mutable_type{13, 0, 0, 0, 0};
// auto e_copy =e;
// auto o = coll.begin();
// *o = e;
// REQUIRE(*o == e_copy);
// }
// const_iterator
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<const_iterator, CollectionType::value_type>);
// STATIC_REQUIRE(std::is_same_v<std::iter_value_t<const_iterator>, std::decay_t<const_iterator::value_type>>);
// {
// auto coll = CollectionType{};
// coll.create().cellID(42);
// auto e = iterator::value_type{13, 0, 0, 0, 0};
// auto e_copy = e;
// auto o = coll.cbegin();
// *o = e;
// REQUIRE(*o == e_copy);
// }
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<const_iterator, CollectionType::value_type::mutable_type>);
// STATIC_REQUIRE(std::is_same_v<std::iter_value_t<const_iterator>,
// std::decay_t<const_iterator::value_type::mutable_type>>);
// {
// auto coll = CollectionType{};
// coll.create().cellID(42);
// auto e = iterator::value_type::mutable_type{13, 0, 0, 0, 0};
// auto e_copy = e;
// auto o = coll.cbegin();
// *o = e;
// REQUIRE(*o == e_copy);
// }

// iterator
DOCUMENTED_STATIC_FAILURE(std::output_iterator<iterator, CollectionType::value_type>);
DOCUMENTED_STATIC_FAILURE(std::output_iterator<iterator, CollectionType::value_type::mutable_type>);
// const_iterator
DOCUMENTED_STATIC_FAILURE(std::output_iterator<const_iterator, CollectionType::value_type>);
DOCUMENTED_STATIC_FAILURE(std::output_iterator<const_iterator, CollectionType::value_type::mutable_type>);
}

SECTION("forward_iterator") {
// iterator
DOCUMENTED_STATIC_FAILURE(std::forward_iterator<iterator>);
// {
// REQUIRE(iterator{} == iterator{});
// auto coll = CollectionType();
// coll.create();
// auto i = coll.begin();
// auto j = coll.begin();
// REQUIRE(i == j);
// REQUIRE(++i == ++j);
// i = coll.begin();
// REQUIRE(((void)[](auto x) { ++x; }(i), *i) == *i);
// Pointers and references obtained from a forward iterator into a range remain valid while the range exists.
// Is this even unit-testable?
// }
// const_iterator
DOCUMENTED_STATIC_FAILURE(std::forward_iterator<const_iterator>);
// {
// REQUIRE(const_iterator{} == const_iterator{});
// auto coll = CollectionType();
// coll.create();
// auto i = coll.cbegin();
// auto j = coll.cbegin();
// REQUIRE(i == j);
// REQUIRE(++i == ++j);
// i = coll.cbegin();
// REQUIRE(((void)[](auto x) { ++x; }(i), *i) == *i);
// Pointers and references obtained from a forward iterator into a range remain valid while the range exists.
// Is this even unit-testable?
// }
}

SECTION("bidirectional_iterator") {
// iterator
DOCUMENTED_STATIC_FAILURE(std::bidirectional_iterator<iterator>);
// TODO check semantic requirements
// const_iterator
DOCUMENTED_STATIC_FAILURE(std::bidirectional_iterator<const_iterator>);
// TODO check semantic requirements
}

SECTION("random_access_iterator") {
// iterator
DOCUMENTED_STATIC_FAILURE(std::random_access_iterator<iterator>);
// TODO check semantic requirements
// const_iterator
DOCUMENTED_STATIC_FAILURE(std::random_access_iterator<const_iterator>);
// TODO check semantic requirements
}

SECTION("contiguous_iterator_iterator") {
// iterator
DOCUMENTED_STATIC_FAILURE(std::contiguous_iterator<iterator>);
// TODO check semantic requirements
// const_iterator
DOCUMENTED_STATIC_FAILURE(std::contiguous_iterator<const_iterator>);
// TODO check semantic requirements
}
#endif
TEST_CASE("Collection and unsupported iterator concepts", "[collection][container][iterator][std]") {
// std::indirectly_writable
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<iterator, CollectionType::value_type>);
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<iterator, CollectionType::value_type::mutable_type>);
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<const_iterator, CollectionType::value_type>);
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<const_iterator, CollectionType::value_type::mutable_type>);
// std::output_iterator
DOCUMENTED_STATIC_FAILURE(std::output_iterator<iterator, CollectionType::value_type>);
DOCUMENTED_STATIC_FAILURE(std::output_iterator<iterator, CollectionType::value_type::mutable_type>);
DOCUMENTED_STATIC_FAILURE(std::output_iterator<const_iterator, CollectionType::value_type>);
DOCUMENTED_STATIC_FAILURE(std::output_iterator<const_iterator, CollectionType::value_type::mutable_type>);
// std::forward_iterator
DOCUMENTED_STATIC_FAILURE(std::forward_iterator<iterator>);
DOCUMENTED_STATIC_FAILURE(std::forward_iterator<const_iterator>);
// std::bidirectional_iterator
DOCUMENTED_STATIC_FAILURE(std::bidirectional_iterator<iterator>);
DOCUMENTED_STATIC_FAILURE(std::bidirectional_iterator<const_iterator>);
// std::random_access_iterator
DOCUMENTED_STATIC_FAILURE(std::random_access_iterator<iterator>);
DOCUMENTED_STATIC_FAILURE(std::random_access_iterator<const_iterator>);
// std::contiguous_iterator
DOCUMENTED_STATIC_FAILURE(std::contiguous_iterator<iterator>);
DOCUMENTED_STATIC_FAILURE(std::contiguous_iterator<const_iterator>);
}
#endif // __cplusplus >= 202002L

TEST_CASE("Collection iterators", "[collection][container][iterator][std]") {
// the checks are duplicated for iterator and const_iterator as expectations on them are slightly different
Expand Down

0 comments on commit 68c4dbc

Please sign in to comment.