Class: RubyIndexer::URITest

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/ruby_indexer/test/uri_test.rb

Instance Method Summary collapse

Instance Method Details

#test_allows_adding_require_path_with_load_path_entryObject



64
65
66
67
68
69
70
# File 'lib/ruby_indexer/test/uri_test.rb', line 64

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

#test_from_path_computes_require_path_when_load_path_entry_is_givenObject



59
60
61
62
# File 'lib/ruby_indexer/test/uri_test.rb', line 59

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

#test_from_path_escapes_colon_charactersObject



72
73
74
75
76
# File 'lib/ruby_indexer/test/uri_test.rb', line 72

def test_from_path_escapes_colon_characters
  uri = URI::Generic.from_path(path: "c:/some/windows/path with/spaces/file.rb")
  assert_equal("c:/some/windows/path with/spaces/file.rb", uri.to_standardized_path)
  assert_equal("file:///c%3A/some/windows/path%20with/spaces/file.rb", uri.to_s)
end

#test_from_path_on_unixObject



8
9
10
11
# File 'lib/ruby_indexer/test/uri_test.rb', line 8

def test_from_path_on_unix
  uri = URI::Generic.from_path(path: "/some/unix/path/to/file.rb")
  assert_equal("/some/unix/path/to/file.rb", uri.path)
end

#test_from_path_on_windowsObject



13
14
15
16
# File 'lib/ruby_indexer/test/uri_test.rb', line 13

def test_from_path_on_windows
  uri = URI::Generic.from_path(path: "C:/some/windows/path/to/file.rb")
  assert_equal("/C%3A/some/windows/path/to/file.rb", uri.path)
end

#test_from_path_on_windows_with_lowercase_driveObject



18
19
20
21
# File 'lib/ruby_indexer/test/uri_test.rb', line 18

def test_from_path_on_windows_with_lowercase_drive
  uri = URI::Generic.from_path(path: "c:/some/windows/path/to/file.rb")
  assert_equal("/c%3A/some/windows/path/to/file.rb", uri.path)
end

#test_from_path_windows_long_file_pathsObject



54
55
56
57
# File 'lib/ruby_indexer/test/uri_test.rb', line 54

def test_from_path_windows_long_file_paths
  uri = URI::Generic.from_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_path)
end

#test_from_path_with_fragmentObject



49
50
51
52
# File 'lib/ruby_indexer/test/uri_test.rb', line 49

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

#test_from_path_with_unicode_charactersObject



78
79
80
81
82
83
# File 'lib/ruby_indexer/test/uri_test.rb', line 78

def test_from_path_with_unicode_characters
  path = "/path/with/unicode/文件.rb"
  uri = URI::Generic.from_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

#test_plus_signs_are_properly_unescapedObject



43
44
45
46
47
# File 'lib/ruby_indexer/test/uri_test.rb', line 43

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

#test_to_standardized_path_on_unixObject



23
24
25
26
# File 'lib/ruby_indexer/test/uri_test.rb', line 23

def test_to_standardized_path_on_unix
  uri = URI::Generic.from_path(path: "/some/unix/path/to/file.rb")
  assert_equal(uri.path, uri.to_standardized_path)
end

#test_to_standardized_path_on_windowsObject



28
29
30
31
# File 'lib/ruby_indexer/test/uri_test.rb', line 28

def test_to_standardized_path_on_windows
  uri = URI::Generic.from_path(path: "C:/some/windows/path/to/file.rb")
  assert_equal("C:/some/windows/path/to/file.rb", uri.to_standardized_path)
end

#test_to_standardized_path_on_windows_with_lowercase_driveObject



33
34
35
36
# File 'lib/ruby_indexer/test/uri_test.rb', line 33

def test_to_standardized_path_on_windows_with_lowercase_drive
  uri = URI::Generic.from_path(path: "c:/some/windows/path/to/file.rb")
  assert_equal("c:/some/windows/path/to/file.rb", uri.to_standardized_path)
end

#test_to_standardized_path_on_windows_with_received_uriObject



38
39
40
41
# File 'lib/ruby_indexer/test/uri_test.rb', line 38

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_path)
end