forked from ingydotnet/jemplate
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn on duplicate template or block name.
Fixes ingydotnet#8. Duplicate block name in the same file can't be reported from Jemplate, we need to fix Template instead (in progress).
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
use Jemplate; | ||
my $jemplate = Jemplate->new; | ||
|
||
my %warning_seen; | ||
local $SIG{__WARN__} = sub { | ||
if ($_[0] =~ /Duplicate template or block name (b1|t2)/) { | ||
++$warning_seen{$1}; | ||
} else { | ||
die "Unexpected warning: @_"; | ||
} | ||
}; | ||
|
||
$jemplate->compile_template_content( | ||
'[% BLOCK b1 %] first [% END %]', | ||
't1', | ||
); | ||
|
||
$jemplate->compile_template_content( | ||
'[% BLOCK b1 %] duplicate block [% END %]', | ||
't2', | ||
); | ||
|
||
$jemplate->compile_template_content( | ||
'[% BLOCK b2 %] duplicate template [% END %]', | ||
't2', | ||
); | ||
|
||
is_deeply( | ||
\%warning_seen, | ||
{ b1 => 1, t2 => 1 }, | ||
'duplicate warning seen' | ||
); | ||
|
||
done_testing(); |