test/option_test.rb in rumonade-0.2.0 vs test/option_test.rb in rumonade-0.2.1
- old
+ new
@@ -2,21 +2,22 @@
class OptionTest < Test::Unit::TestCase
include Rumonade
include MonadAxiomTestHelpers
- def test_when_option_with_nil_returns_none_singleton
- assert_same None, Option.unit(nil)
+ def test_when_option_with_nil_returns_none_singleton_except_unit
assert_same None, Option(nil)
assert_same NoneClass.instance, None
+ assert_not_equal None, Option.unit(nil)
end
def test_when_option_with_value_returns_some
assert_equal Some(42), Option.unit(42)
assert_equal Some(42), Option(42)
assert_equal Some(42), Some.new(42)
assert_not_equal None, Some(nil)
+ assert_equal Some(nil), Option.unit(nil)
end
def test_when_option_constructor_raises
assert_raise(TypeError) { Option.new }
end
@@ -83,10 +84,11 @@
def test_to_s_behaves_correctly
assert_equal "Some(1)", Some(1).to_s
assert_equal "None", None.to_s
assert_equal "Some(Some(None))", Some(Some(None)).to_s
+ assert_equal "Some(nil)", Some(nil).to_s
end
def test_each_behaves_correctly
vals = [None, Some(42)].inject([]) { |arr, opt| assert_nil(opt.each { |val| arr << val }); arr }
assert_equal [42], vals
@@ -105,7 +107,13 @@
def test_select_behaves_correctly
assert_equal Some(1), Some(1).select { |n| n > 0 }
assert_equal None, Some(1).select { |n| n < 0 }
assert_equal None, None.select { |n| n < 0 }
+ end
+
+ def test_some_map_to_nil_follows_scala_behavior_returning_some_of_nil
+ # scala> Option(1).map { x => null }
+ # res0: Option[Null] = Some(null)
+ assert_equal Some(nil), Option(1).map { |n| nil }
end
end