OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 class A { | 6 class A { |
7 int value; | 7 int value; |
8 A(this.value); | 8 A(this.value); |
9 void set(int value) { this.value = value; } | 9 void set(int value) { this.value = value; } |
10 int get() => value; | 10 int get() => value; |
11 int operator[](int index) => value + index; | 11 int operator[](int index) => value + index; |
12 void operator[]=(int index, int newValue) { value += -index + newValue; } | 12 void operator[]=(int index, int newValue) { value += -index + newValue; } |
13 void test(int expected) { | 13 void test(int expected) { |
14 Expect.equals(expected, value); | 14 Expect.equals(expected, value); |
15 } | 15 } |
16 Function limp(int n) { | 16 Function limp(int n) { |
17 if (n == 0) return set; | 17 if (n == 0) return set; |
18 return () => limp(n - 1); | 18 return () => limp(n - 1); |
19 } | 19 } |
20 A get self() => this; | 20 A get self => this; |
21 A operator+(A other) { | 21 A operator+(A other) { |
22 this.value += other.value; | 22 this.value += other.value; |
23 return this; | 23 return this; |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 class Box { | 27 class Box { |
28 A value; | 28 A value; |
29 Box(this.value); | 29 Box(this.value); |
30 A operator[](int pos) => value; | 30 A operator[](int pos) => value; |
31 void operator[]=(int pos, A a) { value = a; } | 31 void operator[]=(int pos, A a) { value = a; } |
32 A get x() => value; | 32 A get x => value; |
33 void set x(A a) { value = a; } | 33 void set x(A a) { value = a; } |
34 } | 34 } |
35 | 35 |
36 // Subset of grammar being tested. | 36 // Subset of grammar being tested. |
37 // | 37 // |
38 // expression: | 38 // expression: |
39 // assignableExpression assignmentOperator expression | 39 // assignableExpression assignmentOperator expression |
40 // | conditionalExpression cascadeSection* | 40 // | conditionalExpression cascadeSection* |
41 // ; | 41 // ; |
42 // expressionWithoutCascade: | 42 // expressionWithoutCascade: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Should parse as: | 128 // Should parse as: |
129 // box = (box..x = (a.value == 21 ? b : c)..x.test(117)); | 129 // box = (box..x = (a.value == 21 ? b : c)..x.test(117)); |
130 box = box..x = a.value == 21 ? b : c..x.test(117); | 130 box = box..x = a.value == 21 ? b : c..x.test(117); |
131 Expect.equals(originalBox, box); | 131 Expect.equals(originalBox, box); |
132 Expect.equals(box.value, b); | 132 Expect.equals(box.value, b); |
133 | 133 |
134 // New cascades are allowed inside an expressionWithoutCascade if properly | 134 // New cascades are allowed inside an expressionWithoutCascade if properly |
135 // delimited. | 135 // delimited. |
136 box..x = (a..set(42)..test(42))..x.test(42); | 136 box..x = (a..set(42)..test(42))..x.test(42); |
137 } | 137 } |
OLD | NEW |