Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[t/spec] Some unfudging, test review/tweak and additional tests for a…

…ttribute initialization.

git-svn-id: http://svn.pugscode.org/pugs@26892 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit 6b40e88b0115f804d3b7d869ef165255d41abd5a 1 parent 71ef855
jnthn authored
Showing with 18 additions and 5 deletions.
  1. +18 −5 S12-attributes/instance.t
View
23 S12-attributes/instance.t
@@ -2,7 +2,7 @@ use v6;
use Test;
-plan 118;
+plan 122;
=begin pod
@@ -193,15 +193,15 @@ class Foo1 { has $.bar; };
ok eval('class Foo7 { has $.attr = 42 }; 1'), "class definition worked";
is eval('Foo7.new.attr'), 42, "default attribute value (1)";
-#?rakudo skip 'lexicals visible outside eval'
{
my $was_in_supplier = 0;
sub forty_two_supplier() { $was_in_supplier++; 42 }
- ok eval('class Foo10 { has $.attr = { forty_two_supplier() } }; 1'),
+ ok eval('class Foo10 { has $.attr = forty_two_supplier() }; 1'),
'class definition using "= {...}" worked';
is eval('Foo10.new.attr'), 42, "default attribute value (4)";
- is $was_in_supplier, 1, "forty_two_supplier() was actually executed (1)";
-
+ is $was_in_supplier, 1, "forty_two_supplier() was actually executed";
+ eval('Foo10.new');
+ is $was_in_supplier, 2, "forty_two_supplier() is executed per instantiation";
}
# check that doing something in submethod BUILD works
@@ -473,4 +473,17 @@ is eval('Foo7.new.attr'), 42, "default attribute value (1)";
dies_ok {$o.h<blubb><bla> = 3 }, 'No autovivification (typed hash)';
is_deeply $o.h<a b c d>, (1, 2, 3, 4), 'hash still unchanged';
}
+
+# attribute initialization based upon other attributes
+{
+ class AttrInitTest {
+ has $.a = 1;
+ has $.b = 2;
+ has $.c = $.a + $.b;
+ }
+ is AttrInitTest.new.c, 3, 'Can initialize one attribute based on another (1)';
+ is AttrInitTest.new(a => 2).c, 4, 'Can initialize one attribute based on another (2)';
+ is AttrInitTest.new(c => 9).c, 9, 'Can initialize one attribute based on another (3)';
+}
+
# vim: ft=perl6
Please sign in to comment.
Something went wrong with that request. Please try again.