summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakira <akira@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-04 04:02:16 +0000
committerakira <akira@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-04 04:02:16 +0000
commitef5883c016d02059beff0f7c5711e54a35318b32 (patch)
tree0917473376a6608a91af0361e0c15a25c8ad10c2
parentd6f70951dbf2dcdec6515ee783de539d739875dd (diff)
* test/uri/* (6 files): added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--test/uri/test_common.rb49
-rw-r--r--test/uri/test_ftp.rb61
-rw-r--r--test/uri/test_generic.rb634
-rw-r--r--test/uri/test_http.rb73
-rw-r--r--test/uri/test_ldap.rb118
-rw-r--r--test/uri/test_mailto.rb139
7 files changed, 1079 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 52200987f7..168a55c580 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-Sat Oct 4 12:44:45 2003 akira yamada <[email protected]>
+Sat Oct 4 12:58:48 2003 akira yamada <[email protected]>
+
+ * test/uri/* (6 files): added.
+
+Sat Oct 4 12:44:45 2003 akira yamada <[email protected]>
* lib/uri/ftp.rb, lib/uri/mailto.rb: renamed to #to_s from #to_str.
diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb
new file mode 100644
index 0000000000..b93a71f553
--- /dev/null
+++ b/test/uri/test_common.rb
@@ -0,0 +1,49 @@
+#
+# $Id$
+#
+# Copyright (c) 2002 akira yamada <[email protected]>
+# You can redistribute it and/or modify it under the same term as Ruby.
+#
+
+require 'runit/testcase'
+require 'runit/cui/testrunner'
+require 'uri'
+
+class TestCommon < RUNIT::TestCase
+ def setup
+ end
+
+ def teardown
+ end
+
+ def test_extract
+ # ruby-list:36086
+ assert_equal(['http://example.com'],
+ URI.extract('http://example.com'))
+ assert_equal(['http://example.com'],
+ URI.extract('(http://example.com)'))
+ assert_equal(['http://example.com/foo)'],
+ URI.extract('(http://example.com/foo)'))
+ assert_equal(['http://example.jphttp://example.jp'],
+ URI.extract('http://example.jphttp://example.jp'))
+ assert_equal(['http://example.jphttp://example.jp'],
+ URI.extract('http://example.jphttp://example.jp', ['http']))
+ assert_equal(['http://', 'mailto:'].sort,
+ URI.extract('ftp:// http:// mailto: https://', ['http', 'mailto']).sort)
+ # reported by Doug Kearns <[email protected]>
+ assert_equal(['From:', 'mailto:[email protected]]'].sort,
+ URI.extract('From: XXX [mailto:[email protected]]').sort)
+ end
+end
+
+if $0 == __FILE__
+ if ARGV.size == 0
+ suite = TestCommon.suite
+ else
+ suite = RUNIT::TestSuite.new
+ ARGV.each do |testmethod|
+ suite.add_test(TestGeneric.new(testmethod))
+ end
+ end
+ RUNIT::CUI::TestRunner.run(suite)
+end
diff --git a/test/uri/test_ftp.rb b/test/uri/test_ftp.rb
new file mode 100644
index 0000000000..123eb22e4a
--- /dev/null
+++ b/test/uri/test_ftp.rb
@@ -0,0 +1,61 @@
+#
+# $Id$
+#
+# Copyright (c) 2001 akira yamada <[email protected]>
+# You can redistribute it and/or modify it under the same term as Ruby.
+#
+
+require 'runit/testcase'
+require 'runit/testsuite'
+require 'runit/cui/testrunner'
+
+require 'uri/ftp'
+module URI
+ class Generic
+ def to_ary
+ component_ary
+ end
+ end
+end
+
+class TestFTP < RUNIT::TestCase
+ def setup
+ end
+
+ def test_parse
+ url = URI.parse('ftp://user:[email protected]/abc/def')
+ assert_kind_of(URI::FTP, url)
+
+ exp = [
+ 'ftp',
+ 'user:pass', 'host.com', URI::FTP.default_port,
+ '/abc/def', nil,
+ ]
+ ary = url.to_ary
+ assert_equal(exp, ary)
+
+ assert_equal('user', url.user)
+ assert_equal('pass', url.password)
+ end
+
+ def test_select
+ assert_equal(['ftp', 'a.b.c', 21], URI.parse('ftp://a.b.c/').select(:scheme, :host, :port))
+ u = URI.parse('ftp://a.b.c/')
+ assert_equal(u.to_ary, u.select(*u.component))
+ assert_exception(ArgumentError) do
+ u.select(:scheme, :host, :not_exist, :port)
+ end
+ end
+end
+
+if $0 == __FILE__
+ if ARGV.size == 0
+ suite = TestFTP.suite
+ else
+ suite = RUNIT::TestSuite.new
+ ARGV.each do |testmethod|
+ suite.add_test(TestFTP.new(testmethod))
+ end
+ end
+ RUNIT::CUI::TestRunner.run(suite)
+end
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
new file mode 100644
index 0000000000..12e76b765a
--- /dev/null
+++ b/test/uri/test_generic.rb
@@ -0,0 +1,634 @@
+#
+# $Id$
+#
+# Copyright (c) 2002 akira yamada <[email protected]>
+# You can redistribute it and/or modify it under the same term as Ruby.
+#
+
+require 'runit/testcase'
+require 'runit/cui/testrunner'
+require 'uri'
+module URI
+ class Generic
+ def to_ary
+ component_ary
+ end
+ end
+end
+
+class TestGeneric < RUNIT::TestCase
+ def setup
+ @url = 'http://a/b/c/d;p?q'
+ @base_url = URI.parse(@url)
+ end
+
+ def teardown
+ end
+
+ def test_parse
+ # 0
+ assert_kind_of(URI::HTTP, @base_url)
+
+ exp = [
+ 'http',
+ nil, 'a', URI::HTTP.default_port,
+ '/b/c/d;p',
+ 'q',
+ nil
+ ]
+ ary = @base_url.to_ary
+ assert_equal(exp, ary)
+
+ # 1
+ url = URI.parse('ftp://ftp.is.co.za/rfc/rfc1808.txt')
+ assert_kind_of(URI::FTP, url)
+
+ exp = [
+ 'ftp',
+ nil, 'ftp.is.co.za', URI::FTP.default_port,
+ '/rfc/rfc1808.txt', nil,
+ ]
+ ary = url.to_ary
+ assert_equal(exp, ary)
+
+ # 2
+ url = URI.parse('gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles')
+ assert_kind_of(URI::Generic, url)
+
+ exp = [
+ 'gopher',
+ nil, 'spinaltap.micro.umn.edu', nil, nil,
+ '/00/Weather/California/Los%20Angeles', nil,
+ nil,
+ nil
+ ]
+ ary = url.to_ary
+ assert_equal(exp, ary)
+
+ # 3
+ url = URI.parse('http://www.math.uio.no/faq/compression-faq/part1.html')
+ assert_kind_of(URI::HTTP, url)
+
+ exp = [
+ 'http',
+ nil, 'www.math.uio.no', URI::HTTP.default_port,
+ '/faq/compression-faq/part1.html',
+ nil,
+ nil
+ ]
+ ary = url.to_ary
+ assert_equal(exp, ary)
+
+ # 4
+ url = URI.parse('mailto:[email protected]')
+ assert_kind_of(URI::Generic, url)
+
+ exp = [
+ 'mailto',
+ []
+ ]
+ ary = url.to_ary
+ assert_equal(exp, ary)
+
+ # 5
+ url = URI.parse('news:comp.infosystems.www.servers.unix')
+ assert_kind_of(URI::Generic, url)
+
+ exp = [
+ 'news',
+ nil, nil, nil, nil,
+ nil, 'comp.infosystems.www.servers.unix',
+ nil,
+ nil
+ ]
+ ary = url.to_ary
+ assert_equal(exp, ary)
+
+ # 6
+ url = URI.parse('telnet://melvyl.ucop.edu/')
+ assert_kind_of(URI::Generic, url)
+
+ exp = [
+ 'telnet',
+ nil, 'melvyl.ucop.edu', nil, nil,
+ '/', nil,
+ nil,
+ nil
+ ]
+ ary = url.to_ary
+ assert_equal(exp, ary)
+
+ # 7
+ # reported by Mr. Kubota <[email protected]>
+ assert_exception(URI::InvalidURIError) { URI.parse('http://a_b:80/') }
+ assert_exception(URI::InvalidURIError) { URI.parse('http://a_b/') }
+
+ # 8
+ # reporte by m_seki
+ uri = URI.parse('file:///foo/bar.txt')
+ assert_kind_of(URI::Generic, url)
+ uri = URI.parse('file:/foo/bar.txt')
+ assert_kind_of(URI::Generic, url)
+ end
+
+ def test_merge
+ u1 = URI.parse('http://foo')
+ u2 = URI.parse('http://foo/')
+ u3 = URI.parse('http://foo/bar')
+ u4 = URI.parse('http://foo/bar/')
+
+ assert_equal(URI.parse('http://foo/baz'), u1 + 'baz')
+ assert_equal(URI.parse('http://foo/baz'), u2 + 'baz')
+ assert_equal(URI.parse('http://foo/baz'), u3 + 'baz')
+ assert_equal(URI.parse('http://foo/bar/baz'), u4 + 'baz')
+
+ assert_equal(URI.parse('http://foo/baz'), u1 + '/baz')
+ assert_equal(URI.parse('http://foo/baz'), u2 + '/baz')
+ assert_equal(URI.parse('http://foo/baz'), u3 + '/baz')
+ assert_equal(URI.parse('http://foo/baz'), u4 + '/baz')
+
+ # from [ruby-dev:11508] Re: uri
+ url = URI.parse('http://hoge/a.html') + 'b.html'
+ assert_equal('http://hoge/b.html', url.to_s)
+
+ # reported by Mr. Kubota <[email protected]>
+ url = URI.parse('http://a/b') + 'http://x/y'
+ assert_equal('http://x/y', url.to_s)
+ assert_equal(url, URI.parse('') + 'http://x/y')
+ assert_equal(url, URI.parse('').normalize + 'http://x/y')
+ assert_equal(url, URI.parse('http://a/b').normalize + 'http://x/y')
+
+ u = URI.parse('http://foo/bar/baz')
+ assert_equal(nil, u.merge!(""))
+ assert_equal(nil, u.merge!(u))
+ assert(nil != u.merge!("."))
+ assert_equal('http://foo/bar/', u.to_s)
+ assert(nil != u.merge!("../baz"))
+ assert_equal('http://foo/baz', u.to_s)
+ end
+
+ def test_route
+ url = URI.parse('http://hoge/a.html').route_to('http://hoge/b.html')
+ assert_equal('b.html', url.to_s)
+
+ url = URI.parse('http://hoge/a/').route_to('http://hoge/b/')
+ assert_equal('../b/', url.to_s)
+ url = URI.parse('http://hoge/a/b').route_to('http://hoge/b/')
+ assert_equal('../b/', url.to_s)
+
+ url = URI.parse('http://hoge/a/b/').route_to('http://hoge/b/')
+ assert_equal('../../b/', url.to_s)
+ end
+
+ def test_rfc2396_examples
+# http://a/b/c/d;p?q
+# g:h = g:h
+ url = @base_url.merge('g:h')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g:h', url.to_s)
+ url = @base_url.route_to('g:h')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g:h', url.to_s)
+
+# http://a/b/c/d;p?q
+# g = http://a/b/c/g
+ url = @base_url.merge('g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g', url.to_s)
+
+# http://a/b/c/d;p?q
+# ./g = http://a/b/c/g
+ url = @base_url.merge('./g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g')
+ assert_kind_of(URI::Generic, url)
+ assert('./g' != url.to_s) # ok
+ assert_equal('g', url.to_s)
+
+# http://a/b/c/d;p?q
+# g/ = http://a/b/c/g/
+ url = @base_url.merge('g/')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g/', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g/')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g/', url.to_s)
+
+# http://a/b/c/d;p?q
+# /g = http://a/g
+ url = @base_url.merge('/g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/g', url.to_s)
+ url = @base_url.route_to('http://a/g')
+ assert_kind_of(URI::Generic, url)
+ assert('/g' != url.to_s) # ok
+ assert_equal('../../g', url.to_s)
+
+# http://a/b/c/d;p?q
+# //g = http://g
+ url = @base_url.merge('//g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://g', url.to_s)
+ url = @base_url.route_to('http://g')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('//g', url.to_s)
+
+# http://a/b/c/d;p?q
+# ?y = http://a/b/c/?y
+ url = @base_url.merge('?y')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/?y', url.to_s)
+ url = @base_url.route_to('http://a/b/c/?y')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('?y', url.to_s)
+
+# http://a/b/c/d;p?q
+# g?y = http://a/b/c/g?y
+ url = @base_url.merge('g?y')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g?y', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g?y')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g?y', url.to_s)
+
+# http://a/b/c/d;p?q
+# #s = (current document)#s
+ url = @base_url.merge('#s')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal(@base_url.to_s + '#s', url.to_s)
+ url = @base_url.route_to(@base_url.to_s + '#s')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('#s', url.to_s)
+
+# http://a/b/c/d;p?q
+# g#s = http://a/b/c/g#s
+ url = @base_url.merge('g#s')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g#s', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g#s')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g#s', url.to_s)
+
+# http://a/b/c/d;p?q
+# g?y#s = http://a/b/c/g?y#s
+ url = @base_url.merge('g?y#s')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g?y#s', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g?y#s')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g?y#s', url.to_s)
+
+# http://a/b/c/d;p?q
+# ;x = http://a/b/c/;x
+ url = @base_url.merge(';x')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/;x', url.to_s)
+ url = @base_url.route_to('http://a/b/c/;x')
+ assert_kind_of(URI::Generic, url)
+ assert_equal(';x', url.to_s)
+
+# http://a/b/c/d;p?q
+# g;x = http://a/b/c/g;x
+ url = @base_url.merge('g;x')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g;x', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g;x')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g;x', url.to_s)
+
+# http://a/b/c/d;p?q
+# g;x?y#s = http://a/b/c/g;x?y#s
+ url = @base_url.merge('g;x?y#s')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g;x?y#s', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g;x?y#s')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g;x?y#s', url.to_s)
+
+# http://a/b/c/d;p?q
+# . = http://a/b/c/
+ url = @base_url.merge('.')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/', url.to_s)
+ url = @base_url.route_to('http://a/b/c/')
+ assert_kind_of(URI::Generic, url)
+ assert('.' != url.to_s) # ok
+ assert_equal('./', url.to_s)
+
+# http://a/b/c/d;p?q
+# ./ = http://a/b/c/
+ url = @base_url.merge('./')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/', url.to_s)
+ url = @base_url.route_to('http://a/b/c/')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('./', url.to_s)
+
+# http://a/b/c/d;p?q
+# .. = http://a/b/
+ url = @base_url.merge('..')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/', url.to_s)
+ url = @base_url.route_to('http://a/b/')
+ assert_kind_of(URI::Generic, url)
+ assert('..' != url.to_s) # ok
+ assert_equal('../', url.to_s)
+
+# http://a/b/c/d;p?q
+# ../ = http://a/b/
+ url = @base_url.merge('../')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/', url.to_s)
+ url = @base_url.route_to('http://a/b/')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('../', url.to_s)
+
+# http://a/b/c/d;p?q
+# ../g = http://a/b/g
+ url = @base_url.merge('../g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/g', url.to_s)
+ url = @base_url.route_to('http://a/b/g')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('../g', url.to_s)
+
+# http://a/b/c/d;p?q
+# ../.. = http://a/
+ url = @base_url.merge('../..')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/', url.to_s)
+ url = @base_url.route_to('http://a/')
+ assert_kind_of(URI::Generic, url)
+ assert('../..' != url.to_s) # ok
+ assert_equal('../../', url.to_s)
+
+# http://a/b/c/d;p?q
+# ../../ = http://a/
+ url = @base_url.merge('../../')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/', url.to_s)
+ url = @base_url.route_to('http://a/')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('../../', url.to_s)
+
+# http://a/b/c/d;p?q
+# ../../g = http://a/g
+ url = @base_url.merge('../../g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/g', url.to_s)
+ url = @base_url.route_to('http://a/g')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('../../g', url.to_s)
+
+# http://a/b/c/d;p?q
+# <> = (current document)
+ url = @base_url.merge('')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/d;p?q', url.to_s)
+ url = @base_url.route_to('http://a/b/c/d;p?q')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('', url.to_s)
+
+# http://a/b/c/d;p?q
+# /./g = http://a/./g
+ url = @base_url.merge('/./g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/./g', url.to_s)
+ url = @base_url.route_to('http://a/./g')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('/./g', url.to_s)
+
+# http://a/b/c/d;p?q
+# /../g = http://a/../g
+ url = @base_url.merge('/../g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/../g', url.to_s)
+ url = @base_url.route_to('http://a/../g')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('/../g', url.to_s)
+
+# http://a/b/c/d;p?q
+# g. = http://a/b/c/g.
+ url = @base_url.merge('g.')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g.', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g.')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g.', url.to_s)
+
+# http://a/b/c/d;p?q
+# .g = http://a/b/c/.g
+ url = @base_url.merge('.g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/.g', url.to_s)
+ url = @base_url.route_to('http://a/b/c/.g')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('.g', url.to_s)
+
+# http://a/b/c/d;p?q
+# g.. = http://a/b/c/g..
+ url = @base_url.merge('g..')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g..', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g..')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g..', url.to_s)
+
+# http://a/b/c/d;p?q
+# ..g = http://a/b/c/..g
+ url = @base_url.merge('..g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/..g', url.to_s)
+ url = @base_url.route_to('http://a/b/c/..g')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('..g', url.to_s)
+
+# http://a/b/c/d;p?q
+# ../../../g = http://a/../g
+ url = @base_url.merge('../../../g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/../g', url.to_s)
+ url = @base_url.route_to('http://a/../g')
+ assert_kind_of(URI::Generic, url)
+ assert('../../../g' != url.to_s) # ok? yes, it confuses you
+ assert_equal('/../g', url.to_s) # and it is clearly
+
+# http://a/b/c/d;p?q
+# ../../../../g = http://a/../../g
+ url = @base_url.merge('../../../../g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/../../g', url.to_s)
+ url = @base_url.route_to('http://a/../../g')
+ assert_kind_of(URI::Generic, url)
+ assert('../../../../g' != url.to_s) # ok? yes, it confuses you
+ assert_equal('/../../g', url.to_s) # and it is clearly
+
+# http://a/b/c/d;p?q
+# ./../g = http://a/b/g
+ url = @base_url.merge('./../g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/g', url.to_s)
+ url = @base_url.route_to('http://a/b/g')
+ assert_kind_of(URI::Generic, url)
+ assert('./../g' != url.to_s) # ok
+ assert_equal('../g', url.to_s)
+
+# http://a/b/c/d;p?q
+# ./g/. = http://a/b/c/g/
+ url = @base_url.merge('./g/.')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g/', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g/')
+ assert_kind_of(URI::Generic, url)
+ assert('./g/.' != url.to_s) # ok
+ assert_equal('g/', url.to_s)
+
+# http://a/b/c/d;p?q
+# g/./h = http://a/b/c/g/h
+ url = @base_url.merge('g/./h')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g/h', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g/h')
+ assert_kind_of(URI::Generic, url)
+ assert('g/./h' != url.to_s) # ok
+ assert_equal('g/h', url.to_s)
+
+# http://a/b/c/d;p?q
+# g/../h = http://a/b/c/h
+ url = @base_url.merge('g/../h')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/h', url.to_s)
+ url = @base_url.route_to('http://a/b/c/h')
+ assert_kind_of(URI::Generic, url)
+ assert('g/../h' != url.to_s) # ok
+ assert_equal('h', url.to_s)
+
+# http://a/b/c/d;p?q
+# g;x=1/./y = http://a/b/c/g;x=1/y
+ url = @base_url.merge('g;x=1/./y')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g;x=1/y', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g;x=1/y')
+ assert_kind_of(URI::Generic, url)
+ assert('g;x=1/./y' != url.to_s) # ok
+ assert_equal('g;x=1/y', url.to_s)
+
+# http://a/b/c/d;p?q
+# g;x=1/../y = http://a/b/c/y
+ url = @base_url.merge('g;x=1/../y')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/y', url.to_s)
+ url = @base_url.route_to('http://a/b/c/y')
+ assert_kind_of(URI::Generic, url)
+ assert('g;x=1/../y' != url.to_s) # ok
+ assert_equal('y', url.to_s)
+
+# http://a/b/c/d;p?q
+# g?y/./x = http://a/b/c/g?y/./x
+ url = @base_url.merge('g?y/./x')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g?y/./x', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g?y/./x')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g?y/./x', url.to_s)
+
+# http://a/b/c/d;p?q
+# g?y/../x = http://a/b/c/g?y/../x
+ url = @base_url.merge('g?y/../x')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g?y/../x', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g?y/../x')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g?y/../x', url.to_s)
+
+# http://a/b/c/d;p?q
+# g#s/./x = http://a/b/c/g#s/./x
+ url = @base_url.merge('g#s/./x')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g#s/./x', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g#s/./x')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g#s/./x', url.to_s)
+
+# http://a/b/c/d;p?q
+# g#s/../x = http://a/b/c/g#s/../x
+ url = @base_url.merge('g#s/../x')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http://a/b/c/g#s/../x', url.to_s)
+ url = @base_url.route_to('http://a/b/c/g#s/../x')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('g#s/../x', url.to_s)
+
+# http://a/b/c/d;p?q
+# http:g = http:g ; for validating parsers
+# | http://a/b/c/g ; for backwards compatibility
+ url = @base_url.merge('http:g')
+ assert_kind_of(URI::HTTP, url)
+ assert_equal('http:g', url.to_s)
+ url = @base_url.route_to('http:g')
+ assert_kind_of(URI::Generic, url)
+ assert_equal('http:g', url.to_s)
+ end
+
+ def test_join
+ assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo/bar'))
+ assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo', 'bar'))
+ assert_equal(URI.parse('http://foo/bar/'), URI.join('http://foo', 'bar/'))
+
+ assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', 'baz'))
+ assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', '/baz'))
+ assert_equal(URI.parse('http://foo/baz/'), URI.join('http://foo', 'bar', '/baz/'))
+ assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/', 'baz'))
+ assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar', 'baz', 'hoge'))
+
+ assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/baz'))
+ assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge'))
+ assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge'))
+ assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge'))
+ assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge'))
+ assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge'))
+ assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge'))
+ end
+
+ # ruby-dev:16728
+ def test_set_component
+ uri = URI.parse('http://foo:bar@baz')
+ assert_equal('oof', uri.user = 'oof')
+ assert_equal('http://oof:bar@baz', uri.to_s)
+ assert_equal('rab', uri.password = 'rab')
+ assert_equal('http://oof:rab@baz', uri.to_s)
+ assert_equal('foo', uri.userinfo = 'foo')
+ assert_equal('http://foo:rab@baz', uri.to_s)
+ assert_equal(['foo', 'bar'], uri.userinfo = ['foo', 'bar'])
+ assert_equal('http://foo:bar@baz', uri.to_s)
+ assert_equal(['foo'], uri.userinfo = ['foo'])
+ assert_equal('http://foo:bar@baz', uri.to_s)
+ assert_equal('zab', uri.host = 'zab')
+ assert_equal('http://foo:bar@zab', uri.to_s)
+ assert_equal(8080, uri.port = 8080)
+ assert_equal('http://foo:bar@zab:8080', uri.to_s)
+ assert_equal('/', uri.path = '/')
+ assert_equal('http://foo:bar@zab:8080/', uri.to_s)
+ assert_equal('a=1', uri.query = 'a=1')
+ assert_equal('http://foo:bar@zab:8080/?a=1', uri.to_s)
+ assert_equal('b123', uri.fragment = 'b123')
+ assert_equal('http://foo:bar@zab:8080/?a=1#b123', uri.to_s)
+ end
+end
+
+if $0 == __FILE__
+ if ARGV.size == 0
+ suite = TestGeneric.suite
+ else
+ suite = RUNIT::TestSuite.new
+ ARGV.each do |testmethod|
+ suite.add_test(TestGeneric.new(testmethod))
+ end
+ end
+ RUNIT::CUI::TestRunner.run(suite)
+end
diff --git a/test/uri/test_http.rb b/test/uri/test_http.rb
new file mode 100644
index 0000000000..65fc2ef630
--- /dev/null
+++ b/test/uri/test_http.rb
@@ -0,0 +1,73 @@
+require 'runit/testcase'
+require 'runit/cui/testrunner'
+require 'uri/http'
+module URI
+ class Generic
+ def to_ary
+ component_ary
+ end
+ end
+end
+
+class TestHTTP < RUNIT::TestCase
+ def setup
+ end
+
+ def teardown
+ end
+
+ def test_parse
+ u = URI.parse('http://a')
+ assert_kind_of(URI::HTTP, u)
+ assert_equal(['http',
+ nil, 'a', URI::HTTP.default_port,
+ '', nil, nil], u.to_ary)
+ end
+
+ def test_normalize
+ host = 'aBcD'
+ u1 = URI.parse('http://' + host + '/eFg?HiJ')
+ u2 = URI.parse('http://' + host.downcase + '/eFg?HiJ')
+ assert(u1.normalize.host == 'abcd')
+ assert(u1.normalize.path == u1.path)
+ assert(u1.normalize == u2.normalize)
+ assert(!u1.normalize.host.equal?(u1.host))
+ assert( u2.normalize.host.equal?(u2.host))
+
+ assert_equal('http://abc/', URI.parse('http://abc').normalize.to_s)
+ end
+
+ def test_equal
+ assert(URI.parse('http://abc') == URI.parse('http://ABC'))
+ assert(URI.parse('http://abc/def') == URI.parse('http://ABC/def'))
+ assert(URI.parse('http://abc/def') != URI.parse('http://ABC/DEF'))
+ end
+
+ def test_request_uri
+ assert_equal('/', URI.parse('http://a.b.c/').request_uri)
+ assert_equal('/?abc=def', URI.parse('http://a.b.c/?abc=def').request_uri)
+ assert_equal('/', URI.parse('http://a.b.c').request_uri)
+ assert_equal('/?abc=def', URI.parse('http://a.b.c?abc=def').request_uri)
+ end
+
+ def test_select
+ assert_equal(['http', 'a.b.c', 80], URI.parse('http://a.b.c/').select(:scheme, :host, :port))
+ u = URI.parse('http://a.b.c/')
+ assert_equal(u.to_ary, u.select(*u.component))
+ assert_exception(ArgumentError) do
+ u.select(:scheme, :host, :not_exist, :port)
+ end
+ end
+end
+
+if $0 == __FILE__
+ if ARGV.size == 0
+ suite = TestHTTP.suite
+ else
+ suite = RUNIT::TestSuite.new
+ ARGV.each do |testmethod|
+ suite.add_test(TestHTTP.new(testmethod))
+ end
+ end
+ RUNIT::CUI::TestRunner.run(suite)
+end
diff --git a/test/uri/test_ldap.rb b/test/uri/test_ldap.rb
new file mode 100644
index 0000000000..df55f6490b
--- /dev/null
+++ b/test/uri/test_ldap.rb
@@ -0,0 +1,118 @@
+#
+# $Id$
+#
+# Copyright (c) 2001 Takaaki Tateishi <[email protected]> and
+# akira yamada <[email protected]>.
+# You can redistribute it and/or modify it under the same term as Ruby.
+#
+
+require 'runit/testcase'
+require 'runit/cui/testrunner'
+require 'uri/ldap'
+module URI
+ class Generic
+ def to_ary
+ component_ary
+ end
+ end
+end
+
+class TestLDAP < RUNIT::TestCase
+ def setup
+ end
+
+ def teardown
+ end
+
+ def test_parse
+ url = 'ldap://ldap.jaist.ac.jp/o=JAIST,c=JP?sn?base?(sn=ttate*)'
+ u = URI.parse(url)
+ assert_kind_of(URI::LDAP, u)
+ assert_equal(url, u.to_s)
+ assert_equal('o=JAIST,c=JP', u.dn)
+ assert_equal('sn', u.attributes)
+ assert_equal('base', u.scope)
+ assert_equal('(sn=ttate*)', u.filter)
+ assert_equal(nil, u.extensions)
+
+ u.scope = URI::LDAP::SCOPE_SUB
+ u.attributes = 'sn,cn,mail'
+ assert_equal('ldap://ldap.jaist.ac.jp/o=JAIST,c=JP?sn,cn,mail?sub?(sn=ttate*)', u.to_s)
+ assert_equal('o=JAIST,c=JP', u.dn)
+ assert_equal('sn,cn,mail', u.attributes)
+ assert_equal('sub', u.scope)
+ assert_equal('(sn=ttate*)', u.filter)
+ assert_equal(nil, u.extensions)
+
+ # from RFC2255, section 6.
+ urls = {
+ 'ldap:///o=University%20of%20Michigan,c=US' =>
+ ['ldap', nil, URI::LDAP::DEFAULT_PORT,
+ 'o=University%20of%20Michigan,c=US',
+ nil, nil, nil, nil],
+
+ 'ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US' =>
+ ['ldap', 'ldap.itd.umich.edu', URI::LDAP::DEFAULT_PORT,
+ 'o=University%20of%20Michigan,c=US',
+ nil, nil, nil, nil],
+
+ 'ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress' =>
+ ['ldap', 'ldap.itd.umich.edu', URI::LDAP::DEFAULT_PORT,
+ 'o=University%20of%20Michigan,c=US',
+ 'postalAddress', nil, nil, nil],
+
+ 'ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)' =>
+ ['ldap', 'host.com', 6666,
+ 'o=University%20of%20Michigan,c=US',
+ nil, 'sub', '(cn=Babs%20Jensen)', nil],
+
+ 'ldap://ldap.itd.umich.edu/c=GB?objectClass?one' =>
+ ['ldap', 'ldap.itd.umich.edu', URI::LDAP::DEFAULT_PORT,
+ 'c=GB',
+ 'objectClass', 'one', nil, nil],
+
+ 'ldap://ldap.question.com/o=Question%3f,c=US?mail' =>
+ ['ldap', 'ldap.question.com', URI::LDAP::DEFAULT_PORT,
+ 'o=Question%3f,c=US',
+ 'mail', nil, nil, nil],
+
+ 'ldap://ldap.netscape.com/o=Babsco,c=US??(int=%5c00%5c00%5c00%5c04)' =>
+ ['ldap', 'ldap.netscape.com', URI::LDAP::DEFAULT_PORT,
+ 'o=Babsco,c=US',
+ nil, '(int=%5c00%5c00%5c00%5c04)', nil, nil],
+
+ 'ldap:///??sub??bindname=cn=Manager%2co=Foo' =>
+ ['ldap', nil, URI::LDAP::DEFAULT_PORT,
+ '',
+ nil, 'sub', nil, 'bindname=cn=Manager%2co=Foo'],
+
+ 'ldap:///??sub??!bindname=cn=Manager%2co=Foo' =>
+ ['ldap', nil, URI::LDAP::DEFAULT_PORT,
+ '',
+ nil, 'sub', nil, '!bindname=cn=Manager%2co=Foo'],
+ }.each do |url, ary|
+ u = URI.parse(url)
+ assert_equal(ary, u.to_ary)
+ end
+ end
+
+ def test_select
+ u = URI.parse('ldap:///??sub??!bindname=cn=Manager%2co=Foo')
+ assert_equal(u.to_ary, u.select(*u.component))
+ assert_exception(ArgumentError) do
+ u.select(:scheme, :host, :not_exist, :port)
+ end
+ end
+end
+
+if $0 == __FILE__
+ if ARGV.size == 0
+ suite = TestLDAP.suite
+ else
+ suite = RUNIT::TestSuite.new
+ ARGV.each do |testmethod|
+ suite.add_test(TestLDAP.new(testmethod))
+ end
+ end
+ RUNIT::CUI::TestRunner.run(suite)
+end
diff --git a/test/uri/test_mailto.rb b/test/uri/test_mailto.rb
new file mode 100644
index 0000000000..4fd1476625
--- /dev/null
+++ b/test/uri/test_mailto.rb
@@ -0,0 +1,139 @@
+#
+# $Id$
+#
+# Copyright (c) 2001 akira yamada <[email protected]>
+# You can redistribute it and/or modify it under the same term as Ruby.
+#
+
+require 'runit/testcase'
+require 'runit/cui/testrunner'
+require 'uri/mailto'
+module URI
+ class Generic
+ def to_ary
+ component_ary
+ end
+ end
+end
+
+class TestMailTo < RUNIT::TestCase
+ def setup
+ @u = URI::MailTo
+ end
+
+ def teardown
+ end
+
+ def test_build
+ ok = []
+ bad = []
+
+ # RFC2368, 6. Examples
+ ok << ["mailto:[email protected]"]
+ ok[-1] << ["[email protected]", nil]
+ ok[-1] << {:to => "[email protected]"}
+
+ # mailto:[email protected]?subject=current-issue
+ ok << ["mailto:[email protected]?subject=current-issue"]
+ ok[-1] << ["[email protected]", ["subject=current-issue"]]
+ ok[-1] << {:to => "[email protected]",
+ :headers => ["subject=current-issue"]}
+
+ # mailto:[email protected]?body=send%20current-issue
+ ok << ["mailto:[email protected]?body=send%20current-issue"]
+ ok[-1] << ["[email protected]", ["body=send%20current-issue"]]
+ ok[-1] << {:to => "[email protected]",
+ :headers => ["body=send%20current-issue"]}
+
+ # mailto:[email protected]?body=send%20current-issue%0D%0Asend%20index
+ ok << ["mailto:[email protected]?body=send%20current-issue%0D%0Asend%20index"]
+ ok[-1] << ["[email protected]",
+ ["body=send%20current-issue%0D%0Asend%20index"]]
+ ok[-1] << {:to => "[email protected]",
+ :headers => ["body=send%20current-issue%0D%0Asend%20index"]}
+
+ # mailto:[email protected]?In-Reply-To=%[email protected]
+ ok << ["mailto:[email protected]?In-Reply-To=%[email protected]"]
+ ok[-1] << ["[email protected]",
+ ["In-Reply-To=%[email protected]"]]
+ ok[-1] << {:to => "[email protected]",
+ :headers => ["In-Reply-To=%[email protected]"]}
+
+ # mailto:[email protected]?body=subscribe%20bamboo-l
+ ok << ["mailto:[email protected]?body=subscribe%20bamboo-l"]
+ ok[-1] << ["[email protected]", ["body=subscribe%20bamboo-l"]]
+ ok[-1] << {:to => "[email protected]",
+ :headers => ["body=subscribe%20bamboo-l"]}
+
+ ok << ["mailto:[email protected][email protected]&body=hello"]
+ ok[-1] << ["[email protected]", ["[email protected]", "body=hello"]]
+ ok[-1] << {:to => "[email protected]",
+ :headers => ["[email protected]", "body=hello"]}
+
+ ok << ["mailto:[email protected]&[email protected]&body=hello"]
+ ok[-1] << [nil,
+ ["[email protected]", "[email protected]", "body=hello"]]
+ ok[-1] << {:headers => ["[email protected]",
+ "[email protected]", "body=hello"]}
+
+ # mailto:gorby%[email protected]
+ ok << ["mailto:gorby%[email protected]"]
+ ok[-1] << ["gorby%[email protected]", nil]
+ ok[-1] << {:to => "gorby%[email protected]"}
+
+ # mailto:unlikely%[email protected]?blat=foop
+ ok << ["mailto:unlikely%[email protected]?blat=foop"]
+ ok[-1] << ["unlikely%[email protected]", ["blat=foop"]]
+ ok[-1] << {:to => "unlikely%[email protected]",
+ :headers => ["blat=foop"]}
+
+ ok_all = ok.flatten.join("\0")
+
+ # mailto:[email protected][email protected]?body=hello ; WRONG!
+ bad << ["[email protected]", ["[email protected]?body=hello"]]
+
+ # mailto:javascript:alert()
+ bad << ["javascript:alert()", []]
+
+ # '=' which is in hname or hvalue is wrong.
+ bad << ["[email protected]?subject=1+1=2", []]
+
+ ok.each do |x|
+ assert_equal(x[0],
+ @u.build(x[1]).to_s)
+ assert_equal(x[0],
+ @u.build(x[2]).to_s)
+ end
+
+ bad.each do |x|
+ assert_exception(URI::InvalidComponentError) {
+ @u.build(x)
+ }
+ end
+
+ assert_equal(ok_all, ok.flatten.join("\0"))
+ end
+
+ def test_select
+ u = URI.parse('mailto:[email protected][email protected]&body=hello')
+ assert_equal(u.to_ary, u.select(*u.component))
+ assert_exception(ArgumentError) do
+ u.select(:scheme, :host, :not_exist, :port)
+ end
+ end
+end
+
+if $0 == __FILE__
+ if ARGV.size == 0
+ suite = TestMailTo.suite
+ else
+ suite = RUNIT::TestSuite.new
+ ARGV.each do |testmethod|
+ suite.add_test(TestMailTo.new(testmethod))
+ end
+ end
+ RUNIT::CUI::TestRunner.run(suite)
+end