Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 212 lines (186 sloc) 7.744 kB
ff2f9de @sorear Prototype of the Array class
authored
1 # vim: ft=perl6
2 use Test;
9f1bf0e @sorear Implement &sort
authored
3 use MONKEY_TYPING;
ff2f9de @sorear Prototype of the Array class
authored
4
ca4d6f1 @sorear Implement use of submethod BUILD
authored
5 {
6 my class Bt {
7 has $!pie;
8 method get_pie() { $!pie }
9 submethod BUILD(:$x) { $!pie = $x }
10 }
11 is Bt.new(x => 5).get_pie, 5, "BUILD basically works";
12 my class SubBT is Bt {
13 has $!pie2;
14 method get_pie2() { $!pie2 }
15 submethod BUILD(:$y) { $!pie2 = $y }
16 }
17 is SubBT.new(x => 5, y => 2).get_pie, 5, "superclass' BUILD in subclass";
18 is SubBT.new(x => 5, y => 2).get_pie2, 2, "subclass' BUILD in subclass";
904bb14 @sorear Fix binding to existing @vars
authored
19
20 my @l;
21 @l := [1,2,3];
22 is +[@l], 3, 'binding to existing list vars works';
ca4d6f1 @sorear Implement use of submethod BUILD
authored
23 }
24
44f7995 @sorear Steal ... and ...^ from Rakudo
authored
25 is [ 1,2,3 ... 10 ], [1..10];
26 is [ 1,2,4 ... 256 ], [map 2 ** *, 0..8];
27 is [ 1,1,*+* ...^ *>100 ], [1,1,2,3,5,8,13,21,34,55,89];
28
e51f7a9 @sorear [remove-CURLEX] Reimplementation of STD is_name
authored
29 eval_lives_ok q[
30 class F2855::G7136 { ... }
31 class F2855::G7136 { }
32 ], "can stub then define nested classes";
33
dff3b35 @sorear 36 new tests for tighter/looser/equiv. tighter+looser is not tested,…
authored
34 {
21aca01 @sorear Make for-loops work in blasts
authored
35 my @l = gather for 1,2 { take $_ };
36 is ~@l, "1 2", "gather for works";
dff3b35 @sorear 36 new tests for tighter/looser/equiv. tighter+looser is not tested,…
authored
37
2c21c29 @sorear Rewrite stash handling
authored
38 eval_dies_ok 'class { has $!foo; has $!foo; }',
39 "double attribute declaration caught";
dff3b35 @sorear 36 new tests for tighter/looser/equiv. tighter+looser is not tested,…
authored
40
2c21c29 @sorear Rewrite stash handling
authored
41 eval_dies_ok 'class { method abar {}; method abar {}; }',
42 "double method declaration caught";
dff3b35 @sorear 36 new tests for tighter/looser/equiv. tighter+looser is not tested,…
authored
43
44 # <chain> isn't tested here. It's not possible to do the same AST
45 # reconstruction tricks. However if <right> etc work, and chained
46 # comparisons work, it's pretty likely to work combinationally.
47 sub infix:<@a> { "a(@_.Str())" }
48 sub infix:<@b> is assoc<right> { "b(@_.Str())" }
49 sub infix:<@c> is assoc<list> { "c(@_.Str())" }
c835aaa @sorear Fixup assoc/tighter/equiv/looser tests; now fully working
authored
50 sub infix:<@d> is assoc<list> { "d(@_.Str())" } #OK not used
dff3b35 @sorear 36 new tests for tighter/looser/equiv. tighter+looser is not tested,…
authored
51 sub infix:<@e> is assoc<non> { "e(@_.Str())" }
52 sub infix:<@f> is assoc<left> { "f(@_.Str())" }
53
54 is (1 @a 2), 'a(1 2)', 'basic operator function';
55 is (1 @a 2 @a 3), 'a(a(1 2) 3)', 'operators default to left assoc';
56 is (1 @f 2 @f 3), 'f(f(1 2) 3)', 'explicit assoc<left> works too';
c835aaa @sorear Fixup assoc/tighter/equiv/looser tests; now fully working
authored
57 is (1 @f 2 @a 3), 'a(f(1 2) 3)', 'mixed <left> at same prec works (1)';
58 is (1 @a 2 @f 3), 'f(a(1 2) 3)', 'mixed <left> at same prec works (2)';
dff3b35 @sorear 36 new tests for tighter/looser/equiv. tighter+looser is not tested,…
authored
59 is (1 @b 2 @b 3), 'b(1 b(2 3))', 'assoc<right> overrides';
60 is (1 @c 2 @c 3), 'c(1 2 3)', 'assoc<list> takes all 3 at once';
61 eval_dies_ok q[1 @c 2 @d 3], 'mixed <list> at same prec dies';
62 eval_dies_ok q[1 @e 2 @e 3], '<non> dies with 3';
63 is (1 @e 2), 'e(1 2)', '<non> with 2 works';
64
c835aaa @sorear Fixup assoc/tighter/equiv/looser tests; now fully working
authored
65 sub infix:<@g> is tighter<@a> { "g(@_.Str())" } #OK not used
66 sub infix:<@h> is looser<@a> { "h(@_.Str())" } #OK not used
67 sub infix:<@i> is tighter(&infix:<@a>) { "i(@_.Str())" } #OK not used
68 sub infix:<@j> is looser(&infix:<@a>) { "j(@_.Str())" } #OK not used
69 sub infix:<@k> is tighter<@h> { "k(@_.Str())" } #OK not used
70 sub infix:<@l> is looser<@g> { "l(@_.Str())" } #OK not used
71 sub infix:<@m> is equiv<@a> { "m(@_.Str())" } #OK not used
72 sub infix:<@n> is equiv(&infix:<@a>) { "n(@_.Str())" } #OK not used
73 sub infix:<@o> is equiv<@g> { "o(@_.Str())" } #OK not used
74 sub infix:<@p> is equiv<@h> { "p(@_.Str())" } #OK not used
75 sub infix:<@q> is equiv<@b> { "q(@_.Str())" } #OK not used
dff3b35 @sorear 36 new tests for tighter/looser/equiv. tighter+looser is not tested,…
authored
76
77 my @cmptests = (
78 'a', 'g', 1, 0, 'tighter<> works',
79 'h', 'a', 1, 0, 'looser<> works',
80 'a', 'i', 1, 0, 'tighter<> works with code object',
81 'j', 'a', 1, 0, 'looser<> works with code object',
82 'h', 'k', 1, 0, 'tighter of a looser works',
83 'l', 'g', 1, 0, 'looser of a tighter works',
84 'k', 'a', 1, 0, 'tighter of a looser is still looser',
85 'a', 'l', 1, 0, 'looser of a tighter is still tighter',
86 'm', 'a', 0, 0, 'equiv works',
87 'n', 'a', 0, 0, 'equiv works with code object',
88 'o', 'g', 0, 0, 'equiv of tighter works',
89 'p', 'h', 0, 0, 'equiv of looser works',
90 'q', 'q', 1, 1, 'equiv also copies associativity',
91 );
c835aaa @sorear Fixup assoc/tighter/equiv/looser tests; now fully working
authored
92 sub ckb($res is copy) { #OK not used
93 $res ~~ s:g /<.alpha>//; #::
94 $res eq '((1 2) 3)' ?? 0 !! 1;
95 }
dff3b35 @sorear 36 new tests for tighter/looser/equiv. tighter+looser is not tested,…
authored
96 my @frags;
c835aaa @sorear Fixup assoc/tighter/equiv/looser tests; now fully working
authored
97 for @cmptests -> $lt, $gt, $right_br_ord, $right_br_opp, $msg {
98 push @frags, "is ckb(1 @$lt 2 @$gt 3), $right_br_ord, '$msg (1)';\n";
99 push @frags, "is ckb(1 @$gt 2 @$lt 3), $right_br_opp, '$msg (2)';\n";
dff3b35 @sorear 36 new tests for tighter/looser/equiv. tighter+looser is not tested,…
authored
100 }
101 eval @frags.join;
102 }
103
9fa31a8 @sorear my-variables default to Any but with Mu constraint
authored
104 {
105 lives_ok { my $x; $x = Mu },
106 "can assign Mu to default-typed variable (noninline)";
107 lives_ok { if 1 { my $x; $x = Mu } },
108 "can assign Mu to default-typed variable (inline)";
109 dies_ok { my Any $x; $x = Mu },
110 "cannot assign Mu to Any-typed variable (noninline)";
111 dies_ok { if 1 { my Any $x; $x = Mu } },
112 "cannot assign Mu to Any-typed variable (inline)";
113 ok { my $x; $x }.() === Any,
114 "default-typed variable receives Any (noninline)";
115 ok { if 1 { my $x; $x } }.() === Any,
116 "default-typed variable receives Any (inline)";
117
118 lives_ok { my @x; push @x, Mu }, "can push Mu";
119 lives_ok { my @x; push @x, 5; @x[0] = Mu }, "push creates Mu-ready vars";
120 lives_ok { my @x; unshift @x, Mu }, "can unshift Mu";
121 lives_ok { my @x; unshift @x, 5; @x[0] = Mu }, "unshift creates Mu-ready vars";
122 lives_ok { my $x; $x[0] = Mu }, "array creation autoviv supports Mu";
123 lives_ok { my @x; @x[0] = Mu }, "element creation autoviv supports Mu";
124 lives_ok { my $x; $x<a> = Mu }, "hash creation autoviv supports Mu";
125 lives_ok { my %x; %x<a> = Mu }, "hash element creation autoviv supports Mu";
126 }
127
ba002dd @sorear Fix heredoc interpolation space oddity (thou++)
authored
128 # regression test from thou
129 {
130 my $x = 'Bar';
131 my $in = qq:to [A] ;
4d02280 @sorear Fix heredoc despacing for real, now with a working test too
authored
132 $x Foo
133 A
134 is $in.substr(0,8), 'Bar Foo', "spaces preserved after heredoc interpolation";
ba002dd @sorear Fix heredoc interpolation space oddity (thou++)
authored
135 }
136
27122b4 @sorear Fix binding to package-scoped arrays (yet again), @*ARGS and %*ENV fl…
authored
137 {
138 ok @*ARGS.flattens, '@*ARGS is a flatteny thing';
139 ok %*ENV.flattens, '%*ENV is a flatteny thing';
140 @Y8158::z := [1,2,3];
141 ok @Y8158::z.flattens, 'binding to @foo::bar works';
142 }
143
d6516ab @sorear Incorporate colomon's power tests
authored
144 # from colomon
145 {
146 isa_ok 1 ** 2, Int, "1 squared is an Int";
147 is 1 ** 2, 1, "1 squared is 1";
148
149 isa_ok 2 ** 3, Int, "2 ** 3 is an Int";
150 is 2 ** 3, 8, "2 ** 3 is 8";
151 isa_ok (2/3) ** 3, Rat, "(2/3) ** 3 is a Rat";
152 is (2/3) ** 3, 8 / 27, "(2/3) ** 3 is 8 / 27";
153 isa_ok FatRat.new(2, 3) ** 3, FatRat, "FatRat.new(2, 3) ** 3 is a FatRat";
154 is FatRat.new(2, 3) ** 3, 8 / 27, "FatRat.new(2, 3) ** 3 is 8 / 27";
155 isa_ok 2.54e0 ** 3, Num, "2.54e0 ** 3 is an Num";
156 is 2.54e0 ** 3, 16.387064e0, "2.54e0 ** 3 is 16.387064e0";
157
158 isa_ok 2 ** -3, Rat, "2 ** -3 is an Rat"; # spec?
159 is 2 ** -3, 1/8, "2 ** -3 is 1/8";
160 isa_ok (2/3) ** -3, Rat, "(2/3) ** -3 is a Rat";
161 is (2/3) ** -3, 27 / 8, "(2/3) ** -3 is 27 / 8";
162 isa_ok FatRat.new(2, 3) ** -3, FatRat, "FatRat.new(2, 3) ** -3 is a FatRat";
163 is FatRat.new(2, 3) ** -3, 27 / 8, "FatRat.new(2, 3) ** -3 is 27 / 8";
164 isa_ok 2.54e0 ** -3, Num, "2.54e0 ** -3 is an Num";
165 is_approx (2.54e0 ** -3), 0.0610237440947323, "2.54e0 ** -3 is 0.0610237440947323, more or less";
166
167 is_approx 1i ** 2, -1, "1i ** 2 is -1";
168 is_approx 1i ** 3, -1i, "1i ** 3 is -i";
169 is_approx 1i ** 4, 1, "1i ** 4 is 1";
170 }
171
bad54f1 @sorear Fix @x is copy for non-flatteny arguments
authored
172 {
173 "x" ~~ /./;
174 $/.perl; # regression; failure mode was infinite loop
175 my $x = 1;
176 2 R+= $x;
177 is $x, 3, 'R+= works';
178
179 sub foo(@y is copy) { +@y }
180 is foo([1,2,4]), 3, '@y is copy works with non-flatteny values';
181 }
182
212ba5b @sorear Fix ^2 X ^2 (Util)
authored
183 lives_ok { ^2 X ^2 }, 'X works on Ranges';
184
0fa6f23 @sorear Fix Foo::Bar regression
authored
185 #is $?ORIG.substr(0,5), '# vim', '$?ORIG works';
186
187 # {
188 # {
189 # our $x = 5; #OK
190 # }
191 # ok $::x == 5, '$::x finds our variable';
192 #
193 # package Fao { our $y = 6; } #OK
194 # ok $::Fao::y == 6, '$::Fao::y works as $Fao::y';
195 #
196 # { class Mao { } }
197 # ok ::Mao.new.defined, 'can use classes via ::Mao';
198 # }
199 #
200 # {
201 # my $x = 7; #OK
202 # ok $::x == 7, '$::x can find lexicals';
203 # class A3 {
204 # method moo { 42 }
205 # class B4 {
206 # ok ::A3.moo, '::A3 can find outer classes';
207 # }
208 # }
209 # }
ae2e557 @sorear Implement control operators next, redo, last, return
authored
210
025e408 @pmurias [Test.pm6] remove &done-testing and &done_testing
pmurias authored
211 done;
Something went wrong with that request. Please try again.