瀏覽代碼

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

Sam Jaffe 5 年之前
父節點
當前提交
5e9f9bba8a
共有 2 個文件被更改,包括 8 次插入7 次删除
  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); });
 }