293cbd1dc9
Now that ddc, dart2js, and dart2wasm are consistent on toString outputs for JS objects, we should test to make sure this behavior doesn't regress. Change-Id: I2b1b4819e5a2425ae813dc944a4dea7b2147d5bc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322365 Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com> Auto-Submit: Srujan Gaddam <srujzs@google.com>
68 lines
2.3 KiB
Dart
68 lines
2.3 KiB
Dart
// Copyright (c) 2023, 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.
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
// Avoid static type optimization by running all tests using this.
|
|
@pragma('dart2js:noInline')
|
|
@pragma('dart2js:assumeDynamic')
|
|
confuse(x) => x;
|
|
|
|
void testHashCode(x) {
|
|
var hashCodeResult = confuse(x.hashCode);
|
|
Expect.type<int>(hashCodeResult);
|
|
Expect.equals(x.hashCode, hashCodeResult);
|
|
}
|
|
|
|
void testRuntimeType(x) {
|
|
var runtimeTypeResult = confuse(x.runtimeType);
|
|
Expect.type<Type>(runtimeTypeResult);
|
|
Expect.equals(x.runtimeType, runtimeTypeResult);
|
|
}
|
|
|
|
void testNoSuchMethod(x) {
|
|
var noSuchMethodResult = Expect.throws(
|
|
() => x.noSuchMethod(Invocation.method(Symbol('testMethod'), null)));
|
|
Expect.type<NoSuchMethodError>(noSuchMethodResult);
|
|
Expect.contains('testMethod', noSuchMethodResult.toString());
|
|
}
|
|
|
|
void testNoSuchMethodTearoff(x) {
|
|
var noSuchMethodTearoff = confuse(x.noSuchMethod);
|
|
Expect.type<dynamic Function(Invocation)>(noSuchMethodTearoff);
|
|
Expect.equals(x.noSuchMethod, noSuchMethodTearoff);
|
|
var noSuchMethodResult = Expect.throws(
|
|
() => noSuchMethodTearoff(Invocation.method(Symbol('testMethod'), null)));
|
|
Expect.type<NoSuchMethodError>(noSuchMethodResult);
|
|
Expect.contains('testMethod', noSuchMethodResult.toString());
|
|
}
|
|
|
|
void testToString(x, String expected) {
|
|
var toStringResult = confuse(x.toString());
|
|
Expect.type<String>(toStringResult);
|
|
Expect.isTrue(toStringResult.isNotEmpty);
|
|
Expect.equals(toStringResult, expected);
|
|
Expect.equals(x.toString(), toStringResult);
|
|
}
|
|
|
|
void testToStringTearoff(x, String expected) {
|
|
var toStringTearoff = confuse(x.toString);
|
|
Expect.type<String Function()>(toStringTearoff);
|
|
Expect.equals(x.toString, toStringTearoff);
|
|
var toStringResult = toStringTearoff();
|
|
Expect.type<String>(toStringResult);
|
|
Expect.isTrue(toStringResult.isNotEmpty);
|
|
Expect.equals(toStringResult, expected);
|
|
Expect.equals(x.toString(), toStringResult);
|
|
}
|
|
|
|
void testEquals(x, other) {
|
|
var y = confuse(other);
|
|
var equalityResult = x == y;
|
|
Expect.type<bool>(equalityResult);
|
|
Expect.isFalse(equalityResult);
|
|
Expect.equals(equalityResult, x == y);
|
|
Expect.isTrue(confuse(x) == x);
|
|
}
|