]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/30-scalar.t
Don't assign results in check blocks
[perl/modules/Variable-Magic.git] / t / 30-scalar.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 2 * 14 + 2 + 1;
7
8 use Variable::Magic qw/cast dispell/;
9
10 use lib 't/lib';
11 use Variable::Magic::TestWatcher;
12
13 my $wiz = init
14         [ qw/get set len clear free copy dup local fetch store exists delete/ ],
15         'scalar';
16
17 my $n = int rand 1000;
18 my $a = $n;
19
20 check { cast $a, $wiz } { }, 'cast';
21
22 my $b = check { $a } { get => 1 }, 'assign to';
23 is $b, $n, 'scalar: assign to correctly';
24
25 $b = check { "X${a}Y" } { get => 1 }, 'interpolate';
26 is $b, "X${n}Y", 'scalar: interpolate correctly';
27
28 $b = check { \$a } { }, 'reference';
29
30 check { $a = 123; () } { set => 1 }, 'assign to';
31
32 check { ++$a; () } { get => 1, set => 1 }, 'increment';
33
34 check { --$a; () } { get => 1, set => 1 }, 'decrement';
35
36 check { $a *= 1.5; () } { get => 1, set => 1 }, 'multiply in place';
37
38 check { $a /= 1.5; () } { get => 1, set => 1 }, 'divide in place';
39
40 check {
41  my $b = $n;
42  check { cast $b, $wiz } { }, 'cast 2';
43 } { free => 1 }, 'scope end';
44
45 check { undef $a } { set => 1 }, 'undef';
46
47 check { dispell $a, $wiz } { }, 'dispell';