OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Test symbol literals. | 5 // Test symbol literals. |
6 | 6 |
7 library symbol_literal_test; | 7 library symbol_literal_test; |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 | 10 |
11 foo(a, b) => Expect.isTrue(identical(a, b)); | 11 foo(a, b) => Expect.isTrue(identical(a, b)); |
12 | 12 |
13 var check = foo; // Indirection used to avoid inlining. | 13 var check = foo; // Indirection used to avoid inlining. |
14 | 14 |
15 testSwitch(Symbol s) { | 15 testSwitch(Symbol s) { |
16 switch (s) { | 16 switch(s) { |
17 case #abc: | 17 case #abc: return 1; |
18 return 1; | 18 case const Symbol("def"): return 2; |
19 case const Symbol("def"): | 19 default: return 0; |
20 return 2; | |
21 default: | |
22 return 0; | |
23 } | 20 } |
24 } | 21 } |
25 | 22 |
26 main() { | 23 main() { |
27 check(const Symbol("a"), #a); | 24 check(const Symbol("a"), #a); |
28 check(const Symbol("a"), #a); | 25 check(const Symbol("a"), # |
| 26 a); |
29 check(const Symbol("ab"), #ab); | 27 check(const Symbol("ab"), #ab); |
30 check(const Symbol("ab"), #ab); | 28 check(const Symbol("ab"), # |
| 29 ab); |
31 check(const Symbol("a.b"), #a.b); | 30 check(const Symbol("a.b"), #a.b); |
32 check(const Symbol("a.b"), #a.b); | 31 check(const Symbol("a.b"), # |
| 32 a |
| 33 . |
| 34 b); |
33 check(const Symbol("=="), #==); | 35 check(const Symbol("=="), #==); |
34 check(const Symbol("=="), #==); | 36 check(const Symbol("=="), # ==); |
35 check(const Symbol("a.toString"), #a.toString); | 37 check(const Symbol("a.toString"), #a.toString); |
36 | 38 |
37 Expect.equals(1, testSwitch(#abc)); | 39 Expect.equals(1, testSwitch(#abc)); |
38 | 40 |
39 const m = const <Symbol, int>{#A: 0, #B: 1}; | 41 const m = const <Symbol, int>{#A:0, #B:1}; |
40 Expect.equals(1, m[#B]); | 42 Expect.equals(1, m[#B]); |
41 | 43 |
42 // Tries to call the symbol literal #a.toString | 44 // Tries to call the symbol literal #a.toString |
43 Expect.throws(() => #a.toString(), (e) => e is NoSuchMethodError); //# 01: sta
tic type warning | 45 Expect.throws(() => #a.toString(), (e) => e is NoSuchMethodError); //# 01: sta
tic type warning |
44 } | 46 } |
OLD | NEW |