[ruby/uri] Added test for constant definition and remove URI::REGEXP when using RFC3986_PARSER

https://github.com/ruby/uri/commit/6f616d97fc
This commit is contained in:
Hiroshi SHIBATA 2024-07-18 13:16:20 +09:00 committed by git
parent 2a56c1841d
commit 082335494b
2 changed files with 19 additions and 1 deletions

View File

@ -26,8 +26,8 @@ module URI
remove_const(:Parser) if defined?(Parser)
const_set("Parser", parser.class)
remove_const(:REGEXP) if defined?(REGEXP)
if Parser == RFC2396_Parser
remove_const(:REGEXP) if defined?(REGEXP)
const_set("REGEXP", URI::RFC2396_REGEXP)
Parser.new.pattern.each_pair do |sym, str|
unless REGEXP::PATTERN.const_defined?(sym)
@ -35,6 +35,7 @@ module URI
end
end
end
Parser.new.regexp.each_pair do |sym, str|
remove_const(sym) if const_defined?(sym)
const_set(sym, str)

View File

@ -10,6 +10,23 @@ class URI::TestCommon < Test::Unit::TestCase
def teardown
end
def test_parser_switch
assert_equal(URI::Parser, URI::RFC3986_Parser)
refute defined?(::URI::REGEXP)
URI.parser = URI::RFC2396_PARSER
assert_equal(URI::Parser, URI::RFC2396_Parser)
assert defined?(URI::REGEXP)
URI.parser = URI::RFC3986_PARSER
assert_equal(URI::Parser, URI::RFC3986_Parser)
refute defined?(URI::REGEXP)
ensure
URI.parser = URI::RFC3986_PARSER
end
def test_extract
EnvUtil.suppress_warning do
assert_equal(['http://example.com'],