Files
sdk/tests/language/patterns/non_interface_object_pattern_test.dart
T
Sergey G. Grekhov 82b78916fd [tests] Remove obsolete Dart 3.0 experiments from language tests
Change-Id: If31c487e3ebe2c1ae847aff7c8994580b8b6f2f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309660
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-06-15 08:26:27 +00:00

69 lines
1.8 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 'dart:async';
import 'package:expect/expect.dart';
typedef FunctionType = void Function();
typedef GenericFunctionType<T> = T Function(T);
test<T>(o) {
if (o case FunctionType(:var hashCode)) {
print(hashCode);
return 1;
}
if (o case GenericFunctionType<int>(:var hashCode)) {
print(hashCode);
return 2;
}
if (o case GenericFunctionType<String>(:var hashCode)) {
print(hashCode);
return 3;
}
if (o case GenericFunctionType<T>(:var hashCode)) {
print(hashCode);
return 4;
}
if (o case GenericFunctionType(:var hashCode)) {
print(hashCode);
return 5;
}
if (o case Null(:var hashCode)) {
print(hashCode);
return 6;
}
if (o case FutureOr<int>(:var hashCode)) {
print(hashCode);
return 7;
}
if (o case dynamic(: var hashCode)) {
print(hashCode);
return 0;
}
return -1;
}
void function() {}
int intFunction(int i) => i;
String stringFunction(String s) => s;
bool boolFunction(bool b) => b;
dynamic dynamicFunction(dynamic d) => d;
void multiArgFunction(int i, String s) {}
main() {
Expect.equals(1, test(function));
Expect.equals(2, test(intFunction));
Expect.equals(3, test(stringFunction));
Expect.equals(4, test<bool>(boolFunction));
Expect.equals(0, test(boolFunction));
Expect.equals(0, test<num>(boolFunction));
Expect.equals(4, test(dynamicFunction));
Expect.equals(4, test<dynamic>(dynamicFunction));
Expect.equals(5, test<bool>(dynamicFunction));
Expect.equals(0, test(multiArgFunction));
Expect.equals(6, test(null));
Expect.equals(7, test(0));
Expect.equals(7, test(new Future<int>.value(0)));
}