dart-sdk/tests/language/unsorted/core_type_check_test.dart
Robert Nystrom d4154ac6dc Migrate language_2/unsorted to NNBD.
Change-Id: Iad2963c7f9c184b089dc6d15aa4442f58d194bc2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151983
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2020-06-26 18:34:14 +00:00

54 lines
1.5 KiB
Dart

// Copyright (c) 2012, 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";
check(value, expectComparable, expectPattern) {
Expect.equals(expectComparable, value is Comparable);
Expect.equals(expectPattern, value is Pattern);
}
int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1));
class A implements Comparable {
int compareTo(o) => 0;
}
class B {}
class C implements Pattern {
matchAsPrefix(String s, [int start = 0]) => null;
allMatches(String s, [int start = 0]) => throw "uncalled";
}
class D implements Pattern, Comparable {
int compareTo(o) => 0;
matchAsPrefix(String s, [int start = 0]) => null;
allMatches(String s, [int start = 0]) => throw "uncalled";
}
main() {
var things = [
[],
4,
4.2,
'foo',
new Object(),
new A(),
new B(),
new C(),
new D()
];
check(things[inscrutable(0)], false, false); // List
check(things[inscrutable(1)], true, false); // int
check(things[inscrutable(2)], true, false); // num
check(things[inscrutable(3)], true, true); // string
check(things[inscrutable(4)], false, false); // Object
check(things[inscrutable(5)], true, false); // A
check(things[inscrutable(6)], false, false); // B
check(things[inscrutable(7)], false, true); // C
check(things[inscrutable(8)], true, true); // D
}