| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Tests map literals. | 5 // Tests map literals. |
| 6 | 6 |
| 7 class MapLiteralTest { | 7 class MapLiteralTest { |
| 8 MapLiteralTest() {} | 8 MapLiteralTest() {} |
| 9 | 9 |
| 10 static testMain() { | 10 static testMain() { |
| 11 var test = new MapLiteralTest(); | 11 var test = new MapLiteralTest(); |
| 12 test.testStaticInit(); | 12 test.testStaticInit(); |
| 13 test.testConstInit(); | 13 test.testConstInit(); |
| 14 } | 14 } |
| 15 | 15 |
| 16 testStaticInit() { | 16 testStaticInit() { |
| 17 var testClass = new StaticInit(); | 17 var testClass = new StaticInit(); |
| 18 testClass.test(); | 18 testClass.test(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 testConstInit() { | 21 testConstInit() { |
| 22 var testClass = new ConstInit(); | 22 var testClass = new ConstInit(); |
| 23 testClass.test(); | 23 testClass.test(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 testLocalInit() { | 26 testLocalInit() { |
| 27 // Test construction of static final map literals | 27 // Test construction of static const map literals |
| 28 var map1 = {"a":1, "b":2}; | 28 var map1 = {"a":1, "b":2}; |
| 29 // Test construction of static final map literals, with numbers | 29 // Test construction of static const map literals, with numbers |
| 30 var map2 = {"1":1, "2":2}; | 30 var map2 = {"1":1, "2":2}; |
| 31 | 31 |
| 32 Expect.equals(1, map1["a"]); | 32 Expect.equals(1, map1["a"]); |
| 33 Expect.equals(2, map1["b"]); | 33 Expect.equals(2, map1["b"]); |
| 34 | 34 |
| 35 Expect.equals(1, map2["1"]); | 35 Expect.equals(1, map2["1"]); |
| 36 Expect.equals(2, map2["2"]); | 36 Expect.equals(2, map2["2"]); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 class StaticInit { | 40 class StaticInit { |
| 41 StaticInit() {} | 41 StaticInit() {} |
| 42 | 42 |
| 43 // Test construction of static final map literals | 43 // Test construction of static const map literals |
| 44 static final map1 = const {"a":1, "b":2}; | 44 static const map1 = const {"a":1, "b":2}; |
| 45 // Test construction of static final map literals, with numbers | 45 // Test construction of static const map literals, with numbers |
| 46 static final map2 = const {"1":1, "2":2}; | 46 static const map2 = const {"1":1, "2":2}; |
| 47 | 47 |
| 48 test() { | 48 test() { |
| 49 Expect.equals(1, map1["a"]); | 49 Expect.equals(1, map1["a"]); |
| 50 Expect.equals(2, map1["b"]); | 50 Expect.equals(2, map1["b"]); |
| 51 | 51 |
| 52 Expect.equals(1, map2["1"]); | 52 Expect.equals(1, map2["1"]); |
| 53 Expect.equals(2, map2["2"]); | 53 Expect.equals(2, map2["2"]); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 Expect.equals(2, map1["b"]); | 67 Expect.equals(2, map1["b"]); |
| 68 | 68 |
| 69 Expect.equals(1, map2["1"]); | 69 Expect.equals(1, map2["1"]); |
| 70 Expect.equals(2, map2["2"]); | 70 Expect.equals(2, map2["2"]); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 main() { | 74 main() { |
| 75 MapLiteralTest.testMain(); | 75 MapLiteralTest.testMain(); |
| 76 } | 76 } |
| OLD | NEW |