| OLD | NEW |
| (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, issue 7665. |
| 6 |
| 7 main() { |
| 8 var a = new Element(null); |
| 9 Expect.equals(1, a.path0.length); |
| 10 Expect.equals(a, a.path0[0]); |
| 11 |
| 12 Expect.equals(1, a.path1.length); // 2 instead of 1 |
| 13 Expect.equals(a, a.path1[0]); |
| 14 |
| 15 Expect.equals(1, a.path2.length); // NPE. |
| 16 |
| 17 var b = new Element(a); |
| 18 Expect.equals(2, b.path0.length); |
| 19 Expect.equals(a, b.path0[0]); |
| 20 Expect.equals(b, b.path0[1]); |
| 21 |
| 22 Expect.equals(2, b.path1.length); // 3 instead of 2. |
| 23 Expect.equals(a, b.path1[0]); |
| 24 Expect.equals(b, b.path1[1]); |
| 25 |
| 26 Expect.equals(2, b.path2.length); // NPE. |
| 27 } |
| 28 |
| 29 |
| 30 class Element { |
| 31 final Element parent; |
| 32 |
| 33 Element(this.parent); |
| 34 |
| 35 List<Element> get path0 { |
| 36 if (parent == null) { |
| 37 return <Element>[this]; |
| 38 } else { |
| 39 return parent.path0..add(this); |
| 40 } |
| 41 } |
| 42 |
| 43 List<Element> get path1 { |
| 44 return (parent == null) ? <Element>[this] : parent.path1..add(this); |
| 45 } |
| 46 |
| 47 List<Element> get path2 { |
| 48 return (parent == null) ? <Element>[this] : (parent.path2..add(this)); |
| 49 } |
| 50 } |
| OLD | NEW |