Chromium Code Reviews| Index: tests/compiler/dart2js/expect_annotations_test.dart |
| diff --git a/tests/compiler/dart2js/expect_annotations_test.dart b/tests/compiler/dart2js/expect_annotations_test.dart |
| index ed8889ae13d7f74e6648f88f4fdce57a9097d94e..1c03d8b4426c0588893941e03846c3f982d2211c 100644 |
| --- a/tests/compiler/dart2js/expect_annotations_test.dart |
| +++ b/tests/compiler/dart2js/expect_annotations_test.dart |
| @@ -8,6 +8,8 @@ import 'package:async_helper/async_helper.dart'; |
| import 'package:compiler/src/dart2jslib.dart'; |
| import 'package:compiler/src/elements/elements.dart'; |
| import 'package:compiler/src/js_backend/js_backend.dart'; |
| +import 'package:compiler/src/types/types.dart'; |
| +import 'type_mask_test_helper.dart'; |
| import 'memory_compiler.dart'; |
| const Map MEMORY_SOURCE_FILES = const { |
| @@ -28,12 +30,19 @@ int methodNoInlining(String arg) => arg.length; |
| @NoInlining() @TrustTypeAnnotations() |
| int methodNoInliningTrustTypeAnnotations(String arg) => arg.length; |
| +@AssumeDynamic() @TrustTypeAnnotations() |
| +int methodAssumeDynamicTrustTypeAnnotations(String arg) => arg.length; |
| + |
| + |
| void main(List<String> args) { |
| print(method(args[0])); |
| print(methodAssumeDynamic('foo')); |
| - print(methodTrustTypeAnnotations(null)); |
| + print(methodTrustTypeAnnotations(42)); |
| + print(methodTrustTypeAnnotations("fourtyTwo")); |
| print(methodNoInlining('bar')); |
| - print(methodNoInliningTrustTypeAnnotations(null)); |
| + print(methodNoInliningTrustTypeAnnotations(42)); |
| + print(methodNoInliningTrustTypeAnnotations("fourtyTwo")); |
| + print(methodAssumeDynamicTrustTypeAnnotations(null)); |
| } |
| """ |
| }; |
| @@ -50,9 +59,19 @@ main() { |
| Expect.isNotNull(backend.annotations.expectAssumeDynamicClass, |
| 'AssumeDynamicClass is unresolved.'); |
| + void testTypeMatch(FunctionElement function, TypeMask expectedType, |
| + TypesInferrer inferrer) { |
| + for (ParameterElement parameter in function.parameters) { |
| + TypeMask type = inferrer.getTypeOfElement(parameter); |
| + print("$parameter $type"); |
|
Johnni Winther
2015/02/06 10:49:39
Move this to the [reason] (third) argument of Expe
floitsch
2015/02/06 10:54:56
debug print.
herhut
2015/02/06 11:37:53
Acknowledged.
herhut
2015/02/06 11:37:53
Done.
|
| + Expect.equals(expectedType, simplify(type, compiler)); |
| + } |
| + } |
| + |
| void test(String name, |
| {bool expectNoInlining: false, |
| bool expectTrustTypeAnnotations: false, |
| + TypeMask expectedType: null, |
| bool expectAssumeDynamic: false}) { |
| Element method = compiler.mainApp.find(name); |
| Expect.isNotNull(method); |
| @@ -68,14 +87,32 @@ main() { |
| expectAssumeDynamic, |
| backend.annotations.assumeDynamic(method), |
| "Unexpected annotation of @AssumeDynamic on '$method'."); |
| + TypesInferrer inferrer = compiler.typesTask.typesInferrer; |
| + if (expectTrustTypeAnnotations && expectedType != null) { |
| + testTypeMatch(method, expectedType, inferrer); |
| + } else if (expectAssumeDynamic) { |
| + testTypeMatch(method, compiler.typesTask.dynamicType, inferrer); |
| + } |
| } |
| + TypeMask stringType = compiler.typesTask.stringType; |
|
Johnni Winther
2015/02/06 10:49:39
Maybe [jsStringType]
herhut
2015/02/06 11:37:53
Done.
|
| + TypeMask genericStringType = new TypeMask.subtype(compiler.stringClass, |
|
Johnni Winther
2015/02/06 10:49:39
and [coreStringType] ?
herhut
2015/02/06 11:37:52
Done.
|
| + compiler.world); |
| + |
| test('method'); |
| test('methodAssumeDynamic', expectAssumeDynamic: true); |
| - test('methodTrustTypeAnnotations', expectTrustTypeAnnotations: true); |
| + test('methodTrustTypeAnnotations', |
| + expectTrustTypeAnnotations: true, |
| + expectedType: stringType); |
| test('methodNoInlining', expectNoInlining: true); |
| test('methodNoInliningTrustTypeAnnotations', |
| expectNoInlining: true, |
| - expectTrustTypeAnnotations: true); |
| + expectTrustTypeAnnotations: true, |
| + expectedType: stringType); |
| + test('methodAssumeDynamicTrustTypeAnnotations', |
| + expectAssumeDynamic: true, |
| + expectTrustTypeAnnotations: true, |
| + expectedType: genericStringType); |
| + |
| })); |
| } |