1 # frozen_string_literal: false
5 class URI::TestFile < Test::Unit::TestCase
7 u = URI("file://example.com/file")
8 assert_equal "/file", u.path
10 u = URI("file://localhost/file")
11 assert_equal "/file", u.path
12 assert_equal "file:///file", u.to_s
14 u = URI("file://localhost:30/file")
15 assert_equal "", u.host
16 assert_equal nil, u.port
17 assert_equal "/file", u.path
18 assert_equal "file:///file", u.to_s
20 u = URI("file:///file")
21 assert_equal "/file", u.path
22 assert_equal "file:///file", u.to_s
25 assert_equal "/file", u.path
26 assert_equal "file:///file", u.to_s
28 u = URI("file://foo:pass@example.com/file")
29 assert_equal "/file", u.path
30 assert_equal nil, u.user
31 assert_equal nil, u.password
33 u = URI("file:///c:/path/to/file")
34 assert_equal "/c:/path/to/file", u.path
36 # this form is not supported
37 u = URI("file:c:/path/to/file")
38 assert_equal "c:/path/to/file", u.opaque
43 u = URI::File.build(scheme: "file", host: "example.com", path:"/file")
44 assert_equal "/file", u.path
45 assert_equal "file://example.com/file", u.to_s
46 assert_raise(URI::InvalidURIError){ u.user = "foo" }
47 assert_raise(URI::InvalidURIError){ u.password = "foo" }
48 assert_raise(URI::InvalidURIError){ u.userinfo = "foo" }
49 assert_raise(URI::InvalidURIError){ URI::File.build(scheme: "file", userinfo: "foo", host: "example.com", path:"/file") }
51 u = URI::File.build(scheme: "file", path:"/file")
52 assert_equal "", u.host
53 assert_equal "/file", u.path
54 assert_equal "file:///file", u.to_s
56 u = URI::File.build(scheme: "file", host: "localhost", path:"/file")
57 assert_equal "", u.host
58 assert_equal "/file", u.path
59 assert_equal "file:///file", u.to_s
61 u = URI::File.build(scheme: "file", path:"/file", port: 30)
62 assert_equal "", u.host
63 assert_equal nil, u.port
64 assert_equal "/file", u.path
65 assert_equal "file:///file", u.to_s