Skip to content
Newer
Older
100644 64 lines (53 sloc) 2.03 KB
d4c216d [t/spec] Test for RT #61108
kyle authored Jul 10, 2009
1 use v6;
2 use Test;
3
3500e66 @moritz RT #69316, constructing objects of inner class in constructor of oute…
moritz authored Jan 8, 2012
4 plan 14;
d4c216d [t/spec] Test for RT #61108
kyle authored Jul 10, 2009
5
6 =begin pod
7
8 Tests for lexical classes delcared with 'my class'
9
10 =end pod
11
12 # L<S12/Classes>
13
4722738 [t/spec] A bunch more tests for lexical classes.
jnthn authored Apr 24, 2010
14 # A few basic tests.
d4c216d [t/spec] Test for RT #61108
kyle authored Jul 10, 2009
15 eval_lives_ok 'my class A {}', 'my class parses OK';
4722738 [t/spec] A bunch more tests for lexical classes.
jnthn authored Apr 24, 2010
16 eval_lives_ok '{ my class B {} }; { my class B {} }',
d4c216d [t/spec] Test for RT #61108
kyle authored Jul 10, 2009
17 'declare classes with the same name in two scopes.';
4722738 [t/spec] A bunch more tests for lexical classes.
jnthn authored Apr 24, 2010
18 eval_lives_ok '{ my class B {}; B.new; }',
19 'can instantiate lexical class';
e33900b @coke pugs fudge
coke authored Apr 9, 2012
20 #?pugs todo
4722738 [t/spec] A bunch more tests for lexical classes.
jnthn authored Apr 24, 2010
21 eval_dies_ok '{ my class B {}; B.new; }; B.new',
22 'scope is correctly restricted';
23
24 {
25 my class WeissBier {
26 has $.name;
27 method describe() { 'outstanding flavour' }
28 }
29 my $pint = WeissBier.new(name => 'Erdinger');
30 ok $pint ~~ WeissBier, 'can smart-match against lexical class';
31 is $pint.name, 'Erdinger', 'attribute in lexical class works';
32 is $pint.describe, 'outstanding flavour', 'method call on lexical class works';
d417a87 @jnthn Update a test for latest stringification semantics.
jnthn authored Jul 4, 2011
33 is WeissBier.gist, 'WeissBier()', 'lexical type object stringifies correct';
f7743f7 [t/spec] Tests for inheritance and role composition involving lexical…
jnthn authored May 1, 2010
34
35 my class LessThanAmazingWeissBier is WeissBier {
36 method describe() { 'tastes like sweetcorn' }
37 }
38 ok LessThanAmazingWeissBier ~~ WeissBier, 'inehritance between lexical classes works';
39 my $ltapint = LessThanAmazingWeissBier.new(name => 'Baltika 7');
40 ok $ltapint ~~ LessThanAmazingWeissBier, 'can smart-match class that inherits';
41 ok $ltapint ~~ WeissBier, 'can smart-match against parent class too';
42 is $ltapint.describe, 'tastes like sweetcorn', 'can call overridden method';
43 is $ltapint.name, 'Baltika 7', 'can call inherited method that accesses inherited attribute';
4722738 [t/spec] A bunch more tests for lexical classes.
jnthn authored Apr 24, 2010
44 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored Aug 8, 2009
45
3500e66 @moritz RT #69316, constructing objects of inner class in constructor of oute…
moritz authored Jan 8, 2012
46 # RT #69316
e33900b @coke pugs fudge
coke authored Apr 9, 2012
47 #?pugs skip 'bless'
3500e66 @moritz RT #69316, constructing objects of inner class in constructor of oute…
moritz authored Jan 8, 2012
48 {
49 class Forest {
50 class Frog {
51 method speak { "ribbit ribbit" }
52 };
53 has Frog $.frog;
54 method new() {
55 my Frog $frog .= new;
56 self.bless(*, :$frog);
57 };
58 }
59 is Forest.new.frog.speak, 'ribbit ribbit',
60 'can construct objects of inner class in outer constructor';
61 }
62
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored Aug 8, 2009
63 # vim: ft=perl6
Something went wrong with that request. Please try again.