]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/30-scalar.t
Convert t/30-scalar.t to the new testing framework
[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;
23 check { $b = $a } { get => 1 }, 'assign to';
24 is $b, $n, 'scalar: assign to correctly';
25
26 check { $b = "X${a}Y" } { get => 1 }, 'interpolate';
27 is $b, "X${n}Y", 'scalar: interpolate correctly';
28
29 check { $b = \$a } { }, 'reference';
30
31 check { $a = 123; () } { set => 1 }, 'assign to';
32
33 check { ++$a; () } { get => 1, set => 1 }, 'increment';
34
35 check { --$a; () } { get => 1, set => 1 }, 'decrement';
36
37 check { $a *= 1.5; () } { get => 1, set => 1 }, 'multiply in place';
38
39 check { $a /= 1.5; () } { get => 1, set => 1 }, 'divide in place';
40
41 check {
42  my $b = $n;
43  check { cast $b, $wiz } { }, 'cast 2';
44 } { free => 1 }, 'scope end';
45
46 check { undef $a } { set => 1 }, 'undef';
47
48 check { dispell $a, $wiz } { }, 'dispell';