Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: tests/language/symbol_literal_test.dart

Issue 781203005: Allow Symbols in switch and maps (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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) {
16 switch(s) {
17 case #abc: return 1;
18 case const Symbol("def"): return 2;
19 default: return 0;
20 }
21 }
22
15 main() { 23 main() {
16 check(const Symbol("a"), #a); 24 check(const Symbol("a"), #a);
17 check(const Symbol("a"), # 25 check(const Symbol("a"), #
18 a); 26 a);
19 check(const Symbol("ab"), #ab); 27 check(const Symbol("ab"), #ab);
20 check(const Symbol("ab"), # 28 check(const Symbol("ab"), #
21 ab); 29 ab);
22 check(const Symbol("a.b"), #a.b); 30 check(const Symbol("a.b"), #a.b);
23 check(const Symbol("a.b"), # 31 check(const Symbol("a.b"), #
24 a 32 a
25 . 33 .
26 b); 34 b);
27 check(const Symbol("=="), #==); 35 check(const Symbol("=="), #==);
28 check(const Symbol("=="), # ==); 36 check(const Symbol("=="), # ==);
29 check(const Symbol("a.toString"), #a.toString); 37 check(const Symbol("a.toString"), #a.toString);
30 38
39 Expect.equals(1, testSwitch(#abc));
40
41 const m = const <Symbol, int>{#A:0, #B:1};
42 Expect.equals(1, m[#B]);
43
31 // Tries to call the symbol literal #a.toString 44 // Tries to call the symbol literal #a.toString
32 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
33 } 46 }
OLDNEW
« runtime/vm/object_store.cc ('K') | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698