From ca0fcced20eef89dfbea6f76fcab5b854cc6e870 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Mon, 19 Sep 2016 23:57:29 +0200 Subject: [PATCH] Added tests for pathToUri and findFilesRecursive --- fixtures/recursive/a.txt | 1 + fixtures/recursive/search/b.txt | 1 + fixtures/recursive/search/here/c.txt | 1 + src/utils.php | 62 +++++++++++++------------ tests/Utils/FileUriTest.php | 36 ++++++++++++++ tests/Utils/RecursiveFileSearchTest.php | 21 +++++++++ 6 files changed, 92 insertions(+), 30 deletions(-) create mode 100644 fixtures/recursive/a.txt create mode 100644 fixtures/recursive/search/b.txt create mode 100644 fixtures/recursive/search/here/c.txt create mode 100644 tests/Utils/FileUriTest.php create mode 100644 tests/Utils/RecursiveFileSearchTest.php diff --git a/fixtures/recursive/a.txt b/fixtures/recursive/a.txt new file mode 100644 index 0000000..8c7e5a6 --- /dev/null +++ b/fixtures/recursive/a.txt @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/fixtures/recursive/search/b.txt b/fixtures/recursive/search/b.txt new file mode 100644 index 0000000..7371f47 --- /dev/null +++ b/fixtures/recursive/search/b.txt @@ -0,0 +1 @@ +B \ No newline at end of file diff --git a/fixtures/recursive/search/here/c.txt b/fixtures/recursive/search/here/c.txt new file mode 100644 index 0000000..d5274b3 --- /dev/null +++ b/fixtures/recursive/search/here/c.txt @@ -0,0 +1 @@ +Peeakboo! \ No newline at end of file diff --git a/src/utils.php b/src/utils.php index 2743439..2d62dc0 100644 --- a/src/utils.php +++ b/src/utils.php @@ -1,31 +1,33 @@ -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'); + $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/'); + $this->assertEquals('file:///a/b/c', $uri); + + $uri = \LanguageServer\pathToUri('/d/e/f'); + $this->assertEquals('file:///d/e/f', $uri); + } + + public function testBackslashesAreTransformed() + { + $uri = \LanguageServer\pathToUri('c:\\foo\\bar.baz'); + $this->assertEquals('file:///c%3A/foo/bar.baz', $uri); + } +} diff --git a/tests/Utils/RecursiveFileSearchTest.php b/tests/Utils/RecursiveFileSearchTest.php new file mode 100644 index 0000000..bcefbdc --- /dev/null +++ b/tests/Utils/RecursiveFileSearchTest.php @@ -0,0 +1,21 @@ +assertEquals([ + $path . DIRECTORY_SEPARATOR . 'a.txt', + $path . DIRECTORY_SEPARATOR . 'search' . DIRECTORY_SEPARATOR . 'b.txt', + $path . DIRECTORY_SEPARATOR . 'search' . DIRECTORY_SEPARATOR . 'here' . DIRECTORY_SEPARATOR . 'c.txt', + ], $files); + } +}