From bb58e65e6596a2ffac2e85e9fda1e8568aa9b4b1 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 25 Feb 2020 20:57:06 +0100 Subject: new_type: implement cbegin --- test/src/iterable_suite.cpp | 84 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp index 8c08a66..3bdb16b 100644 --- a/test/src/iterable_suite.cpp +++ b/test/src/iterable_suite.cpp @@ -21,6 +21,7 @@ namespace auto begin() -> iterator; auto begin() const -> const_iterator; + auto cbegin() const -> const_iterator; }; } // namespace @@ -86,18 +87,77 @@ inline namespace begin_tests } // namespace begin_tests +inline namespace cbegin_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cbegin_v)); + } + + auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cbegin() -> void + { + static_assert(!nt::impl::has_cbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cbegin_v)); + } + + auto a_new__type_based_on_an_iterable_type_with_member_cbegin_deriving_iterable_has_member_cbegin() -> void + { + static_assert(nt::impl::has_member_cbegin_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_cbegin_v); + } + + auto a_new__type_based_on_an_iterable_type_without_free_cbegin_deriving_iterable_has_no_free_cbegin() -> void + { + static_assert(!nt::impl::has_free_cbegin_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_cbegin_v); + } + + auto accessing_the_first_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() + -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto weak = std::array{42, 21, 10}; + auto strong = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(*weak.cbegin(), *strong.cbegin()); + } + + auto an_iterator_obtained_via_member_cbegin_compares_equal_to_an_iterator_obtained_via_free_cbegin() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto instance = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(cbegin(instance), instance.cbegin()); + } + +} // namespace cbegin_tests + auto iterable_suite() -> std::pair { - return {{ - /// 'begin' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_begin), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_begin), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin), - KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_begin_deriving_iterable_has_no_free_begin), - KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_begin_deriving_iterable_has_no_constant_free_begin), - KAWAII(accessing_the_first_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_begin_compares_equal_to_an_iterator_obtained_via_free_begin), - }, - "Iterable Tests"}; + return { + { + // clang-format off + /// 'begin' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_begin), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_begin), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin), + KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_begin_deriving_iterable_has_no_free_begin), + KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_begin_deriving_iterable_has_no_constant_free_begin), + KAWAII(accessing_the_first_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_begin_compares_equal_to_an_iterator_obtained_via_free_begin), + + /// 'begin' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_cbegin), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cbegin), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_cbegin_deriving_iterable_has_member_cbegin), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_cbegin_deriving_iterable_has_no_free_cbegin), + KAWAII(accessing_the_first_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_cbegin_compares_equal_to_an_iterator_obtained_via_free_cbegin), + // clang-format on + }, + "Iterable Tests"}; } \ No newline at end of file -- cgit v1.2.3