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

Unified Diff: tests/compiler/dart2js/type_inference7_test.dart

Issue 1342213003: Add optional message to assert in Dart2js - continued (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add --assert-message flag Created 5 years, 3 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
Index: tests/compiler/dart2js/type_inference7_test.dart
diff --git a/tests/compiler/dart2js/type_inference7_test.dart b/tests/compiler/dart2js/type_inference7_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..64b8cbc9e4693095879030ff4484c0e3240de6dd
--- /dev/null
+++ b/tests/compiler/dart2js/type_inference7_test.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2011, 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:async_helper/async_helper.dart";
+import "package:expect/expect.dart";
+import 'compiler_helper.dart';
+import 'type_mask_test_helper.dart';
+import 'dart:async';
+
+const String TEST = r"""
+foo(x, [y]) => y;
+
+main() {
+ assert(foo('Hi', true), foo(true));
+ foo(1);
+}
+""";
+
+Future runTest() async {
+ Uri uri = new Uri(scheme: 'source');
+ {
+ // Assertions enabled:
+ var compiler = compilerFor(TEST, uri, enableUserAssertions: true);
+ await compiler.runCompiler(uri);
+ var typesTask = compiler.typesTask;
+ var typesInferrer = typesTask.typesInferrer;
+ var foo = findElement(compiler, "foo");
+ // Return type is null|bool.
+ var mask = typesInferrer.getReturnTypeOfElement(foo);
+ Expect.isTrue(mask.isNullable);
+ Expect.equals(typesTask.boolType, simplify(mask.nonNullable(), compiler));
+ // First parameter is uint31|String|bool.
+ var mask1 = typesInferrer.getTypeOfElement(foo.parameters[0]);
+ Expect.isTrue(mask1.isUnion);
+ var expectedTypes = new Set.from([typesTask.uint31Type,
+ typesTask.stringType,
+ typesTask.boolType]);
+ for (var typeMask in mask1.disjointMasks) {
+ Expect.isFalse(typeMask.isNullable);
+ var simpleType = simplify(typeMask, compiler);
+ Expect.isTrue(expectedTypes.remove(simpleType), "$simpleType");
+ }
+ Expect.isTrue(expectedTypes.isEmpty);
+ // Second parameter is bool or null.
+ var mask2 = typesInferrer.getTypeOfElement(foo.parameters[1]);
+ Expect.isTrue(mask2.isNullable);
+ Expect.equals(typesTask.boolType, simplify(mask2.nonNullable(), compiler));
+ }
+
+ {
+ // Assertions disabled:
+ var compiler = compilerFor(TEST, uri, enableUserAssertions: false);
+ await compiler.runCompiler(uri);
+ var typesTask = compiler.typesTask;
+ var typesInferrer = typesTask.typesInferrer;
+ var foo = findElement(compiler, "foo");
+ // Return type is null.
+ var mask = typesInferrer.getReturnTypeOfElement(foo);
+ Expect.isTrue(mask.isNullable);
+ Expect.isTrue(mask.nonNullable().isEmpty);
+ // First parameter is uint31.
+ var mask1 = typesInferrer.getTypeOfElement(foo.parameters[0]);
+ Expect.isFalse(mask1.isNullable);
+ Expect.equals(typesTask.uint31Type, simplify(mask1, compiler));
+ // Second parameter is null.
+ var mask2 = typesInferrer.getTypeOfElement(foo.parameters[1]);
+ Expect.isTrue(mask2.isNullable);
+ Expect.isTrue(simplify(mask2.nonNullable(), compiler).isEmpty);
+ }
+}
+
+main() {
+ asyncStart();
+ runTest().then((_) {
+ // Make sure that the type is still correct when we do a second compilation.
+ return runTest();
+ }).whenComplete(asyncEnd);
+}

Powered by Google App Engine
This is Rietveld 408576698