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

Unified Diff: tests/compiler/dart2js_extra/consistent_codeUnitAt_error_test.dart

Issue 1463933004: Test dart2js for consistent codeUnitAt errors under optimization (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js_extra/consistent_codeUnitAt_error_test.dart
diff --git a/tests/compiler/dart2js_extra/consistent_codeUnitAt_error_test.dart b/tests/compiler/dart2js_extra/consistent_codeUnitAt_error_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8d3929ffd52ef4c3c21a01c8b4c513bb112ffeb1
--- /dev/null
+++ b/tests/compiler/dart2js_extra/consistent_codeUnitAt_error_test.dart
@@ -0,0 +1,132 @@
+// Copyright (c) 2015, 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.
+
+import "package:expect/expect.dart";
+
+// Test that optimized codeUnitAt and slow path codeUnitAt produce the same
+// error.
+
+@NoInline()
+@AssumeDynamic()
+confuse(x) => x;
+
+void check2(String name, name1, f1, name2, f2) {
+ Error trap(part, f) {
+ try {
+ f();
+ } catch (e) {
+ return e;
+ }
+ Expect.fail('should throw: $name.$part');
+ }
+ var e1 = trap(name1, f1);
+ var e2 = trap(name2, f2);
+ var s1 = '$e1';
+ var s2 = '$e2';
+ Expect.equals(s1, s2, '\n $name.$name1: "$s1"\n $name.$name2: "$s2"\n');
+}
+
+void check(String name, f1, f2, [f3, f4]) {
+ check2(name, 'f1', f1, 'f2', f2);
+ if (f3 != null) check2(name, 'f1', f1, 'f3', f3);
+ if (f4 != null) check2(name, 'f1', f1, 'f4', f4);
+}
+
+
+class TooHigh {
+ static f1() {
+ return confuse('AB').codeUnitAt(3); // dynamic receiver.
+ }
+
+ static f2() {
+ var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
+ var i = confuse(3);
+ return a.codeUnitAt(i);
+ }
+
+ static f3() {
+ var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
+ return a.codeUnitAt(3);
+ }
+
+ static test() {
+ check('TooHigh', f1, f2, f3);
+ }
+}
+
+class Negative {
+ static f1() {
+ return confuse('AB').codeUnitAt(-3); // dynamic receiver.
+ }
+
+ static f2() {
+ var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
+ var i = confuse(-3);
+ return a.codeUnitAt(i);
+ }
+
+ static f3() {
+ var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
+ var i = confuse(true) ? -3 : 0;
+ return a.codeUnitAt(i);
+ }
+
+ static f4() {
+ var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
+ return a.codeUnitAt(-3);
+ }
+
+ static test() {
+ check('Negative', f1, f2, f3, f4);
+ }
+}
+
+class Empty {
+ static f1() {
+ return confuse('').codeUnitAt(0); // dynamic receiver.
+ }
+
+ static f2() {
+ var a = confuse(true) ? '' : 'ABCDE'; // Empty String with unknown length.
+ var i = confuse(true) ? 0 : 1;
+ return a.codeUnitAt(i);
+ }
+
+ static f3() {
+ var a = confuse(true) ? '' : 'ABCDE'; // Empty String with unknown length.
+ return a.codeUnitAt(0);
+ }
+
+ static test() {
+ check('Empty', f1, f2, f3);
+ }
+}
+
+class BadType {
+ static f1() {
+ return confuse('AB').codeUnitAt('a'); // dynamic receiver.
+ }
+
+ static f2() {
+ var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
+ var i = confuse('a');
+ return a.codeUnitAt(i);
+ }
+
+ static f3() {
+ var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
+ return a.codeUnitAt('a');
+ }
+
+ static test() {
+ check('BadType', f1, f2, f3);
+ }
+}
+
+main() {
+ TooHigh.test();
+ Negative.test();
+ Empty.test();
+ BadType.test();
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698