File: 21-set.t

package info (click to toggle)
libvariable-magic-perl 0.64-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 476 kB
  • sloc: perl: 4,256; ansic: 633; makefile: 8
file content (37 lines) | stat: -rw-r--r-- 640 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!perl -T

use strict;
use warnings;

use Test::More tests => (2 * 5 + 3) + (2 * 2 + 1);

use Variable::Magic qw<cast>;

use lib 't/lib';
use Variable::Magic::TestWatcher;
use Variable::Magic::TestValue;

my $wiz = init_watcher 'set', 'set';

my $a = 0;

watch { cast $a, $wiz } { }, 'cast';

my $n = int rand 1000;

watch { $a = $n } { set => 1 }, 'assign';
is $a, $n, 'set: assign correctly';

watch { ++$a } { set => 1 }, 'increment';
is $a, $n + 1, 'set: increment correctly';

watch { --$a } { set => 1 }, 'decrement';
is $a, $n, 'set: decrement correctly';

{
 my $val = 0;

 init_value $val, 'set', 'set';

 value { $val = 1 } \1;
}