Simon Strandgaard
10/31/2003 8:00:00 PM
While working on my own regexp engine, I found out that
there is many cases where a range doesn't raise an exception.
Shouldn't Ruby's Regexp class raise an exception here ???
def test_illegal_range1
input = [
"a{3", # premature end of input
"a{,}b", # neither min or max specified
"a{,3}b", # min expected, but got none
"a{43x3}b", # either ',' or '}' expected, got 'x'
"a{43,333", # premature end of input
"a{43,333x", # expected '}', got 'x'
"a{999,666}" # expected (min <= max), got (min > max)
]
res = input.map{|str|
ok = false
begin
Regexp.new(str)
rescue RegexpError
ok = true
end
ok
}
assert_equal([true] * input.size, res)
end
Output when running via Ruby-1.8.1
1) Failure:
test_illegal_range1(TestRubyRegex) [test_ruby_regex.rb:135]:
<[true, true, true, true, true, true, true]> expected but was
<[false, false, false, false, false, false, true]>.
As you can see only the last case is OK, the others are broken.
--
Simon Strandgaard