use Scalar::Util directly
[gitmo/Mouse.git] / t / 201-squirrel.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Scalar::Util 'blessed';
8
9 do {
10     package Foo;
11     use Squirrel;
12
13     has foo => (
14         isa => "Int",
15         is  => "rw",
16     );
17
18     no Squirrel;
19 };
20
21 # note that 'Foo' is defined before this, to prevent Moose being loaded from
22 # affecting its definition
23
24 BEGIN {
25     plan skip_all => "Moose required for this test" unless eval { require Moose };
26     plan tests => 12;
27 }
28
29 do {
30     package Bar;
31     use Squirrel;
32
33     has foo => (
34         isa => "Int",
35         is  => "rw",
36     );
37
38     no Squirrel;
39 };
40
41 my $foo = Foo->new(foo => 3);
42 isa_ok($foo, "Foo");
43 isa_ok($foo, "Mouse::Object");
44 is($foo->foo, 3, "accessor");
45
46 my $bar = Bar->new(foo => 3);
47 isa_ok($bar, "Bar");
48 isa_ok($bar, "Moose::Object");
49 is($bar->foo, 3, "accessor");
50
51 ok(!Foo->can('has'), "Mouse::has was unimported");
52 ok(!Bar->can('has'), "Moose::has was unimported");
53
54 eval "
55     package Foo;
56     use Squirrel;
57
58     has bar => (is => 'rw');
59     __PACKAGE__->meta->make_immutable;
60
61     package Bar;
62     use Squirrel;
63
64     has bar => (is => 'rw');
65     __PACKAGE__->meta->make_immutable;
66 ";
67 warn $@ if $@;
68
69 is(blessed(Foo->meta->get_attribute('foo')), 'Mouse::Meta::Attribute');
70 is(blessed(Foo->meta->get_attribute('bar')), 'Mouse::Meta::Attribute', 'Squirrel is consistent if Moose was loaded between imports');
71
72 is(blessed(Bar->meta->get_attribute('foo')), 'Moose::Meta::Attribute');
73 is(blessed(Bar->meta->get_attribute('bar')), 'Moose::Meta::Attribute');
74