Skip to content

Commit 44c1595

Browse files
committed
Test whitespace fixes
1 parent 5ce3dbf commit 44c1595

5 files changed

Lines changed: 34 additions & 11 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"require": {
2121
"php": ">=8.2",
22-
"devtheorem/php-handlebars-parser": "^2.0"
22+
"devtheorem/php-handlebars-parser": "dev-fix-chained-else-if-whitespace"
2323
},
2424
"require-dev": {
2525
"friendsofphp/php-cs-fixer": "^3.95",

composer.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

php_handlebars_template.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Compiled 1000 times | 3.08 ms/compile | 24.0 KB code | 1.8 MB peak
2-
Executed 1000 times | 1.39 ms/render | 139.9 KB output | 1.9 MB peak
1+
Compiled 1000 times | 3.14 ms/compile | 24.0 KB code | 1.8 MB peak
2+
Executed 1000 times | 1.37 ms/render | 139.9 KB output | 1.9 MB peak
33
<?php
44
use DevTheorem\Handlebars\Runtime as LR;
55
return function (mixed $in = null, array $options = []) {

tests/RegressionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,28 @@ public static function whitespaceProvider(): array
14571457
'expected' => "NO\n",
14581458
],
14591459

1460+
'GH-1716: should strip trailing indent from chained else if blocks' => [
1461+
'template' => "{{#if a}}\n {{#if a.b}}\n no\n {{else if a.b}}\n no\n {{else}}\n yes\n {{/if}}\n after\n{{/if}}",
1462+
'data' => ['a' => ['c' => true]],
1463+
'expected' => " yes\n after\n",
1464+
],
1465+
1466+
'GH-2031: whitespace control in one else if branch should not affect another branch' => [
1467+
'template' => "{{#if a}}\na\n{{else if b}}\nb\n{{else if c}}\nc\n{{~else if d}}\nd\n{{else if e}}\ne\n{{else if f}}\nf{{/if}}",
1468+
'data' => ['c' => 1],
1469+
'expected' => 'c',
1470+
],
1471+
'GH-2031: whitespace control in one else if branch should not affect another branch (2)' => [
1472+
'template' => "{{#if a}}\na\n{{else if b}}\nb\n{{else if c}}\nc\n{{~else if d}}\nd\n{{else if e}}\ne\n{{else if f}}\nf{{/if}}",
1473+
'data' => ['d' => 1],
1474+
'expected' => "d\n",
1475+
],
1476+
'GH-2031: whitespace control in one else if branch should not affect another branch (3)' => [
1477+
'template' => "{{#if a}}\na\n{{else if b}}\nb\n{{else if c}}\nc\n{{~else if d}}\nd\n{{else if e}}\ne\n{{else if f}}\nf{{/if}}",
1478+
'data' => ['e' => 1],
1479+
'expected' => "e\n",
1480+
],
1481+
14601482
'each with leading whitespace' => [
14611483
'template' => " {{#each foo}}\n{{@key}}: {{.}}\n{{/each}}\nDONE",
14621484
'data' => ['foo' => ['a' => 'A', 'b' => 'BOY!']],

tests/templates/large-page.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<a href="{{replace linkTemplate "{id}" item.id}}">{{lookup item key}}</a>
9393
{{else}}
9494
{{lookup item key}}
95-
{{!--- avoid extra whitespace! ---}}{{/if}}
95+
{{/if}}
9696
</td>
9797
{{/each}}
9898
{{#if ../showActions}}

0 commit comments

Comments
 (0)