// // common_test.cxx // stream-test // // Created by Sam Jaffe on 4/2/23. // #include "stream/view/common.h" #include "stream_helpers.h" #include "stream_matchers.h" using testing::StaticAssertTypeEq; TEST(CommonView, CoercesSentinelIntoCommon) { Range, Sentinel> input; auto range = input | views::common(); StaticAssertTypeEq(); } TEST(CommonView, DoesNotWrapNonSentinelTypes) { Range, Common> input{0, 1, 2, 3, 4}; auto range = input | views::common(); StaticAssertTypeEq(); } TEST(CommonView, IteratesThroughSameValues) { Range, Sentinel> input{0, 1, 2, 3, 4}; auto range = input | views::common(); EXPECT_THAT(range, RangesEq(input)); } TEST(CommonView, NotRequiredToProvideSizeOrEmpty) { Range, Sentinel> input{0, 1, 2, 3, 4}; auto range = input | views::common(); static_assert(!stream::detail::has_size_v); static_assert(!stream::detail::has_empty_v); } TEST(CommonView, PropagatesSize) { Range, Sentinel, Sized> input{0, 1, 2, 3, 4}; auto range = input | views::common(); static_assert(stream::detail::has_size_v); EXPECT_THAT(range.size(), input.size()); } TEST(CommonView, PropagatesEmpty) { Range, Sentinel, Sized> input{0, 1, 2, 3, 4}; auto range = input | views::common(); static_assert(stream::detail::has_empty_v); EXPECT_THAT(range.empty(), input.empty()); }