6 use Test::More tests => (2 * 14 + 2) + 2 * (2 * 8 + 4) + 1;
8 use Variable::Magic qw/cast dispell/;
11 use Variable::Magic::TestWatcher;
14 [ qw/get set len clear free copy dup local fetch store exists delete/ ],
17 my $n = int rand 1000;
20 check { cast $a, $wiz } { }, 'cast';
22 my $b = check { $a } { get => 1 }, 'assign to';
23 is $b, $n, 'scalar: assign to correctly';
25 $b = check { "X${a}Y" } { get => 1 }, 'interpolate';
26 is $b, "X${n}Y", 'scalar: interpolate correctly';
28 $b = check { \$a } { }, 'reference';
30 check { $a = 123; () } { set => 1 }, 'assign to';
32 check { ++$a; () } { get => 1, set => 1 }, 'increment';
34 check { --$a; () } { get => 1, set => 1 }, 'decrement';
36 check { $a *= 1.5; () } { get => 1, set => 1 }, 'multiply in place';
38 check { $a /= 1.5; () } { get => 1, set => 1 }, 'divide in place';
42 check { cast $b, $wiz } { }, 'cast 2';
43 } { free => 1 }, 'scope end';
45 check { undef $a } { set => 1 }, 'undef';
47 check { dispell $a, $wiz } { }, 'dispell';
53 check { cast $a[1], $wiz } { }, 'array element: cast';
55 check { $a[1] = 6; () } { set => 1 }, 'array element: set';
57 $b = check { $a[1] } { get => 1 }, 'array element: get';
58 is $b, 6, 'scalar: array element: get correctly';
60 check { $a[0] = 5 } { }, 'array element: set other';
62 $b = check { $a[2] } { }, 'array element: get other';
63 is $b, 9, 'scalar: array element: get other correctly';
65 $b = check { exists $a[1] } { }, 'array element: exists';
66 is $b, 1, 'scalar: array element: exists correctly';
68 $b = check { delete $a[1] } { get => 1, free => ($] > 5.008005 ? 1 : 0) }, 'array element: delete';
69 is $b, 6, 'scalar: array element: delete correctly';
71 check { $a[1] = 4 } { }, 'array element: set after delete';
75 my %h = (a => 7, b => 8);
77 check { cast $h{b}, $wiz } { }, 'hash element: cast';
79 check { $h{b} = 6; () } { set => 1 }, 'hash element: set';
81 $b = check { $h{b} } { get => 1 }, 'hash element: get';
82 is $b, 6, 'scalar: hash element: get correctly';
84 check { $h{a} = 5 } { }, 'hash element: set other';
86 $b = check { $h{a} } { }, 'hash element: get other';
87 is $b, 5, 'scalar: hash element: get other correctly';
89 $b = check { exists $h{b} } { }, 'hash element: exists';
90 is $b, 1, 'scalar: hash element: exists correctly';
92 $b = check { delete $h{b} } { get => 1, free => 1 }, 'hash element: delete';
93 is $b, 6, 'scalar: hash element: delete correctly';
95 check { $h{b} = 4 } { }, 'hash element: set after delete';