More tests in uri_test.rb
This commit is contained in:
parent
8bf050292a
commit
fb2e77a2ce
|
@ -12,26 +12,33 @@ class URITest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_simple_uri
|
def test_simple_uri
|
||||||
|
# Simplest case
|
||||||
match(URIChunk, 'http://www.example.com',
|
match(URIChunk, 'http://www.example.com',
|
||||||
:scheme =>'http', :host =>'www.example.com', :path => nil,
|
:scheme =>'http', :host =>'www.example.com', :path => nil,
|
||||||
:link_text => 'http://www.example.com'
|
:link_text => 'http://www.example.com'
|
||||||
)
|
)
|
||||||
|
# With trailing slash
|
||||||
match(URIChunk, 'http://www.example.com/',
|
match(URIChunk, 'http://www.example.com/',
|
||||||
:scheme =>'http', :host =>'www.example.com', :path => '/',
|
:scheme =>'http', :host =>'www.example.com', :path => '/',
|
||||||
:link_text => 'http://www.example.com/'
|
:link_text => 'http://www.example.com/'
|
||||||
)
|
)
|
||||||
|
# Without http://
|
||||||
match(URIChunk, 'www.example.com',
|
match(URIChunk, 'www.example.com',
|
||||||
:scheme =>'http', :host =>'www.example.com', :link_text => 'www.example.com'
|
:scheme =>'http', :host =>'www.example.com', :link_text => 'www.example.com'
|
||||||
)
|
)
|
||||||
|
# two parts
|
||||||
match(URIChunk, 'example.com',
|
match(URIChunk, 'example.com',
|
||||||
:scheme =>'http',:host =>'example.com', :link_text => 'example.com'
|
:scheme =>'http',:host =>'example.com', :link_text => 'example.com'
|
||||||
)
|
)
|
||||||
|
# "unusual" base domain (was a bug in an early version)
|
||||||
match(URIChunk, 'http://example.com.au/',
|
match(URIChunk, 'http://example.com.au/',
|
||||||
:scheme =>'http', :host =>'example.com.au', :link_text => 'http://example.com.au/'
|
:scheme =>'http', :host =>'example.com.au', :link_text => 'http://example.com.au/'
|
||||||
)
|
)
|
||||||
|
# "unusual" base domain without http://
|
||||||
match(URIChunk, 'example.com.au',
|
match(URIChunk, 'example.com.au',
|
||||||
:scheme =>'http', :host =>'example.com.au', :link_text => 'example.com.au'
|
:scheme =>'http', :host =>'example.com.au', :link_text => 'example.com.au'
|
||||||
)
|
)
|
||||||
|
# Another "unusual" base domain
|
||||||
match(URIChunk, 'http://www.example.co.uk/',
|
match(URIChunk, 'http://www.example.co.uk/',
|
||||||
:scheme =>'http', :host =>'www.example.co.uk',
|
:scheme =>'http', :host =>'www.example.co.uk',
|
||||||
:link_text => 'http://www.example.co.uk/'
|
:link_text => 'http://www.example.co.uk/'
|
||||||
|
@ -39,14 +46,56 @@ class URITest < Test::Unit::TestCase
|
||||||
match(URIChunk, 'example.co.uk',
|
match(URIChunk, 'example.co.uk',
|
||||||
:scheme =>'http', :host =>'example.co.uk', :link_text => 'example.co.uk'
|
:scheme =>'http', :host =>'example.co.uk', :link_text => 'example.co.uk'
|
||||||
)
|
)
|
||||||
|
# With some path at the end
|
||||||
match(URIChunk, 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation',
|
match(URIChunk, 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation',
|
||||||
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
|
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
|
||||||
:link_text => 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation'
|
:link_text => 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation'
|
||||||
)
|
)
|
||||||
|
# With some path at the end, and withot http:// prefix
|
||||||
match(URIChunk, 'moinmoin.wikiwikiweb.de/HelpOnNavigation',
|
match(URIChunk, 'moinmoin.wikiwikiweb.de/HelpOnNavigation',
|
||||||
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
|
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
|
||||||
:link_text => 'moinmoin.wikiwikiweb.de/HelpOnNavigation'
|
:link_text => 'moinmoin.wikiwikiweb.de/HelpOnNavigation'
|
||||||
)
|
)
|
||||||
|
# With a port number
|
||||||
|
match(URIChunk, 'http://www.example.com:80',
|
||||||
|
:scheme =>'http', :host =>'www.example.com', :port => '80', :path => nil,
|
||||||
|
:link_text => 'http://www.example.com:80')
|
||||||
|
# With a port number and a path
|
||||||
|
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation',
|
||||||
|
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
|
||||||
|
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation')
|
||||||
|
# With a query
|
||||||
|
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val',
|
||||||
|
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
|
||||||
|
:query => 'arg=val',
|
||||||
|
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val')
|
||||||
|
# Query with two arguments
|
||||||
|
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2',
|
||||||
|
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
|
||||||
|
:query => 'arg=val&arg2=val2',
|
||||||
|
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2')
|
||||||
|
# HTTPS
|
||||||
|
match(URIChunk, 'https://www.example.com',
|
||||||
|
:scheme =>'https', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
|
||||||
|
:link_text => 'https://www.example.com')
|
||||||
|
# FTP
|
||||||
|
match(URIChunk, 'ftp://www.example.com',
|
||||||
|
:scheme =>'ftp', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
|
||||||
|
:link_text => 'ftp://www.example.com')
|
||||||
|
# mailto
|
||||||
|
match(URIChunk, 'mailto:www@example.com',
|
||||||
|
:scheme =>'mailto', :host =>'example.com', :port => nil, :path => nil, :query => nil,
|
||||||
|
:link_text => 'mailto:www@example.com')
|
||||||
|
# something nonexistant
|
||||||
|
match(URIChunk, 'foobar://www.example.com',
|
||||||
|
:scheme =>'foobar', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
|
||||||
|
:link_text => 'foobar://www.example.com')
|
||||||
|
|
||||||
|
# Soap opera (the most complex case imaginable... well, not really, there should be more evil)
|
||||||
|
match(URIChunk, 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2',
|
||||||
|
:scheme =>'http', :host =>'www.example.com.tw', :port => '80',
|
||||||
|
:path => '/~jdoe123/Help%20Me%20', :query => 'arg=val&arg2=val2',
|
||||||
|
:link_text => 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_email_uri
|
def test_email_uri
|
||||||
|
@ -63,15 +112,17 @@ class URITest < Test::Unit::TestCase
|
||||||
def test_non_uri
|
def test_non_uri
|
||||||
assert_no_match(URIChunk.pattern, 'httpd.conf')
|
assert_no_match(URIChunk.pattern, 'httpd.conf')
|
||||||
assert_no_match(URIChunk.pattern, 'libproxy.so')
|
assert_no_match(URIChunk.pattern, 'libproxy.so')
|
||||||
|
assert_no_match(URIChunk.pattern, 'ld.so.conf')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uri_in_text
|
def test_uri_in_text
|
||||||
match(URIChunk, 'Go to: http://www.example.com/', :host => 'www.example.com', :path =>'/')
|
match(URIChunk, 'Go to: http://www.example.com/', :host => 'www.example.com', :path =>'/')
|
||||||
match(URIChunk, 'http://www.example.com/ is a link.', :host => 'www.example.com')
|
match(URIChunk, 'http://www.example.com/ is a link.', :host => 'www.example.com')
|
||||||
match(URIChunk,
|
match(URIChunk,
|
||||||
'Email david@loudthinking.com',
|
'Email david@loudthinking.com',
|
||||||
:scheme =>'mailto', :user =>'david', :host =>'loudthinking.com'
|
:scheme =>'mailto', :user =>'david', :host =>'loudthinking.com')
|
||||||
)
|
# check that trailing punctuation is not included in the hostname
|
||||||
|
match(URIChunk, '"link":http://fake.link.com.', :scheme => 'http', :host => 'fake.link.com')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uri_in_parentheses
|
def test_uri_in_parentheses
|
||||||
|
@ -99,5 +150,5 @@ class URITest < Test::Unit::TestCase
|
||||||
:query => 'arg=val'
|
:query => 'arg=val'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue