Improve type_literal_test
- Fix expectations for dart2js generic function types - Split out Type canonicalization tests - Do some partial checking for dart2js minification Change-Id: Ifb6e38c1138311baf1a9852286e208c59aaa03fa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107686 Reviewed-by: Leaf Petersen <leafp@google.com> Commit-Queue: Stephen Adams <sra@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
a108bef7fb
commit
0f20911022
@@ -201,7 +201,7 @@ tearoff_dynamic_test: RuntimeError
|
||||
truncdiv_test: RuntimeError # non JS number semantics - Issue 15246
|
||||
type_constants_test/none: RuntimeError # Issue 35052
|
||||
type_error_test: RuntimeError
|
||||
type_literal_test: RuntimeError
|
||||
type_literal_canonicalization_test: RuntimeError
|
||||
type_promotion_more_specific_test/04: CompileTimeError
|
||||
vm/*: SkipByDesign # Tests for the VM.
|
||||
|
||||
@@ -498,7 +498,7 @@ symbol_literal_test/01: MissingCompileTimeError
|
||||
tearoff_dynamic_test: RuntimeError
|
||||
truncdiv_test: RuntimeError # non JS number semantics - Issue 15246
|
||||
type_check_const_function_typedef2_test: MissingCompileTimeError
|
||||
type_literal_test: RuntimeError
|
||||
type_literal_canonicalization_test: RuntimeError
|
||||
type_parameter_test/06: Crash # Internal Error: Unexpected type variable in static context.
|
||||
type_parameter_test/09: Crash # Internal Error: Unexpected type variable in static context.
|
||||
type_variable_scope_test/03: Crash # Internal Error: Unexpected type variable in static context.
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// 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";
|
||||
|
||||
class Foo {}
|
||||
|
||||
class Box<T> {
|
||||
Type get typeArg => T;
|
||||
}
|
||||
|
||||
/// A typedef that defines a non-generic function type.
|
||||
typedef int Func1(bool b);
|
||||
|
||||
/// Semantically identical to [Func], but using the Dart 2 syntax.
|
||||
typedef Func2 = int Function(bool);
|
||||
|
||||
main() {
|
||||
// Literals are canonicalized.
|
||||
Expect.identical(Foo, Foo);
|
||||
Expect.identical(Box, Box);
|
||||
Expect.identical(new Box<Foo>().typeArg, new Box<Foo>().typeArg);
|
||||
Expect.identical(Func1, Func1);
|
||||
Expect.identical(Func2, Func2);
|
||||
}
|
||||
@@ -69,18 +69,16 @@ main() {
|
||||
["GenericTypedef2", "GenericTypedef2<dynamic>", "(dynamic) => int"]);
|
||||
testType(new Box<GenericTypedef<int>>().typeArg,
|
||||
["GenericTypedef<int>", "(int) => int"]);
|
||||
testType(GenericFunc, ["GenericFunc", "<T>(T) => int"]);
|
||||
testType(GenericFunc, ["GenericFunc", "<T>(T) => int", "<T1>(T1) => int"]);
|
||||
testType(GenericTypedefAndFunc, [
|
||||
"GenericTypedefAndFunc",
|
||||
"GenericTypedefAndFunc<dynamic>",
|
||||
"<T>(T) => dynamic"
|
||||
"<T>(T) => dynamic",
|
||||
"<T1>(T1) => dynamic",
|
||||
]);
|
||||
|
||||
// Literals are canonicalized.
|
||||
Expect.identical(Foo, Foo);
|
||||
Expect.identical(Box, Box);
|
||||
Expect.identical(new Box<Foo>().typeArg, new Box<Foo>().typeArg);
|
||||
Expect.identical(Func, Func);
|
||||
// See type_literal_canonicalization_test.dart
|
||||
|
||||
// Static member uses are not type literals.
|
||||
Foo.property = "value";
|
||||
@@ -97,13 +95,19 @@ main() {
|
||||
}
|
||||
|
||||
void testType(Type type, Object expectedToStringValues) {
|
||||
Expect.isTrue(type is Type);
|
||||
String text = type.toString();
|
||||
|
||||
// dart2js minified names should be tagged. We can still test types that don't
|
||||
// contains minified names.
|
||||
if (text.contains('minified:')) return;
|
||||
|
||||
if (expectedToStringValues is List) {
|
||||
var s = type.toString();
|
||||
Expect.isTrue(expectedToStringValues.contains(s),
|
||||
Expect.isTrue(expectedToStringValues.contains(text),
|
||||
'type `$type`.toString() should be one of: $expectedToStringValues.');
|
||||
} else {
|
||||
var string = expectedToStringValues as String;
|
||||
Expect.equals(string, type.toString());
|
||||
Expect.equals(string, text);
|
||||
}
|
||||
Expect.isTrue(type is Type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user