| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Test cascades, issues 7494 (vm), 7689 (dart2js). | 7 // Test cascades, issues 7494 (vm), 7689 (dart2js). |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 var a = new Element(null); | 10 var a = new Element(null); |
| 11 Expect.equals(1, a.path0.length); | 11 Expect.equals(1, a.path0.length); |
| 12 Expect.equals(a, a.path0[0]); | 12 Expect.equals(a, a.path0[0]); |
| 13 | 13 |
| 14 // Issue 7693: e0 ? e1 : e2..f() parses as (e0 ? e1 : e2)..f(). | 14 // Issue 7693: e0 ? e1 : e2..f() parses as (e0 ? e1 : e2)..f(). |
| 15 Expect.equals(2, a.path1.length); | 15 Expect.equals(2, a.path1.length); |
| 16 Expect.equals(a, a.path1[0]); | 16 Expect.equals(a, a.path1[0]); |
| 17 Expect.equals(a, a.path1[1]); | 17 Expect.equals(a, a.path1[1]); |
| 18 | 18 |
| 19 Expect.equals(1, a.path2.length); // NPE. | 19 Expect.equals(1, a.path2.length); // NPE. |
| 20 | 20 |
| 21 var b = new Element(a); | 21 var b = new Element(a); |
| 22 Expect.equals(2, b.path0.length); | 22 Expect.equals(2, b.path0.length); |
| 23 Expect.equals(a, b.path0[0]); | 23 Expect.equals(a, b.path0[0]); |
| 24 Expect.equals(b, b.path0[1]); | 24 Expect.equals(b, b.path0[1]); |
| 25 | 25 |
| 26 Expect.equals(3, b.path1.length); | 26 Expect.equals(3, b.path1.length); |
| 27 Expect.equals(a, b.path1[0]); | 27 Expect.equals(a, b.path1[0]); |
| 28 Expect.equals(a, b.path1[1]); | 28 Expect.equals(a, b.path1[1]); |
| 29 Expect.equals(b, b.path1[2]); | 29 Expect.equals(b, b.path1[2]); |
| 30 | 30 |
| 31 Expect.equals(2, b.path2.length); // NPE. | 31 Expect.equals(2, b.path2.length); // NPE. |
| 32 } | 32 } |
| 33 | 33 |
| 34 | |
| 35 class Element { | 34 class Element { |
| 36 final Element parent; | 35 final Element parent; |
| 37 | 36 |
| 38 Element(this.parent); | 37 Element(this.parent); |
| 39 | 38 |
| 40 List<Element> get path0 { | 39 List<Element> get path0 { |
| 41 if (parent == null) { | 40 if (parent == null) { |
| 42 return <Element>[this]; | 41 return <Element>[this]; |
| 43 } else { | 42 } else { |
| 44 return parent.path0..add(this); | 43 return parent.path0..add(this); |
| 45 } | 44 } |
| 46 } | 45 } |
| 47 | 46 |
| 48 List<Element> get path1 { | 47 List<Element> get path1 { |
| 49 return (parent == null) ? <Element>[this] : parent.path1..add(this); | 48 return (parent == null) ? <Element>[this] : parent.path1 |
| 49 ..add(this); |
| 50 } | 50 } |
| 51 | 51 |
| 52 List<Element> get path2 { | 52 List<Element> get path2 { |
| 53 return (parent == null) ? <Element>[this] : (parent.path2..add(this)); | 53 return (parent == null) ? <Element>[this] : (parent.path2..add(this)); |
| 54 } | 54 } |
| 55 } | 55 } |
| OLD | NEW |