Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 205 lines (154 sloc) 5.435 kb
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
1 use v6;
2
3 use Test;
4
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
5 plan 42;
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
6
199e76c [t/spec] more :by removal
moritz authored
7 # L<S03/Invocant marker/"will apply the :xxx adverb">
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
8 sub prefix:<blub> (Str $foo, Int :$times = 1) {
9 ("BLUB" x $times) ~ $foo;
10 }
11
12 is prefix:<blub>("bar"), 'BLUBbar', 'user-defined prefix operator, long name';
13 is prefix:<blub>("bar", times => 2), 'BLUBBLUBbar', 'user-defined prefix operator, long name, optional parameter';
14 is prefix:<blub>(:times(2), "bar"), 'BLUBBLUBbar', 'user-defined prefix operator, long name, :times adverb, leading';
15 is prefix:<blub>("bar", :times(2)), 'BLUBBLUBbar', 'user-defined prefix operator, long name, :times adverb, trailing';
16 is blub "bar", 'BLUBbar', 'user-defined prefix operator, basic call';
17 is blub "bar" :times(2), 'BLUBBLUBbar', 'user-defined prefix operator, :times adverb, space';
18 is blub "bar":times(2), 'BLUBBLUBbar', 'user-defined prefix operator, :times adverb, no space';
19
20 {
21 # These basic adverb tests are copied from a table in A12.
22 my $bar = 123;
23 my @many = (4,5);
24 sub dostuff(){"stuff"}
25 my ($v,$e);
26 $e = (foo => $bar);
27 $v = :foo($bar);
28 is ~$v, ~$e, ':foo($bar)';
29
30 $e = (foo => [1,2,3,@many]);
31 $v = :foo[1,2,3,@many];
32 is ~$v, ~$e, ':foo[1,2,3,@many]';
33
34 $e = (foo => «alice bob charles»);
35 $v = :foo«alice bob charles»;
36 is ~$v, ~$e, ':foo«alice bob charles»';
37
38 $e = (foo => 'alice');
39 $v = :foo«alice»;
40 is ~$v, ~$e, ':foo«alice»';
41
42 $e = (foo => { a => 1, b => 2 });
43 $v = eval ':foo{ a => 1, b => 2 }';
44 is ~$v, ~$e, ':foo{ a => 1, b => 2 }';
45
46 $e = (foo => { dostuff() });
47 $v = :foo{ dostuff() };
48 is ~$v, ~$e, ':foo{ dostuff() }';
49
50 $e = (foo => 0);
51 $v = :foo(0);
52 is ~$v, ~$e, ':foo(0)';
53
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
54 $e = (foo => Bool::True);
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
55 $v = :foo;
56 is ~$v, ~$e, ':foo';
57 }
58
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
59 # Exercise various mixes of "fiddle", parens "()",
60 # and adverbs with "X' and without "x" an argument.
61 sub violin($x) {
62 if $x ~~ Bool {
63 $x ?? "1" !! "0";
64 } else {
65 $x;
66 }
67 }
68 sub fiddle(:$x,:$y){ violin($x) ~ violin($y) }
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
69
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
70 #?niecza skip 'Multi colonpair syntax not yet understood'
71 {
72 # fiddle(XY) fiddle(YX) fiddle(xY) fiddle(Xy)
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
73
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
74 is fiddle(:x("a"):y("b")), "ab", 'fiddle(:x("a"):y("b"))';
75 is fiddle(:y("b"):x("a")), "ab", 'fiddle(:y("b"):x("a"))';
76 is fiddle(:x:y("b")), "1b", 'fiddle(:x:y("b"))';
77 is fiddle(:x("a"):y), "a1", 'fiddle(:x("a"):y)';
78 }
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
79
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
80 {
81 # fiddle(X)Y fiddle(Y)X fiddle(x)Y fiddle(X)y fiddle(x)y
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
82
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
83 is fiddle(:x("a")):y("b"), "ab", 'fiddle(:x("a")):y("b")';
84 is fiddle(:y("b")):x("a"), "ab", 'fiddle(:y("b")):x("a")';
85 is fiddle(:x):y("b"), "1b", 'fiddle(:x("a")):y("b")';
86 is fiddle(:x("a")):y, "a1", 'fiddle(:x("a")):y';
87 is fiddle(:x):y, "11", 'fiddle(:x):y';
88 }
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
89
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
90 {
91 # fiddle()XY fiddle()YX fiddle()xY fiddle()Xy fiddle()xy
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
92
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
93 is fiddle():x("a"):y("b"), "ab", 'fiddle():x("a"):y("b")';
94 is fiddle():y("b"):x("a"), "ab", 'fiddle():y("b"):x("a")';
95 is fiddle():x:y("b"), "1b", 'fiddle():x:y("b")';
96 is fiddle():x("a"):y, "a1", 'fiddle():x("a"):y';
97 is fiddle():x:y, "11", 'fiddle():x:y';
98 }
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
99
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
100 {
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
101 # f_X(Y) f_X_Y() f_X_Y_() f_XY_() f_XY() fXY ()
102
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
103 # $v = fiddle :x("a")(:y("b"));
104 # is $v, "ab", 'fiddle :x("a")(:y("b"))';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
105 # Since the demagicalizing of pairs, this test shouldn't and doesn't work any
106 # longer.
107
108 # $v = 'eval failed';
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
109 # eval '$v = fiddle :x("a") :y("b")()';
7347a84 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
110 # #?pugs todo 'bug'
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
111 # is $v, "ab", 'fiddle :x("a") :y("b")()';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
112
113 # $v = 'eval failed';
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
114 # eval '$v = fiddle :x("a") :y("b") ()';
7347a84 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
115 # #?pugs todo 'bug'
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
116 # is $v, "ab", 'fiddle :x("a") :y("b") ()';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
117
118 # $v = 'eval failed';
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
119 # eval '$v = fiddle :x("a"):y("b") ()';
7347a84 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
120 # #?pugs todo 'bug'
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
121 # is $v, "ab", 'fiddle :x("a"):y("b") ()';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
122
123 # $v = 'eval failed';
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
124 # eval '$v = fiddle :x("a"):y("b")()';
7347a84 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
125 # #?pugs todo 'bug'
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
126 # is $v, "ab", 'fiddle :x("a"):y("b")()';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
127
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
128 # $v = fiddle:x("a"):y("b") ();
129 # is $v, "ab", 'fiddle:x("a"):y("b") ()';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
130 }
131
132 {
133 # Exercise mixes of adverbs and positional arguments.
134
135 my $v;
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
136 my sub f($s,:$x) { violin($x) ~ violin($s) }
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
137 my sub g($s1,$s2,:$x) {$s1~$x~$s2}
138 my sub h(*@a) {@a.perl}
139 my sub i(*%h) {%h.perl}
140 my sub j($s1,$s2,*%h) {$s1~%h.perl~$s2}
141
142 # f(X s) f(Xs) f(s X) f(sX) f(xs) f(sx)
143
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
144 is f(:x("a"), "b"), "ab", 'f(:x("a") "b")';
145 is f(:x("a"),"b"), "ab", 'f(:x("a")"b")';
146 is f("b", :x("a")), "ab", 'f("b" :x("a"))';
147 is f("b",:x("a")), "ab", 'f("b":x("a"))';
148 is f(:x, "b"), "1b", 'f(:x "b")';
149 is f("b", :x), "1b", 'f("b" :x)';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
150
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
151 # f(s)X
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
152
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
153 is f("b"):x("a"), "ab", 'f("b"):x("a")';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
154
155 # fs X fsX fs x fsx
156
157 # $v = f "b" :x("a");
158 # is $v, "ab", 'f "b" :x("a")';
159
160 # $v = f "b":x("a");
161 # is $v, "ab", 'f "b":x("a")';
162
163 # $v = f "b" :x;
164 # is $v, "1b", 'f "b" :x';
165
166 # $v = f "b":x;
167 # is $v, "1b", 'f "b":x';
168
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
169 # add more tests...
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
170
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
171 }
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
172
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
173 #?niecza skip 'Multi colonpair syntax not yet understood'
174 { # adverbs as pairs
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
175
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
176 my sub f1($s,:$x){$s.perl~$x}
177 is f1(\:bar :x("b")), '("bar" => Bool::True)b', 'f1(\:bar :x("b"))';
178 }
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
179
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
180 {
181 # adverbs as pairs, cont.
182 my sub f2(Pair $p){$p.perl}
183 is f2((:bar)), ("bar" => Bool::True).perl, 'f2((:bar))';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
184
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
185 my sub f3(Pair $p1, Pair $p2){$p1.perl~" - "~$p2.perl}
186 is f3((:bar),(:hee(3))), "{(bar => Bool::True).perl} - {(hee => 3).perl}", 'f3((:bar),(:hee(3)))';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
187 }
188
868ae08 @colomon Complete overhaul -- make tests one liners, regroup somewhat, and eli…
colomon authored
189
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
190 {
191 # Exercise adverbs on operators.
192
193 sub prefix:<zpre>($a,:$x){join(",",$a,$x)}
194 is (zpre 4 :x(5)), '4,5', '(zpre 4 :x(5))';
195
196 sub postfix:<zpost>($a,:$x){join(",",$a,$x)}
e548330 [inplace.t] missing lparen
lwall authored
197 is (4zpost :x(5)), '4,5', '(4 zpost :x(5))';
b74ae44 [t] move adverbial_modifiers.t to spec/
moritz authored
198
199 sub infix:<zin>($a,$b,:$x){join(",",$a,$b,$x)}
200 is (3 zin 4 :x(5)), '3,4,5', '(3 zin 4 :x(5))';
201
202 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
203
204 # vim: ft=perl6
Something went wrong with that request. Please try again.