Created
December 19, 2012 12:21
-
-
Save yappo/4336310 to your computer and use it in GitHub Desktop.
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
use strict; | |
use warnings; | |
use Test::More; | |
use Text::Xslate; | |
subtest 'scope ok' => sub { | |
my $tx = Text::Xslate->new({ | |
syntax => 'TTerse' | |
}); | |
my $ret = $tx->render_string(<<TMPL,); | |
[% IF 1 -%] | |
[% SET chin = 'kiranai' -%] | |
[% chin -%] | |
[% END -%] | |
[% chin -%] | |
TMPL | |
is $ret, "kiranai"; | |
}; | |
subtest 'scope bug?' => sub { | |
my $tx = Text::Xslate->new({ | |
syntax => 'TTerse' | |
}); | |
my $ret = $tx->render_string(<<TMPL,); | |
[% SET chin = 'kiru' -%] | |
[% IF 1 -%] | |
[% SET chin = 'kiranai' -%] | |
[% chin -%] | |
[% END -%] | |
[% chin -%] | |
TMPL | |
is $ret, "kiranaikiru"; # kiranaikiranai が帰って来て失敗する | |
}; | |
done_testing; |
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
use strict; | |
use warnings; | |
use Test::More; | |
use Text::Xslate; | |
subtest 'ok' => sub { | |
my $tx = Text::Xslate->new({ | |
syntax => 'TTerse' | |
}); | |
eval { | |
$tx->render_string(<<TMPL,); | |
[% SET chin -%] | |
[% IF 1 -%] | |
[% chin = 'kiru' -%] | |
[% ELSIF 0 -%] | |
[% END -%] | |
TMPL | |
}; | |
is $@, ''; | |
}; | |
subtest 'ng' => sub { | |
my $tx = Text::Xslate->new({ | |
syntax => 'TTerse' | |
}); | |
eval { | |
$tx->render_string(<<TMPL,); | |
[% SET chin -%] | |
[% IF 1 -%] | |
[% chin = 'kiru' -%] | |
[% ELSIF 0 -%] | |
[% chin = 'kiranai' -%] | |
[% END -%] | |
TMPL | |
}; | |
like $@, qr/Text::Xslate::Compiler: Cannot modify chin, which is not a lexical variable/; | |
}; | |
subtest 'ng 2' => sub { | |
my $tx = Text::Xslate->new({ | |
syntax => 'TTerse' | |
}); | |
eval { | |
$tx->render_string(<<TMPL,); | |
[% IF 1 -%] | |
[% SET chin = 'kiru' -%] | |
[% ELSIF 0 -%] | |
[% SET chin = 'kiranai' -%] | |
[% END -%] | |
TMPL | |
}; | |
like $@, qr/Text::Xslate::Compiler: Cannot modify chin, which is not a lexical variable/; | |
}; | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment