Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 94 lines (71 sloc) 2.321 kb
81a61b0 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access in t...
moritz authored
1 use v6;
2
3 use Test;
4
04034a9 [t/spec]: Refactor overflow tests from increment.t into overflow.t .
pmichaud authored
5 plan 24;
81a61b0 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access in t...
moritz authored
6
7 #L<S03/Autoincrement precedence>
8
9 =begin description
10
04034a9 [t/spec]: Refactor overflow tests from increment.t into overflow.t .
pmichaud authored
11 Verify that autoincrement/autodecrement work properly.
12 (Overflow cases are handled in S03-operators/overflow.t)
81a61b0 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access in t...
moritz authored
13
14 =end description
15
dba025f [t/spec] Fudged increment.t for rakudo
azawawi authored
16 #?rakudo skip 'unimpl undef++'
04034a9 [t/spec]: Refactor overflow tests from increment.t into overflow.t .
pmichaud authored
17 my $a = undef;
81a61b0 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access in t...
moritz authored
18 is($a++, 0, 'undef++ == 0');
19
20 $a = undef;
de076fd [t/spec] removed some obsolete usages of 'is $stuff, undef'
moritz authored
21 ok($a-- ~~ undef, 'undef-- is undefined');
81a61b0 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access in t...
moritz authored
22
23 $a = 'x';
24 is($a++, 'x', 'magical ++ should not be numified');
25 isa_ok($a, "Str", "it isa Str");
26
27 my %a = ('a' => 1);
28 %a{"a"}++;
29 is(%a{'a'}, 2, "hash key");
30
31
32 my %b = ('b' => 1);
33 my $var = 'b';
34 %b{$var}++;
35 is(%b{$var}, 2, "hash key via var");
36
37 my @a = (1);
38 @a[0]++;
39 is(@a[0], 2, "array elem");
40
41 my @b = (1);
42 my $moo = 0;
43 @b[$moo]++;
44 is(@b[$moo], 2, "array elem via var");
45 is($moo, 0, "var was not touched");
46
47 # Test that the expression to increment will only be evaluated once.
dba025f [t/spec] Fudged increment.t for rakudo
azawawi authored
48 #?rakudo skip "unimpl Lexically scoped subs"
81a61b0 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access in t...
moritz authored
49 {
50 my $was_in_foo;
51 my sub foo () { $was_in_foo++; 0 };
52
53 my @array = (42);
54
55 is(++@array[+foo()], 43, "++ evaluates the expression to increment only once (1)");
56 is($was_in_foo, 1, "++ evaluates the expression to increment only once (2)");
57 }
58
59 # Test case courtesy of Limbic_Region
60 {
61 my $curr = 4;
62 my @array = 1..5;
63 is @array[$curr], 5, "postincrements in array subscripts work";
64 @array[ --$curr ]++;
65
66 is $curr, 3, "postincrements in array subscripts work";
67 is @array[$curr], 5, "postincrements in array subscripts work";
68 }
69
70 # test incrementing literals
71 # all of those can be detected at compile time, so use eval_dies_ok here
72 {
73 eval_dies_ok ' 4++ ', "can't postincrement a literal number";
74 eval_dies_ok ' ++4 ', "can't preincrement a literal number";
75 eval_dies_ok ' 4-- ', "can't postdecrement a literal number";
76 eval_dies_ok ' --4 ', "can't predecrement a literal number";
77 eval_dies_ok ' "x"++ ', "can't postincrement a literal string";
78 eval_dies_ok ' ++"x" ', "can't preincrement a literal string";
79 eval_dies_ok ' "x"-- ', "can't postdecrement a literal string";
80 eval_dies_ok ' --"x" ', "can't predecrement a literal string";
81 }
813e945 [t/spec] test for rakudo regression (Num += Int)
moritz authored
82
83 # this used to be a rakudo regression
84 #?rakudo skip 'Num += Int'
85 {
86 my $x = 2.0;
87 $x += 1;
88 ok $x == 3.0, 'can add Int to Num with +=';
89
90 my Num $y = 2.0;
91 $y += 1;
92 ok $y == 3.0, 'can add Int to Num with += and type constraint';
93 }
Something went wrong with that request. Please try again.