diff options
author | Brandon Black <blblack@gmail.com> | 2007-04-17 08:14:36 -0500 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-04-19 14:48:20 +0000 |
commit | e1a479c5e0c08fb10925261f03573261c69ca0dc (patch) | |
tree | 09088fd1ef489ff5660300a532f799144ff7ae6a /t/mro/basic_02_dfs.t | |
parent | 0a311364e00e9bf5b4fcb140ade49b02e46833dd (diff) | |
download | perl-e1a479c5e0c08fb10925261f03573261c69ca0dc.tar.gz |
Re: new C3 MRO patch
From: "Brandon Black" <blblack@gmail.com>
Message-ID: <84621a60704171114k29b0460el5b08ce5185d55ed5@mail.gmail.com>
p4raw-id: //depot/perl@30980
Diffstat (limited to 't/mro/basic_02_dfs.t')
-rw-r--r-- | t/mro/basic_02_dfs.t | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/t/mro/basic_02_dfs.t b/t/mro/basic_02_dfs.t new file mode 100644 index 0000000000..bbce6a05a0 --- /dev/null +++ b/t/mro/basic_02_dfs.t @@ -0,0 +1,121 @@ +#!./perl + +use strict; +use warnings; +BEGIN { + unless (-d 'blib') { + chdir 't' if -d 't'; + @INC = '../lib'; + } +} + +use Test::More tests => 10; + +=pod + +This example is take from: http://www.python.org/2.3/mro.html + +"My first example" +class O: pass +class F(O): pass +class E(O): pass +class D(O): pass +class C(D,F): pass +class B(D,E): pass +class A(B,C): pass + + + 6 + --- +Level 3 | O | (more general) + / --- \ + / | \ | + / | \ | + / | \ | + --- --- --- | +Level 2 3 | D | 4| E | | F | 5 | + --- --- --- | + \ \ _ / | | + \ / \ _ | | + \ / \ | | + --- --- | +Level 1 1 | B | | C | 2 | + --- --- | + \ / | + \ / \ / + --- +Level 0 0 | A | (more specialized) + --- + +=cut + +{ + package Test::O; + use mro 'dfs'; + + package Test::F; + use mro 'dfs'; + use base 'Test::O'; + + package Test::E; + use base 'Test::O'; + use mro 'dfs'; + + sub C_or_E { 'Test::E' } + + package Test::D; + use mro 'dfs'; + use base 'Test::O'; + + sub C_or_D { 'Test::D' } + + package Test::C; + use base ('Test::D', 'Test::F'); + use mro 'dfs'; + + sub C_or_D { 'Test::C' } + sub C_or_E { 'Test::C' } + + package Test::B; + use mro 'dfs'; + use base ('Test::D', 'Test::E'); + + package Test::A; + use base ('Test::B', 'Test::C'); + use mro 'dfs'; +} + +is_deeply( + mro::get_linear_isa('Test::F'), + [ qw(Test::F Test::O) ], + '... got the right MRO for Test::F'); + +is_deeply( + mro::get_linear_isa('Test::E'), + [ qw(Test::E Test::O) ], + '... got the right MRO for Test::E'); + +is_deeply( + mro::get_linear_isa('Test::D'), + [ qw(Test::D Test::O) ], + '... got the right MRO for Test::D'); + +is_deeply( + mro::get_linear_isa('Test::C'), + [ qw(Test::C Test::D Test::O Test::F) ], + '... got the right MRO for Test::C'); + +is_deeply( + mro::get_linear_isa('Test::B'), + [ qw(Test::B Test::D Test::O Test::E) ], + '... got the right MRO for Test::B'); + +is_deeply( + mro::get_linear_isa('Test::A'), + [ qw(Test::A Test::B Test::D Test::O Test::E Test::C Test::F) ], + '... got the right MRO for Test::A'); + +is(Test::A->C_or_D, 'Test::D', '... got the expected method output'); +is(Test::A->can('C_or_D')->(), 'Test::D', '... can got the expected method output'); +is(Test::A->C_or_E, 'Test::E', '... got the expected method output'); +is(Test::A->can('C_or_E')->(), 'Test::E', '... can got the expected method output'); |