Regenerate test files
[gitmo/Mouse.git] / t / 020_attributes / 034_numeric_defaults.t
CommitLineData
fde8e43f 1#!/usr/bin/env 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;
5use strict;
6use warnings;
7use Test::More;
8use Test::Mouse;
9use B;
10
11{
12 package Foo;
13 use Mouse;
14
15 has foo => (is => 'ro', default => 100);
16
17 sub bar { 100 }
18}
19
20with_immutable {
21 my $foo = Foo->new;
22 for my $meth (qw(foo bar)) {
23 my $val = $foo->$meth;
24 my $b = B::svref_2object(\$val);
25 my $flags = $b->FLAGS;
26 ok($flags & B::SVf_IOK || $flags & B::SVp_IOK, "it's an int");
27 ok(!($flags & B::SVf_POK), "not a string");
28 }
29} 'Foo';
30
31{
32 package Bar;
33 use Mouse;
34
35 has foo => (is => 'ro', lazy => 1, default => 100);
36
37 sub bar { 100 }
38}
39
40with_immutable {
41 my $bar = Bar->new;
42 for my $meth (qw(foo bar)) {
43 my $val = $bar->$meth;
44 my $b = B::svref_2object(\$val);
45 my $flags = $b->FLAGS;
46 ok($flags & B::SVf_IOK || $flags & B::SVp_IOK, "it's an int");
47 ok(!($flags & B::SVf_POK), "not a string");
48 }
49} 'Bar';
50
51{
52 package Baz;
53 use Mouse;
54
55 has foo => (is => 'ro', isa => 'Int', lazy => 1, default => 100);
56
57 sub bar { 100 }
58}
59
60with_immutable {
61 my $baz = Baz->new;
62 for my $meth (qw(foo bar)) {
63 my $val = $baz->$meth;
64 my $b = B::svref_2object(\$val);
65 my $flags = $b->FLAGS;
66 ok($flags & B::SVf_IOK || $flags & B::SVp_IOK, "it's an int");
67 ok(!($flags & B::SVf_POK), "not a string");
68 }
69} 'Baz';
70
71{
72 package Foo2;
73 use Mouse;
74
75 has foo => (is => 'ro', default => 10.5);
76
77 sub bar { 10.5 }
78}
79
80with_immutable {
81 my $foo2 = Foo2->new;
82 for my $meth (qw(foo bar)) {
83 my $val = $foo2->$meth;
84 my $b = B::svref_2object(\$val);
85 my $flags = $b->FLAGS;
86 ok($flags & B::SVf_NOK || $flags & B::SVp_NOK, "it's a num");
87 ok(!($flags & B::SVf_POK), "not a string");
88 }
89} 'Foo2';
90
91{
92 package Bar2;
93 use Mouse;
94
95 has foo => (is => 'ro', lazy => 1, default => 10.5);
96
97 sub bar { 10.5 }
98}
99
100with_immutable {
101 my $bar2 = Bar2->new;
102 for my $meth (qw(foo bar)) {
103 my $val = $bar2->$meth;
104 my $b = B::svref_2object(\$val);
105 my $flags = $b->FLAGS;
106 ok($flags & B::SVf_NOK || $flags & B::SVp_NOK, "it's a num");
107 ok(!($flags & B::SVf_POK), "not a string");
108 }
109} 'Bar2';
110
111{
112 package Baz2;
113 use Mouse;
114
115 has foo => (is => 'ro', isa => 'Num', lazy => 1, default => 10.5);
116
117 sub bar { 10.5 }
118}
119
120with_immutable {
121 my $baz2 = Baz2->new;
122 for my $meth (qw(foo bar)) {
123 my $val = $baz2->$meth;
124 my $b = B::svref_2object(\$val);
125 my $flags = $b->FLAGS;
126 ok($flags & B::SVf_NOK || $flags & B::SVp_NOK, "it's a num");
127 ok(!($flags & B::SVf_POK), "not a string");
128 }
129} 'Baz2';
130
131done_testing;