X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Ftest%2FPsy%2FTest%2FCodeCleaner%2FNamespacePassTest.php;fp=vendor%2Fpsy%2Fpsysh%2Ftest%2FPsy%2FTest%2FCodeCleaner%2FNamespacePassTest.php;h=553a699a76ce8601f14932b3014645ac74ef8f92;hp=0000000000000000000000000000000000000000;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae diff --git a/vendor/psy/psysh/test/Psy/Test/CodeCleaner/NamespacePassTest.php b/vendor/psy/psysh/test/Psy/Test/CodeCleaner/NamespacePassTest.php new file mode 100644 index 000000000..553a699a7 --- /dev/null +++ b/vendor/psy/psysh/test/Psy/Test/CodeCleaner/NamespacePassTest.php @@ -0,0 +1,56 @@ +cleaner = new CodeCleaner(); + $this->setPass(new NamespacePass($this->cleaner)); + } + + public function testProcess() + { + $this->process('array_merge()'); + $this->assertNull($this->cleaner->getNamespace()); + + // A non-block namespace statement should set the current namespace. + $this->process('namespace Alpha'); + $this->assertEquals(array('Alpha'), $this->cleaner->getNamespace()); + + // A new non-block namespace statement should override the current namespace. + $this->process('namespace Beta; class B {}'); + $this->assertEquals(array('Beta'), $this->cleaner->getNamespace()); + + // @todo Figure out if we can detect when the last namespace block is + // bracketed or unbracketed, because this should really clear the + // namespace at the end... + $this->process('namespace Gamma { array_merge(); }'); + $this->assertEquals(array('Gamma'), $this->cleaner->getNamespace()); + + // A null namespace clears out the current namespace. + $this->process('namespace { array_merge(); }'); + $this->assertNull($this->cleaner->getNamespace()); + } + + private function process($code) + { + $stmts = $this->parse($code); + $this->traverse($stmts); + } +}