Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 183 lines (146 sloc) 6.415 kB
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
2 use Test;
3
18413a7 @ShimmerFairy Add TODO'd tests for RT #81336
ShimmerFairy authored
4 plan 124;
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
5
6 ## N.B.: Tests for infix:«<=>» (spaceship) and infix:<cmp> belong
7 ## in F<t/S03-operators/comparison.t>.
8
9 #L<S03/Chaining binary precedence>
10
11 # from t/operators/relational.t
12
13 ## numeric relationals ( < , >, <=, >= )
14
15 ok(1 < 2, '1 is less than 2');
16 ok(!(2 < 1), '2 is ~not~ less than 1');
17
c8d20e0 [t/spec] more rational relational tests
kyle authored
18 ok 1/4 < 3/4, '1/4 is less than 3/4';
19 ok !(3/4 < 1/4), '3/4 is not less than 1/4';
20 ok 1/2 < 1, '1/2 is less than 1';
21 ok !(1 < 1/2), '1 is not less than 1/2';
22
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
23 ok(2 > 1, '2 is greater than 1');
24 ok(!(1 > 2), '1 is ~not~ greater than 2');
25
c8d20e0 [t/spec] more rational relational tests
kyle authored
26 ok 3/4 > 1/4, '3/4 is greater than 1/4';
27 ok !(1/4 > 3/4), '1/2 is not greater than 3/4';
28 ok 1 > 1/2, '1 is greater than 1/2';
29 ok !(1/2 > 1), '1/2 is not greater than 1';
30
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
31 ok(1 <= 2, '1 is less than or equal to 2');
32 ok(1 <= 1, '1 is less than or equal to 1');
33 ok(!(1 <= 0), '1 is ~not~ less than or equal to 0');
34
c8d20e0 [t/spec] more rational relational tests
kyle authored
35 ok 1/4 <= 3/4, '1/4 is less than or equal to 3/4';
36 ok !(3/4 <= 1/4), '3/4 is not less than or equal to 1/4';
37 ok 1/2 <= 1, '1/2 is less than or equal to 1';
38 ok !(1 <= 1/2), '1 is not less than or equal to 1/2';
39 ok 1/2 <= 1/2, '1/2 is less than or equal to 1/2';
40
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
41 ok(2 >= 1, '2 is greater than or equal to 1');
42 ok(2 >= 2, '2 is greater than or equal to 2');
43 ok(!(2 >= 3), '2 is ~not~ greater than or equal to 3');
44
c8d20e0 [t/spec] more rational relational tests
kyle authored
45 ok !(1/4 >= 3/4), '1/4 is greater than or equal to 3/4';
46 ok 3/4 >= 1/4, '3/4 is not greater than or equal to 1/4';
47 ok !(1/2 >= 1), '1/2 is greater than or equal to 1';
48 ok 1 >= 1/2, '1 is not greater than or equal to 1/2';
49 ok 1/2 >= 1/2, '1/2 is greater than or equal to 1/2';
50
2d9ebad [gsoc_spectest] many relational tests (checking that Bool::True or Bo…
Auzon authored
51 # Ensure that these operators actually return Bool::True or Bool::False
52 is(1 < 2, Bool::True, '< true');
53 is(1 > 0, Bool::True, '> true');
54 is(1 <= 2, Bool::True, '<= true');
55 is(1 >= 0, Bool::True, '>= true');
56 is(1 < 0, Bool::False, '< false');
57 is(1 > 2, Bool::False, '> false');
58 is(1 <= 0, Bool::False, '<= false');
59 is(1 >= 2, Bool::False, '>= false');
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
60
61 ## string relationals ( lt, gt, le, ge )
62
63 ok('a' lt 'b', 'a is less than b');
64 ok(!('b' lt 'a'), 'b is ~not~ less than a');
65
66 ok('b' gt 'a', 'b is greater than a');
67 ok(!('a' gt 'b'), 'a is ~not~ greater than b');
68
69 ok('a' le 'b', 'a is less than or equal to b');
70 ok('a' le 'a', 'a is less than or equal to a');
71 ok(!('b' le 'a'), 'b is ~not~ less than or equal to a');
72
73 ok('b' ge 'a', 'b is greater than or equal to a');
74 ok('b' ge 'b', 'b is greater than or equal to b');
75 ok(!('b' ge 'c'), 'b is ~not~ greater than or equal to c');
76
2d9ebad [gsoc_spectest] many relational tests (checking that Bool::True or Bo…
Auzon authored
77 # +'a' is 0. This means 1 is less than 'a' in numeric context but not string
78 ok(!('a' lt '1'), 'lt uses string context');
79 ok(!('a' le '1'), 'le uses string context (1)');
80 ok(!('a' le '0'), 'le uses string context (2)');
81 ok('a' gt '1', 'gt uses string context');
82 ok('a' ge '1', 'ge uses string context (1)');
83 ok('a' ge '0', 'ge uses string context (2)');
84
85 # Ensure that these operators actually return Bool::True or Bool::False
86 is('b' lt 'c', Bool::True, 'lt true');
87 is('b' gt 'a', Bool::True, 'gt true');
88 is('b' le 'c', Bool::True, 'le true');
89 is('b' ge 'a', Bool::True, 'ge true');
90 is('b' lt 'a', Bool::False, 'lt false');
91 is('b' gt 'c', Bool::False, 'gt false');
92 is('b' le 'a', Bool::False, 'le false');
93 is('b' ge 'c', Bool::False, 'ge false');
8a1a068 Some initial test refactors and cleanups for basic operators.
pmichaud authored
94
95 ## Multiway comparisons (RFC 025)
96 # L<S03/"Chained comparisons">
97
98 ok(5 > 4 > 3, "chained >");
99 ok(3 < 4 < 5, "chained <");
100 ok(5 == 5 > -5, "chained mixed = and > ");
101 ok(!(3 > 4 < 5), "chained > and <");
102 ok(5 <= 5 > -5, "chained <= and >");
103 ok(-5 < 5 >= 5, "chained < and >=");
104
105 is(5 > 1 < 10, 5 > 1 && 1 < 10, 'chained 5 > 1 < 10');
106 is(5 < 1 < 10, 5 < 1 && 1 < 10, 'chained 5 < 1 < 10');
107
108 ok('e' gt 'd' gt 'c', "chained gt");
109 ok('c' lt 'd' lt 'e', "chained lt");
110 ok('e' eq 'e' gt 'a', "chained mixed = and gt ");
111 ok(!('c' gt 'd' lt 'e'), "chained gt and lt");
112 ok('e' le 'e' gt 'a', "chained le and gt");
113 ok('a' lt 'e' ge 'e', "chained lt and ge");
114
115 is('e' gt 'a' lt 'j', 'e' gt 'a' && 'a' lt 'j', 'e gt a lt j');
116 is('e' lt 'a' lt 'j', 'e' lt 'a' && 'a' lt 'j', 'e lt a lt j');
117
f3dcabf [t] removed operators/relational.t, which is mostly integrated into
moritz authored
118 ok("5" gt "4" gt "3", "5 gt 4 gt 3 chained str comparison");
119 ok("3" lt "4" lt "5", "3 lt 4 gt 5 chained str comparison");
120 ok(!("3" gt "4" lt "5"), "!(3 gt 4 lt 5) chained str comparison");
121 ok("5" eq "5" gt "0", '"5" eq "5" gt "0" chained str comparison with equality');
122 ok("5" le "5" gt "0", "5 le 5 gt 0 chained str comparison with le");
123 ok("0" lt "5" ge "5", "0 lt 5 ge 5 chained comparison with ge");
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
124
18413a7 @ShimmerFairy Add TODO'd tests for RT #81336
ShimmerFairy authored
125 #?rakudo 2 todo 'RT #81336'
126 is(0 ~~ 0 ~~ 0, 0 ~~ 0 && 0 ~~ 0, "chained smartmatch");
127 is("foo" ~~ "foo" ge "bar", "foo" ~~ "foo" && "foo" ge "bar", "chained mixed ~~ and ge");
128
8b6048b @moritz Revert "Remove # chars from fudge messages"
moritz authored
129 #?rakudo 4 todo 'RT #121987'
d2e7215 @dwarring Added test cases for RT121987
dwarring authored
130 is 1 !before 2 !before 3, 1 !before 2 && 2 !before 3, 'chained !before';
1e3997c @dwarring typo
dwarring authored
131 is 1 !after 2 !after 2, 1 !after 2 && 2 !after 2, 'chained !after';
132 is 3 !> 3 !> 1, 3 !> 3 && 3 !> 1, 'chained !>';
133 is 3 !< 3 !< 2, 3 !< 3 && 3 !< 2, 'chained !<';
d2e7215 @dwarring Added test cases for RT121987
dwarring authored
134
0d4c9fc [S03/relational.t] more tests to detect bad comparison semantics invo…
lwall authored
135 # make sure we don't have "padding" or "trimming" semantics
136 ok("a" lt "a\0", 'a lt a\0');
137 ok("a" lt "a ", 'a lt a\x20');
138 ok("a\0" gt "a", 'a\0 gt a');
139 ok("a " gt "a", 'a\x20 gt a');
140
ef5b438 @pmichaud Add relational op tests for NaN.
pmichaud authored
141 # test NaN relational ops
142 is(NaN == 1, Bool::False, 'NaN == 1');
143 is(NaN < 1, Bool::False, 'NaN < 1');
144 is(NaN <= 1, Bool::False, 'NaN <= 1');
145 is(NaN > 1, Bool::False, 'NaN > 1');
146 is(NaN >= 1, Bool::False, 'NaN >= 1');
147 is(NaN != 1, Bool::True, 'NaN != 1');
148
149 is(1 == NaN, Bool::False, '1 == NaN');
150 is(1 < NaN, Bool::False, '1 < NaN');
151 is(1 <= NaN, Bool::False, '1 <= NaN');
152 is(1 > NaN, Bool::False, '1 > NaN');
153 is(1 >= NaN, Bool::False, '1 >= NaN');
154 is(1 != NaN, Bool::True, '1 != NaN');
155
156 is(NaN == NaN, Bool::False, 'NaN == NaN');
157 is(NaN < NaN, Bool::False, 'NaN < NaN');
158 is(NaN <= NaN, Bool::False, 'NaN <= NaN');
159 is(NaN > NaN, Bool::False, 'NaN > NaN');
160 is(NaN >= NaN, Bool::False, 'NaN >= NaN');
161 is(NaN != NaN, Bool::True, 'NaN != NaN');
162
33d6754 @pmichaud Add some tests for the &infix:«<»(Int, Rat) bug discovered today.
pmichaud authored
163 # regression test for rakudo failure 2012-07-08 (pmichaud)
164 # Int,Rat comparisons
165 is(7 == 2.4, False, 'Int == Rat');
166 is(7 != 2.4, True , 'Int != Rat');
167 is(7 < 2.4, False, 'Int < Rat');
168 is(7 <= 2.4, False, 'Int <= Rat');
169 is(7 > 2.4, True , 'Int > Rat');
170 is(7 >= 2.4, True , 'Int >= Rat');
3a5af16 @lizmat Increase/Decrease -> Less/More migration
lizmat authored
171 is(7 <=> 2.4, Order::More, 'Int <=> Rat');
33d6754 @pmichaud Add some tests for the &infix:«<»(Int, Rat) bug discovered today.
pmichaud authored
172
173 # Rat,Int comparisons
174 is(2.4 == 7, False, 'Rat == Int');
175 is(2.4 != 7, True , 'Rat != Int');
176 is(2.4 < 7, True , 'Rat < Int');
177 is(2.4 <= 7, True , 'Rat <= Int');
178 is(2.4 > 7, False, 'Rat > Int');
179 is(2.4 >= 7, False, 'Rat >= Int');
3a5af16 @lizmat Increase/Decrease -> Less/More migration
lizmat authored
180 is(2.4 <=> 7, Order::Less, 'Rat <=> Int');
33d6754 @pmichaud Add some tests for the &infix:«<»(Int, Rat) bug discovered today.
pmichaud authored
181
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
182 # vim: ft=perl6
Something went wrong with that request. Please try again.