common_test.cxx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // common_test.cxx
  3. // stream-test
  4. //
  5. // Created by Sam Jaffe on 4/2/23.
  6. //
  7. #include "stream/view/common.h"
  8. #include "stream_helpers.h"
  9. #include "stream_matchers.h"
  10. using testing::StaticAssertTypeEq;
  11. TEST(CommonView, CoercesSentinelIntoCommon) {
  12. Range<std::vector<int>, Sentinel> input;
  13. auto range = input | views::common();
  14. StaticAssertTypeEq<decltype(range.begin()), decltype(range.end())>();
  15. }
  16. TEST(CommonView, DoesNotWrapNonSentinelTypes) {
  17. Range<std::vector<int>, Common> input{0, 1, 2, 3, 4};
  18. auto range = input | views::common();
  19. StaticAssertTypeEq<decltype(input), decltype(range)>();
  20. }
  21. TEST(CommonView, IteratesThroughSameValues) {
  22. Range<std::vector<int>, Sentinel> input{0, 1, 2, 3, 4};
  23. auto range = input | views::common();
  24. EXPECT_THAT(range, RangesEq(input));
  25. }
  26. TEST(CommonView, NotRequiredToProvideSizeOrEmpty) {
  27. Range<std::vector<int>, Sentinel> input{0, 1, 2, 3, 4};
  28. auto range = input | views::common();
  29. static_assert(stream::detail::has_size_v<decltype(range)>);
  30. static_assert(stream::detail::has_empty_v<decltype(range)>);
  31. }
  32. TEST(CommonView, PropagatesSize) {
  33. Range<std::vector<int>, Sentinel, Sized> input{0, 1, 2, 3, 4};
  34. auto range = input | views::common();
  35. static_assert(stream::detail::has_size_v<decltype(range)>);
  36. EXPECT_THAT(range.size(), input.size());
  37. }
  38. TEST(CommonView, PropagatesEmpty) {
  39. Range<std::vector<int>, Sentinel, Sized> input{0, 1, 2, 3, 4};
  40. auto range = input | views::common();
  41. static_assert(stream::detail::has_empty_v<decltype(range)>);
  42. EXPECT_THAT(range.empty(), input.empty());
  43. }