diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-15 16:51:31 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-15 16:51:31 +0000 |
commit | 04883f12c8944922117482d4d446502e5d5d3413 (patch) | |
tree | f53ea95a094653f08804dcd0797129c1a96ce1d2 /test | |
parent | 09fb6248389be31975480306654a18cf4cea232a (diff) |
Introduce URI::File to handle file URI scheme
* the default value of URI::File's authority is "" (localhost).
Both nil and "localhost" is normalized to "" by default.
* URI::File ignores setting userinfo and port
[Feature #14035]
fix https://github.com/ruby/ruby/pull/1719
fic https://github.com/ruby/ruby/pull/1832
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/uri/test_file.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/uri/test_file.rb b/test/uri/test_file.rb new file mode 100644 index 0000000000..7e542b652d --- /dev/null +++ b/test/uri/test_file.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: false +require 'test/unit' +require 'uri/file' + +class URI::TestFile < Test::Unit::TestCase + def test_parse + u = URI("file://example.com/file") + assert_equal "/file", u.path + + u = URI("file://localhost/file") + assert_equal "/file", u.path + assert_equal "file:///file", u.to_s + + u = URI("file://localhost:30/file") + assert_equal "", u.host + assert_equal nil, u.port + assert_equal "/file", u.path + assert_equal "file:///file", u.to_s + + u = URI("file:///file") + assert_equal "/file", u.path + assert_equal "file:///file", u.to_s + + u = URI("file:/file") + assert_equal "/file", u.path + assert_equal "file:///file", u.to_s + + u = URI("file://foo:[email protected]/file") + assert_equal "/file", u.path + assert_equal nil, u.user + assert_equal nil, u.password + + u = URI("file:///c:/path/to/file") + assert_equal "/c:/path/to/file", u.path + + # this form is not supported + u = URI("file:c:/path/to/file") + assert_equal "c:/path/to/file", u.opaque + + end + + def test_build + u = URI::File.build(scheme: "file", host: "example.com", path:"/file") + assert_equal "/file", u.path + assert_equal "file://example.com/file", u.to_s + assert_raise(URI::InvalidURIError){ u.user = "foo" } + assert_raise(URI::InvalidURIError){ u.password = "foo" } + assert_raise(URI::InvalidURIError){ u.userinfo = "foo" } + assert_raise(URI::InvalidURIError){ URI::File.build(scheme: "file", userinfo: "foo", host: "example.com", path:"/file") } + + u = URI::File.build(scheme: "file", path:"/file") + assert_equal "", u.host + assert_equal "/file", u.path + assert_equal "file:///file", u.to_s + + u = URI::File.build(scheme: "file", host: "localhost", path:"/file") + assert_equal "", u.host + assert_equal "/file", u.path + assert_equal "file:///file", u.to_s + + u = URI::File.build(scheme: "file", path:"/file", port: 30) + assert_equal "", u.host + assert_equal nil, u.port + assert_equal "/file", u.path + assert_equal "file:///file", u.to_s + end +end |