2016-09-30 09:30:08 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace LanguageServer\Tests\Utils;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class FileUriTest extends TestCase
|
|
|
|
{
|
2016-10-04 11:47:36 +00:00
|
|
|
public function testPathToUri()
|
2016-09-30 09:30:08 +00:00
|
|
|
{
|
|
|
|
$uri = \LanguageServer\pathToUri('var/log');
|
|
|
|
$this->assertEquals('file:///var/log', $uri);
|
|
|
|
|
|
|
|
$uri = \LanguageServer\pathToUri('/usr/local/bin');
|
|
|
|
$this->assertEquals('file:///usr/local/bin', $uri);
|
|
|
|
|
|
|
|
$uri = \LanguageServer\pathToUri('a/b/c/test.txt');
|
|
|
|
$this->assertEquals('file:///a/b/c/test.txt', $uri);
|
|
|
|
|
|
|
|
$uri = \LanguageServer\pathToUri('/d/e/f');
|
|
|
|
$this->assertEquals('file:///d/e/f', $uri);
|
|
|
|
|
2016-10-04 11:47:36 +00:00
|
|
|
// 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
|
2016-09-30 09:30:08 +00:00
|
|
|
$uri = \LanguageServer\pathToUri('c:\\foo\\bar.baz');
|
|
|
|
$this->assertEquals('file:///c%3A/foo/bar.baz', $uri);
|
|
|
|
}
|
2016-10-04 11:47:36 +00:00
|
|
|
|
2016-10-04 09:53:50 +00:00
|
|
|
public function testUriToPath()
|
2016-09-30 11:08:52 +00:00
|
|
|
{
|
2016-10-04 09:53:50 +00:00
|
|
|
$uri = 'file:///var/log';
|
|
|
|
$this->assertEquals('/var/log', \LanguageServer\uriToPath($uri));
|
2016-10-04 11:47:36 +00:00
|
|
|
|
2016-10-04 09:53:50 +00:00
|
|
|
$uri = 'file:///usr/local/bin';
|
|
|
|
$this->assertEquals('/usr/local/bin', \LanguageServer\uriToPath($uri));
|
2016-10-04 11:47:36 +00:00
|
|
|
|
2016-10-04 09:53:50 +00:00
|
|
|
$uri = 'file:///a/b/c/test.txt';
|
|
|
|
$this->assertEquals('/a/b/c/test.txt', \LanguageServer\uriToPath($uri));
|
2016-10-04 11:47:36 +00:00
|
|
|
|
|
|
|
$uri = 'file:///d/e/f';
|
|
|
|
$this->assertEquals('/d/e/f', \LanguageServer\uriToPath($uri));
|
|
|
|
|
|
|
|
$uri = 'file:///c:/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php';
|
2016-10-04 09:53:50 +00:00
|
|
|
$this->assertEquals('c:\\path\\to\\file\\dürüm döner.php', \LanguageServer\uriToPath($uri));
|
2016-10-04 11:47:36 +00:00
|
|
|
|
|
|
|
$uri = 'file:///c:/foo/bar.baz';
|
|
|
|
$this->assertEquals('c:\\foo\\bar.baz', \LanguageServer\uriToPath($uri));
|
2016-09-30 11:08:52 +00:00
|
|
|
}
|
2016-09-30 09:30:08 +00:00
|
|
|
}
|