Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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