| 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 // Basic test of Symbol class. | 5 // Basic test of Symbol class. |
| 6 | 6 |
| 7 main() { | 7 main() { |
| 8 var x; | 8 var x; |
| 9 print(x = const Symbol('fisk')); | 9 print(x = const Symbol('fisk')); |
| 10 | |
| 11 try { | 10 try { |
| 12 print(const Symbol(0)); //# 01: compile-time error | 11 print(const Symbol(0)); //# 01: compile-time error |
| 13 } on NoSuchMethodError { | 12 } on NoSuchMethodError { |
| 14 print('Caught NoSuchMethodError'); | 13 print('Caught NoSuchMethodError'); |
| 15 } on TypeError { | 14 } on TypeError { |
| 16 print('Caught TypeError'); | 15 print('Caught TypeError'); |
| 17 } | 16 } |
| 18 | 17 |
| 19 try { | 18 try { |
| 20 print(const Symbol('0')); //# 02: compile-time error | 19 print(const Symbol('0')); //# 02: compile-time error |
| 21 } on ArgumentError catch (e) { | 20 } on ArgumentError catch (e) { |
| 22 print('Caught $e'); | 21 print('Caught $e'); |
| 23 } | 22 } |
| 24 | 23 |
| 25 try { | 24 try { |
| 26 print(const Symbol('_')); //# 03: compile-time error | 25 print(const Symbol('_')); //# 03: compile-time error |
| 27 } on ArgumentError catch (e) { | 26 } on ArgumentError catch (e) { |
| 28 print('Caught $e'); | 27 print('Caught $e'); |
| 29 } | 28 } |
| 30 | 29 |
| 31 try { | 30 try { |
| 32 var y = 0; | 31 var y = 0; |
| 33 print(new Symbol(y)); //# 04: compile-time error | 32 print(new Symbol(y)); //# 04: compile-time error |
| 34 throw 'Expected a NoSuchMethodError or a TypeError'; | 33 throw 'Expected a NoSuchMethodError or a TypeError'; //# 04: ok |
| 35 } on NoSuchMethodError { | 34 } on NoSuchMethodError { |
| 36 print('Caught NoSuchMethodError'); | 35 print('Caught NoSuchMethodError'); |
| 37 } on TypeError { | 36 } on TypeError { |
| 38 print('Caught TypeError'); | 37 print('Caught TypeError'); |
| 39 } | 38 } |
| 40 | 39 |
| 41 try { | 40 try { |
| 42 print(new Symbol('0')); | 41 print(new Symbol('0')); |
| 43 throw 'Expected an ArgumentError'; | 42 throw 'Expected an ArgumentError'; |
| 44 } on ArgumentError catch (e) { | 43 } on ArgumentError catch (e) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 new Symbol('fisk').hashCode as int; | 80 new Symbol('fisk').hashCode as int; |
| 82 | 81 |
| 83 if (new Symbol('fisk').hashCode != x.hashCode) { | 82 if (new Symbol('fisk').hashCode != x.hashCode) { |
| 84 throw "non-const Symbol's hashCode not equal to its const equivalent"; | 83 throw "non-const Symbol's hashCode not equal to its const equivalent"; |
| 85 } | 84 } |
| 86 | 85 |
| 87 if (new Symbol('') != const Symbol('')) { | 86 if (new Symbol('') != const Symbol('')) { |
| 88 throw 'empty Symbol not equals to itself'; | 87 throw 'empty Symbol not equals to itself'; |
| 89 } | 88 } |
| 90 } | 89 } |
| OLD | NEW |