Files
sdk/tests/corelib/symbol_test.dart
Martin Kustermann 76548a7ab9 [tests] Rewrite various tests to not depend on <obj>.runtimeType.toString()
In dart2wasm applications are by default deployed in `-O2` mode which
implies `--minify`.

Given this is the default configuration for customers, we want good
testing of this configuration and not large numbers of approved failures.

=> Rewrite various tests to not depend on `<obj>.runtimeType.toString()`

Change-Id: I1108b28c63b8bec6ad94df0d7b878b3339776df9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436281
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-06-24 01:16:24 -07:00

67 lines
1.7 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.
// Formatting can break multitests, so don't format them.
// dart format off
// Basic test of Symbol class.
import 'package:expect/variations.dart';
main() {
var constFiskSymbol;
print(constFiskSymbol = 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'), constFiskSymbol)) {
throw 'Symbol constant is not canonicalized';
}
if (const Symbol('fisk') != constFiskSymbol) {
throw 'Symbol constant is not equal to itself';
}
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';
}
constFiskSymbol.hashCode as int;
new Symbol('fisk').hashCode as int;
if (!minifiedSymbols) {
if (const Symbol('fisk') != new Symbol('fisk')) {
throw 'Symbol constant is not equal to its non-const equivalent';
}
if (new Symbol('fisk').hashCode != constFiskSymbol.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';
}
}
}