Skip to content

Commit 6eb5ec8

Browse files
committed
add tests
1 parent 066305c commit 6eb5ec8

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

tests/Parsem/ParserTest.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ public function testDefaultValueWithFilter()
115115

116116
$parsed = Parser::parseString($string, $args);
117117
Assert::equal('Hello wo...!', $parsed, 'Filter applied correctly to default value.');
118-
118+
119119
$parsed = Parser::parseString($string2, $args);
120120
Assert::equal('Hello wo!', $parsed, 'Filter applied correctly to default value.');
121-
121+
122122
$parsed = Parser::parseString($string3, $args);
123123
Assert::equal('Hello !', $parsed, 'Filter applied correctly to empty default value.');
124124
}
@@ -345,6 +345,53 @@ public function testNegatedArgument()
345345
Assert::equal($expected, $parsed, 'Negated false is true.');
346346
Assert::equal($expected2, $parsed2, 'Negated true is false -> else shown.');
347347
}
348+
349+
/** @testCase */
350+
public function testNegation()
351+
{
352+
$template1 = '<% if $true %>not negated<% endif %>';
353+
$expected1 = 'not negated';
354+
$template2 = '<% if !$false %>negated<% endif %>';
355+
$expected2 = 'negated';
356+
$template3 = '<% if !$true %>negated<% endif %>';
357+
$expected3 = '';
358+
$template4 = '<% if true %>literal<% endif %>';
359+
$expected4 = 'literal';
360+
361+
$parsed1 = Parser::parseString($template1, ['true' => true]);
362+
$parsed2 = Parser::parseString($template2, ['false' => false]);
363+
$parsed3 = Parser::parseString($template3, ['true' => true]);
364+
$parsed4 = Parser::parseString($template4);
365+
Assert::equal($expected1, $parsed1, 'Negation of true is false.');
366+
Assert::equal($expected2, $parsed2, 'Negation of false is true.');
367+
Assert::equal($expected3, $parsed3, 'Negation of true is false.');
368+
Assert::equal($expected4, $parsed4, 'Parsed literal.');
369+
}
370+
371+
/** @testCase */
372+
public function testComments()
373+
{
374+
$string = 'Hello <# This is a comment #>World!';
375+
$string2 = 'Hello <#This is a comment#>World!';
376+
$expected = 'Hello World!';
377+
378+
$parsed = Parser::parseString($string);
379+
$parsed2 = Parser::parseString($string2);
380+
Assert::equal($expected, $parsed, 'Comment is removed.');
381+
Assert::equal($expected, $parsed2, 'Comment without spaces is removed.');
382+
}
383+
384+
/** @testCase */
385+
public function testCommentsWithConditionsAndVariables()
386+
{
387+
$string = 'Hello <# This is a comment <% if $condition %> #>World!<# <% $variable %> <% endif %> #>';
388+
$expected = 'Hello World!';
389+
390+
$parsed = Parser::parseString($string);
391+
$parsed2 = Parser::parseString($string, ['condition' => true, 'variable' => 'test']);
392+
Assert::equal($expected, $parsed, 'Comment with condition and variable is removed.');
393+
Assert::equal($expected, $parsed2, 'Comment with condition and variable is removed even with arguments.');
394+
}
348395
}
349396

350397
(new ParserTest())->run();

0 commit comments

Comments
 (0)