Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 109 lines (88 sloc) 2.312 kb
2e38e94 [gsoc_spectest] tests for is also/instead/open. (added 16 tests)
Auzon authored
1 use v6;
2
3 use Test;
4
ef25233 @coke add test for RT #117165
coke authored
5 plan 13;
2e38e94 [gsoc_spectest] tests for is also/instead/open. (added 16 tests)
Auzon authored
6
7 # L<S12/"Open vs Closed Classes"/"Otherwise you'll get a class redefinition error.">
8
e221cd7 [t/spec] rename is_also_instead.t and update syntax
moritz authored
9
5b8dbb5 @lizmat "use MONKEY_TYPING" -> "use MONKEY-TYPING"
lizmat authored
10 use MONKEY-TYPING;
cc196ec [t/spec] set some svn props, and clean up inconsistent newlines
moritz authored
11 {
12 class Foo {
13 method a {'called Foo.a'}
14 }
e221cd7 [t/spec] rename is_also_instead.t and update syntax
moritz authored
15 augment class Foo {
cc196ec [t/spec] set some svn props, and clean up inconsistent newlines
moritz authored
16 method b {'called Foo.b'}
17 }
2e38e94 [gsoc_spectest] tests for is also/instead/open. (added 16 tests)
Auzon authored
18
19 my $o = Foo.new;
20 is($o.a, 'called Foo.a', 'basic method call works');
e221cd7 [t/spec] rename is_also_instead.t and update syntax
moritz authored
21 is($o.b, 'called Foo.b', 'added method call works');
22
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored
23 dies-ok { EVAL('augment class NonExistent { }') },
001e798 @moritz &eval does not catch exceptions.
moritz authored
24 'augment on non-existent class dies';
2e38e94 [gsoc_spectest] tests for is also/instead/open. (added 16 tests)
Auzon authored
25 }
cc196ec [t/spec] set some svn props, and clean up inconsistent newlines
moritz authored
26
5af9d23 @moritz test for augment on lexical class, RT #74910
moritz authored
27 # RT #74910
28 {
29 my class LexFoo { };
30 augment class LexFoo { method b { 'called LexFoo.b' } };
31 is LexFoo.b, 'called LexFoo.b', 'can augment lexical class';
32 }
33
e0d5199 @moritz Hash should be augmentable
moritz authored
34 # RT #76104
35 {
36 augment class Hash {
37 method foo() { self.keys };
38 }
39 is { a => 1 }.foo, 'a', 'can augment Hash';
40 }
41
323cebd [t/spec] test for RT #66694, redefining methods by augmenting stuff
moritz authored
42 # RT #66694
0cbc065 @lizmat s/eval_dies_ok/eval-dies-ok/g
lizmat authored
43 eval-dies-ok q[
323cebd [t/spec] test for RT #66694, redefining methods by augmenting stuff
moritz authored
44 class MethodClash { method foo() { 3 } };
45 augment class MethodClash { method foo() { 3 } };
46 ], 'cannot override a method by monkey-typing';
47
b518730 @moritz test for RT #76600, augmenting a class should not re-apply roles
moritz authored
48 # RT #76600
e816632 @lizmat s/eval_lives_ok/eval-lives-ok/g
lizmat authored
49 eval-lives-ok q[
5b8dbb5 @lizmat "use MONKEY_TYPING" -> "use MONKEY-TYPING"
lizmat authored
50 use MONKEY-TYPING;
b518730 @moritz test for RT #76600, augmenting a class should not re-apply roles
moritz authored
51 role Bar { has $.counter; }
52 class Pub does Bar { has $.saloon; }
53 augment class Pub { method snug() { } }
54 ], 'augmenting a class which has a role composed works';
55
56
9c40515 @dnmfarrell fixed appended RT number to be within quoted string
dnmfarrell authored
57 #?rakudo skip 'redeclaration of symbol Bar RT #125046'
cc196ec [t/spec] set some svn props, and clean up inconsistent newlines
moritz authored
58 {
5b8dbb5 @lizmat "use MONKEY_TYPING" -> "use MONKEY-TYPING"
lizmat authored
59 use MONKEY-TYPING;
cc196ec [t/spec] set some svn props, and clean up inconsistent newlines
moritz authored
60 class Bar {
61 method c {'called Bar.c'}
62 }
e221cd7 [t/spec] rename is_also_instead.t and update syntax
moritz authored
63 supersede class Bar {
cc196ec [t/spec] set some svn props, and clean up inconsistent newlines
moritz authored
64 method d {'called Bar.d'}
65 }
2e38e94 [gsoc_spectest] tests for is also/instead/open. (added 16 tests)
Auzon authored
66
67 my $o = Bar.new;
0cbc065 @lizmat s/eval_dies_ok/eval-dies-ok/g
lizmat authored
68 eval-dies-ok('$o.c', 'overridden method is gone completely');
2e38e94 [gsoc_spectest] tests for is also/instead/open. (added 16 tests)
Auzon authored
69 is($o.d, 'called Bar.d', 'new method is present instead');
70 }
e221cd7 [t/spec] rename is_also_instead.t and update syntax
moritz authored
71
43de0a9 @tadzik Test for RT #75432
tadzik authored
72 # RT #75432
73 {
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
74 lives-ok {
43de0a9 @tadzik Test for RT #75432
tadzik authored
75 class A { multi method a() { }};
76 augment class A { multi method a() { } }
77 }, 'RT #75432'
78 }
79
04d8876 @moritz RT #71456
moritz authored
80 # RT #71456
81 # some integers produces from ranges didn't have
82 # methods that augment added. Weird.
83
84 {
85 augment class Int {
86 method prime { True };
87 }
88 my $primes = 0;
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
89 lives-ok {
04d8876 @moritz RT #71456
moritz authored
90 for 1..5 {
91 $primes++ if .prime;
92 }
93 }, 'integers produced from ranges have augmented methods';
94 }
95
9c0a20d @coke add test for RT #117163
coke authored
96 # RT #117163
97 {
98 try EVAL 'class F { also is F; }';
99 ok ~$! ~~ / 'cannot inherit from itself' /, "used to crash rakudo";
100 }
101
ef25233 @coke add test for RT #117165
coke authored
102 # RT #117165
103 {
104 try EVAL 'class ::F { ... }; class F is ::F';
105 ok ~$! ~~ / 'cannot inherit from itself' /, "used to crash rakudo";
106 }
107
e221cd7 [t/spec] rename is_also_instead.t and update syntax
moritz authored
108 # vim: ft=perl6
Something went wrong with that request. Please try again.