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