From 6c0a0188bd28d2bb43dfcf797a4e04bdbc84b0e9 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 3 Oct 2011 18:59:26 -0500 Subject: add test for inferring being fulfilled by subclasses --- t/infer-subclasses.t | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 t/infer-subclasses.t (limited to 't') diff --git a/t/infer-subclasses.t b/t/infer-subclasses.t new file mode 100644 index 0000000..b50b909 --- /dev/null +++ b/t/infer-subclasses.t @@ -0,0 +1,100 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + package NonMoose; + sub new { bless { data => $_[0] }, shift } +} + +{ + package Foo; + use Moose; + + has non_moose => ( + is => 'ro', + isa => 'NonMoose', + required => 1, + ); +} + +{ + package Bar; + use Moose; + + has foo => ( + is => 'ro', + isa => 'Foo', + required => 1, + ); +} + +{ + package Container; + use Moose; + use Bread::Board::Declare; + + has non_moose => ( + is => 'ro', + isa => 'NonMoose', + block => sub { NonMoose->new("blah") }, + ); + + has foo => ( + is => 'ro', + isa => 'Foo', + dependencies => ['non_moose'], + ); + + has bar => ( + is => 'ro', + isa => 'Bar', + infer => 1, + ); +} + +{ + my $c = Container->new; + my $bar = $c->bar; + isa_ok($bar->foo->non_moose, 'NonMoose'); +} + +{ + package Foo::Sub; + use Moose; + + extends 'Foo'; +} + +{ + package Container2; + use Moose; + use Bread::Board::Declare; + + has non_moose => ( + is => 'ro', + isa => 'NonMoose', + block => sub { NonMoose->new("blah") }, + ); + + has foo => ( + is => 'ro', + isa => 'Foo::Sub', + dependencies => ['non_moose'], + ); + + has bar => ( + is => 'ro', + isa => 'Bar', + infer => 1, + ); +} + +{ + my $c = Container2->new; + my $bar = $c->bar; + isa_ok($bar->foo->non_moose, 'NonMoose'); +} + +done_testing; -- cgit v1.2.3-54-g00ecf