| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //
- // 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<std::vector<int>, Sentinel> input;
- auto range = input | views::common();
- StaticAssertTypeEq<decltype(range.begin()), decltype(range.end())>();
- }
- TEST(CommonView, DoesNotWrapNonSentinelTypes) {
- Range<std::vector<int>, Common> input{0, 1, 2, 3, 4};
- auto range = input | views::common();
- StaticAssertTypeEq<decltype(input), decltype(range)>();
- }
- TEST(CommonView, IteratesThroughSameValues) {
- Range<std::vector<int>, Sentinel> input{0, 1, 2, 3, 4};
- auto range = input | views::common();
- EXPECT_THAT(range, RangesEq(input));
- }
- TEST(CommonView, NotRequiredToProvideSizeOrEmpty) {
- Range<std::vector<int>, Sentinel> input{0, 1, 2, 3, 4};
- auto range = input | views::common();
- static_assert(stream::detail::has_size_v<decltype(range)>);
- static_assert(stream::detail::has_empty_v<decltype(range)>);
- }
- TEST(CommonView, PropagatesSize) {
- Range<std::vector<int>, Sentinel, Sized> input{0, 1, 2, 3, 4};
- auto range = input | views::common();
- static_assert(stream::detail::has_size_v<decltype(range)>);
- EXPECT_THAT(range.size(), input.size());
- }
- TEST(CommonView, PropagatesEmpty) {
- Range<std::vector<int>, Sentinel, Sized> input{0, 1, 2, 3, 4};
- auto range = input | views::common();
- static_assert(stream::detail::has_empty_v<decltype(range)>);
- EXPECT_THAT(range.empty(), input.empty());
- }
|