···3434 Literal.check(caught.result, self)
3535 caught.result
3636 else
3737- Literal.check(caught, @success_type)
3838- success(caught)
3737+ raise Literal::ArgumentError.new("Expected block to throw a success or failure result")
3938 end
4039 end
4140
+8-18
test/result.test.rb
···1111 assert_equal 42, result.value!
1212end
13131414-test "result block wraps returned success values" do
1515- result = Literal::Result(Integer, Symbol) do
1616- 42
1717- end
1818-1919- assert result.success?
2020- assert_equal 42, result.value!
2121- assert_equal Integer, result.success_type
2222- assert_equal Symbol, result.failure_type
2323-end
2424-2525-test "result block checks returned values against success type" do
2626- error = assert_raises(Literal::TypeError) do
1414+test "result block requires throwing a result" do
1515+ error = assert_raises(Literal::ArgumentError) do
2716 Literal::Result(Integer, Symbol) do
2828- "42"
1717+ 42
2918 end
3019 end
31203232- assert_equal Integer, error.to_h[:expected]
3333- assert_equal "42", error.to_h[:actual]
2121+ assert_equal "Expected block to throw a success or failure result", error.message
3422end
35233636-test "result block must return a matching result" do
3737- assert_raises(Literal::TypeError) do
2424+test "result block must throw, not return, a result" do
2525+ error = assert_raises(Literal::ArgumentError) do
3826 Literal::Result(Integer, Symbol) do
3927 Literal::Result(String, Symbol) { |type| type.success("42") }
4028 end
4129 end
3030+3131+ assert_equal "Expected block to throw a success or failure result", error.message
4232end
43334434test "then adopts returned success type" do