Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: tests/language/operations_on_non_num_operand_test.dart

Issue 1411633002: Generalize and_operation_on_non_int_operand_test. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/language/and_operation_on_non_integer_operand_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Regression test for dart2js that used to miscompile boolean and operations
6 /// if one of the operands was an int and the other was not (issue 22427).
7 ///
8 /// Extended to all operations as there is a risk of similar bugs with other
9 /// operators, e.g. `a % 2` _looks_ like it might be 0 or 1.
10
11 import "package:expect/expect.dart";
12
13 @AssumeDynamic() @NoInline()
14 confuse(x) => x;
15
16 class Thing1 {
17 operator&(b) => this;
18 operator|(b) => this;
19 operator^(b) => this;
20 operator<<(b) => this;
21 operator>>(b) => this;
22
23 operator+(b) => this;
24 operator-(b) => this;
25 operator*(b) => this;
26 operator/(b) => this;
27 operator~/(b) => this;
28 operator%(b) => this;
29 remainder(b) => this;
30
31 operator<(b) => this;
32 operator<=(b) => this;
33 operator>(b) => this;
34 operator>=(b) => this;
35 }
36
37 class Thing2 {
38 @NoInline() operator&(b) => this;
39 @NoInline() operator|(b) => this;
40 @NoInline() operator^(b) => this;
41 @NoInline() operator<<(b) => this;
42 @NoInline() operator>>(b) => this;
43
44 @NoInline() operator+(b) => this;
45 @NoInline() operator-(b) => this;
46 @NoInline() operator*(b) => this;
47 @NoInline() operator/(b) => this;
48 @NoInline() operator~/(b) => this;
49 @NoInline() operator%(b) => this;
50 @NoInline() remainder(b) => this;
51
52 @NoInline() operator<(b) => this;
53 @NoInline() operator<=(b) => this;
54 @NoInline() operator>(b) => this;
55 @NoInline() operator>=(b) => this;
56 }
57
58
59 confused() {
60 var a = new Thing1();
61 Expect.equals(a, confuse(a) & 5 & 2);
62 Expect.equals(a, confuse(a) | 5 | 2);
63 Expect.equals(a, confuse(a) ^ 5 ^ 2);
64 Expect.equals(a, confuse(a) << 5 << 2);
65 Expect.equals(a, confuse(a) >> 5 >> 2);
66
67 Expect.equals(a, confuse(a) + 5 + 2);
68 Expect.equals(a, confuse(a) - 5 - 2);
69 Expect.equals(a, confuse(a) * 5 * 2);
70 Expect.equals(a, confuse(a) / 5 / 2);
71 Expect.equals(a, confuse(a) % 5 % 2);
72 Expect.equals(a, confuse(a) ~/ 5 ~/ 2);
73 Expect.equals(a, confuse(a).remainder(5).remainder(2));
74
75 Expect.equals(a, (confuse(a) < 5) < 2);
76 Expect.equals(a, (confuse(a) <= 5) <= 2);
77 Expect.equals(a, (confuse(a) > 5) > 2);
78 Expect.equals(a, (confuse(a) >= 5) >= 2);
79 }
80
81 direct1() {
82 var a = new Thing1();
83 Expect.equals(a, a & 5 & 2);
84 Expect.equals(a, a | 5 | 2);
85 Expect.equals(a, a ^ 5 ^ 2);
86 Expect.equals(a, a << 5 << 2);
87 Expect.equals(a, a >> 5 >> 2);
88
89 Expect.equals(a, a + 5 + 2);
90 Expect.equals(a, a - 5 - 2);
91 Expect.equals(a, a * 5 * 2);
92 Expect.equals(a, a / 5 / 2);
93 Expect.equals(a, a % 5 % 2);
94 Expect.equals(a, a ~/ 5 ~/ 2);
95 Expect.equals(a, a.remainder(5).remainder(2));
96
97 Expect.equals(a, (a < 5) < 2);
98 Expect.equals(a, (a <= 5) <= 2);
99 Expect.equals(a, (a > 5) > 2);
100 Expect.equals(a, (a >= 5) >= 2);
101 }
102
103 direct2() {
104 var a = new Thing2();
105 Expect.equals(a, a & 5 & 2);
106 Expect.equals(a, a | 5 | 2);
107 Expect.equals(a, a ^ 5 ^ 2);
108 Expect.equals(a, a << 5 << 2);
109 Expect.equals(a, a >> 5 >> 2);
110
111 Expect.equals(a, a + 5 + 2);
112 Expect.equals(a, a - 5 - 2);
113 Expect.equals(a, a * 5 * 2);
114 Expect.equals(a, a / 5 / 2);
115 Expect.equals(a, a % 5 % 2);
116 Expect.equals(a, a ~/ 5 ~/ 2);
117 Expect.equals(a, a.remainder(5).remainder(2));
118
119 Expect.equals(a, (a < 5) < 2);
120 Expect.equals(a, (a <= 5) <= 2);
121 Expect.equals(a, (a > 5) > 2);
122 Expect.equals(a, (a >= 5) >= 2);
123 }
124
125 main () {
126 confused();
127 direct1();
128 direct2();
129 }
OLDNEW
« no previous file with comments | « tests/language/and_operation_on_non_integer_operand_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698