1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/ruby/test_range.rb
akr 16457d4b96 add exclude_end? method to DuckRange.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-08-05 23:56:02 +00:00

34 lines
714 B
Ruby

require 'test/unit'
class TestRange < Test::Unit::TestCase
def test_range_string
# XXX: Is this really the test of Range?
assert_equal([], ("a" ... "a").to_a)
assert_equal(["a"], ("a" .. "a").to_a)
assert_equal(["a"], ("a" ... "b").to_a)
assert_equal(["a", "b"], ("a" .. "b").to_a)
end
def test_evaluation_order
arr = [1,2]
r = (arr.shift)..(arr.shift)
assert_equal(1..2, r, "[ruby-dev:26383]")
end
class DuckRange
def initialize(b,e,excl=false)
@begin = b
@end = e
@excl = excl
end
attr_reader :begin, :end
def exclude_end?
@excl
end
end
def test_duckrange
assert_equal("bc", "abcd"[DuckRange.new(1,2)])
end
end