Changelogging
[gitmo/Mouse.git] / t-failing / 070_native_traits / 204_trait_number.t
CommitLineData
fde8e43f 1#!/usr/bin/perl
2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
5
6use strict;
7use warnings;
8
9use Test::More;
10$TODO = q{Mouse is not yet completed};
11use Test::Mouse;
12
13{
14 package Real;
15 use Mouse;
16
17 has 'integer' => (
18 traits => ['Number'],
19 is => 'ro',
20 isa => 'Int',
21 default => 5,
22 handles => {
23 set => 'set',
24 add => 'add',
25 sub => 'sub',
26 mul => 'mul',
27 div => 'div',
28 mod => 'mod',
29 abs => 'abs',
30 inc => [ add => 1 ],
31 dec => [ sub => 1 ],
32 odd => [ mod => 2 ],
33 cut_in_half => [ div => 2 ],
34
35 },
36 );
37}
38
39my $real = Real->new;
40isa_ok( $real, 'Real' );
41
42can_ok( $real, $_ ) for qw[
43 set add sub mul div mod abs inc dec odd cut_in_half
44];
45
46is $real->integer, 5, 'Default to five';
47
48$real->add(10);
49
50is $real->integer, 15, 'Add ten for fithteen';
51
52$real->sub(3);
53
54is $real->integer, 12, 'Subtract three for 12';
55
56$real->set(10);
57
58is $real->integer, 10, 'Set to ten';
59
60$real->div(2);
61
62is $real->integer, 5, 'divide by 2';
63
64$real->mul(2);
65
66is $real->integer, 10, 'multiplied by 2';
67
68$real->mod(2);
69
70is $real->integer, 0, 'Mod by 2';
71
72$real->set(7);
73
74$real->mod(5);
75
76is $real->integer, 2, 'Mod by 5';
77
78$real->set(-1);
79
80$real->abs;
81
82is $real->integer, 1, 'abs 1';
83
84$real->set(12);
85
86$real->inc;
87
88is $real->integer, 13, 'inc 12';
89
90$real->dec;
91
92is $real->integer, 12, 'dec 13';
93
94## test the meta
95
96my $attr = $real->meta->get_attribute('integer');
97does_ok( $attr, 'Mouse::Meta::Attribute::Native::Trait::Number' );
98
99is_deeply(
100 $attr->handles,
101 {
102 set => 'set',
103 add => 'add',
104 sub => 'sub',
105 mul => 'mul',
106 div => 'div',
107 mod => 'mod',
108 abs => 'abs',
109 inc => [ add => 1 ],
110 dec => [ sub => 1 ],
111 odd => [ mod => 2 ],
112 cut_in_half => [ div => 2 ],
113 },
114 '... got the right handles mapping'
115);
116
117done_testing;