| Index: dart/tests/corelib/symbol_test.dart
|
| diff --git a/dart/tests/corelib/symbol_test.dart b/dart/tests/corelib/symbol_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d6d4a43900683ffce010cd5c720d27079b46a386
|
| --- /dev/null
|
| +++ b/dart/tests/corelib/symbol_test.dart
|
| @@ -0,0 +1,78 @@
|
| +// 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.
|
| +
|
| +// Basic test of Symbol class.
|
| +
|
| +main() {
|
| + var x;
|
| + print(x = const Symbol('fisk'));
|
| +
|
| + try {
|
| + print(const Symbol(0)); /// 01: compile-time error
|
| + } on ArgumentError {
|
| + print('Caught ArgumentError');
|
| + } on TypeError {
|
| + print('Caught TypeError');
|
| + }
|
| +
|
| + try {
|
| + print(const Symbol('0')); /// 02: compile-time error
|
| + } on ArgumentError catch (e) {
|
| + print('Caught $e');
|
| + }
|
| +
|
| + try {
|
| + print(const Symbol('_')); /// 03: compile-time error
|
| + } on ArgumentError catch (e) {
|
| + print('Caught $e');
|
| + }
|
| +
|
| + try {
|
| + var y = 0;
|
| + print(new Symbol(y));
|
| + throw 'Expected an ArgumentError or a TypeError';
|
| + } on ArgumentError {
|
| + print('Caught ArgumentError');
|
| + } on TypeError {
|
| + print('Caught TypeError');
|
| + }
|
| +
|
| + try {
|
| + print(new Symbol('0'));
|
| + throw 'Expected an ArgumentError';
|
| + } on ArgumentError catch (e) {
|
| + print('Caught $e');
|
| + }
|
| +
|
| + try {
|
| + print(new Symbol('_'));
|
| + throw 'Expected an ArgumentError';
|
| + } on ArgumentError catch (e) {
|
| + print('Caught $e');
|
| + }
|
| +
|
| + if (!identical(const Symbol('fisk'), x)) {
|
| + throw 'Symbol constant is not canonicalized';
|
| + }
|
| +
|
| + if (const Symbol('fisk') != x) {
|
| + throw 'Symbol constant is not equal to itself';
|
| + }
|
| +
|
| + if (const Symbol('fisk') != new Symbol('fisk')) {
|
| + throw 'Symbol constant is not equal to its non-const equivalent';
|
| + }
|
| +
|
| + if (new Symbol('fisk') != new Symbol('fisk')) {
|
| + throw 'new Symbol is not equal to its equivalent';
|
| + }
|
| +
|
| + x.hashCode as int;
|
| +
|
| + new Symbol('fisk').hashCode as int;
|
| +
|
| + if (new Symbol('fisk').hashCode != x.hashCode) {
|
| + throw "non-const Symbol's hashCode not equal to its const equivalent";
|
| + }
|
| +}
|
|
|