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