Integrate perlio:
[p5sagit/p5-mst-13.2.git] / t / lib / tb-xvari.t
CommitLineData
3270c621 1BEGIN {
2 chdir 't' if -d 't';
3 @INC = '../lib';
4}
5
6# Before `make install' is performed this script should be runnable with
7# `make test'. After `make install' it should work as `perl test.pl'
8
9######################### We start with some black magic to print on failure.
10
11# Change 1..1 below to 1..last_test_to_print .
12# (It may become useful if the test is moved to ./t subdirectory.)
13
14BEGIN { $| = 1; print "1..77\n"; }
15END {print "not ok 1\n" unless $loaded;}
16use Text::Balanced qw ( extract_variable );
17$loaded = 1;
18print "ok 1\n";
19$count=2;
20use vars qw( $DEBUG );
21sub debug { print "\t>>>",@_ if $DEBUG }
22
23######################### End of black magic.
24
25
26$cmd = "print";
27$neg = 0;
28while (defined($str = <DATA>))
29{
30 chomp $str;
31 if ($str =~ s/\A# USING://) { $neg = 0; $cmd = $str; next; }
32 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
33 elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
34 $str =~ s/\\n/\n/g;
35 debug "\tUsing: $cmd\n";
36 debug "\t on: [$str]\n";
37
38 my @res;
39 $var = eval "\@res = $cmd";
40 debug "\t list got: [" . join("|",@res) . "]\n";
41 debug "\t list left: [$str]\n";
42 print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
43 print "ok ", $count++;
44 print " ($@)" if $@ && $DEBUG;
45 print "\n";
46
47 pos $str = 0;
48 $var = eval $cmd;
49 $var = "<undef>" unless defined $var;
50 debug "\t scalar got: [$var]\n";
51 debug "\t scalar left: [$str]\n";
52 print "not " if ($str =~ '\A;')==$neg;
53 print "ok ", $count++;
54 print " ($@)" if $@ && $DEBUG;
55 print "\n";
56}
57
58__DATA__
59
60# USING: extract_variable($str);
61# THESE SHOULD FAIL
62$a->;
63$a (1..3) { print $a };
64
65# USING: extract_variable($str);
66*var;
67*$var;
68*{var};
69*{$var};
70*var{cat};
71\&var;
72\&mod::var;
73\&mod'var;
74$a;
75$_;
76$a[1];
77$_[1];
78$a{cat};
79$_{cat};
80$a->[1];
81$a->{"cat"}[1];
82@$listref;
83@{$listref};
84$obj->nextval;
85@{$obj->nextval};
86@{$obj->nextval($cat,$dog)->{new}};
87@{$obj->nextval($cat?$dog:$fish)->{new}};
88@{$obj->nextval(cat()?$dog:$fish)->{new}};
89$ a {'cat'};
90$a::b::c{d}->{$e->()};
91$a'b'c'd{e}->{$e->()};
92$a'b::c'd{e}->{$e->()};
93$#_;
94$#array;
95$#{array};
96$var[$#var];
97
98# THESE SHOULD FAIL
99$a->;
100@{$;
101$ a :: b :: c
102$ a ' b ' c
103
104# USING: extract_variable($str,'=*');
105========$a;