Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 159 lines (123 sloc) 4.604 kb
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
c1196a1 [spec] convert basic S12 class tests
particle authored
2
3 use Test;
4
a5f67aa @TimToady test for Foo.new.perl leaving out parens
TimToady authored
5 plan 40;
c1196a1 [spec] convert basic S12 class tests
particle authored
6
4cf7d0a [spec] convert pod to pod6
particle authored
7 =begin pod
c1196a1 [spec] convert basic S12 class tests
particle authored
8
9 Very basic class tests from L<S12/Classes>
10
2e1aca6 [spec] really fix pod this time
particle authored
11 =end pod
c1196a1 [spec] convert basic S12 class tests
particle authored
12
13 # L<S12/Classes>
14 class Foo {}
15
b56b14e [t/spec] test for Classname.perl (RT #65260)
moritz authored
16 is Foo.perl, 'Foo', 'Classname.perl produces the class name';
a5f67aa @TimToady test for Foo.new.perl leaving out parens
TimToady authored
17 is Foo.new.perl, 'Foo.new', 'Classname.new.perl just adds .new';
b56b14e [t/spec] test for Classname.perl (RT #65260)
moritz authored
18
c1196a1 [spec] convert basic S12 class tests
particle authored
19 my $foo = Foo.new();
20 ok($foo ~~ Foo, '... smartmatch our $foo to the Foo class');
21
22 # note that S12 says that .isa() should be called on metaclasses.
23 # However, making it an object .isa() means that classes are free to
24 # override the behaviour without playing with the metamodel via traits
e52dcf1 [spectest] Some fudging/unfudging to add another test to Rakudo.
jnthn authored
25 ok($foo.isa(Foo), '.isa(Foo)');
c1196a1 [spec] convert basic S12 class tests
particle authored
26 ok($foo.isa(::Foo), '.isa(::Foo)');
3a7da94 @coke niecza fudging
coke authored
27 #?niecza todo
c1196a1 [spec] convert basic S12 class tests
particle authored
28 ok($foo.isa("Foo"), '.isa("Foo")');
29 ok(!$foo.isa("Bar"), '!.isa("Bar")');
77849bc [spectest] Fix line ending issues and set svn:eol-style native on S12-cl...
jnthn authored
30
31 {
e52dcf1 [spectest] Some fudging/unfudging to add another test to Rakudo.
jnthn authored
32 my $foo_clone = $foo.clone();
77849bc [spectest] Fix line ending issues and set svn:eol-style native on S12-cl...
jnthn authored
33 ok($foo_clone ~~ Foo, '... smartmatch our $foo_clone to the Foo class');
e52dcf1 [spectest] Some fudging/unfudging to add another test to Rakudo.
jnthn authored
34 }
c1196a1 [spec] convert basic S12 class tests
particle authored
35
5c01bc1 [t/spec] Tests for proto-object being undefined.
jnthn authored
36 # Definedness of proto-objects and objects.
37 ok(!Foo.defined, 'proto-objects are undefined');
38 my Foo $ut1;
39 ok(!$ut1.defined, 'proto-objects are undefined');
40 ok(Foo.new.defined, 'instances of the object are defined');
41
c1196a1 [spec] convert basic S12 class tests
particle authored
42 class Foo::Bar {}
43
44 my $foo_bar = Foo::Bar.new();
45 ok($foo_bar ~~ Foo::Bar, '... smartmatch our $foo_bar to the Foo::Bar class');
46
e52dcf1 [spectest] Some fudging/unfudging to add another test to Rakudo.
jnthn authored
47 ok($foo_bar.isa(Foo::Bar), '.isa(Foo::Bar)');
c1196a1 [spec] convert basic S12 class tests
particle authored
48 ok(!$foo_bar.isa(::Foo), '!Foo::Bar.new.isa(::Foo)');
49
50
51 # L<S12/Classes/An isa is just a trait that happens to be another class>
52 class Bar is Foo {}
53
54 ok(Bar ~~ Foo, '... smartmatch our Bar to the Foo class');
55
56 my $bar = Bar.new();
57 ok($bar ~~ Bar, '... smartmatch our $bar to the Bar class');
58 ok($bar.isa(Bar), "... .isa(Bar)");
59 ok($bar ~~ Foo, '... smartmatch our $bar to the Foo class');
60 ok($bar.isa(Foo), "new Bar .isa(Foo)");
77849bc [spectest] Fix line ending issues and set svn:eol-style native on S12-cl...
jnthn authored
61
e52dcf1 [spectest] Some fudging/unfudging to add another test to Rakudo.
jnthn authored
62 {
63 my $bar_clone = $bar.clone();
64 ok($bar_clone ~~ Bar, '... smartmatch our $bar_clone to the Bar class');
65 ok($bar_clone.isa(Bar), "... .isa(Bar)");
66 ok($bar_clone ~~ Foo, '... smartmatch our $bar_clone to the Foo class');
67 ok($bar_clone.isa(Foo), "... .isa(Foo)");
68 }
c1196a1 [spec] convert basic S12 class tests
particle authored
69
77849bc [spectest] Fix line ending issues and set svn:eol-style native on S12-cl...
jnthn authored
70 # Same, but with the "is Foo" declaration inlined
d20b0d2 @lizmat Fix the things I unfixed the past hours
lizmat authored
71 #?rakudo skip 'Calling is will never work with argument types (Foo)'
3a7da94 @coke niecza fudging
coke authored
72 #?niecza skip 'No value for parameter \$expected in Test is'
e52dcf1 [spectest] Some fudging/unfudging to add another test to Rakudo.
jnthn authored
73 {
74 class Baz { is Foo }
75 ok(Baz ~~ Foo, '... smartmatch our Baz to the Foo class');
76 my $baz = Baz.new();
77 ok($baz ~~ Baz, '... smartmatch our $baz to the Baz class');
78 ok($baz.isa(Baz), "... .isa(Baz)");
79 }
d0d00f4 [t/spec] test for the presence of a type registry
moritz authored
80
81 # test that lcfirst class names and ucfirst method names are allowed
82
83 {
84 class lowerCase {
85 method UPPERcase {
86 return 'works';
87 }
88 }
89 is lowerCase.new.UPPERcase, 'works',
90 'type distinguishing is not done by case of first letter';
91 }
92
93 eval_dies_ok 'my $x; $x ~~ NonExistingClassName',
94 'die on non-existing class names';
0af1c1c Add test for the class portion of:
chrisdolan authored
95
96 # you can declare classes over vivified namespaces, but not over other classes
97
98 class One::Two::Three { } # auto-vivifies package One::Two
99 class One::Two { }
100 ok(One::Two.new, 'created One::Two after One::Two::Three');
06ae909 @FROGGS eval => EVAL in S10 to S12
FROGGS authored
101 dies_ok { EVAL 'class One::Two { }' }, 'cannot redeclare an existing class';
adc10fd @coke fudge for rakudo.jvm release
coke authored
102 eval_lives_ok q[BEGIN {class Level1::Level2::Level3 {};}; class Level1::Level2 {};], 'RT #62898';
e70591f add tests for isa override and method creation with eval RT #60946 and R...
ron authored
103
12d03bf @colomon Refudge for niecza. (new test added?)
colomon authored
104 #?niecza skip "Methods must be used in some kind of package"
3a7da94 @coke niecza fudging
coke authored
105 {
2267094 @jnthn Fix some package/eval related issues.
jnthn authored
106 class A61354_1 {
06ae909 @FROGGS eval => EVAL in S10 to S12
FROGGS authored
107 EVAL('method x { "OH HAI" }')
2267094 @jnthn Fix some package/eval related issues.
jnthn authored
108 };
06ae909 @FROGGS eval => EVAL in S10 to S12
FROGGS authored
109 is A61354_1.x, "OH HAI", "can just use EVAL to add method to class";
3a7da94 @coke niecza fudging
coke authored
110 }
e70591f add tests for isa override and method creation with eval RT #60946 and R...
ron authored
111
69a779c [t/spec] Test for RT #67784
kyle authored
112 # RT #67784
113 {
114 class class {}
3a7da94 @coke niecza fudging
coke authored
115 #?niecza todo
69a779c [t/spec] Test for RT #67784
kyle authored
116 isa_ok( class.new, 'class' );
117 }
9fa4075 [t/spec] Test for RT #64686
kyle authored
118
119 # RT #64686
120 eval_dies_ok 'class Romeo::Tango {}; Romeo::Juliet.rt64686',
121 'call to missing method in A::B dies after class A::C defined';
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
122
8344991 [t/spec] test for RT #72286: self should not be writeable
moritz authored
123 # RT 72286
124 eval_dies_ok 'class WritableSelf { method f { self = 5 } }; WritableSelf.new.f',
125 'self is not writable';
126
adc10fd @coke fudge for rakudo.jvm release
coke authored
127 # RT #65022
060abcc [t/spec] Added tests for RT 65022 - Nested classes declared inside diffe...
radus authored
128 eval_lives_ok 'class Test1 { class A {};}; class Test2 {class A {};};',
129 'RT65022 - Nested classes in different classes can have the same name';
15664cb @moritz test for RT #76270, named class declaration should return the class
moritz authored
130
131 # RT #76270
132 {
133 my $x = class Named { };
134 isa_ok $x, Named, 'named class declaration returns the class object';
135 }
369d517 @diakopter test RT #72916
diakopter authored
136
137 # RT #72916
138 {
139 #?niecza todo 'Exception: Unable to resolve method add_method in type ClassHOW'
140 eval_lives_ok 'Rat.^add_method("lol", method ($what) { say "lol$what" }) ~~ Method',
141 'add_method returns a Method object';
142 }
143
b676ed8 @usev6 Add test for RT #72338
usev6 authored
144 # RT #72338
145 {
146 my $rt72338;
147 class x {
148 multi method y { self.y("void") }
149 multi method y (Str $arg) { $rt72338 = $arg }
150 }
151 x.new.y;
152 is $rt72338, 'void',
153 'no need to add a semicolon after closing brace of class definition followed by newline';
154 }
155
c5545ff @Mouq Test that methods can be called on class definitions
Mouq authored
156 is class :: { method foo { 42 }}.foo, 42, "Can call method on class definition without parens";
157
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
158 # vim: ft=perl6
Something went wrong with that request. Please try again.