From: Brandon L Black Date: Sun, 15 Apr 2007 20:16:43 +0000 (+0000) Subject: import some mro tests X-Git-Tag: 0.02~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FClass-C3-XS.git;a=commitdiff_plain;h=b9e73af7c2fca0058d6d91827363c07fee7c3867 import some mro tests --- diff --git a/t/01_MRO.t b/t/01_MRO.t new file mode 100644 index 0000000..32d99a2 --- /dev/null +++ b/t/01_MRO.t @@ -0,0 +1,44 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; + +BEGIN { + use_ok('Class::C3::XS'); +} + +=pod + +This tests the classic diamond inheritence pattern. + + + / \ + + \ / + + +=cut + +{ + package Diamond_A; + our @ISA = qw//; +} +{ + package Diamond_B; + use base 'Diamond_A'; +} +{ + package Diamond_C; + use base 'Diamond_A'; +} +{ + package Diamond_D; + use base ('Diamond_B', 'Diamond_C'); +} + +is_deeply( + [ Class::C3::XS::calculateMRO('Diamond_D') ], + [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ], + '... got the right MRO for Diamond_D'); diff --git a/t/02_MRO.t b/t/02_MRO.t new file mode 100644 index 0000000..72001d0 --- /dev/null +++ b/t/02_MRO.t @@ -0,0 +1,102 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 7; + +BEGIN { + use_ok('Class::C3::XS'); +} + +=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; + our @ISA = qw//; + + package Test::F; + use base 'Test::O'; + + package Test::E; + use base 'Test::O'; + + package Test::D; + use base 'Test::O'; + + package Test::C; + use base ('Test::D', 'Test::F'); + + package Test::B; + use base ('Test::D', 'Test::E'); + + package Test::A; + use base ('Test::B', 'Test::C'); +} + +is_deeply( + [ Class::C3::XS::calculateMRO('Test::F') ], + [ qw(Test::F Test::O) ], + '... got the right MRO for Test::F'); + +is_deeply( + [ Class::C3::XS::calculateMRO('Test::E') ], + [ qw(Test::E Test::O) ], + '... got the right MRO for Test::E'); + +is_deeply( + [ Class::C3::XS::calculateMRO('Test::D') ], + [ qw(Test::D Test::O) ], + '... got the right MRO for Test::D'); + +is_deeply( + [ Class::C3::XS::calculateMRO('Test::C') ], + [ qw(Test::C Test::D Test::F Test::O) ], + '... got the right MRO for Test::C'); + +is_deeply( + [ Class::C3::XS::calculateMRO('Test::B') ], + [ qw(Test::B Test::D Test::E Test::O) ], + '... got the right MRO for Test::B'); + +is_deeply( + [ Class::C3::XS::calculateMRO('Test::A') ], + [ qw(Test::A Test::B Test::C Test::D Test::E Test::F Test::O) ], + '... got the right MRO for Test::A'); + diff --git a/t/03_MRO.t b/t/03_MRO.t new file mode 100644 index 0000000..8ea22fe --- /dev/null +++ b/t/03_MRO.t @@ -0,0 +1,81 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; + +BEGIN { + use_ok('Class::C3::XS'); +} + +=pod + + +This example is take from: http://www.python.org/2.3/mro.html + +"My second example" +class O: pass +class F(O): pass +class E(O): pass +class D(O): pass +class C(D,F): pass +class B(E,D): pass +class A(B,C): pass + + 6 + --- +Level 3 | O | + / --- \ + / | \ + / | \ + / | \ + --- --- --- +Level 2 2 | E | 4 | D | | F | 5 + --- --- --- + \ / \ / + \ / \ / + \ / \ / + --- --- +Level 1 1 | B | | C | 3 + --- --- + \ / + \ / + --- +Level 0 0 | A | + --- + +>>> A.mro() +(, , , +, , , +) + +=cut + +{ + package Test::O; + our @ISA = qw//; + + package Test::F; + use base 'Test::O'; + + package Test::E; + use base 'Test::O'; + + package Test::D; + use base 'Test::O'; + + package Test::C; + use base ('Test::D', 'Test::F'); + + package Test::B; + use base ('Test::E', 'Test::D'); + + package Test::A; + use base ('Test::B', 'Test::C'); +} + +is_deeply( + [ Class::C3::XS::calculateMRO('Test::A') ], + [ qw(Test::A Test::B Test::E Test::C Test::D Test::F Test::O) ], + '... got the right MRO for Test::A'); diff --git a/t/04_MRO.t b/t/04_MRO.t new file mode 100644 index 0000000..9297b58 --- /dev/null +++ b/t/04_MRO.t @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; + +BEGIN { + use_ok('Class::C3::XS'); +} + +=pod + +example taken from: L + + Object + ^ + | + LifeForm + ^ ^ + / \ + Sentient BiPedal + ^ ^ + | | + Intelligent Humanoid + ^ ^ + \ / + Vulcan + + define class () end class; + define class () end class; + define class () end class; + define class () end class; + define class (, ) end class; + +=cut + +{ + package Object; + our @ISA = qw//; + + package LifeForm; + use base 'Object'; + + package Sentient; + use base 'LifeForm'; + + package BiPedal; + use base 'LifeForm'; + + package Intelligent; + use base 'Sentient'; + + package Humanoid; + use base 'BiPedal'; + + package Vulcan; + use base ('Intelligent', 'Humanoid'); +} + +is_deeply( + [ Class::C3::XS::calculateMRO('Vulcan') ], + [ qw(Vulcan Intelligent Sentient Humanoid BiPedal LifeForm Object) ], + '... got the right MRO for the Vulcan Dylan Example'); diff --git a/t/05_MRO.t b/t/05_MRO.t new file mode 100644 index 0000000..ef400e0 --- /dev/null +++ b/t/05_MRO.t @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 3; + +BEGIN { + use_ok('Class::C3::XS'); + use_ok('t::lib::F'); +} + +=pod + +From the parrot test t/pmc/object-meths.t + + A B A E + \ / \ / + C D + \ / + \ / + F + +=cut + +is_deeply( + [ Class::C3::XS::calculateMRO('t::lib::F') ], + [ qw(t::lib::F t::lib::C t::lib::D t::lib::A t::lib::B t::lib::E) ], + '... got the right MRO for t::lib::F'); + diff --git a/t/lib/A.pm b/t/lib/A.pm new file mode 100644 index 0000000..94faabc --- /dev/null +++ b/t/lib/A.pm @@ -0,0 +1,3 @@ +package t::lib::A; +our @ISA = qw//; +1; diff --git a/t/lib/B.pm b/t/lib/B.pm new file mode 100644 index 0000000..5d02adf --- /dev/null +++ b/t/lib/B.pm @@ -0,0 +1,3 @@ +package t::lib::B; +our @ISA = qw//; +1; diff --git a/t/lib/C.pm b/t/lib/C.pm new file mode 100644 index 0000000..f770021 --- /dev/null +++ b/t/lib/C.pm @@ -0,0 +1,3 @@ +package t::lib::C; +use base ('t::lib::A', 't::lib::B'); +1; diff --git a/t/lib/D.pm b/t/lib/D.pm new file mode 100644 index 0000000..d9562d6 --- /dev/null +++ b/t/lib/D.pm @@ -0,0 +1,3 @@ +package t::lib::D; +use base ('t::lib::A', 't::lib::E'); +1; diff --git a/t/lib/E.pm b/t/lib/E.pm new file mode 100644 index 0000000..fa0e58d --- /dev/null +++ b/t/lib/E.pm @@ -0,0 +1,3 @@ +package t::lib::E; +our @ISA = qw//; +1; diff --git a/t/lib/F.pm b/t/lib/F.pm new file mode 100644 index 0000000..b0c3eb5 --- /dev/null +++ b/t/lib/F.pm @@ -0,0 +1,3 @@ +package t::lib::F; +use base ('t::lib::C', 't::lib::D'); +1;