Skip to content

Commit

Permalink
Fix interpolation (#94)
Browse files Browse the repository at this point in the history
* Standard coverage output in the PHPUnit settings
* CI for PHP 7.1
* Swap ! and # behaviours for interpolations to match pug-js
* Fix PHP 7.1 non-numeric error
  • Loading branch information
kylekatarnls authored Nov 29, 2016
1 parent d58aed2 commit 0f1ecb2
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Coverage
/build
coverage.xml
/coverage

# Composer
/vendor
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

before_script:
Expand Down
83 changes: 44 additions & 39 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
<phpunit
bootstrap="tests/lib/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="WhiteSpace">
<file>tests/features/whiteSpace.php</file>
</testsuite>
<testsuite name="Templates">
<file>tests/features/templates.php</file>
</testsuite>
<testsuite name="Issues">
<file>tests/features/issues.php</file>
</testsuite>
<testsuite name="Features">
<directory suffix=".php">tests/features</directory>
<exclude>tests/features/templates.php</exclude>
<exclude>tests/features/whiteSpace.php</exclude>
<exclude>tests/features/issues.php</exclude>
</testsuite>
<testsuite name="Compiler">
<directory suffix=".php">tests/nodes</directory>
<directory suffix=".php">tests/compiler</directory>
</testsuite>
<testsuite name="Performance">
<directory suffix=".php">tests/performance</directory>
</testsuite>
<testsuite name="Example">
<file>tests/example/example.php</file>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
bootstrap="tests/lib/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="WhiteSpace">
<file>tests/features/whiteSpace.php</file>
</testsuite>
<testsuite name="Templates">
<file>tests/features/templates.php</file>
</testsuite>
<testsuite name="Issues">
<file>tests/features/issues.php</file>
</testsuite>
<testsuite name="Features">
<directory suffix=".php">tests/features</directory>
<exclude>tests/features/templates.php</exclude>
<exclude>tests/features/whiteSpace.php</exclude>
<exclude>tests/features/issues.php</exclude>
</testsuite>
<testsuite name="Compiler">
<directory suffix=".php">tests/nodes</directory>
<directory suffix=".php">tests/compiler</directory>
</testsuite>
<testsuite name="Performance">
<directory suffix=".php">tests/performance</directory>
</testsuite>
<testsuite name="Example">
<file>tests/example/example.php</file>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="./coverage/result.xml" />
<log type="coverage-html" target="./coverage/result" />
<log type="coverage-text" target="./coverage/result.txt" />
</logging>
</phpunit>
2 changes: 1 addition & 1 deletion src/Jade/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function interpolate($text)
protected function interpolateFromCapture($match)
{
if ($match[1] === '') {
return trim($this->escapeIfNeeded($match[2] === '!', $match[3]));
return trim($this->escapeIfNeeded($match[2] !== '!', $match[3]));
}

return substr($match[0], 1);
Expand Down
2 changes: 1 addition & 1 deletion src/Jade/Compiler/SubCodeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function handleNestedExpression(&$result)
$arguments,
$handleRecursion(
array($start, $end),
$name * 10 + count($arguments)
intval($name) * 10 + count($arguments)
)
);
}
Expand Down
22 changes: 11 additions & 11 deletions tests/features/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static private function rawHtml($html, $convertSingleQuote = true)

static private function simpleHtml($html)
{
return trim(preg_replace('`\r\n|\r|\n\s*\n`', "\n", $html));
return trim(preg_replace('`\r\n|\r|(\n\s*| *)\n`', "\n", $html));
}

