summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorTim Bunce <Tim.Bunce@ig.co.uk>1994-10-19 04:46:27 +1200
committerChip Salzenberg <chip@atlantic.net>1997-05-16 10:15:00 +1200
commit843b46037eafc2992e27517b56604eb93b3adf73 (patch)
tree230580d7b39577b5348fc0ceb022af5a1335c3ab /t
parentd27fe803587dd19cb1812b267492c364c09580fa (diff)
downloadperl-843b46037eafc2992e27517b56604eb93b3adf73.tar.gz
Fix recursive substitution [test]
Diffstat (limited to 't')
-rwxr-xr-xt/op/subst.t33
1 files changed, 32 insertions, 1 deletions
diff --git a/t/op/subst.t b/t/op/subst.t
index 0f554b6ee6..b2332b84d1 100755
--- a/t/op/subst.t
+++ b/t/op/subst.t
@@ -2,7 +2,7 @@
# $RCSfile: s.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:22 $
-print "1..56\n";
+print "1..60\n";
$x = 'foo';
$_ = "x";
@@ -198,3 +198,34 @@ print $_ eq 'a,/' ? "ok 55\n" : "not ok 55\n";
$_ = '+,-';
tr/-+,/ab\-/;
print $_ eq 'b-a' ? "ok 56\n" : "not ok 56\n";
+
+
+# test recursive substitutions
+# code based on the recursive expansion of makefile variables
+
+my %MK = (
+ AAAAA => '$(B)', B=>'$(C)', C => 'D', # long->short
+ E => '$(F)', F=>'p $(G) q', G => 'HHHHH', # short->long
+ DIR => '$(UNDEFINEDNAME)/xxx',
+);
+sub var {
+ my($var,$level) = @_;
+ return "\$($var)" unless exists $MK{$var};
+ return exp_vars($MK{$var}, $level+1); # can recurse
+}
+sub exp_vars {
+ my($str,$level) = @_;
+ $str =~ s/\$\((\w+)\)/var($1, $level+1)/ge; # can recurse
+ #warn "exp_vars $level = '$str'\n";
+ $str;
+}
+
+print exp_vars('$(AAAAA)',0) eq 'D'
+ ? "ok 57\n" : "not ok 57\n";
+print exp_vars('$(E)',0) eq 'p HHHHH q'
+ ? "ok 58\n" : "not ok 58\n";
+print exp_vars('$(DIR)',0) eq '$(UNDEFINEDNAME)/xxx'
+ ? "ok 59\n" : "not ok 59\n";
+print exp_vars('foo $(DIR)/yyy bar',0) eq 'foo $(UNDEFINEDNAME)/xxx/yyy bar'
+ ? "ok 60\n" : "not ok 60\n";
+