2003-10-16 22:18:01 -04:00
|
|
|
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
|
2005-06-30 02:27:05 -04:00
|
|
|
|
|
|
|
def test_evaluation_order
|
|
|
|
arr = [1,2]
|
|
|
|
r = (arr.shift)..(arr.shift)
|
|
|
|
assert_equal(1..2, r, "[ruby-dev:26383]")
|
|
|
|
end
|
2005-08-04 01:19:44 -04:00
|
|
|
|
|
|
|
class DuckRange
|
2005-08-05 19:56:02 -04:00
|
|
|
def initialize(b,e,excl=false)
|
2005-08-04 01:19:44 -04:00
|
|
|
@begin = b
|
|
|
|
@end = e
|
2005-08-05 19:56:02 -04:00
|
|
|
@excl = excl
|
2005-08-04 01:19:44 -04:00
|
|
|
end
|
|
|
|
attr_reader :begin, :end
|
2005-08-05 19:56:02 -04:00
|
|
|
|
|
|
|
def exclude_end?
|
|
|
|
@excl
|
|
|
|
end
|
2005-08-04 01:19:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_duckrange
|
|
|
|
assert_equal("bc", "abcd"[DuckRange.new(1,2)])
|
|
|
|
end
|
2003-10-16 22:18:01 -04:00
|
|
|
end
|