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

Unified Diff: tests/language/src/ClosuresWithComplexParamsTest.dart

Issue 8343049: Test with difficult to parse formal parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/src/ClosuresWithComplexParamsTest.dart
diff --git a/tests/language/src/ClosuresWithComplexParamsTest.dart b/tests/language/src/ClosuresWithComplexParamsTest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7f4f0bbbfd4aa55da1f34bb3bb4c2ff08fde41e6
--- /dev/null
+++ b/tests/language/src/ClosuresWithComplexParamsTest.dart
@@ -0,0 +1,58 @@
+// 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.
+
+// Tests for parsing closures with complex parameter types.
+
+main() {
+ test1();
+ test2();
+ test3();
+}
+
+class Pair<A, B> {
+ final A fst;
+ final B snd;
+ Pair(A this.fst, B this.snd);
+}
+
+test1() {
+ // Closures with nested parameterized types.
+ var cdar1 = (Pair<int, Pair<int, int>> pr) => pr.snd.fst;
+ var cdar2 = (Pair<int, Pair<int, int> > pr) => pr.snd.fst;
+
+ var e = new Pair<int, Pair<int, int>>(100, new Pair<int, int>(200, 300));
+
+ Expect.equals(200, cdar1(e));
+ Expect.equals(200, cdar2(e));
+}
+
+test2() {
+ // Closures with nested parameterized types in optional position
+ var cdar1 = ([Pair<int, Pair<int, int>> pr = null]) => pr.snd.fst;
+ var cdar2 = ([Pair<int, Pair<int, int> > pr = null]) => pr.snd.fst;
+
+ var e = new Pair<int, Pair<int, int>>(100, new Pair<int, int>(200, 300));
+
+ Expect.equals(200, cdar1(e));
+ Expect.equals(200, cdar2(e));
+}
+
+test3() {
+ // Closures with nested parameterized types.
+ var f1 = (Pair<int, Pair<int, int>> pr) => pr.snd.fst + 1;
+ var f2 = (Pair<int, Pair<int, int> > pr) => pr.snd.fst + 2;
+
+ // Closures with function type with nested parameterized types.
+ var ap1 = (f(Pair<int, Pair<int, int>> pr), Pair<int, Pair<int, int>> pr)
+ => f(pr) * 10;
+ var ap2 = (f(Pair<int, Pair<int, int> > pr), Pair<int, Pair<int, int> > pr)
+ => f(pr) * 100;
+
+ var e = new Pair<int, Pair<int, int>>(100, new Pair<int, int>(200, 300));
+
+ Expect.equals(2010, ap1(f1, e));
+ Expect.equals(2020, ap1(f2, e));
+ Expect.equals(20100, ap2(f1, e));
+ Expect.equals(20200, ap2(f2, e));
+}
« 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