Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 123 lines (94 sloc) 2.952 kb
81a61b0e »
2008-07-01 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access i…
1 use v6;
2
3 use Test;
4
9955089b »
2012-01-06 RT #74912, ++++$x
5 plan 31;
81a61b0e »
2008-07-01 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access i…
6
7 #L<S03/Autoincrement precedence>
8
9 =begin description
10
04034a90 »
2008-11-28 [t/spec]: Refactor overflow tests from increment.t into overflow.t .
11 Verify that autoincrement/autodecrement work properly.
12 (Overflow cases are handled in S03-operators/overflow.t)
81a61b0e »
2008-07-01 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access i…
13
14 =end description
15
8f9a1198 »
2009-11-25 [t/] unify compartmentalized undef and Object concepts into Mu
16 my $a = Mu;
17 is($a++, 0, 'Mu++ == 0');
81a61b0e »
2008-07-01 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access i…
18
db85667a »
2011-07-09 reflect current rakudo/nom state
19 #?rakudo todo 'nom regression'
737ff9d3 »
2011-12-13 niecza fudging (with tickets)
20 #?niecza todo '#88'
8f9a1198 »
2009-11-25 [t/] unify compartmentalized undef and Object concepts into Mu
21 $a = Mu;
08f19603 »
2011-02-23 start to remove .notdef
22 nok(defined($a--), 'Mu-- is undefined');
81a61b0e »
2008-07-01 [spec] moved operators/inc.t to spec/. rakudo says "Null PCM access i…
23
24 $a = 'x';
25 is($a++, 'x', 'magical ++ should not be numified');
26 isa_ok($a, "Str", "it isa Str");
27
28 my %a = ('a' => 1);
29 %a{"a"}++;
30 is(%a{'a'}, 2, "hash key");
31
32
33 my %b = ('b' => 1);
34 my $var = 'b';
35 %b{$var}++;
36 is(%b{$var}, 2, "hash key via var");
37
38 my @a = (1);
39 @a[0]++;
40 is(@a[0], 2, "array elem");
41
42 my @b = (1);
43 my $moo = 0;
44 @b[$moo]++;
45 is(@b[$moo], 2, "array elem via var");
46 is($moo, 0, "var was not touched");
47
48 # Test that the expression to increment will only be evaluated once.
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 }
813e9457 »
2008-11-11 [t/spec] test for rakudo regression (Num += Int)
82
83 # this used to be a rakudo regression
84 {
85 my $x = 2.0;
86 $x += 1;
00c17909 »
2010-03-01 [t/spec] Add fudge, change to reflect 2.0's new status as Rat, add tw…
87 ok $x == 3.0, 'can add Int to Rat with +=';
88
89 my Rat $y = 2.0;
90 $y += 1;
91 ok $y == 3.0, 'can add Int to Rat with += and type constraint';
92 }
93
94 {
95 my $x = 2.0.Num;
96 $x += 1;
813e9457 »
2008-11-11 [t/spec] test for rakudo regression (Num += Int)
97 ok $x == 3.0, 'can add Int to Num with +=';
98
00c17909 »
2010-03-01 [t/spec] Add fudge, change to reflect 2.0's new status as Rat, add tw…
99 my Num $y = 2.0.Num;
813e9457 »
2008-11-11 [t/spec] test for rakudo regression (Num += Int)
100 $y += 1;
101 ok $y == 3.0, 'can add Int to Num with += and type constraint';
102 }
ef0570fd »
2009-04-23 [t/spec] tests for .succ/.pred on Bool
103
104 # also a Rakudo regression
105 {
106 my $x = Bool::False;
107 is ++$x, Bool::True, '++ on False works';
108 $x = Bool::False;
109 is $x.succ, Bool::True, '.succ on False works';
110
111 $x = Bool::True;
112 is --$x, Bool::False, '-- on True works';
113 $x = Bool::True;
88faa1d1 »
2009-04-26 [t/spec] corrected test as pointed out by PhatEddy++
114 is $x.pred, Bool::False, '.succ on False works';
ef0570fd »
2009-04-23 [t/spec] tests for .succ/.pred on Bool
115 }
7f29bc53 »
2009-08-08 [t/spec] Add vim: lines everywhere.
116
9955089b »
2012-01-06 RT #74912, ++++$x
117 # RT #74912
d3006fd3 »
2012-01-06 Additional fudging for niecza.
118 #?niecza todo 'Works fine in niecza...'
9955089b »
2012-01-06 RT #74912, ++++$x
119 eval_dies_ok 'my $x = 0; ++++$x',
120 'can not double-increment, because the return value is not a container';
121
7f29bc53 »
2009-08-08 [t/spec] Add vim: lines everywhere.
122 # vim: ft=perl6
Something went wrong with that request. Please try again.