-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd77c2a
commit 45cec14
Showing
6 changed files
with
406 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
namespace Leuffen\TextTemplate; | ||
|
||
require __DIR__ . "/../vendor/autoload.php"; | ||
|
||
|
||
use Tester\Assert; | ||
|
||
|
||
|
||
\Tester\Environment::setup(); | ||
|
||
|
||
$vars = ["val" => true]; | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if && val}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression '&& val': Unexpected '&&'."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if || val}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression '|| val': Unexpected '||'."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if val &&}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression 'val &&': Unexpected end of expression."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if val ||}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression 'val ||': Unexpected end of expression."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if (val}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression '(val': Unmatched '('."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if val)}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression 'val)': Unexpected ')'. No matching opening '('."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if !(val}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression '!(val': Unmatched '('."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if (val))}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression '(val))': Unexpected ')'. No matching opening '('."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if ((val)}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression '((val)': Unmatched '('."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if (!(val)}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression '(!(val)': Unmatched '('."); | ||
|
||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if (val) val}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression '(val) val': Unexpected 'val'."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if val (val)}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression 'val (val)': Unexpected '('."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if (val) (val)}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression '(val) (val)': Unexpected '('."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if val && &&}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression 'val && &&': Unexpected '&&' instead of value."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if val && ||}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression 'val && ||': Unexpected '||' instead of value."); | ||
|
||
Assert::throws(function() use ($vars) { | ||
$in = "{if val && )}{/if}"; | ||
$tt = new TextTemplate($in); | ||
$tt->apply($vars, false); | ||
}, TemplateParsingException::class, "Error parsing expression 'val && )': Unexpected ')' instead of value."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
return [ | ||
"yes" => true, | ||
"no" => false | ||
]; |
Oops, something went wrong.