Files
sdk/tests/lib/js/object_apis_utils.dart
T
Robert Nystrom 2f2bdc3c22 Reformat tests/lib/js and /js_interop_unsafe using 3.8 style.
Change-Id: I182e28a3c4b44dd899e5ea30ac5c5c3ba60fd6cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425333
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2025-04-29 21:21:29 -07:00

70 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);
}