Skip to content

Commit

Permalink
Fix #40: Variables should accept expressions and compute them
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloscustodio committed Jul 23, 2015
1 parent 9b7d862 commit d37c93b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
19 changes: 19 additions & 0 deletions t/fix_040.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/perl

# Copyright (c) 2015 Paulo Custodio. All Rights Reserved.
# May be used/distributed under the GPL.

use strict;
use warnings;
use Test::More;

use_ok 'Text::MacroScript';

my $ms;

$ms = new_ok('Text::MacroScript');
is $ms->expand("%DEFINE_VARIABLE N1 [#N1+1]#N1"), "1";
is $ms->expand("%DEFINE_VARIABLE N1 [#N1+1]#N1"), "2";
is $ms->expand("%DEFINE_VARIABLE N1 [#N1+1]#N1"), "3";

done_testing;
39 changes: 19 additions & 20 deletions t/variables.t
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,24 @@ is $ms->expand("SHOW"),

#------------------------------------------------------------------------------
# compute
diag 'Issue #40: Variables should accept expressions and compute them';
#for (1..5) {
# $ms->define_variable("N$_", ($_*2)."/2");
#}
#is $ms->expand("SHOW"),
# "N1=1=1, N2=2=2, N3=3=3, N4=4=4, N5=5=5.";
#
#for (1..5) {
# is $ms->expand("%DEFINE_VARIABLE N$_ [".($_*2)."/2]"), "";
#}
#is $ms->expand("SHOW"),
# "N1=1=1, N2=2=2, N3=3=3, N4=4=4, N5=5=5.";
#
#$ms->define_variable("N1", "#N1+1");
#is $ms->expand("SHOW"),
# "N1=2=2, N2=2=2, N3=3=3, N4=4=4, N5=5=5.";
#
#is $ms->expand("%DEFINE_VARIABLE N1 [#N1+1]"), "";
#is $ms->expand("SHOW"),
# "N1=3=3, N2=2=2, N3=3=3, N4=4=4, N5=5=5.";
for (1..5) {
$ms->define_variable("N$_", ($_*2)."/2");
}
is $ms->expand("SHOW"),
"N1=1=1, N2=2=2, N3=3=3, N4=4=4, N5=5=5.";

for (1..5) {
is $ms->expand("%DEFINE_VARIABLE N$_ [".($_*2)."/2]"), "";
}
is $ms->expand("SHOW"),
"N1=1=1, N2=2=2, N3=3=3, N4=4=4, N5=5=5.";

$ms->define_variable("N1", "#N1+1");
is $ms->expand("SHOW"),
"N1=2=2, N2=2=2, N3=3=3, N4=4=4, N5=5=5.";

is $ms->expand("%DEFINE_VARIABLE N1 [#N1+1]"), "";
is $ms->expand("SHOW"),
"N1=3=3, N2=2=2, N3=3=3, N4=4=4, N5=5=5.";

done_testing;

0 comments on commit d37c93b

Please sign in to comment.