Selaa lähdekoodia

Get rid of value() function - forcing the caller to handle both cases directly instead of allowing bypass.

Sam Jaffe 5 vuotta sitten
vanhempi
commit
5e9f9bba8a
2 muutettua tiedostoa jossa 8 lisäystä ja 7 poistoa
  1. 0 2
      include/stream/either_stream.hpp
  2. 8 5
      test/either_stream_test.cxx

+ 0 - 2
include/stream/either_stream.hpp

@@ -86,8 +86,6 @@ namespace stream {
         return right(std::get<1>(value_));
       }
     }
-
-    ::either<T, E> const & value() const { return value_; }
   };
 
 }

+ 8 - 5
test/either_stream_test.cxx

@@ -39,8 +39,8 @@ TEST(EitherStreamTest, ContainsErrorValue) {
   auto strm = stream::either::make_stream<MathObject>(1.0).flatmap(
       [](double d) { return divide(d, 0); });
 
-  EXPECT_THAT(strm.value().index(), Eq(1));
-  EXPECT_THAT(std::get<MathError>(strm.value()), Eq(MathError::DivideByZero));
+  strm.match([](double) { GTEST_FAIL(); },
+             [](MathError me) { EXPECT_THAT(me, MathError::DivideByZero); });
 }
 
 TEST(EitherStreamTest, ErrorValueMatchesToErrorHandler) {
@@ -74,12 +74,15 @@ TEST(EitherStreamTest, ErrorPropogatesBypassingMap) {
 TEST(EitherStreamTest, ErrorPropogatesBypassingFlatmap) {
   auto ex = stream::either::make_stream<MathObject>(1.0).flatmap(
       [](double d) { return log(0.0, d); });
-  EXPECT_THAT(std::get<MathError>(ex.value()), Eq(MathError::DomainError));
+  ex.match([](double) { GTEST_FAIL(); },
+           [](MathError me) { EXPECT_THAT(me, MathError::DomainError); });
 
   auto strm = stream::either::make_stream<MathObject>(1.0).flatmap(
       [](double d) { return log(1.0, d); });
-  EXPECT_THAT(std::get<MathError>(strm.value()), Eq(MathError::DivideByZero));
+  strm.match([](double) { GTEST_FAIL(); },
+             [](MathError me) { EXPECT_THAT(me, MathError::DivideByZero); });
 
   strm = strm.flatmap([](double d) { return log(0.0, d); });
-  EXPECT_THAT(std::get<MathError>(strm.value()), Eq(MathError::DivideByZero));
+  strm.match([](double) { GTEST_FAIL(); },
+             [](MathError me) { EXPECT_THAT(me, MathError::DivideByZero); });
 }