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

Side by Side Diff: frog/tests/leg_only/src/CascadeTest.dart

Issue 9958009: Implement cascaded calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Proof-of-concept implementation of cascade Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test cascades.
6
7 class A {
8 int x;
9 int y;
10 A(this.x, this.y);
11 A setX(int x) { this.x = x; return this; }
12 void setY(int y) { this.y = y; }
13 Function swap() {
14 int tmp = x;
15 x = y;
16 y = tmp;
17 return this.swap;
18 }
19 void check(int x, int y) {
20 Expect.equals(x, this.x);
21 Expect.equals(y, this.y);
22 }
23 int operator[](var i) {
24 if (i == 0) return x;
25 if (i == 1) return y;
26 if (i == "swap") return this.swap;
27 return null;
28 }
29 int operator[]=(int i, int value) {
30 if (i == 0) {
31 x = value;
32 } else if (i == 1) {
33 y = value;
34 }
35 }
36 }
37
38 main() {
39 A a = new A(1, 2);
40 a..check(1, 2)..swap()..check(2, 1)..x = 4
41 ..check(4, 1)..setX(10)..check(10, 1)..y = 5
42 ..check(10, 5)..swap()()()..check(5, 10)..[0] = 2
43 ..check(2, 10)..setX(10).setY(3)..check(10, 3)
sra1 2012/03/30 21:52:20 Could you reformat it so that the assignment forms
Lasse Reichstein Nielsen 2012/04/10 08:12:43 Good point. I wasn't expecting it to work, but th
44 ..["swap"]()()()..check(3, 10);
45 a..(42); /// 01: compile-time error
46 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698