dart-sdk/tests/language/symbol_literal_test.dart
hausner@google.com 8ece5c1b84 Allow Symbols in switch and maps
Allow Symbol literals (and const Symbol instances) as switch expression
and as key values in const Maps.

This implements the most recent Spec changes.

R=regis@google.com

Review URL: https://codereview.chromium.org//781203005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42230 260f80e4-7a28-3924-810f-c04153c831b5
2014-12-10 00:24:07 +00:00

47 lines
1.3 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test symbol literals.
library symbol_literal_test;
import 'package:expect/expect.dart';
foo(a, b) => Expect.isTrue(identical(a, b));
var check = foo; // Indirection used to avoid inlining.
testSwitch(Symbol s) {
switch(s) {
case #abc: return 1;
case const Symbol("def"): return 2;
default: return 0;
}
}
main() {
check(const Symbol("a"), #a);
check(const Symbol("a"), #
a);
check(const Symbol("ab"), #ab);
check(const Symbol("ab"), #
ab);
check(const Symbol("a.b"), #a.b);
check(const Symbol("a.b"), #
a
.
b);
check(const Symbol("=="), #==);
check(const Symbol("=="), # ==);
check(const Symbol("a.toString"), #a.toString);
Expect.equals(1, testSwitch(#abc));
const m = const <Symbol, int>{#A:0, #B:1};
Expect.equals(1, m[#B]);
// Tries to call the symbol literal #a.toString
Expect.throws(() => #a.toString(), (e) => e is NoSuchMethodError); /// 01: static type warning
}