Skip to content
Newer
Older
100644 128 lines (113 sloc) 4.41 KB
ff2f9de @sorear Prototype of the Array class
authored Aug 4, 2010
1 # vim: ft=perl6
2 use Test;
9f1bf0e @sorear Implement &sort
authored Oct 13, 2010
3 use MONKEY_TYPING;
ff2f9de @sorear Prototype of the Array class
authored Aug 4, 2010
4
ca4d6f1 @sorear Implement use of submethod BUILD
authored Jun 7, 2011
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 Jun 8, 2011
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 Jun 8, 2011
23 }
24
44f7995 @sorear Steal ... and ...^ from Rakudo
authored Jun 8, 2011
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 Jun 12, 2011
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 Jun 16, 2011
34 {
35 my @l = gather for 1,2 { take $_ };
36 is ~@l, "1 2", "gather for works";
37
38 eval_dies_ok 'class { has $!foo; has $!foo; }',
39 "double attribute declaration caught";
40
41 eval_dies_ok 'class { method abar {}; method abar {}; }',
42 "double method declaration caught";
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())" }
50 sub infix:<@d> is assoc<list> { "d(@_.Str())" }
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';
57 is (1 @f 2 @a 3), 'f(a(1 2) 3)', 'mixed <left> at same prec works (1)';
58 is (1 @a 2 @f 3), 'a(f(1 2) 3)', 'mixed <left> at same prec works (2)';
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
65 sub infix:<@g> is tighter<@a> { "g(@_.Str())" }
66 sub infix:<@h> is looser<@a> { "h(@_.Str())" }
67 sub infix:<@i> is tighter(&infix:<@a>) { "i(@_.Str())" }
68 sub infix:<@j> is looser(&infix:<@a>) { "j(@_.Str())" }
69 sub infix:<@k> is tighter<@h> { "k(@_.Str())" }
70 sub infix:<@l> is looser<@g> { "l(@_.Str())" }
71 sub infix:<@m> is equiv<@a> { "m(@_.Str())" }
72 sub infix:<@n> is equiv(&infix:<@a>) { "n(@_.Str())" }
73 sub infix:<@o> is equiv<@g> { "o(@_.Str())" }
74 sub infix:<@p> is equiv<@h> { "p(@_.Str())" }
75 sub infix:<@q> is equiv<@b> { "q(@_.Str())" }
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 );
92 my @frags;
93 for @cmptests -> $lt, $gt, $right_br_order, $right_br_opp, $msg {
94 my @br = "'{$lt}({$gt}(1 2) 3)'", "'{$lt}(1 {$gt}(2 3))'";
95 push @frags, "is (1 @$lt 2 @$gt 3), @br[$right_br_ord], '$msg (1)';\n";
96 push @frags, "is (1 @$gt 2 @$lt 3), @br[$right_br_opp], '$msg (2)';\n";
97 }
98 eval @frags.join;
99 }
100
0fa6f23 @sorear Fix Foo::Bar regression
authored Oct 6, 2010
101 #is $?ORIG.substr(0,5), '# vim', '$?ORIG works';
102
103 # {
104 # {
105 # our $x = 5; #OK
106 # }
107 # ok $::x == 5, '$::x finds our variable';
108 #
109 # package Fao { our $y = 6; } #OK
110 # ok $::Fao::y == 6, '$::Fao::y works as $Fao::y';
111 #
112 # { class Mao { } }
113 # ok ::Mao.new.defined, 'can use classes via ::Mao';
114 # }
115 #
116 # {
117 # my $x = 7; #OK
118 # ok $::x == 7, '$::x can find lexicals';
119 # class A3 {
120 # method moo { 42 }
121 # class B4 {
122 # ok ::A3.moo, '::A3 can find outer classes';
123 # }
124 # }
125 # }
ae2e557 @sorear Implement control operators next, redo, last, return
authored Sep 15, 2010
126
025e408 @pmurias [Test.pm6] remove &done-testing and &done_testing
pmurias authored Dec 31, 2010
127 done;
Something went wrong with that request. Please try again.