1
0
Fork 0

Use PHP_CodeSniffer as a formatter

pull/35/head
Michal Niewrzal 2016-10-04 13:47:36 +02:00 committed by Felix Becker
parent 8de18847ee
commit 8268d158cd
2 changed files with 19 additions and 23 deletions

View File

@ -41,6 +41,6 @@ function pathToUri(string $filepath): string {
*/ */
function uriToPath(string $uri) function uriToPath(string $uri)
{ {
$path = urldecode(parse_url($uri)['path']); $filepath = urldecode(parse_url($uri)['path']);
return strpos($path, ':') ? str_replace(\DIRECTORY_SEPARATOR, '\\', substr($path, 1)) : $path; return strpos($filepath, ':') === false ? $filepath : str_replace('/', '\\', $filepath);
} }

View File

@ -7,13 +7,7 @@ use PHPUnit\Framework\TestCase;
class FileUriTest extends TestCase class FileUriTest extends TestCase
{ {
public function testSpecialCharsAreEscaped() public function testPathToUri()
{
$uri = \LanguageServer\pathToUri('c:/path/to/file/dürüm döner.php');
$this->assertEquals('file:///c%3A/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php', $uri);
}
public function testUriIsWellFormed()
{ {
$uri = \LanguageServer\pathToUri('var/log'); $uri = \LanguageServer\pathToUri('var/log');
$this->assertEquals('file:///var/log', $uri); $this->assertEquals('file:///var/log', $uri);
@ -26,32 +20,34 @@ class FileUriTest extends TestCase
$uri = \LanguageServer\pathToUri('/d/e/f'); $uri = \LanguageServer\pathToUri('/d/e/f');
$this->assertEquals('file:///d/e/f', $uri); $this->assertEquals('file:///d/e/f', $uri);
}
public function testBackslashesAreTransformed() // special chars are escaped
{ $uri = \LanguageServer\pathToUri('c:/path/to/file/dürüm döner.php');
$this->assertEquals('file:///c%3A/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php', $uri);
//backslashes are transformed
$uri = \LanguageServer\pathToUri('c:\\foo\\bar.baz'); $uri = \LanguageServer\pathToUri('c:\\foo\\bar.baz');
$this->assertEquals('file:///c%3A/foo/bar.baz', $uri); $this->assertEquals('file:///c%3A/foo/bar.baz', $uri);
} }
public function testUriToPath() public function testUriToPath()
{ {
$uri = 'file:///var/log'; $uri = 'file:///var/log';
$this->assertEquals('/var/log', \LanguageServer\uriToPath($uri)); $this->assertEquals('/var/log', \LanguageServer\uriToPath($uri));
$uri = 'file:///usr/local/bin'; $uri = 'file:///usr/local/bin';
$this->assertEquals('/usr/local/bin', \LanguageServer\uriToPath($uri)); $this->assertEquals('/usr/local/bin', \LanguageServer\uriToPath($uri));
$uri = 'file:///d/e/f';
$this->assertEquals('/d/e/f', \LanguageServer\uriToPath($uri));
$uri = 'file:///a/b/c/test.txt'; $uri = 'file:///a/b/c/test.txt';
$this->assertEquals('/a/b/c/test.txt', \LanguageServer\uriToPath($uri)); $this->assertEquals('/a/b/c/test.txt', \LanguageServer\uriToPath($uri));
$uri = 'file:///c%3A/foo/bar.baz'; $uri = 'file:///d/e/f';
$this->assertEquals('c:\\foo\\bar.baz', \LanguageServer\uriToPath($uri)); $this->assertEquals('/d/e/f', \LanguageServer\uriToPath($uri));
$uri = 'file:///c%3A/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php'; $uri = 'file:///c:/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php';
$this->assertEquals('c:\\path\\to\\file\\dürüm döner.php', \LanguageServer\uriToPath($uri)); $this->assertEquals('c:\\path\\to\\file\\dürüm döner.php', \LanguageServer\uriToPath($uri));
$uri = 'file:///c:/foo/bar.baz';
$this->assertEquals('c:\\foo\\bar.baz', \LanguageServer\uriToPath($uri));
} }
} }