| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, 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 the use of general expression as keys in map literals. |
| 6 |
| 7 library map_literal5_test; |
| 8 |
| 9 import "package:expect/expect.dart"; |
| 10 |
| 11 void main() { |
| 12 test(true); |
| 13 test(false); |
| 14 } |
| 15 |
| 16 void test(bool b) { |
| 17 var m = create(b); |
| 18 Expect.equals(b, m.containsKey(true)); |
| 19 Expect.equals(b, m.containsKey(2)); |
| 20 Expect.equals(b, m.containsKey(1)); |
| 21 Expect.equals(!b, m.containsKey(false)); |
| 22 Expect.equals(!b, m.containsKey("bar")); |
| 23 Expect.equals(!b, m.containsKey("foo")); |
| 24 if (b) { |
| 25 Expect.equals(0, m[true]); |
| 26 Expect.equals(3, m[2]); |
| 27 Expect.equals(2, m[1]); |
| 28 } else { |
| 29 Expect.equals(0, m[false]); |
| 30 Expect.equals("baz", m["bar"]); |
| 31 Expect.equals(2, m["foo"]); |
| 32 } |
| 33 } |
| 34 |
| 35 create(bool b) { |
| 36 return { |
| 37 b: 0, |
| 38 m(b): n(b), |
| 39 b ? 1 : "foo": 2, |
| 40 }; |
| 41 } |
| 42 |
| 43 m(bool b) => b ? 2 : "bar"; |
| 44 n(bool b) => b ? 3 : "baz"; |
| OLD | NEW |