Add error checking directive and unit tests for it

This commit is contained in:
Kijin Sung 2023-10-18 00:29:32 +09:00
parent d4654eb5cf
commit 0f14ad8ccf
5 changed files with 98 additions and 0 deletions

View file

@ -0,0 +1,11 @@
<div class="alert">
<p>You have an error!</p>
<p><strong>[Ref. #2]</strong></p>
</div>
<div class="alert">
<p>You have an error!</p>
<p><strong>[Ref. #4]</strong></p>
</div>

View file

@ -0,0 +1,41 @@
@version(2)
<!--// No error yet -->
@error('foo/bar/baz/1')
<div class="alert">
<p>{$XE_VALIDATOR_MESSAGE}</p>
<p><strong>[Ref. #1]</strong></p>
</div>
@enderror
<!--// We set error ID and message now -->
{@ $XE_VALIDATOR_ID = 'foo/bar/baz/1'}
{@ $XE_VALIDATOR_MESSAGE = 'You have an error!'}
<!--// This should work -->
@error('foo/bar/baz/3', 'foo/bar/baz/2', 'foo/bar/baz/1')
<div class="alert">
<p>{$XE_VALIDATOR_MESSAGE}</p>
<p><strong>[Ref. #2]</strong></p>
</div>
@enderror
<!--// Wrong error ID -->
@error('foo/bar/baz/6', 'foo/bar/baz/5', 'foo/bar/baz/4')
<div class="alert">
<p>{$XE_VALIDATOR_MESSAGE}</p>
<p><strong>[Ref. #3]</strong></p>
</div>
@enderror
<!--// Check for any error, this should also work -->
@error
<div class="alert">
<p>{$XE_VALIDATOR_MESSAGE}</p>
<p><strong>[Ref. #4]</strong></p>
</div>
@enderror
<!--// Cleanup -->
{@ $XE_VALIDATOR_ID = null}
{@ $XE_VALIDATOR_MESSAGE = null}