Permalink
Browse files

[gsoc_spectest] tests for is also/instead/open. (added 16 tests)

git-svn-id: http://svn.pugscode.org/pugs@20833 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
Auzon Auzon
Auzon authored and Auzon committed Jun 16, 2008
1 parent 20243dc commit 2e38e9414a838f8594aef64afac08cb623926a75
Showing with 90 additions and 0 deletions.
  1. +34 −0 S12-class/is_also_instead.t
  2. +56 −0 S12-class/open_closed.t
@@ -0,0 +1,34 @@
+use v6;
+
+use Test;
+
+plan 4;
+
+# L<S12/"Open vs Closed Classes"/"Otherwise you'll get a class redefinition error.">
+
+class Foo {
+ method a {'called Foo.a'}
+}
+
+class Foo is also {
+ method b {'called Foo.b'}
+}
+
+{
+ my $o = Foo.new;
+ is($o.a, 'called Foo.a', 'basic method call works');
+ is($o.b, 'called Foo.b', 'added method call works');
+}
+
+class Bar {
+ method c {'called Bar.c'}
+}
+class Bar is instead {
+ method d {'called Bar.d'}
+}
+
+{
+ my $o = Bar.new;
+ eval_dies_ok('$o.c', 'overridden method is gone completely');
+ is($o.d, 'called Bar.d', 'new method is present instead');
+}
View
@@ -0,0 +1,56 @@
+use v6;
+
+use Test;
+
+plan 12;
+
+# syn r14552
+
+# L<S12/"Open vs Closed Classes"/"a pragma for selecting global semantics of the underlying object-oriented engine">
+
+use oo :closed :final;
+
+class Foo {
+ method a {'called Foo.a'}
+}
+
+eval_dies_ok('class Foo is also {method b {"called Foo.b"}}}', 'adding to closed class dies');
+
+class Bar is open {
+ method c {'called Bar.c'}
+}
+lives_ok({class Bar is also {method d {'called Bar.d'}}}, 'adding to opened class lives (using "is open")');
+
+{
+ my $o = Bar.new;
+ is($o.c, 'called Bar.c', 'old method is still present');
+ is($o.d, 'called Bar.d', 'new method is also present');
+}
+
+{
+ # S12 gives the example of 'use class :open' as well as 'use oo :closed'
+ # this seems weird to me.
+ use class :open;
+ class Baz {method e {'called Baz.e'}}
+ lives_ok({class Baz is also {method f {'called Baz.f'}}}, 'adding to open class lives (lexically scoped pragma)');
+
+ my $o = Baz.new;
+ is($o.e, 'called Baz.e', 'old method is still present');
+ is($o.f, 'called Baz.f', 'new method is present as well');
+}
+
+# L<S12/"Open vs Closed Classes"/"or by lexically scoped pragma around the class definition">
+# and just when you thought I ran out of generic identifiers
+use class :open<Qux>;
+class Qux {method g {'called Qux.g'}}
+lives_ok({class Qux is also {method h {'called Qux.i'}}}, 'adding to open class lives (global pragma with class name)');
+{
+ my $o = Qux.new;
+ is($o.g, 'called Qux.g', 'old is still present');
+ is($o.h, 'called Qux.h', 'new method is present as well');
+}
+
+# L<S12/"Open vs Closed Classes"/"declaring individual classes closed or final">
+# try a few things that come to mind to make sure it's not lurking
+eval_dies_ok('class ClosedAlpha is closed {}', '"is closed" is not implemented');
+eval_dies_ok('class ClosedBeta is final {}', '"is final" is not implemented');

0 comments on commit 2e38e94

Please sign in to comment.