Skip to content

Commit

Permalink
Pretty printer test coverage
Browse files Browse the repository at this point in the history
Our output for yield / yield from is currently not very nice, but
also not easy to change.
  • Loading branch information
nikic committed Feb 20, 2016
1 parent 1fe8f09 commit a73aa7e
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 3 deletions.
29 changes: 29 additions & 0 deletions test/code/prettyPrinter/expr/intrinsics.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
isset, empty, unset, exit, die, clone, eval
-----
<?php

isset($a, $a[$b]);
empty($a);
empty('foo');
unset($a, $a[$b]);
exit;
exit();
exit(1);
die;
die();
die("foo");
clone $foo;
eval('str');
-----
isset($a, $a[$b]);
empty($a);
empty('foo');
unset($a, $a[$b]);
die;
die;
die(1);
die;
die;
die('foo');
clone $foo;
eval('str');
11 changes: 11 additions & 0 deletions test/code/prettyPrinter/expr/literals.test
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ b';
'a
b';
}

// shell exec (similar to double quoted string)
`foo`;
`foo$a`;
`foo{$a}bar`;
`\`\'\"`;
-----
// magic constants
__LINE__;
Expand Down Expand Up @@ -153,3 +159,8 @@ b';
'a
b';
}
// shell exec (similar to double quoted string)
`foo`;
`foo{$a}`;
`foo{$a}bar`;
`\`\\'\\"`;
44 changes: 44 additions & 0 deletions test/code/prettyPrinter/expr/yield.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Yield
-----
<?php

function gen()
{
yield;
yield $a;
yield $a => $b;
$a = yield;
$a = (yield $b);
$a = (yield $b => $c);
}
// TODO Get rid of parens for cases 2 and 3
-----
function gen()
{
yield;
(yield $a);
(yield $a => $b);
$a = yield;
$a = (yield $b);
$a = (yield $b => $c);
}
-----
<?php

function gen()
{
$a = yield $b;
$a = yield $b => $c;
yield from $a;
$a = yield from $b;
}
// TODO Get rid of parens for last case
-----
!!php7
function gen()
{
$a = (yield $b);
$a = (yield $b => $c);
yield from $a;
$a = (yield from $b);
}
7 changes: 6 additions & 1 deletion test/code/prettyPrinter/onlyPHP.file-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ echo 'Bar Foo';
<?php

echo 'Foo Bar';
echo 'Bar Foo';
echo 'Bar Foo';
-----
<?php
// avoid trim
-----
<?php
17 changes: 15 additions & 2 deletions test/code/prettyPrinter/stmt/class.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Class
-----
<?php

class Foo
class Foo extends Bar implements ABC, \DEF, namespace\GHI
{
var $a = 'foo';
private $b = 'bar';
Expand All @@ -17,8 +17,15 @@ class Foo
public function foo() {}
abstract static function bar() {}
}

trait Bar
{
function test()
{
}
}
-----
class Foo
class Foo extends Bar implements ABC, \DEF, namespace\GHI
{
var $a = 'foo';
private $b = 'bar';
Expand All @@ -37,4 +44,10 @@ class Foo
static abstract function bar()
{
}
}
trait Bar
{
function test()
{
}
}
11 changes: 11 additions & 0 deletions test/code/prettyPrinter/stmt/const.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Constant declarations
-----
<?php

const FOO = 'BAR';
const FOO = 1 + 1;
const FOO = BAR, BAR = FOO;
-----
const FOO = 'BAR';
const FOO = 1 + 1;
const FOO = BAR, BAR = FOO;
11 changes: 11 additions & 0 deletions test/code/prettyPrinter/stmt/global_static_variables.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Global and static variables
-----
<?php

global $a, $$a, ${$a[$a]};
static $a, $b;
static $a = 'foo', $b = 'bar';
-----
global $a, ${$a}, ${$a[$a]};
static $a, $b;
static $a = 'foo', $b = 'bar';

0 comments on commit a73aa7e

Please sign in to comment.