summaryrefslogtreecommitdiff
path: root/test/ruby/test_range.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-28 07:31:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-28 07:31:32 +0000
commitd07861fb2fdaec6a630f7198801720cd7581bbab (patch)
treed86939efa049d71963f132597e871ac06f056542 /test/ruby/test_range.rb
parentb6e2851431a12edff6259e876818fee8f4506acb (diff)
range.c: each on endless range
* range.c (range_each): endless range begins with string-like object should iterate from the converted result string, as well as `#each` on a string-end range or `#step` method on an endless range, i.e., `begin.succ` should not be called. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_range.rb')
-rw-r--r--test/ruby/test_range.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index beb0b95..5f2e970 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -288,6 +288,19 @@ class TestRange < Test::Unit::TestCase
o = Object.new
def o.to_int() 1 end
assert_nothing_raised("[ruby-dev:34558]") { (0..2).step(o) {|x| } }
+
+ o = Object.new
+ class << o
+ def to_str() "a" end
+ def <=>(other) to_str <=> other end
+ end
+
+ a = []
+ (o.."c").step(1) {|x| a << x}
+ assert_equal(["a", "b", "c"], a)
+ a = []
+ (o..).step(1) {|x| a << x; break if a.size >= 3}
+ assert_equal(["a", "b", "c"], a)
end
def test_step_ruby_core_35753
@@ -348,6 +361,19 @@ class TestRange < Test::Unit::TestCase
a = []
r2.each {|x| a << x }
assert_equal([], a)
+
+ o = Object.new
+ class << o
+ def to_str() "a" end
+ def <=>(other) to_str <=> other end
+ end
+
+ a = []
+ (o.."c").each {|x| a << x}
+ assert_equal(["a", "b", "c"], a)
+ a = []
+ (o..).each {|x| a << x; break if a.size >= 3}
+ assert_equal(["a", "b", "c"], a)
end
def test_begin_end