Skip to content
Browse files

Added customizable newline character, defaulted new single linefeed (…

…fixes #8)
  • Loading branch information...
1 parent fc0201c commit 1aea667018f38ac10305be2d6e8966d5affa088e @jmalloc jmalloc committed Jan 14, 2013
Showing with 156 additions and 152 deletions.
  1. +38 −36 lib/Icecave/Rasta/Renderer.php
  2. +118 −116 test/suite/Icecave/Rasta/RendererTest.php
View
74 lib/Icecave/Rasta/Renderer.php
@@ -100,10 +100,11 @@
class Renderer implements IVisitor
{
- public function __construct($indentString = ' ')
+ public function __construct($indentString = ' ', $newlineString = "\n")
{
$this->indentString = $indentString;
$this->indentLevel = 0;
+ $this->newlineString = $newlineString;
$this->isInterfaceScope = false;
}
@@ -128,7 +129,7 @@ public function visitGlobalFunction(GlobalFunction $node)
foreach ($node->parameters() as $parameter) {
$parameters[] = $parameter->accept($this);
}
- $code = $this->indent('function ' . $node->name()->accept($this) . '(' . implode(', ', $parameters) . ')' . PHP_EOL);
+ $code = $this->indent('function ' . $node->name()->accept($this) . '(' . implode(', ', $parameters) . ')' . $this->newlineString);
$code .= $node->statementBlock()->accept($this);
return $code;
@@ -166,7 +167,7 @@ public function visitPhpBlock(PhpBlock $node, $closeTag = true)
if (!$node->isShortTag()) {
$code .= 'php';
}
- $code .= PHP_EOL;
+ $code .= $this->newlineString;
$code .= $this->visitChildren($node);
if ($closeTag) {
$code .= '?>';
@@ -178,10 +179,10 @@ public function visitPhpBlock(PhpBlock $node, $closeTag = true)
public function visitBreakStatement(BreakStatement $node)
{
if (1 === $node->depth()) {
- $code = 'break;' . PHP_EOL;
+ $code = 'break;' . $this->newlineString;
} else {
$code = sprintf(
- 'break %d;' . PHP_EOL,
+ 'break %d;' . $this->newlineString,
$node->depth()
);
}
@@ -192,10 +193,10 @@ public function visitBreakStatement(BreakStatement $node)
public function visitContinueStatement(ContinueStatement $node)
{
if (1 === $node->depth()) {
- $code = 'continue;' . PHP_EOL;
+ $code = 'continue;' . $this->newlineString;
} else {
$code = sprintf(
- 'continue %d;' . PHP_EOL,
+ 'continue %d;' . $this->newlineString,
$node->depth()
);
}
@@ -207,14 +208,14 @@ public function visitDoWhileStatement(DoWhileStatement $node)
{
$code = $this->indent('do ');
$code .= $this->generateStatementCode($node->statement());
- $code .= ' while (' . $node->conditionExpression()->accept($this) . ');' . PHP_EOL;
+ $code .= ' while (' . $node->conditionExpression()->accept($this) . ');' . $this->newlineString;
return $code;
}
public function visitExpressionStatement(ExpressionStatement $node)
{
- return $this->indent($node->expression()->accept($this) . ';' . PHP_EOL);
+ return $this->indent($node->expression()->accept($this) . ';' . $this->newlineString);
}
public function visitForeachStatement(ForeachStatement $node)
@@ -226,7 +227,7 @@ public function visitForeachStatement(ForeachStatement $node)
}
$code = $this->indent('foreach (' . $node->sequence()->accept($this) . ' as ' . $unpack . ') ');
$code .= $this->generateStatementCode($node->statement());
- $code .= PHP_EOL;
+ $code .= $this->newlineString;
return $code;
}
@@ -251,7 +252,7 @@ public function visitForStatement(ForStatement $node)
$code = $this->indent('for (' . $init . ';' . $cond . ';' . $iter . ') ');
$code .= $this->generateStatementCode($node->statement());
- $code .= PHP_EOL;
+ $code .= $this->newlineString;
return $code;
}
@@ -268,17 +269,17 @@ public function visitIfStatement(IfStatement $node)
} elseif ($statement) {
$code .= ' else ';
$code .= $this->generateStatementCode($statement);
- $code .= PHP_EOL;
+ $code .= $this->newlineString;
} else {
- $code .= PHP_EOL;
+ $code .= $this->newlineString;
}
return $code;
}
public function visitNamespaceStatement(NamespaceStatement $node)
{
- return $this->indent('namespace ' . $node->name()->accept($this) . ';' . PHP_EOL . PHP_EOL);
+ return $this->indent('namespace ' . $node->name()->accept($this) . ';' . $this->newlineString . $this->newlineString);
}
public function visitReturnStatement(ReturnStatement $node)
@@ -288,15 +289,15 @@ public function visitReturnStatement(ReturnStatement $node)
$expression = ' ' . $expr->accept($this);
}
- return $this->indent('return' . $expression . ';' . PHP_EOL);
+ return $this->indent('return' . $expression . ';' . $this->newlineString);
}
public function visitStatementBlock(StatementBlock $node, $isStandalone = true)
{
if ($isStandalone) {
- $code = $this->indent('{' . PHP_EOL);
+ $code = $this->indent('{' . $this->newlineString);
} else {
- $code = '{' . PHP_EOL;
+ $code = '{' . $this->newlineString;
}
if ($node->children()) {
@@ -306,7 +307,7 @@ public function visitStatementBlock(StatementBlock $node, $isStandalone = true)
}
if ($isStandalone) {
- $code .= $this->indent('}' . PHP_EOL);
+ $code .= $this->indent('}' . $this->newlineString);
} else {
$code .= $this->indent('}');
}
@@ -316,7 +317,7 @@ public function visitStatementBlock(StatementBlock $node, $isStandalone = true)
public function visitThrowStatement(ThrowStatement $node)
{
- return $this->indent('throw ' . $node->expression()->accept($this) . ';' . PHP_EOL);
+ return $this->indent('throw ' . $node->expression()->accept($this) . ';' . $this->newlineString);
}
public function visitUseStatement(UseStatement $node)
@@ -325,7 +326,7 @@ public function visitUseStatement(UseStatement $node)
if ($alias = $node->alias()) {
$code .= ' as ' . $alias->accept($this);
}
- $code .= ';' . PHP_EOL;
+ $code .= ';' . $this->newlineString;
return $code;
}
@@ -334,7 +335,7 @@ public function visitWhileStatement(WhileStatement $node)
{
$code = $this->indent('while (' . $node->conditionExpression()->accept($this) . ') ');
$code .= $this->generateStatementCode($node->statement());
- $code .= PHP_EOL;
+ $code .= $this->newlineString;
return $code;
}
@@ -364,7 +365,7 @@ public function visitAbstractMethod(AbstractMethod $node)
$abstractKeyword = 'abstract ';
}
- return $this->indent($abstractKeyword . $node->accessModifier()->value() . ' function ' . $node->name()->accept($this) . '(' . implode(', ', $parameters) . ');' . PHP_EOL);
+ return $this->indent($abstractKeyword . $node->accessModifier()->value() . ' function ' . $node->name()->accept($this) . '(' . implode(', ', $parameters) . ');' . $this->newlineString);
}
public function visitClassDefinition(ClassDefinition $node)
@@ -388,13 +389,13 @@ public function visitClassDefinition(ClassDefinition $node)
$implements = ' implements ' . implode(', ', $interfaceNames);
}
- $code = PHP_EOL;
- $code .= $this->indent($modifier . 'class ' . $node->name()->accept($this) . $extends . $implements . PHP_EOL);
- $code .= $this->indent('{' . PHP_EOL);
+ $code = $this->newlineString;
+ $code .= $this->indent($modifier . 'class ' . $node->name()->accept($this) . $extends . $implements . $this->newlineString);
+ $code .= $this->indent('{' . $this->newlineString);
$this->startIndent();
$code .= $this->visitChildren($node);
$this->endIndent();
- $code .= $this->indent('}' . PHP_EOL);
+ $code .= $this->indent('}' . $this->newlineString);
return $code;
}
@@ -411,7 +412,7 @@ public function visitConcreteMethod(ConcreteMethod $node)
$modifiers[] = 'static';
}
- $code = $this->indent(implode(' ', $modifiers) . ' function ' . $node->name()->accept($this) . '(' . implode(', ', $parameters) . ')' . PHP_EOL);
+ $code = $this->indent(implode(' ', $modifiers) . ' function ' . $node->name()->accept($this) . '(' . implode(', ', $parameters) . ')' . $this->newlineString);
$code .= $node->statementBlock()->accept($this);
return $code;
@@ -433,7 +434,7 @@ public function visitProperty(Property $node)
);
}
- $code .= ';' . PHP_EOL;
+ $code .= ';' . $this->newlineString;
return $this->indent($code);
}
@@ -445,14 +446,14 @@ public function visitInterfaceDefinition(InterfaceDefinition $node)
$extends .= ' extends ' . $parent->accept($this);
}
- $code = PHP_EOL;
- $code .= $this->indent('interface ' . $node->name()->accept($this) . $extends . PHP_EOL);
+ $code = $this->newlineString;
+ $code .= $this->indent('interface ' . $node->name()->accept($this) . $extends . $this->newlineString);
$this->isInterfaceScope = true;
- $code .= $this->indent('{' . PHP_EOL);
+ $code .= $this->indent('{' . $this->newlineString);
$this->startIndent();
$code .= $this->visitChildren($node);
$this->endIndent();
- $code .= $this->indent('}' . PHP_EOL);
+ $code .= $this->indent('}' . $this->newlineString);
$this->isInterfaceScope = false;
return $code;
@@ -471,7 +472,7 @@ public function visitCall(Call $node)
$code = $argument->accept($this);
// Switch to multiline if any of the arguments contain multiple lines ...
- if ($inline && false !== strpos($code, PHP_EOL)) {
+ if ($inline && false !== strpos($code, $this->newlineString)) {
$inline = false;
}
@@ -483,8 +484,8 @@ public function visitCall(Call $node)
if ($inline) {
$code = $name . '(' . implode(', ', $renderedArguments) . ')';
} else {
- $argumentCode = implode(',' . PHP_EOL, $renderedArguments) . PHP_EOL;
- $code = $name . '(' . PHP_EOL;
+ $argumentCode = implode(',' . $this->newlineString, $renderedArguments) . $this->newlineString;
+ $code = $name . '(' . $this->newlineString;
$code .= $this->indent($argumentCode, 1);
$code .= ')';
}
@@ -541,7 +542,7 @@ public function visitClosure(Closure $node)
$use = ' use ' . '(' . implode(', ', $closureParameters) . ')';
}
- $code = 'function (' . implode(', ', $parameters) . ')' . $use . ' {' . PHP_EOL;
+ $code = 'function (' . implode(', ', $parameters) . ')' . $use . ' {' . $this->newlineString;
$code .= $this->visitChildren($node->statementBlock());
$code .= '}';
@@ -915,5 +916,6 @@ protected function generateStatementCode(IStatement $node, $addBraces = true)
private $indentString;
private $indentLevel;
+ private $newlineString;
private $isInterfaceScope;
}
View
234 test/suite/Icecave/Rasta/RendererTest.php
@@ -50,7 +50,9 @@ class RendererTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
- $this->_renderer = new Renderer;
+ $this->_indentString = ' ';
+ $this->_newlineString = "\r\n";
+ $this->_renderer = new Renderer($this->_indentString, $this->_newlineString);
}
public function testVisitContentBlock()
@@ -80,9 +82,9 @@ public function testVisitGlobalFunction()
$node->addParameter(new Parameter(new Identifier('param')));
$code = $node->accept($this->_renderer);
- $expected = 'function func($param)' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'function func($param)' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -126,42 +128,42 @@ public function testVisitPhpBlock()
{
$node = new PhpBlock;
$code = $node->accept($this->_renderer);
- $this->assertSame('<' . '?php' . PHP_EOL . '?' . '>', $code);
+ $this->assertSame('<' . '?php' . $this->_newlineString . '?' . '>', $code);
}
public function testVisitPhpBlockShortTag()
{
$node = new PhpBlock(true);
$code = $node->accept($this->_renderer);
- $this->assertSame('<' . '?' . PHP_EOL . '?' . '>', $code);
+ $this->assertSame('<' . '?' . $this->_newlineString . '?' . '>', $code);
}
public function testVisitBreakStatement()
{
$node = new BreakStatement;
$code = $node->accept($this->_renderer);
- $this->assertSame('break;' . PHP_EOL, $code);
+ $this->assertSame('break;' . $this->_newlineString, $code);
}
public function testVisitBreakStatementWithDepth()
{
$node = new BreakStatement(111);
$code = $node->accept($this->_renderer);
- $this->assertSame('break 111;' . PHP_EOL, $code);
+ $this->assertSame('break 111;' . $this->_newlineString, $code);
}
public function testVisitContinueStatement()
{
$node = new ContinueStatement;
$code = $node->accept($this->_renderer);
- $this->assertSame('continue;' . PHP_EOL, $code);
+ $this->assertSame('continue;' . $this->_newlineString, $code);
}
public function testVisitContinueStatementWithDepth()
{
$node = new ContinueStatement(111);
$code = $node->accept($this->_renderer);
- $this->assertSame('continue 111;' . PHP_EOL, $code);
+ $this->assertSame('continue 111;' . $this->_newlineString, $code);
}
public function testVisitDoWhileStatement()
@@ -172,16 +174,16 @@ public function testVisitDoWhileStatement()
);
$code = $node->accept($this->_renderer);
- $expected = 'do {' . PHP_EOL;
- $expected .= '} while (true);' . PHP_EOL;
+ $expected = 'do {' . $this->_newlineString;
+ $expected .= '} while (true);' . $this->_newlineString;
$this->assertSame($expected, $code);
}
public function testVisitExpressionStatement()
{
$node = new ExpressionStatement(new Literal(123));
$code = $node->accept($this->_renderer);
- $this->assertSame('123;' . PHP_EOL, $code);
+ $this->assertSame('123;' . $this->_newlineString, $code);
}
public function testVisitForeachStatement()
@@ -194,8 +196,8 @@ public function testVisitForeachStatement()
);
$code = $node->accept($this->_renderer);
- $expected = 'foreach ($thing as $theKey => $theValue) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'foreach ($thing as $theKey => $theValue) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -209,8 +211,8 @@ public function testVisitForeachStatementWithoutKey()
);
$code = $node->accept($this->_renderer);
- $expected = 'foreach ($thing as $theValue) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'foreach ($thing as $theValue) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -224,8 +226,8 @@ public function testVisitForStatement()
);
$code = $node->accept($this->_renderer);
- $expected = 'for (1; 2; 3) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'for (1; 2; 3) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -240,8 +242,8 @@ public function testVisitForStatementWithOnlyInitializeExpression()
);
$code = $node->accept($this->_renderer);
- $expected = 'for (1;;) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'for (1;;) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -256,8 +258,8 @@ public function testVisitForStatementWithOnlyConditionExpression()
);
$code = $node->accept($this->_renderer);
- $expected = 'for (; 2;) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'for (; 2;) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -272,8 +274,8 @@ public function testVisitForStatementWithOnlyIterationExpression()
);
$code = $node->accept($this->_renderer);
- $expected = 'for (;; 3) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'for (;; 3) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -288,8 +290,8 @@ public function testVisitForStatementWithNoExpressions()
);
$code = $node->accept($this->_renderer);
- $expected = 'for (;;) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'for (;;) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -298,8 +300,8 @@ public function testVisitIfStatement()
$node = new IfStatement(new Literal(true));
$code = $node->accept($this->_renderer);
- $expected = 'if (true) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'if (true) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -312,9 +314,9 @@ public function testVisitIfStatementElse()
);
$code = $node->accept($this->_renderer);
- $expected = 'if (true) {' . PHP_EOL;
- $expected .= '} else {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'if (true) {' . $this->_newlineString;
+ $expected .= '} else {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -327,9 +329,9 @@ public function testVisitIfStatementElseIf()
);
$code = $node->accept($this->_renderer);
- $expected = 'if (true) {' . PHP_EOL;
- $expected .= '} elseif (false) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'if (true) {' . $this->_newlineString;
+ $expected .= '} elseif (false) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -341,9 +343,9 @@ public function testVisitIfStatementSingleStatement()
);
$code = $node->accept($this->_renderer);
- $expected = 'if (true) {' . PHP_EOL;
- $expected .= ' foo();' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'if (true) {' . $this->_newlineString;
+ $expected .= ' foo();' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -356,11 +358,11 @@ public function testVisitIfStatementElseSingleStatement()
);
$code = $node->accept($this->_renderer);
- $expected = 'if (true) {' . PHP_EOL;
- $expected .= ' foo();' . PHP_EOL;
- $expected .= '} else {' . PHP_EOL;
- $expected .= ' bar();' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'if (true) {' . $this->_newlineString;
+ $expected .= ' foo();' . $this->_newlineString;
+ $expected .= '} else {' . $this->_newlineString;
+ $expected .= ' bar();' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -378,21 +380,21 @@ public function testVisitNamespaceStatement()
{
$node = new NamespaceStatement(QualifiedIdentifier::fromString('Foo\Bar\Spam'));
$code = $node->accept($this->_renderer);
- $this->assertSame('namespace Foo\Bar\Spam;' . PHP_EOL . PHP_EOL, $code);
+ $this->assertSame('namespace Foo\Bar\Spam;' . $this->_newlineString . $this->_newlineString, $code);
}
public function testVisitReturnStatement()
{
$node = new ReturnStatement;
$code = $node->accept($this->_renderer);
- $this->assertSame('return;' . PHP_EOL, $code);
+ $this->assertSame('return;' . $this->_newlineString, $code);
}
public function testVisitReturnStatementWithExpression()
{
$node = new ReturnStatement(new Literal(123));
$code = $node->accept($this->_renderer);
- $this->assertSame('return 123;' . PHP_EOL, $code);
+ $this->assertSame('return 123;' . $this->_newlineString, $code);
}
public function testVisitStatementBlock()
@@ -403,9 +405,9 @@ public function testVisitStatementBlock()
);
$code = $node->accept($this->_renderer);
- $expected = '{' . PHP_EOL;
- $expected .= ' foo();' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = '{' . $this->_newlineString;
+ $expected .= ' foo();' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -414,8 +416,8 @@ public function testVisitStatementBlockEmpty()
$node = new StatementBlock;
$code = $node->accept($this->_renderer);
- $expected = '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -433,14 +435,14 @@ public function testVisitThrowStatement()
{
$node = new ThrowStatement(new Literal(123));
$code = $node->accept($this->_renderer);
- $this->assertSame('throw 123;' . PHP_EOL, $code);
+ $this->assertSame('throw 123;' . $this->_newlineString, $code);
}
public function testVisitUseStatement()
{
$node = new UseStatement(QualifiedIdentifier::fromString('Foo\Bar\Spam'));
$code = $node->accept($this->_renderer);
- $this->assertSame('use Foo\Bar\Spam;' . PHP_EOL, $code);
+ $this->assertSame('use Foo\Bar\Spam;' . $this->_newlineString, $code);
}
public function testVisitWhileStatement()
@@ -451,16 +453,16 @@ public function testVisitWhileStatement()
);
$code = $node->accept($this->_renderer);
- $expected = 'while (true) {' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'while (true) {' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
public function testVisitUseStatementWithAlias()
{
$node = new UseStatement(QualifiedIdentifier::fromString('Foo\Bar\Spam'), new Identifier('Alias'));
$code = $node->accept($this->_renderer);
- $this->assertSame('use Foo\Bar\Spam as Alias;' . PHP_EOL, $code);
+ $this->assertSame('use Foo\Bar\Spam as Alias;' . $this->_newlineString, $code);
}
public function testVisitSyntaxTree()
@@ -483,7 +485,7 @@ public function testVisitSyntaxTreeWithSinglePhpBlock()
$node = new SyntaxTree;
$node->add(new PhpBlock);
$code = $node->accept($this->_renderer);
- $this->assertSame('<' . '?php' . PHP_EOL, $code);
+ $this->assertSame('<' . '?php' . $this->_newlineString, $code);
}
public function testVisitAbstractMethod()
@@ -492,7 +494,7 @@ public function testVisitAbstractMethod()
$node->addParameter(new Parameter(new Identifier('param')));
$code = $node->accept($this->_renderer);
- $expected = 'abstract public function func($param);' . PHP_EOL;
+ $expected = 'abstract public function func($param);' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -501,10 +503,10 @@ public function testVisitClassDefinition()
$node = new ClassDefinition(new Identifier('Thing'));
$code = $node->accept($this->_renderer);
- $expected = PHP_EOL;
- $expected .= 'class Thing' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = $this->_newlineString;
+ $expected .= 'class Thing' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -514,10 +516,10 @@ public function testVisitClassDefinitionWithParent()
$node->setParentName(QualifiedIdentifier::fromString('ParentThing'));
$code = $node->accept($this->_renderer);
- $expected = PHP_EOL;
- $expected .= 'class Thing extends ParentThing' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = $this->_newlineString;
+ $expected .= 'class Thing extends ParentThing' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -529,10 +531,10 @@ public function testVisitClassDefinitionWithParentAndInterfaces()
$node->addInterface(QualifiedIdentifier::fromString('IBar'));
$code = $node->accept($this->_renderer);
- $expected = PHP_EOL;
- $expected .= 'class Thing extends ParentThing implements IFoo, IBar' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = $this->_newlineString;
+ $expected .= 'class Thing extends ParentThing implements IFoo, IBar' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -541,10 +543,10 @@ public function testVisitClassDefinitionAbstract()
$node = new ClassDefinition(new Identifier('Thing'), ClassModifier::ABSTRACT_());
$code = $node->accept($this->_renderer);
- $expected = PHP_EOL;
- $expected .= 'abstract class Thing' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = $this->_newlineString;
+ $expected .= 'abstract class Thing' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -553,10 +555,10 @@ public function testVisitClassDefinitionFinal()
$node = new ClassDefinition(new Identifier('Thing'), ClassModifier::FINAL_());
$code = $node->accept($this->_renderer);
- $expected = PHP_EOL;
- $expected .= 'final class Thing' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = $this->_newlineString;
+ $expected .= 'final class Thing' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -566,9 +568,9 @@ public function testVisitConcreteMethod()
$node->addParameter(new Parameter(new Identifier('param')));
$code = $node->accept($this->_renderer);
- $expected = 'public function func($param)' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'public function func($param)' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -578,9 +580,9 @@ public function testVisitConcreteMethodStatic()
$node->addParameter(new Parameter(new Identifier('param')));
$code = $node->accept($this->_renderer);
- $expected = 'protected static function func($param)' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = 'protected static function func($param)' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -589,7 +591,7 @@ public function testVisitProperty()
$node = new Property(new Identifier('property'));
$code = $node->accept($this->_renderer);
- $expected = 'private $property;' . PHP_EOL;
+ $expected = 'private $property;' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -598,7 +600,7 @@ public function testVisitPropertyStatic()
$node = new Property(new Identifier('property'), AccessModifier::PROTECTED_(), true);
$code = $node->accept($this->_renderer);
- $expected = 'protected static $property;' . PHP_EOL;
+ $expected = 'protected static $property;' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -608,7 +610,7 @@ public function testVisitPropertyDefault()
$node->setDefaultValue(new Literal('<default>'));
$code = $node->accept($this->_renderer);
- $expected = 'private $property = \'<default>\';' . PHP_EOL;
+ $expected = 'private $property = \'<default>\';' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -618,11 +620,11 @@ public function testVisitInterfaceDefinition()
$node->add(new AbstractMethod(new Identifier('thing')));
$code = $node->accept($this->_renderer);
- $expected = PHP_EOL;
- $expected .= 'interface IThing' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= ' public function thing();' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = $this->_newlineString;
+ $expected .= 'interface IThing' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= ' public function thing();' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -632,10 +634,10 @@ public function testVisitInterfaceDefinitionWithParent()
$node->setParentName(QualifiedIdentifier::fromString('ParentThing'));
$code = $node->accept($this->_renderer);
- $expected = PHP_EOL;
- $expected .= 'interface IThing extends ParentThing' . PHP_EOL;
- $expected .= '{' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = $this->_newlineString;
+ $expected .= 'interface IThing extends ParentThing' . $this->_newlineString;
+ $expected .= '{' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}
@@ -667,11 +669,11 @@ public function testVisitCallMultilineDueToArity()
$node->add(new Literal(4));
$code = $node->accept($this->_renderer);
- $expected = 'foo(' . PHP_EOL;
- $expected .= ' 1,' . PHP_EOL;
- $expected .= ' 2,' . PHP_EOL;
- $expected .= ' 3,' . PHP_EOL;
- $expected .= ' 4' . PHP_EOL;
+ $expected = 'foo(' . $this->_newlineString;
+ $expected .= ' 1,' . $this->_newlineString;
+ $expected .= ' 2,' . $this->_newlineString;
+ $expected .= ' 3,' . $this->_newlineString;
+ $expected .= ' 4' . $this->_newlineString;
$expected .= ')';
$this->assertSame($expected, $code);
}
@@ -689,13 +691,13 @@ public function testVisitCallMultilineDueToNestedMultiline()
$code = $node->accept($this->_renderer);
- $expected = 'foo(' . PHP_EOL;
- $expected .= ' bar(' . PHP_EOL;
- $expected .= ' 1,' . PHP_EOL;
- $expected .= ' 2,' . PHP_EOL;
- $expected .= ' 3,' . PHP_EOL;
- $expected .= ' 4' . PHP_EOL;
- $expected .= ' )' . PHP_EOL;
+ $expected = 'foo(' . $this->_newlineString;
+ $expected .= ' bar(' . $this->_newlineString;
+ $expected .= ' 1,' . $this->_newlineString;
+ $expected .= ' 2,' . $this->_newlineString;
+ $expected .= ' 3,' . $this->_newlineString;
+ $expected .= ' 4' . $this->_newlineString;
+ $expected .= ' )' . $this->_newlineString;
$expected .= ')';
$this->assertSame($expected, $code);
}
@@ -772,8 +774,8 @@ public function testVisitClosure()
);
$code = $node->accept($this->_renderer);
- $expected = 'function ($param) {' . PHP_EOL;
- $expected .= 'foo();' . PHP_EOL;
+ $expected = 'function ($param) {' . $this->_newlineString;
+ $expected .= 'foo();' . $this->_newlineString;
$expected .= '}';
$this->assertSame($expected, $code);
}
@@ -785,7 +787,7 @@ public function testVisitClosureWithUse()
$node->addClosureParameter(new Parameter(new Identifier('closureParam')));
$code = $node->accept($this->_renderer);
- $expected = 'function ($param) use ($closureParam) {' . PHP_EOL;
+ $expected = 'function ($param) use ($closureParam) {' . $this->_newlineString;
$expected .= '}';
$this->assertSame($expected, $code);
}
@@ -813,11 +815,11 @@ public function testVisitClosureIndenting()
$code = $node->accept($this->_renderer);
- $expected = '{' . PHP_EOL;
- $expected .= ' ($target = function () {' . PHP_EOL;
- $expected .= ' foo();' . PHP_EOL;
- $expected .= ' });' . PHP_EOL;
- $expected .= '}' . PHP_EOL;
+ $expected = '{' . $this->_newlineString;
+ $expected .= ' ($target = function () {' . $this->_newlineString;
+ $expected .= ' foo();' . $this->_newlineString;
+ $expected .= ' });' . $this->_newlineString;
+ $expected .= '}' . $this->_newlineString;
$this->assertSame($expected, $code);
}

0 comments on commit 1aea667

Please sign in to comment.
Something went wrong with that request. Please try again.