| 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 class ExpandoTest { | 5 class ExpandoTest { |
| 6 static Expando<int> visits; | 6 static Expando<int> visits; |
| 7 | 7 |
| 8 static testMain() { | 8 static testMain() { |
| 9 visits = new Expando<int>('visits'); | 9 visits = new Expando<int>('visits'); |
| 10 var legal = [ new Object(), | 10 var legal = [ new Object(), |
| 11 new List(), [1,2,3], const [1,2,3], | 11 new List(), [1,2,3], const [1,2,3], |
| 12 new Map(), {'x':1,'y':2}, const {'x':1,'y':2}, | 12 new Map(), {'x':1,'y':2}, const {'x':1,'y':2}, |
| 13 new Expando(), new Expando('horse') ]; | 13 new Expando(), new Expando('horse') ]; |
| 14 for (var object in legal) { | 14 for (var object in legal) { |
| 15 testNamedExpando(object); | 15 testNamedExpando(object); |
| 16 testUnnamedExpando(object); | 16 testUnnamedExpando(object); |
| 17 } | 17 } |
| 18 for (var object in legal) { | 18 for (var object in legal) { |
| 19 Expect.equals(2, visits[object]); | 19 Expect.equals(2, visits[object]); |
| 20 } | 20 } |
| 21 testIllegal(); | 21 testIllegal(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 static visit(object) { | 24 static visit(object) { |
| 25 int count = visits[object]; | 25 int count = visits[object]; |
| 26 count = (count === null) ? 1 : count + 1; | 26 count = (count == null) ? 1 : count + 1; |
| 27 visits[object] = count; | 27 visits[object] = count; |
| 28 } | 28 } |
| 29 | 29 |
| 30 static testNamedExpando(object) { | 30 static testNamedExpando(object) { |
| 31 Expando<int> expando = new Expando<int>('myexpando'); | 31 Expando<int> expando = new Expando<int>('myexpando'); |
| 32 Expect.equals('myexpando', expando.name); | 32 Expect.equals('myexpando', expando.name); |
| 33 Expect.isTrue(expando.toString().startsWith('Expando:myexpando')); | 33 Expect.isTrue(expando.toString().startsWith('Expando:myexpando')); |
| 34 testExpando(expando, object); | 34 testExpando(expando, object); |
| 35 } | 35 } |
| 36 | 36 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 Expect.throws(() => expando[42.87], (exception) | 72 Expect.throws(() => expando[42.87], (exception) |
| 73 => exception is ArgumentError); | 73 => exception is ArgumentError); |
| 74 Expect.throws(() => expando[true], (exception) | 74 Expect.throws(() => expando[true], (exception) |
| 75 => exception is ArgumentError); | 75 => exception is ArgumentError); |
| 76 Expect.throws(() => expando[false], (exception) | 76 Expect.throws(() => expando[false], (exception) |
| 77 => exception is ArgumentError); | 77 => exception is ArgumentError); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 main() => ExpandoTest.testMain(); | 81 main() => ExpandoTest.testMain(); |
| OLD | NEW |