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

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

Issue 2896393003: Remove factory body in *.fromEnvironment, and implement this same behavior (Closed)
Patch Set: Created 3 years, 7 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_extra/new_from_env_test.dart
diff --git a/tests/compiler/dart2js_extra/new_from_env_test.dart b/tests/compiler/dart2js_extra/new_from_env_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..86f62ddd965b7f4e00c77cbe56889b162e1b29ed
--- /dev/null
+++ b/tests/compiler/dart2js_extra/new_from_env_test.dart
@@ -0,0 +1,18 @@
+// 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.
+
+import 'package:expect/expect.dart';
+
+/// Dart2js only supports the const constructor for `?.fromEnvironment`. The
+/// current behavior is to throw at runtime if they call this constructor with
+/// `new` instead of `const`.
+main() {
+ Expect.isFalse(const bool.fromEnvironment('X'));
+ Expect.isNull(const String.fromEnvironment('X'));
+ Expect.equals(const int.fromEnvironment('X', defaultValue: 0), 0);
+
+ Expect.throws(() => new bool.fromEnvironment('X'));
+ Expect.throws(() => new String.fromEnvironment('X'));
+ Expect.throws(() => new int.fromEnvironment('X', defaultValue: 0));
+}

Powered by Google App Engine
This is Rietveld 408576698