| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Tests map literals. | |
| 6 | |
| 7 class MapLiteralTest { | |
| 8 MapLiteralTest() {} | |
| 9 | |
| 10 static testMain() { | |
| 11 var test = new MapLiteralTest(); | |
| 12 test.testStaticInit(); | |
| 13 test.testConstInit(); | |
| 14 } | |
| 15 | |
| 16 testStaticInit() { | |
| 17 var testClass = new StaticInit(); | |
| 18 testClass.test(); | |
| 19 } | |
| 20 | |
| 21 testConstInit() { | |
| 22 var testClass = new ConstInit(); | |
| 23 testClass.test(); | |
| 24 } | |
| 25 | |
| 26 testLocalInit() { | |
| 27 // Test construction of static final map literals | |
| 28 var map1 = {"a":1, "b":2}; | |
| 29 // Test construction of static final map literals, with numbers | |
| 30 var map2 = {"1":1, "2":2}; | |
| 31 | |
| 32 Expect.equals(1, map1["a"]); | |
| 33 Expect.equals(2, map1["b"]); | |
| 34 | |
| 35 Expect.equals(1, map2["1"]); | |
| 36 Expect.equals(2, map2["2"]); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 class StaticInit { | |
| 41 StaticInit() {} | |
| 42 | |
| 43 // Test construction of static final map literals | |
| 44 static final map1 = const {"a":1, "b":2}; | |
| 45 // Test construction of static final map literals, with numbers | |
| 46 static final map2 = const {"1":1, "2":2}; | |
| 47 | |
| 48 test() { | |
| 49 Expect.equals(1, map1["a"]); | |
| 50 Expect.equals(2, map1["b"]); | |
| 51 | |
| 52 Expect.equals(1, map2["1"]); | |
| 53 Expect.equals(2, map2["2"]); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 class ConstInit { | |
| 58 | |
| 59 final map1; | |
| 60 final map2; | |
| 61 | |
| 62 ConstInit() : this.map1 = {"a":1, "b":2}, this.map2 = {"1":1, "2":2} { | |
| 63 } | |
| 64 | |
| 65 test() { | |
| 66 Expect.equals(1, map1["a"]); | |
| 67 Expect.equals(2, map1["b"]); | |
| 68 | |
| 69 Expect.equals(1, map2["1"]); | |
| 70 Expect.equals(2, map2["2"]); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 main() { | |
| 75 MapLiteralTest.testMain(); | |
| 76 } | |
| OLD | NEW |