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

Unified Diff: tests/language/precedence_test.dart

Issue 2755433004: align fasta.PrecedenceInfo.precedence with analyzer.TokenType.precedence (Closed)
Patch Set: fix tilde precedence test Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/test/scanner_roundtrip_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/precedence_test.dart
diff --git a/tests/language/precedence_test.dart b/tests/language/precedence_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..21ce048a7ef232835bf6c225ef8636a145bb2ea1
--- /dev/null
+++ b/tests/language/precedence_test.dart
@@ -0,0 +1,179 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// Dart test program to test operation precedence.
+
+library precedence_test;
Brian Wilkerson 2017/03/18 16:11:28 Unless the library directive is useful to the test
danrubel 2017/03/20 13:06:49 I don't believe its needed. Removed.
+import "package:expect/expect.dart";
+
+main() {
+ testBang();
+ testIndexWithPrefixAdd();
+ testIndexWithPostfixAdd();
+ testTilde();
+ testUnaryPrefixWithAdd();
+ testUnaryPostfixWithAdd();
+ testUnaryPrefixWithMultiply();
+ testUnaryPostfixWithMultiply();
+}
+
+void testBang() {
ahe 2017/03/20 12:19:45 I don't feel this is as well tested as the others.
danrubel 2017/03/20 13:06:49 Good point. Test updated.
+ int x = 3;
+
+ Expect.equals(!true == false, true);
+ Expect.equals(!x.isEven, true);
+ Expect.equals(!(++x).isEven, false);
+ Expect.equals(x, 4);
+ Expect.equals(!(x++).isEven, false);
+ Expect.equals(x, 5);
+}
+
+void testIndexWithPrefixAdd() {
+ var x = <int>[3];
+
+ Expect.equals(++x[0] + 3, 7);
+ Expect.equals(x[0], 4);
+ Expect.equals(++x[0] - 3, 2);
+ Expect.equals(x[0], 5);
+ Expect.equals(--x[0] + 4, 8);
+ Expect.equals(x[0], 4);
+ Expect.equals(--x[0] - 4, -1);
+ Expect.equals(x[0], 3);
+
+ Expect.equals(3 + ++x[0], 7);
+ Expect.equals(x[0], 4);
+ Expect.equals(3 - ++x[0], -2);
+ Expect.equals(x[0], 5);
+ Expect.equals(4 + --x[0], 8);
+ Expect.equals(x[0], 4);
+ Expect.equals(4 - --x[0], 1);
+ Expect.equals(x[0], 3);
+}
+
+void testIndexWithPostfixAdd() {
+ var x = <int>[3];
+
+ Expect.equals(x[0]++ + 3, 6);
+ Expect.equals(x[0], 4);
+ Expect.equals(x[0]++ - 3, 1);
+ Expect.equals(x[0], 5);
+ Expect.equals(x[0]-- + 4, 9);
+ Expect.equals(x[0], 4);
+ Expect.equals(x[0]-- - 4, 0);
+ Expect.equals(x[0], 3);
+
+ Expect.equals(3 + x[0]++, 6);
+ Expect.equals(x[0], 4);
+ Expect.equals(3 - x[0]++, -1);
+ Expect.equals(x[0], 5);
+ Expect.equals(4 + x[0]--, 9);
+ Expect.equals(x[0], 4);
+ Expect.equals(4 - x[0]--, 0);
+ Expect.equals(x[0], 3);
+}
+
+void testTilde() {
+ int x = 3;
+
+ Expect.equals(~x.sign, ~(x.sign));
+ Expect.equals(~x + 7, (~3) + 7);
+
+ Expect.equals(~++x + 7, (~4) + 7);
+ Expect.equals(x, 4);
+ Expect.equals(~x++ + 7, (~4) + 7);
+ Expect.equals(x, 5);
+
+ Expect.equals(~--x + 7, (~4) + 7);
+ Expect.equals(x, 4);
+ Expect.equals(~x-- + 7, (~4) + 7);
+ Expect.equals(x, 3);
+}
+
+void testUnaryPrefixWithAdd() {
+ int x = 3;
+
+ Expect.equals(++x + 3, 7);
+ Expect.equals(x, 4);
+ Expect.equals(++x - 3, 2);
+ Expect.equals(x, 5);
+ Expect.equals(--x + 4, 8);
+ Expect.equals(x, 4);
+ Expect.equals(--x - 4, -1);
+ Expect.equals(x, 3);
+
+ Expect.equals(3 + ++x, 7);
+ Expect.equals(x, 4);
+ Expect.equals(3 - ++x, -2);
+ Expect.equals(x, 5);
+ Expect.equals(4 + --x, 8);
+ Expect.equals(x, 4);
+ Expect.equals(4 - --x, 1);
+ Expect.equals(x, 3);
+}
+
+void testUnaryPostfixWithAdd() {
+ int x = 3;
+
+ Expect.equals(x++ + 3, 6);
+ Expect.equals(x, 4);
+ Expect.equals(x++ - 3, 1);
+ Expect.equals(x, 5);
+ Expect.equals(x-- + 4, 9);
+ Expect.equals(x, 4);
+ Expect.equals(x-- - 4, 0);
+ Expect.equals(x, 3);
+
+ Expect.equals(3 + x++, 6);
+ Expect.equals(x, 4);
+ Expect.equals(3 - x++, -1);
+ Expect.equals(x, 5);
+ Expect.equals(4 + x--, 9);
+ Expect.equals(x, 4);
+ Expect.equals(4 - x--, 0);
+ Expect.equals(x, 3);
+}
+
+void testUnaryPrefixWithMultiply() {
+ int x = 3;
+
+ Expect.equals(++x * 3, 12);
+ Expect.equals(x, 4);
+ Expect.equals(++x / 5, 1.0);
+ Expect.equals(x, 5);
+ Expect.equals(--x * 3, 12);
+ Expect.equals(x, 4);
+ Expect.equals(--x / 4, 0.75);
+ Expect.equals(x, 3);
+
+ Expect.equals(3 * ++x, 12);
+ Expect.equals(x, 4);
+ Expect.equals(5 / ++x, 1.0);
+ Expect.equals(x, 5);
+ Expect.equals(3 * --x, 12);
+ Expect.equals(x, 4);
+ Expect.equals(6 / --x, 2.0);
+ Expect.equals(x, 3);
+}
+
+void testUnaryPostfixWithMultiply() {
+ int x = 3;
+
+ Expect.equals(x++ * 3, 9);
+ Expect.equals(x, 4);
+ Expect.equals(x++ / 4, 1.0);
+ Expect.equals(x, 5);
+ Expect.equals(x-- * 3, 15);
+ Expect.equals(x, 4);
+ Expect.equals(x-- / 4, 1.0);
+ Expect.equals(x, 3);
+
+ Expect.equals(3 * x++, 9);
+ Expect.equals(x, 4);
+ Expect.equals(3 / x++, 0.75);
+ Expect.equals(x, 5);
+ Expect.equals(4 * x--, 20);
+ Expect.equals(x, 4);
+ Expect.equals(4 / x--, 1.0);
+ Expect.equals(x, 3);
+}
+
« no previous file with comments | « pkg/front_end/test/scanner_roundtrip_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698