Files
sdk/pkg/kernel/test/flatten_test.dart
T
Johnni Winther 34f5c9d0b4 [cfe] Implement new async return rules
Closes #41800
Closes #41900
Closes #42134
Closes #42282
Closes #42236
Closes #42169

Change-Id: Ia994bc07fba4e2342fcb59d44fc77608198a328b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152150
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-07-06 07:04:40 +00:00

93 lines
3.4 KiB
Dart

// Copyright (c) 2019, 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" show Expect;
import 'package:kernel/ast.dart' hide MapEntry;
import 'package:kernel/class_hierarchy.dart';
import 'package:kernel/testing/type_parser_environment.dart';
import 'package:kernel/type_environment.dart';
const Set<Test> data = {
const Test('Null', 'Null'),
const Test('Never?', 'Never?'),
const Test('void', 'void'),
const Test('dynamic', 'dynamic'),
const Test('bool', 'bool'),
const Test('bool?', 'bool?'),
const Test('bool*', 'bool*'),
const Test('List<bool>', 'List<bool>'),
const Test('List<bool>?', 'List<bool>?'),
const Test('List<bool>*', 'List<bool>*'),
const Test('FutureOr<bool>', 'bool'),
const Test('FutureOr<bool>?', 'bool?'),
const Test('FutureOr<bool>*', 'bool*'),
const Test('FutureOr<bool?>*', 'bool?'),
const Test('FutureOr<bool?>?', 'bool?'),
const Test('FutureOr<bool*>?', 'bool?'),
const Test('FutureOr<Null>', 'Null'),
const Test('FutureOr<Null>?', 'Null'),
const Test('FutureOr<Null>*', 'Null'),
const Test('Future<bool>', 'bool'),
const Test('Future<bool>?', 'bool?'),
const Test('Future<bool>*', 'bool*'),
const Test('Future<bool?>', 'bool?'),
const Test('Future<bool*>', 'bool*'),
const Test('() ->* bool*', '() ->* bool*'),
const Test('() -> bool*', '() -> bool*'),
const Test('() ->? bool*', '() ->? bool*'),
const Test('() ->* bool', '() ->* bool'),
const Test('() ->? bool', '() ->? bool'),
const Test('() -> bool', '() -> bool'),
const Test('T', 'T', 'T'),
const Test('T?', 'T?', 'T'),
const Test('T*', 'T*', 'T'),
const Test('T', 'T', 'T extends bool'),
const Test('T?', 'T?', 'T extends bool'),
const Test('T*', 'T*', 'T extends bool'),
const Test('T', 'T', 'T extends FutureOr<bool>'),
const Test('T?', 'T?', 'T extends FutureOr<bool>'),
const Test('T*', 'T*', 'T extends FutureOr<bool>'),
const Test('T', 'bool', 'T extends Future<bool>'),
const Test('T?', 'bool?', 'T extends Future<bool>'),
const Test('T*', 'bool*', 'T extends Future<bool>'),
const Test('T & bool', 'T & bool', 'T'),
const Test('T & bool?', 'T & bool?', 'T'),
const Test('T & bool*', 'T & bool*', 'T'),
};
class Test {
final String input;
final String output;
final String typeParameters;
const Test(this.input, this.output, [this.typeParameters]);
}
main() {
Env env = new Env('');
ClassHierarchy classHierarchy =
new ClassHierarchy(env.component, env.coreTypes);
TypeEnvironment typeEnvironment =
new TypeEnvironment(env.coreTypes, classHierarchy);
data.forEach((Test test) {
env.withTypeParameters(test.typeParameters, () {
String input = test.input;
String output = test.output;
DartType inputType = env.parseType(input);
DartType expectedOutputType = env.parseType(output);
DartType actualOutputType = typeEnvironment.flatten(inputType);
print('flatten($inputType) '
'${test.typeParameters != null ? 'with ${test.typeParameters} ' : ''}'
'= $actualOutputType, expected $expectedOutputType');
Expect.equals(
expectedOutputType,
actualOutputType,
"Unexpected flatten of $inputType ('$input'):\n"
"Expected: ${expectedOutputType} ('$output')\n"
"Actual: ${actualOutputType}");
});
});
}