mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:01:42 +00:00
166d474257
Cf. https://github.com/dart-lang/sdk/issues/46207, the semantics of the platform class `Symbol` was changed such that all string argumnts are accepted (previously, only some strings were accepted). Change-Id: I1d2b093e4fdbb5dabf17b7a53c70e9787a7a76a4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205480 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
59 lines
1.5 KiB
Dart
59 lines
1.5 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.
|
|
|
|
// Basic test of Symbol class.
|
|
|
|
main() {
|
|
var x;
|
|
print(x = const Symbol('fisk'));
|
|
try {
|
|
print(const Symbol(0)); //# 01: compile-time error
|
|
} on NoSuchMethodError {
|
|
print('Caught NoSuchMethodError');
|
|
} on TypeError {
|
|
print('Caught TypeError');
|
|
}
|
|
|
|
print(const Symbol('0'));
|
|
print(const Symbol('_'));
|
|
print(new Symbol('0'));
|
|
print(new Symbol('_'));
|
|
|
|
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';
|
|
}
|
|
|
|
if (new Symbol('fisk') == new Symbol('hest')) {
|
|
throw 'unrelated Symbols are equal';
|
|
}
|
|
|
|
if (new Symbol('fisk') == new Object()) {
|
|
throw 'unrelated objects are equal';
|
|
}
|
|
|
|
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";
|
|
}
|
|
|
|
if (new Symbol('') != Symbol.empty) {
|
|
throw 'empty Symbol not equals to itself';
|
|
}
|
|
}
|