summaryrefslogtreecommitdiff
path: root/test/ruby/test_array.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-30 06:00:24 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-30 06:00:24 +0000
commit20c0fb69d65f20d42caf980de042396370dd0ba4 (patch)
tree6e4483a32181bc4e10dea1e42948ecdb920890c6 /test/ruby/test_array.rb
parent00d6bb5108209329996c8062ce3e947489c38ea7 (diff)
* array.c (rb_ary_bsearch): Raise TypeError on bad return from block
* range.c (range_bsearch): ditto * test/ruby/test_array.rb (class): Test for above * test/ruby/test_range.rb (class): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r--test/ruby/test_array.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index ae0f76c970..3ab0895f8c 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -2249,6 +2249,13 @@ class TestArray < Test::Unit::TestCase
assert_raise(ArgumentError) { a.rotate!(1, 1) }
end
+ def test_bsearch_typechecks_return_values
+ assert_raise(TypeError) do
+ [1, 2, 42, 100, 666].bsearch{ "not ok" }
+ end
+ assert_equal [1, 2, 42, 100, 666].bsearch{}, [1, 2, 42, 100, 666].bsearch{false}
+ end
+
def test_bsearch_with_no_block
enum = [1, 2, 42, 100, 666].bsearch
assert_nil enum.size
@@ -2276,9 +2283,4 @@ class TestArray < Test::Unit::TestCase
assert_include([4, 7], a.bsearch {|x| (2**100).coerce((1 - x / 4) * (2**100)).first })
end
-
- def test_bsearch_undefined
- a = [0, 4, 7, 10, 12]
- assert_equal(nil, a.bsearch {|x| "foo" }) # undefined behavior
- end
end