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

Unified Diff: tests/language/parse_closures_in_initializers_test.dart

Issue 232823002: Allow closures in string literals in initializer expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge. Created 6 years, 8 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 | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/parse_closures_in_initializers_test.dart
diff --git a/tests/language/parse_closures_in_initializers_test.dart b/tests/language/parse_closures_in_initializers_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4da7e98e5bda537862fd1071a3c77a063c1bacc4
--- /dev/null
+++ b/tests/language/parse_closures_in_initializers_test.dart
@@ -0,0 +1,45 @@
+// Copyright (c) 2014, 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 function literals are parsed correctly in initializers.
+
+class A {
+ final x;
+ static foo(f) => f();
+
+ A.parenthesized(y) : x = (() => y);
+ A.stringLiteral(y) : x = "**${() => y}--";
+ A.listLiteral(y) : x = [() => y];
+ A.mapLiteral(y) : x = { "fun": () => y };
+ A.arg(y) : x = foo(() => y);
+}
+
+main() {
+ var a, f;
+ a = new A.parenthesized(499);
+ f = a.x;
+ Expect.isTrue(f is Function);
+ Expect.equals(499, f());
+
+ // The toString of closures is not specified. Just make sure that there is no
+ // crash.
+ a = new A.stringLiteral(42);
+ Expect.isTrue(a.x.startsWith("**"));
+ Expect.isTrue(a.x.endsWith("--"));
+
+ a = new A.listLiteral(99);
+ f = a.x[0];
+ Expect.isTrue(f is Function);
+ Expect.equals(99, f());
+
+ a = new A.mapLiteral(314);
+ f = a.x["fun"];
+ Expect.isTrue(f is Function);
+ Expect.equals(314, f());
+
+ a = new A.arg(123);
+ Expect.equals(123, a.x);
+}
« no previous file with comments | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698