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

Side by Side Diff: dart/tests/corelib/symbol_test.dart

Issue 14142003: Add Symbol class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Implement hashCode and equals Created 7 years, 8 months 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
(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 // Basic test of Symbol class.
6
7 main() {
8 var x;
9 print(x = const Symbol('fisk'));
10
11 try {
12 print(const Symbol(0)); /// 01: compile-time error
13 } on ArgumentError {
14 print('Caught ArgumentError');
15 } on TypeError {
16 print('Caught TypeError');
17 }
18
19 try {
20 print(const Symbol('0')); /// 02: compile-time error
21 } on ArgumentError catch (e) {
22 print('Caught $e');
23 }
24
25 try {
26 print(const Symbol('_')); /// 03: compile-time error
27 } on ArgumentError catch (e) {
28 print('Caught $e');
29 }
30
31 try {
32 var y = 0;
33 print(new Symbol(y));
34 throw 'Expected an ArgumentError or a TypeError';
35 } on ArgumentError {
36 print('Caught ArgumentError');
37 } on TypeError {
38 print('Caught TypeError');
39 }
40
41 try {
42 print(new Symbol('0'));
43 throw 'Expected an ArgumentError';
44 } on ArgumentError catch (e) {
45 print('Caught $e');
46 }
47
48 try {
49 print(new Symbol('_'));
50 throw 'Expected an ArgumentError';
51 } on ArgumentError catch (e) {
52 print('Caught $e');
53 }
54
55 if (!identical(const Symbol('fisk'), x)) {
56 throw 'Symbol constant is not canonicalized';
57 }
58
59 if (const Symbol('fisk') != x) {
60 throw 'Symbol constant is not equal to itself';
61 }
62
63 if (const Symbol('fisk') != new Symbol('fisk')) {
64 throw 'Symbol constant is not equal to its non-const equivalent';
65 }
66
67 if (new Symbol('fisk') != new Symbol('fisk')) {
68 throw 'new Symbol is not equal to its equivalent';
69 }
70
71 x.hashCode as int;
72
73 new Symbol('fisk').hashCode as int;
74
75 if (new Symbol('fisk').hashCode != x.hashCode) {
76 throw "non-const Symbol's hashCode not equal to its const equivalent";
77 }
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698