6 use Test::More tests => 11 * (5 + 6) + 5;
8 use Config qw/%Config/;
10 use Variable::Magic qw/wizard cast dispell VMG_OP_INFO_NAME VMG_OP_INFO_OBJECT/;
12 sub Variable::Magic::TestPkg::foo { }
14 my $aelem = $] <= 5.008003 ? 'aelem' : 'aelemfast';
15 my $aelem_op = $Config{useithreads} ? 'B::PADOP' : 'B::SVOP';
20 [ 'len', '@c', undef, 'my $x = @c', [ 'padav', 'B::OP' ] ],
21 [ 'get', '$c[0]', undef, 'my $x = $c[0]', [ $aelem, 'B::OP' ] ],
22 [ 'get', '$o[0]', undef, 'my $x = $o[0]', [ 'aelemfast', $aelem_op ] ],
23 [ 'get', '$c', undef, '++$c', [ 'preinc', 'B::UNOP' ] ],
24 [ 'get', '$c', '$c = 1', '$c ** 2', [ 'pow', 'B::BINOP' ] ],
25 [ 'get', '$c', undef, 'my $x = $c', [ 'sassign', 'B::BINOP' ] ],
26 [ 'get', '$c', undef, '1 if $c', [ 'and', 'B::LOGOP' ] ],
27 [ 'set', '$c', undef, 'bless \$c, "main"', [ 'bless', 'B::LISTOP' ] ],
28 [ 'get', '$c', '$c = ""', '$c =~ /x/', [ 'match', 'B::PMOP' ] ],
29 [ 'get', '$c', '$c = "Variable::Magic::TestPkg"',
30 '$c->foo()', [ 'method_named', 'B::SVOP' ] ],
31 [ 'get', '$c', '$c = ""', '$c =~ y/x/y/', [ 'trans', 'B::PVOP' ] ],
35 my ($key, $var, $init, $test, $exp) = @$_;
37 for my $op_info (VMG_OP_INFO_NAME, VMG_OP_INFO_OBJECT) {
42 # We must test for the $op correctness inside the callback because, if we
43 # bring it out, it will go outside of the eval STRING scope, and what it
44 # points to will no longer exist.
46 $wiz = wizard $key => sub {
49 my $desc = "$key magic with op_info == $op_info";
50 if ($op_info == VMG_OP_INFO_NAME) {
51 is $op, $exp->[0], "$desc gets the right op info";
52 } elsif ($op_info == VMG_OP_INFO_OBJECT) {
53 isa_ok $op, $exp->[1], $desc;
54 is $op->name, $exp->[0], "$desc gets the right op info";
56 is $op, undef, "$desc gets the right op info";
60 }, op_info => $op_info
62 is $@, '', "$key wizard with op_info == $op_info doesn't croak";
66 eval $init if defined $init;
68 eval "cast $var, \$wiz";
69 is $@, '', "$key cast with op_info == $op_info doesn't croak";
72 is $@, '', "$key magic with op_info == $op_info doesn't croak";
74 eval "dispell $var, \$wiz";
75 is $@, '', "$key dispell with op_info == $op_info doesn't croak";
84 is $_[-1], undef, 'get magic with out of bounds op_info';
88 is $@, '', "get wizard with out of bounds op_info doesn't croak";
90 eval { cast $c, $wiz };
91 is $@, '', "get cast with out of bounds op_info doesn't croak";
94 is $@, '', "get magic with out of bounds op_info doesn't croak";
96 eval { dispell $c, $wiz };
97 is $@, '', "get dispell with out of bounds op_info doesn't croak";