/**
Expand Down Expand Up @@ -254,15 +254,15 @@ public function testSingleQuote()
$actual = $jade->render($template);
$expected = "<h1 id='foo' style='color: red;' class='bar'>Hello</h1>";

$this->assertSame(static::rawHtml($actual, false), static::rawHtml($expected, false), 'Single quote enabled on a simple header');
$this->assertSame(static::rawHtml($expected, false), static::rawHtml($actual, false), 'Single quote enabled on a simple header');
$file = __DIR__ . '/../templates/attrs-data.complex';
$this->assertSame(static::simpleHtml($jade->render($file . '.jade')), static::simpleHtml(file_get_contents($file . '.single-quote.html')), 'Single quote enabled on attrs-data.complex');
$this->assertSame(static::simpleHtml(file_get_contents($file . '.single-quote.html')), static::simpleHtml($jade->render($file . '.jade')), 'Single quote enabled on attrs-data.complex');
$file = __DIR__ . '/../templates/attrs-data';
$this->assertSame(static::simpleHtml($jade->render($file . '.jade')), static::simpleHtml(file_get_contents($file . '.single-quote.html')), 'Single quote enabled on attrs-data');
$this->assertSame(static::simpleHtml(file_get_contents($file . '.single-quote.html')), static::simpleHtml($jade->render($file . '.jade')), 'Single quote enabled on attrs-data');
$file = __DIR__ . '/../templates/object-to-css';
$this->assertSame(static::simpleHtml($jade->render($file . '.jade')), static::simpleHtml(file_get_contents($file . '.single-quote.html')), 'Single quote enabled on object-to-css');
$this->assertSame(static::simpleHtml(file_get_contents($file . '.single-quote.html')), static::simpleHtml($jade->render($file . '.jade')), 'Single quote enabled on object-to-css');
$file = __DIR__ . '/../templates/interpolation';
$this->assertSame(static::simpleHtml($jade->render($file . '.jade')), static::simpleHtml(file_get_contents($file . '.single-quote.html')), 'Single quote enabled on interpolation');
$this->assertSame(static::simpleHtml(file_get_contents($file . '.single-quote.html')), static::simpleHtml($jade->render($file . '.jade')), 'Single quote enabled on interpolation');

$jade = new Jade(array(
'prettyprint' => true,
Expand All @@ -271,15 +271,15 @@ public function testSingleQuote()
$actual = $jade->render($template);
$expected = '<h1 id="foo" style="color: red;" class="bar">Hello</h1>';

$this->assertSame(static::rawHtml($actual, false), static::rawHtml($expected, false), 'Single quote disabled on a simple header');
$this->assertSame(static::rawHtml($expected, false), static::rawHtml($actual, false), 'Single quote disabled on a simple header');
$file = __DIR__ . '/../templates/attrs-data.complex';
$this->assertSame(static::simpleHtml($jade->render($file . '.jade')), static::simpleHtml(file_get_contents($file . '.html')), 'Single quote disabled on attrs-data.complex');
$this->assertSame(static::simpleHtml(file_get_contents($file . '.html')), static::simpleHtml($jade->render($file . '.jade')), 'Single quote disabled on attrs-data.complex');
$file = __DIR__ . '/../templates/attrs-data';
$this->assertSame(static::simpleHtml($jade->render($file . '.jade')), static::simpleHtml(file_get_contents($file . '.html')), 'Single quote disabled on attrs-data');
$this->assertSame(static::simpleHtml(file_get_contents($file . '.html')), static::simpleHtml($jade->render($file . '.jade')), 'Single quote disabled on attrs-data');
$file = __DIR__ . '/../templates/object-to-css';
$this->assertSame(static::simpleHtml($jade->render($file . '.jade')), static::simpleHtml(file_get_contents($file . '.html')), 'Single quote disabled on object-to-css');
$this->assertSame(static::simpleHtml(file_get_contents($file . '.html')), static::simpleHtml($jade->render($file . '.jade')), 'Single quote disabled on object-to-css');
$file = __DIR__ . '/../templates/interpolation';
$this->assertSame(static::simpleHtml($jade->render($file . '.jade')), static::simpleHtml(file_get_contents($file . '.html')), 'Single quote disabled on interpolation');
$this->assertSame(static::simpleHtml(file_get_contents($file . '.html')), static::simpleHtml($jade->render($file . '.jade')), 'Single quote disabled on interpolation');
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/templates/interpolation.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h1>1</h1>
<div style="background-image: url(/img/bar.jpg);" class="featured"></div>
<a href="?id=bar"></a>
<p>&lt;b&gt;Yop&lt;/b&gt;</p>
<p><b>Yop</b></p>
3 changes: 3 additions & 0 deletions tests/templates/interpolation.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ h1 #{isMobile}
- $feature = array('foo' => 'bar')
.featured(style='background-image: url(/img/#{feature.foo}.jpg);')
a(href="?id=#{feature.foo}")
- var danger = '<b>Yop</b>'
p #{danger}
p !{danger}
2 changes: 2 additions & 0 deletions tests/templates/interpolation.single-quote.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h1>1</h1>
<div style='background-image: url(/img/bar.jpg);' class='featured'></div>
<a href='?id=bar'></a>
<p>&lt;b&gt;Yop&lt;/b&gt;</p>
<p><b>Yop</b></p>

0 comments on commit 0f1ecb2

Please sign in to comment.