1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/uri/test_file.rb
naruse 04883f12c8 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 ]
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
2018-03-15 16:51:31 +00:00

67 lines
2 KiB
Ruby

# 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:pass@example.com/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