-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,63 @@ | ||
from LSP.plugin.core.url import (filename_to_uri, uri_to_filename) | ||
from LSP.plugin.core.url import filename_to_uri | ||
from LSP.plugin.core.url import uri_to_filename | ||
from LSP.plugin.core.url import view_to_uri | ||
import sys | ||
import unittest | ||
import unittest.mock | ||
import sublime | ||
import os | ||
|
||
|
||
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") | ||
class WindowsTests(unittest.TestCase): | ||
|
||
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") | ||
def test_converts_path_to_uri(self): | ||
self.assertEqual("file:///C:/dir%20ectory/file.txt", filename_to_uri("c:\\dir ectory\\file.txt")) | ||
|
||
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") | ||
def test_converts_uri_to_path(self): | ||
self.assertEqual("C:\\dir ectory\\file.txt", uri_to_filename("file:///c:/dir ectory/file.txt")) | ||
|
||
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") | ||
def test_converts_encoded_bad_drive_uri_to_path(self): | ||
# url2pathname does not understand %3A | ||
self.assertEqual("C:\\dir ectory\\file.txt", uri_to_filename("file:///c%3A/dir%20ectory/file.txt")) | ||
|
||
def test_view_to_uri_with_valid_filename(self): | ||
view = sublime.active_window().active_view() | ||
assert view | ||
view.file_name = unittest.mock.MagicMock( | ||
return_value="C:\\Users\\A b\\popups.css" | ||
) | ||
uri = view_to_uri(view) | ||
self.assertEqual(uri, "file:///C:/Users/A%20b/popups.css") | ||
|
||
|
||
@unittest.skipIf(sys.platform.startswith("win"), "requires non-Windows") | ||
class NixTests(unittest.TestCase): | ||
|
||
@unittest.skipIf(sys.platform.startswith("win"), "requires non-Windows") | ||
def test_converts_path_to_uri(self): | ||
self.assertEqual("file:///dir%20ectory/file.txt", filename_to_uri("/dir ectory/file.txt")) | ||
|
||
@unittest.skipIf(sys.platform.startswith("win"), "requires non-Windows") | ||
def test_converts_uri_to_path(self): | ||
self.assertEqual("/dir ectory/file.txt", uri_to_filename("file:///dir ectory/file.txt")) | ||
|
||
def test_view_to_uri_with_valid_filename(self): | ||
view = sublime.active_window().active_view() | ||
assert view | ||
view.file_name = unittest.mock.MagicMock(return_value="/foo/bar/baz.txt") | ||
uri = view_to_uri(view) | ||
self.assertEqual(uri, "file:///foo/bar/baz.txt") | ||
|
||
|
||
class MultiplatformTests(unittest.TestCase): | ||
|
||
def test_resource_path(self): | ||
uri = filename_to_uri(os.path.join(sublime.installed_packages_path(), "Package Control", "dir", "file.py")) | ||
self.assertEqual(uri, "res://Packages/Package%20Control/dir/file.py") | ||
|
||
def test_buffer_uri(self): | ||
view = sublime.active_window().active_view() | ||
assert view | ||
view.file_name = unittest.mock.MagicMock(return_value=None) | ||
view.buffer_id = unittest.mock.MagicMock(return_value=42) | ||
uri = view_to_uri(view) | ||
self.assertEqual(uri, "buffer://sublime/42") |