Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 132 lines (110 sloc) 4.004 kB
a16f20c [spec] moved S12-enums to spec/, mistakenly added it to t/ first. mor…
moritz authored
1 use v6;
2 use Test;
fc3dc99 @FROGGS add tests for enum alias poisoning, RT #72696
FROGGS authored
3 plan 37;
a16f20c [spec] moved S12-enums to spec/, mistakenly added it to t/ first. mor…
moritz authored
4
5 # Very basic enum tests
6
61bc9c8 [t/spec] fix S12-enums/basic.t (track spec changes)
moritz authored
7 # L<S12/Enumerations/the keys are specified as a parenthesized list>
a16f20c [spec] moved S12-enums to spec/, mistakenly added it to t/ first. mor…
moritz authored
8
9 enum Day <Sun Mon Tue Wed Thu Fri Sat>;
10 {
758acfb @sorear Twiddle basic enum tests to numify where needed, fudge for niecza
sorear authored
11 is 0 + Day::Sun, 0, 'First item of an enum is 0';
12 is 0 + Day::Sat, 6, 'Last item has the right value';
13 is 0 + Sun, 0, 'Values exported into namespace too.';
14 is 0 + Sat, 6, 'Values exported into namespace too.';
a16f20c [spec] moved S12-enums to spec/, mistakenly added it to t/ first. mor…
moritz authored
15 }
16
17 {
7b716f1 [t/spec] tests for RT #63250, ranges from Enum values
moritz authored
18 # check that the values can be used for ordinary tasks, like
19 # constructing ranges
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
20 isa-ok (Mon..Wed), Range, 'Can construct ranges from Enum values';
758acfb @sorear Twiddle basic enum tests to numify where needed, fudge for niecza
sorear authored
21 ok Mon + Tue == Wed, 'Can do arithmetics with Enum values';
7b716f1 [t/spec] tests for RT #63250, ranges from Enum values
moritz authored
22 }
23
9c40515 @dnmfarrell fixed appended RT number to be within quoted string
dnmfarrell authored
24 #?rakudo skip 'Cannot convert string to number RT #124832'
758acfb @sorear Twiddle basic enum tests to numify where needed, fudge for niecza
sorear authored
25 #?niecza skip 'enummish but'
7b716f1 [t/spec] tests for RT #63250, ranges from Enum values
moritz authored
26 {
a16f20c [spec] moved S12-enums to spec/, mistakenly added it to t/ first. mor…
moritz authored
27 my $x = 'Today' but Day::Mon;
28 ok $x.does(Day), 'Can test with .does() for enum type';
29 ok $x ~~ Day, 'Can smartmatch for enum type';
30 ok $x ~~ Day::Mon, 'Can Smartmatch for enum value';
3edb3b0 [t/spec] Unfudge tests for smart-match on enum values, and add explic…
jnthn authored
31 my $check = 0;
32 given $x {
33 when Day::Mon { $check = 1 }
34 when Day::Tue { $check = 2 }
35 }
36 is $check, 1, 'given/when with enum values';
37 $check = 0;
38 given $x {
39 when Tue { $check = 1 }
40 when Mon { $check = 2 }
41 }
42 is $check, 2, 'given/when with enum values';
a16f20c [spec] moved S12-enums to spec/, mistakenly added it to t/ first. mor…
moritz authored
43 }
44
21f6acc [t/spec]
moritz authored
45 {
46 # usually we don't test explicit value for .perl, but here
13cc9c4 [t/spec] 71 typos in 32 files.
Util authored
47 # it's specced, so we make an exception
61bc9c8 [t/spec] fix S12-enums/basic.t (track spec changes)
moritz authored
48 is Day::Mon.perl, 'Day::Mon', '.perl on long form of Enum key';
21f6acc [t/spec]
moritz authored
49 is Mon.perl, 'Day::Mon', '.perl on short form of Enum value';
50
61bc9c8 [t/spec] fix S12-enums/basic.t (track spec changes)
moritz authored
51 is Day::Mon.key, 'Mon', '.key on long form of Enum value';
52 is Mon.key, 'Mon', '.key on short form of Enum value';
d89c1bb [t/spec] Unfudge some enums tests that we now pass; add a test for .W…
jnthn authored
53
0512ff9 @moritz more Type() -> (Type) gistification
moritz authored
54 is Day::Mon.WHAT.gist, '(Day)', '.WHAT.gist on enum value stringifies to the enum name';
21f6acc [t/spec]
moritz authored
55 }
56
0139eae [t/spec] Tests for enum (i => 1, v => 5...) style stuff.
jnthn authored
57 {
758acfb @sorear Twiddle basic enum tests to numify where needed, fudge for niecza
sorear authored
58 enum roman (i => 1, v => 5,
59 x => 10, l => 50,
60 c => 100, d => 500,
61 m => 1000);
62 ok v == 5, 'enum with parens works and non-0 starting point works';
63 is v.perl, 'roman::v', '.perl works on enum with parens';
64 is v.key, 'v', '.key works on enum with parens';
0139eae [t/spec] Tests for enum (i => 1, v => 5...) style stuff.
jnthn authored
65 }
66
5f3694d [spectest] Test for the case where a named enum has a single value, p…
jnthn authored
67 enum JustOne <Thing>;
68 {
758acfb @sorear Twiddle basic enum tests to numify where needed, fudge for niecza
sorear authored
69 ok JustOne::Thing == 0, 'Enum of one element works.';
5f3694d [spectest] Test for the case where a named enum has a single value, p…
jnthn authored
70 }
935a0b3 [spec] added a test for empty enums
s1n authored
71
c491713 @colomon Niecza refudge to deal with the Order issue.
colomon authored
72 #?niecza skip "Enum must have at least one value"
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
73 lives-ok { enum Empty < > }, "empty enum can be constructed";
d89c1bb [t/spec] Unfudge some enums tests that we now pass; add a test for .W…
jnthn authored
74
c491713 @colomon Niecza refudge to deal with the Order issue.
colomon authored
75 #?niecza todo "Enum must have at least one value"
e816632 @lizmat s/eval_lives_ok/eval-lives-ok/g
lizmat authored
76 eval-lives-ok 'enum Empty2 ()', 'empty enum with () can be constructed';
8372d6f [t/spec] Add some passing tests for assigning enum values and using t…
jnthn authored
77
78 enum Color <white gray black>;
79 my Color $c1 = Color::white;
758acfb @sorear Twiddle basic enum tests to numify where needed, fudge for niecza
sorear authored
80 ok($c1 == 0, 'can assign enum value to typed variable with long name');
8372d6f [t/spec] Add some passing tests for assigning enum values and using t…
jnthn authored
81 my Color $c2 = white;
f8e0c0d @usev6 Moving test for RT #75370 to S12-enums/basic.t
usev6 authored
82 ok($c2 == 0, 'can assign enum value to typed variable with short name');
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored
83 dies-ok({ my Color $c3 = "for the fail" }, 'enum as a type enforces checks');
b71bf8f [t/spec] tests for enum/sub name conflicts
moritz authored
84
85 # conflict between subs and enums
86 {
2bea641 [t/basic.t] avoid redeclaration warning
lwall authored
87 my sub white { 'sub' };
758acfb @sorear Twiddle basic enum tests to numify where needed, fudge for niecza
sorear authored
88 ok white == 0, 'short name of the enum without parenthesis is an enum';
89 #?niecza skip 'nonworking'
b71bf8f [t/spec] tests for enum/sub name conflicts
moritz authored
90 is white(), 'sub', 'short name with parenthesis is a sub';
91 }
4cc4a2d [t/spec] tests for .pick on enums
moritz authored
92
777ed62 @diakopter re-fix one more smartlink
diakopter authored
93 # L<S12/The C<.pick> Method/"define a .pick method">
4cc4a2d [t/spec] tests for .pick on enums
moritz authored
94 {
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
95 lives-ok { my Color $k = Color.pick }, 'Color.pick assigns to Color var';
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
96 isa-ok Color.pick, Color.pick.WHAT, 'Color.pick.isa';
6179fc2 [t/spec] something wrong with .pick on an enum
kyle authored
97
4cc4a2d [t/spec] tests for .pick on enums
moritz authored
98 ok ?(Color.pick == any(Color::white, Color::gray, Color::black)),
99 '.pick on enums';
100 ok Color.pick(2) == 2, '.pick(2) on enums';
101 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
102
5c8c4ab [t/spec] Test for RT 71460: Null PMC access
kyle authored
103 {
104 enum RT71460::Bug <rt71460 bug71460 ticket71460>;
758acfb @sorear Twiddle basic enum tests to numify where needed, fudge for niecza
sorear authored
105 ok bug71460 == 1, 'enum element of enum with double colons is in namespace';
5c8c4ab [t/spec] Test for RT 71460: Null PMC access
kyle authored
106 }
107
56d7207 @moritz RT #77982, spooky interactions between enums
moritz authored
108 # RT #77982
109 {
110 enum T1 <a b c>;
111 enum T2 <d e f>;
112 is T1.enums.keys.sort.join('|'), 'a|b|c', 'enum keys (1)';
113 is T2.enums.keys.sort.join('|'), 'd|e|f', 'enum keys (2)';
114 }
115
f8e0c0d @usev6 Moving test for RT #75370 to S12-enums/basic.t
usev6 authored
116 # RT #75370
117 {
118 enum somenum <a b c d e>;
119 my somenum $temp = d;
120 ok $temp eq 'd', "RT #75370 enum name";
121 }
122
fc3dc99 @FROGGS add tests for enum alias poisoning, RT #72696
FROGGS authored
123 # RT #72696
124 {
125 enum S1 <a b c>;
126 enum S2 <b c d>;
08b5de5 @lizmat s/throws_like/throws-like/g
lizmat authored
127 throws-like { say b }, X::PoisonedAlias, :alias<b>, :package-type<enum>, :package-name<S2>;
fc3dc99 @FROGGS add tests for enum alias poisoning, RT #72696
FROGGS authored
128 ok S1::b == 1 && S2::b == 0, 'still can access redeclared enum values via package';
129 }
130
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
131 # vim: ft=perl6
Something went wrong with that request. Please try again.