-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathuri_test.rb
More file actions
85 lines (69 loc) · 3.35 KB
/
uri_test.rb
File metadata and controls
85 lines (69 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# typed: true
# frozen_string_literal: true
require "test_helper"
module RubyIndexer
class URITest < Minitest::Test
def test_from_path_on_unix
uri = URI::Generic.from_unix_path(path: "/some/unix/path/to/file.rb")
assert_equal("/some/unix/path/to/file.rb", uri.path)
end
def test_from_path_on_windows
uri = URI::Generic.from_win_path(path: "C:/some/windows/path/to/file.rb")
assert_equal("/C%3A/some/windows/path/to/file.rb", uri.path)
end
def test_from_path_on_windows_with_lowercase_drive
uri = URI::Generic.from_win_path(path: "c:/some/windows/path/to/file.rb")
assert_equal("/c%3A/some/windows/path/to/file.rb", uri.path)
end
def test_to_standardized_path_on_unix
uri = URI::Generic.from_unix_path(path: "/some/unix/path/to/file.rb")
assert_equal(uri.path, uri.to_standardized_win_path)
end
def test_to_standardized_path_on_windows
uri = URI::Generic.from_win_path(path: "C:/some/windows/path/to/file.rb")
assert_equal("C:/some/windows/path/to/file.rb", uri.to_standardized_win_path)
end
def test_to_standardized_path_on_windows_with_lowercase_drive
uri = URI::Generic.from_win_path(path: "c:/some/windows/path/to/file.rb")
assert_equal("c:/some/windows/path/to/file.rb", uri.to_standardized_win_path)
end
def test_to_standardized_path_on_windows_with_received_uri
uri = URI("file:///c%3A/some/windows/path/to/file.rb")
assert_equal("c:/some/windows/path/to/file.rb", uri.to_standardized_win_path)
end
def test_plus_signs_are_properly_unescaped
path = "/opt/rubies/3.3.0/lib/ruby/3.3.0+0/pathname.rb"
uri = URI::Generic.from_path(path: path)
assert_equal(path, uri.to_standardized_path)
end
def test_from_path_with_fragment
uri = URI::Generic.from_path(path: "/some/unix/path/to/file.rb", fragment: "L1,3-2,9")
assert_equal("file:///some/unix/path/to/file.rb#L1,3-2,9", uri.to_s)
end
def test_from_path_windows_long_file_paths
uri = URI::Generic.from_win_path(path: "//?/C:/hostedtoolcache/windows/Ruby/3.3.1/x64/lib/ruby/3.3.0/open-uri.rb")
assert_equal("C:/hostedtoolcache/windows/Ruby/3.3.1/x64/lib/ruby/3.3.0/open-uri.rb", uri.to_standardized_win_path)
end
def test_from_path_computes_require_path_when_load_path_entry_is_given
uri = URI::Generic.from_path(path: "/some/unix/path/to/file.rb", load_path_entry: "/some/unix/path")
assert_equal("to/file", uri.require_path)
end
def test_allows_adding_require_path_with_load_path_entry
uri = URI::Generic.from_path(path: "/some/unix/path/to/file.rb")
assert_nil(uri.require_path)
uri.add_require_path_from_load_entry("/some/unix/path")
assert_equal("to/file", uri.require_path)
end
def test_from_path_escapes_colon_characters
uri = URI::Generic.from_win_path(path: "c:/some/windows/path with/spaces/file.rb")
assert_equal("c:/some/windows/path with/spaces/file.rb", uri.to_standardized_win_path)
assert_equal("file:///c%3A/some/windows/path%20with/spaces/file.rb", uri.to_s)
end
def test_from_path_with_unicode_characters
path = "/path/with/unicode/文件.rb"
uri = URI::Generic.from_unix_path(path: path)
assert_equal(path, uri.to_standardized_path)
assert_equal("file:///path/with/unicode/%E6%96%87%E4%BB%B6.rb", uri.to_s)
end
end
end