Skip to content
Newer
Older
100644 95 lines (76 sloc) 1.94 KB
9883abb [t] move inplace.t to spec/
moritz authored
1 use v6;
2
3 use Test;
4
971ba26 fix some smartlinks
szabgab authored
5 # L<S03/Assignment operators/A op= B>
9883abb [t] move inplace.t to spec/
moritz authored
6
8447ca8 [inplace.t] Added tests for RT #70676.
Kodi Arfer authored
7 plan 28;
9883abb [t] move inplace.t to spec/
moritz authored
8
9 {
10 my @a = (1, 2, 3);
51ccac4 [t/spec] corrected a test description
moritz authored
11 lives_ok({@a .= map: { $_ + 1 }}, '.= runs with block');
9883abb [t] move inplace.t to spec/
moritz authored
12 is(@a[0], 2, 'inplace map [0]');
13 is(@a[1], 3, 'inplace map [1]');
14 is(@a[2], 4, 'inplace map [2]');
d8a04f3 [t/spec] some inplace.t hacking/fudging
moritz authored
15 }
9883abb [t] move inplace.t to spec/
moritz authored
16
d8a04f3 [t/spec] some inplace.t hacking/fudging
moritz authored
17 {
9883abb [t] move inplace.t to spec/
moritz authored
18 my @b = <foo 123 bar 456 baz>;
2167a01 More tests for RT #71462 (smartmatching against a type should yield a…
Kodi Arfer authored
19 lives_ok { @b.=grep(/<[a..z]>/)},
d8a04f3 [t/spec] some inplace.t hacking/fudging
moritz authored
20 '.= works without surrounding whitespace';
9883abb [t] move inplace.t to spec/
moritz authored
21 is @b[0], 'foo', 'inplace grep [0]';
22 is @b[1], 'bar', 'inplace grep [1]';
23 is @b[2], 'baz', 'inplace grep [2]';
24 }
25
d8a04f3 [t/spec] some inplace.t hacking/fudging
moritz authored
26 {
27 my $a=3.14;
41d8a27 [t/spec] Unfudge a bunch of tests, fudge a bunch more.
colomon authored
28 $a .= Int;
d8a04f3 [t/spec] some inplace.t hacking/fudging
moritz authored
29 is($a, 3, "inplace int");
30
31 my $b = "a_string"; $b .= WHAT;
32 my $c = 42; $c .= WHAT;
33 my $d = 42.23; $d .= WHAT;
34 my @e = <a b c d>; @e .= WHAT;
0ab503a [t/spec] further inplace.t improvements
moritz authored
35 is($b, Str, "inplace WHAT of a Str");
36 is($c, Int, "inplace WHAT of a Num");
37 is($d, Rat, "inplace WHAT of a Rat");
38 is(@e[0], Array, "inplace WHAT of an Array");
d8a04f3 [t/spec] some inplace.t hacking/fudging
moritz authored
39 }
9883abb [t] move inplace.t to spec/
moritz authored
40
41 my $f = "lowercase"; $f .= uc;
42 my $g = "UPPERCASE"; $g .= lc;
43 my $h = "lowercase"; $h .= ucfirst;
44 my $i = "UPPERCASE"; $i .= lcfirst;
45 is($f, "LOWERCASE", "inplace uc");
46 is($g, "uppercase", "inplace lc");
47 is($h, "Lowercase", "inplace ucfist");
48 is($i, "uPPERCASE", "inplace lcfirst");
49
50 # L<S12/"Mutating methods">
51 my @b = <z a b d e>;
52 @b .= sort;
53 is ~@b, "a b d e z", "inplace sort";
0ca9b3a [t/spec] Test for .= on $_.
jnthn authored
54
55 {
56 $_ = -42;
57 .=abs;
58 is($_, 42, '.=foo form works on $_');
59 }
f0b6e6c [t/spec] Tests for RT #64268
kyle authored
60
61 # RT #64268
62 {
63 my @a = 1,3,2;
ea5588e [t/spec] improved readability/clarity after comments from TimToady++
kyle authored
64 my @a_orig = @a;
65
f0b6e6c [t/spec] Tests for RT #64268
kyle authored
66 my @b = @a.sort: {1};
ea5588e [t/spec] improved readability/clarity after comments from TimToady++
kyle authored
67 is @b, @a_orig, 'worked: @a.sort: {1}';
f0b6e6c [t/spec] Tests for RT #64268
kyle authored
68
ea4d235 [t/spec] begin cleansing of eval and todos that should skip
kyle authored
69 @a.=sort: {1};
ea5588e [t/spec] improved readability/clarity after comments from TimToady++
kyle authored
70 is @a, @a_orig, 'worked: @a.=sort: {1}';
f0b6e6c [t/spec] Tests for RT #64268
kyle authored
71
ea4d235 [t/spec] begin cleansing of eval and todos that should skip
kyle authored
72 @a.=sort;
41d8a27 [t/spec] Unfudge a bunch of tests, fudge a bunch more.
colomon authored
73 is @a, [1,2,3], 'worked: @a.=sort';
f0b6e6c [t/spec] Tests for RT #64268
kyle authored
74 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
75
8447ca8 [inplace.t] Added tests for RT #70676.
Kodi Arfer authored
76 # RT #70676
77 {
78 my $x = 5.5;
79 $x .= Int;
80 isa_ok $x, Int, '.= Int (type)';
81 is $x, 5, '.= Int (value)';
82
83 $x = 3;
84 $x .= Str;
85 isa_ok $x, Str, '.= Str (type)';
86 is $x, '3', '.= Str (value)';
87
88 $x = 15;
89 $x .= Bool;
90 isa_ok $x, Bool, '.= Bool (type)';
91 is $x, True, '.= Bool (value)';
92 }
93
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
94 # vim: ft=perl6
Something went wrong with that request. Please try again.