Chromium Code Reviews| 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(1, a.path1.length); // 2 instead of 1 | |
| 11 Expect.equals(1, a.path2.length); // NPE. | |
|
Ivan Posva
2013/01/04 01:29:55
It would be nice if you checked that the result is
srdjan
2013/01/04 01:34:08
Done.
| |
| 12 | |
| 13 var b = new Element(a); | |
| 14 Expect.equals(2, b.path0.length); | |
| 15 Expect.equals(2, b.path1.length); // 3 instead of 2. | |
| 16 Expect.equals(2, b.path2.length); // NPE. | |
| 17 } | |
| 18 | |
| 19 | |
| 20 class Element { | |
| 21 final Element parent; | |
| 22 | |
| 23 Element(this.parent); | |
| 24 | |
| 25 List<Element> get path0 { | |
| 26 if (parent == null) { | |
| 27 return <Element>[this]; | |
| 28 } else { | |
| 29 return parent.path0..add(this); | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 List<Element> get path1 { | |
| 34 return (parent == null) ? <Element>[this] : parent.path1..add(this); | |
| 35 } | |
| 36 | |
| 37 List<Element> get path2 { | |
| 38 return (parent == null) ? <Element>[this] : (parent.path2..add(this)); | |
| 39 } | |
| 40 } | |
| OLD | NEW |