Permalink
Browse files

Correct Regexp#un/optionalize assertions and fix uncovered failures

[#3102 state:incomplete]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent 05b529c commit 66d8063c910b166e58f77ca5149a454f721667c7 @packagethief packagethief committed with jeremy Aug 26, 2009
@@ -9,6 +9,8 @@ def multiline?
class << self
def optionalize(pattern)
+ return pattern if pattern == ""
+
case unoptionalize(pattern)
when /\A(.|\(.*\))\Z/ then "#{pattern}?"
else "(?:#{pattern})?"
@@ -13,14 +13,14 @@ def test_multiline
end
def test_optionalize
- assert "a?", Regexp.optionalize("a")
- assert "(?:foo)?", Regexp.optionalize("foo")
- assert "", Regexp.optionalize("")
+ assert_equal "a?", Regexp.optionalize("a")
+ assert_equal "(?:foo)?", Regexp.optionalize("foo")
+ assert_equal "", Regexp.optionalize("")
end
def test_unoptionalize
- assert "a", Regexp.unoptionalize("a?")
- assert "foo", Regexp.unoptionalize("(?:foo)")
- assert "", Regexp.unoptionalize("")
+ assert_equal "a", Regexp.unoptionalize("a?")
+ assert_equal "foo", Regexp.unoptionalize("(?:foo)?")
+ assert_equal "", Regexp.unoptionalize("")
end
end

0 comments on commit 66d8063

Please sign in to comment.