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 'dart:async'; |
6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
8 import 'compiler_helper.dart'; | 8 import 'compiler_helper.dart'; |
9 | 9 |
10 Future compileAndFind(String code, String name, check(compiler, element)) { | 10 Future compileAndFind(String code, String name, check(compiler, element)) { |
(...skipping 26 matching lines...) Expand all Loading... |
37 (compiler, printElement) { | 37 (compiler, printElement) { |
38 var parameter = printElement.functionSignature.requiredParameters.first; | 38 var parameter = printElement.functionSignature.requiredParameters.first; |
39 var type = compiler.globalInference.results.typeOf(parameter); | 39 var type = compiler.globalInference.results.typeOf(parameter); |
40 checkType(compiler, type); | 40 checkType(compiler, type); |
41 })); | 41 })); |
42 } | 42 } |
43 | 43 |
44 void testBasicTypes() { | 44 void testBasicTypes() { |
45 checkPrintType('true', (compiler, type) { | 45 checkPrintType('true', (compiler, type) { |
46 if (type.isForwarding) type = type.forwardTo; | 46 if (type.isForwarding) type = type.forwardTo; |
47 Expect.identical(compiler.commonMasks.boolType, type); | 47 Expect.identical(compiler.closedWorld.commonMasks.boolType, type); |
48 }); | 48 }); |
49 checkPrintType('1.5', (compiler, type) { | 49 checkPrintType('1.5', (compiler, type) { |
50 Expect.identical(compiler.commonMasks.doubleType, type); | 50 Expect.identical(compiler.closedWorld.commonMasks.doubleType, type); |
51 }); | 51 }); |
52 checkPrintType('1', (compiler, type) { | 52 checkPrintType('1', (compiler, type) { |
53 Expect.identical(compiler.commonMasks.uint31Type, type); | 53 Expect.identical(compiler.closedWorld.commonMasks.uint31Type, type); |
54 }); | 54 }); |
55 checkPrintType('[]', (compiler, type) { | 55 checkPrintType('[]', (compiler, type) { |
56 if (type.isForwarding) type = type.forwardTo; | 56 if (type.isForwarding) type = type.forwardTo; |
57 Expect.identical(compiler.commonMasks.growableListType, type); | 57 Expect.identical(compiler.closedWorld.commonMasks.growableListType, type); |
58 }); | 58 }); |
59 checkPrintType('null', (compiler, type) { | 59 checkPrintType('null', (compiler, type) { |
60 Expect.identical(compiler.commonMasks.nullType, type); | 60 Expect.identical(compiler.closedWorld.commonMasks.nullType, type); |
61 }); | 61 }); |
62 checkPrintType('"foo"', (compiler, type) { | 62 checkPrintType('"foo"', (compiler, type) { |
63 Expect.isTrue(compiler.commonMasks.stringType | 63 Expect.isTrue(compiler.closedWorld.commonMasks.stringType |
64 .containsOnlyString(compiler.closedWorld)); | 64 .containsOnlyString(compiler.closedWorld)); |
65 }); | 65 }); |
66 } | 66 } |
67 | 67 |
68 void testOptionalParameters() { | 68 void testOptionalParameters() { |
69 compileAndFind('fisk(a, [b, c]) {} main() { fisk(1); }', 'fisk', | 69 compileAndFind('fisk(a, [b, c]) {} main() { fisk(1); }', 'fisk', |
70 (compiler, fiskElement) { | 70 (compiler, fiskElement) { |
71 var firstParameter = fiskElement.functionSignature.requiredParameters[0]; | 71 var firstParameter = fiskElement.functionSignature.requiredParameters[0]; |
72 var secondParameter = fiskElement.functionSignature.optionalParameters[0]; | 72 var secondParameter = fiskElement.functionSignature.optionalParameters[0]; |
73 var thirdParameter = fiskElement.functionSignature.optionalParameters[1]; | 73 var thirdParameter = fiskElement.functionSignature.optionalParameters[1]; |
74 var commonMasks = compiler.commonMasks; | 74 var commonMasks = compiler.closedWorld.commonMasks; |
75 var inference = compiler.globalInference; | 75 var inference = compiler.globalInference; |
76 Expect.identical( | 76 Expect.identical( |
77 commonMasks.uint31Type, inference.results.typeOf(firstParameter)); | 77 commonMasks.uint31Type, inference.results.typeOf(firstParameter)); |
78 Expect.identical( | 78 Expect.identical( |
79 commonMasks.nullType, inference.results.typeOf(secondParameter)); | 79 commonMasks.nullType, inference.results.typeOf(secondParameter)); |
80 Expect.identical( | 80 Expect.identical( |
81 commonMasks.nullType, inference.results.typeOf(thirdParameter)); | 81 commonMasks.nullType, inference.results.typeOf(thirdParameter)); |
82 }); | 82 }); |
83 } | 83 } |
84 | 84 |
85 void main() { | 85 void main() { |
86 testBasicTypes(); | 86 testBasicTypes(); |
87 testOptionalParameters(); | 87 testOptionalParameters(); |
88 } | 88 } |
OLD | NEW |