OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
| 5 import 'dart:async'; |
5 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import "package:async_helper/async_helper.dart"; |
6 import 'compiler_helper.dart'; | 8 import 'compiler_helper.dart'; |
7 import 'parser_helper.dart'; | 9 import 'parser_helper.dart'; |
8 | 10 |
9 void compileAndFind(String code, String name, | 11 Future compileAndFind(String code, String name, |
10 check(compiler, element)) { | 12 check(compiler, element)) { |
11 Uri uri = new Uri(scheme: 'source'); | 13 Uri uri = new Uri(scheme: 'source'); |
12 var compiler = compilerFor(code, uri); | 14 var compiler = compilerFor(code, uri); |
13 compiler.runCompiler(uri); | 15 return compiler.runCompiler(uri).then((_) { |
14 var element = findElement(compiler, name); | 16 var element = findElement(compiler, name); |
15 return check(compiler, element); | 17 check(compiler, element); |
| 18 }); |
16 } | 19 } |
17 | 20 |
18 void checkPrintType(String expression, checkType(compiler, type)) { | 21 void checkPrintType(String expression, checkType(compiler, type)) { |
19 compileAndFind( | 22 asyncTest(() => compileAndFind( |
20 'main() { print($expression); }', | 23 'main() { print($expression); }', |
21 'print', | 24 'print', |
22 (compiler, printElement) { | 25 (compiler, printElement) { |
23 var parameter = | 26 var parameter = |
24 printElement.computeSignature(compiler).requiredParameters.head; | 27 printElement.computeSignature(compiler).requiredParameters.head; |
25 var type = compiler.typesTask.getGuaranteedTypeOfElement(parameter); | 28 var type = compiler.typesTask.getGuaranteedTypeOfElement(parameter); |
26 checkType(compiler, type); | 29 checkType(compiler, type); |
27 }); | 30 })); |
28 | 31 |
29 compileAndFind( | 32 asyncTest(() => compileAndFind( |
30 'main() { var x = print; print($expression); }', | 33 'main() { var x = print; print($expression); }', |
31 'print', | 34 'print', |
32 (compiler, printElement) { | 35 (compiler, printElement) { |
33 var parameter = | 36 var parameter = |
34 printElement.computeSignature(compiler).requiredParameters.head; | 37 printElement.computeSignature(compiler).requiredParameters.head; |
35 var type = compiler.typesTask.getGuaranteedTypeOfElement(parameter); | 38 var type = compiler.typesTask.getGuaranteedTypeOfElement(parameter); |
36 var inferrer = compiler.typesTask.typesInferrer; | 39 var inferrer = compiler.typesTask.typesInferrer; |
37 Expect.identical(compiler.typesTask.dynamicType, | 40 Expect.identical(compiler.typesTask.dynamicType, |
38 type.simplify(compiler)); | 41 type.simplify(compiler)); |
39 }); | 42 })); |
40 | 43 |
41 compileAndFind( | 44 asyncTest(() => compileAndFind( |
42 'main() { print($expression); print($expression); }', | 45 'main() { print($expression); print($expression); }', |
43 'print', | 46 'print', |
44 (compiler, printElement) { | 47 (compiler, printElement) { |
45 var parameter = | 48 var parameter = |
46 printElement.computeSignature(compiler).requiredParameters.head; | 49 printElement.computeSignature(compiler).requiredParameters.head; |
47 var type = compiler.typesTask.getGuaranteedTypeOfElement(parameter); | 50 var type = compiler.typesTask.getGuaranteedTypeOfElement(parameter); |
48 checkType(compiler, type); | 51 checkType(compiler, type); |
49 }); | 52 })); |
50 } | 53 } |
51 | 54 |
52 void testBasicTypes() { | 55 void testBasicTypes() { |
53 checkPrintType('true', (compiler, type) { | 56 checkPrintType('true', (compiler, type) { |
54 var inferrer = compiler.typesTask.typesInferrer; | 57 var inferrer = compiler.typesTask.typesInferrer; |
55 Expect.identical(compiler.typesTask.boolType, type); | 58 Expect.identical(compiler.typesTask.boolType, type); |
56 }); | 59 }); |
57 checkPrintType('1.0', (compiler, type) { | 60 checkPrintType('1.0', (compiler, type) { |
58 var inferrer = compiler.typesTask.typesInferrer; | 61 var inferrer = compiler.typesTask.typesInferrer; |
59 Expect.identical(compiler.typesTask.doubleType, type); | 62 Expect.identical(compiler.typesTask.doubleType, type); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 Expect.identical( | 102 Expect.identical( |
100 typesTask.nullType, | 103 typesTask.nullType, |
101 typesTask.getGuaranteedTypeOfElement(thirdParameter)); | 104 typesTask.getGuaranteedTypeOfElement(thirdParameter)); |
102 }); | 105 }); |
103 } | 106 } |
104 | 107 |
105 void main() { | 108 void main() { |
106 testBasicTypes(); | 109 testBasicTypes(); |
107 testOptionalParameters(); | 110 testOptionalParameters(); |
108 } | 111 } |
OLD | NEW |