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

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

Issue 1325843003: Add optional message to assert in Dart2js. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Reintroduce assertHelper for asserts without messages. 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..5a3b5f5530de1a188500ee33033e338f46b26dbe
--- /dev/null
+++ b/tests/compiler/dart2js/type_inference7_test.dart
@@ -0,0 +1,81 @@
+// 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');
+ {
+ // Checked mode:
+ var compiler = compilerFor(TEST, uri, enableTypeAssertions: true);
+ await compiler.runCompiler(uri);
+ var typesTask = compiler.typesTask;
+ var typesInferrer = typesTask.typesInferrer;
+ var element = findElement(compiler, "foo");
+ var parameters = element.parameters;
+ // Return type is null|bool.
+ var mask = typesInferrer.getReturnTypeOfElement(element);
+ Expect.isTrue(mask.isNullable);
+ Expect.equals(typesTask.boolType, simplify(mask.nonNullable(), compiler));
+ // First parameter is uint31|String|bool.
+ var mask1 = typesInferrer.getTypeOfElement(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(parameters[1]);
+ Expect.isTrue(mask2.isNullable);
+ Expect.equals(typesTask.boolType, simplify(mask2.nonNullable(), compiler));
+ }
+ {
+ // Production mode:
+ var compiler = compilerFor(TEST, uri, enableTypeAssertions: false);
+ await compiler.runCompiler(uri);
+ var typesTask = compiler.typesTask;
+ var typesInferrer = typesTask.typesInferrer;
+ var element = findElement(compiler, "foo");
+ var parameters = element.parameters;
+ // Return type is null.
+ var mask = typesInferrer.getReturnTypeOfElement(element);
+ Expect.isTrue(mask.isNullable);
+ Expect.equals(typesTask.emptyType, simplify(mask.nonNullable(), compiler));
+ // First parameter is uint31.
+ var mask1 = typesInferrer.getTypeOfElement(parameters[0]);
+ Expect.isFalse(mask1.isNullable);
+ Expect.equals(typesTask.uint31Type, simplify(mask1, compiler));
+ // Second parameter is null.
+ var mask2 = typesInferrer.getTypeOfElement(parameters[1]);
+ Expect.isTrue(mask2.isNullable);
+ Expect.equals(typesTask.emptyType, simplify(mask2.nonNullable(), compiler));
+ }
+}
+
+main() {
+ asyncStart();
+ runTest().then((_) {
+ // Make sure that the type is still correct when we do a second compilation.
+ return runTest();
+ }).whenComplete(asyncEnd);
+}
« sdk/lib/_internal/js_runtime/lib/js_helper.dart ('K') | « tests/compiler/dart2js/mock_libraries.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698