OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
6 import "package:async_helper/async_helper.dart"; | 6 import "package:async_helper/async_helper.dart"; |
7 import 'package:compiler/src/types/types.dart' | 7 import 'package:compiler/src/types/types.dart' show ContainerTypeMask, TypeMask; |
8 show ContainerTypeMask, TypeMask; | |
9 | 8 |
10 import 'compiler_helper.dart'; | 9 import 'compiler_helper.dart'; |
11 | 10 |
12 | |
13 String generateTest(String key, String value, bool initial) { | 11 String generateTest(String key, String value, bool initial) { |
14 return """ | 12 return """ |
15 double aDouble = 42.5; | 13 double aDouble = 42.5; |
16 List aList = [42]; | 14 List aList = [42]; |
17 | 15 |
18 consume(x) => x; | 16 consume(x) => x; |
19 | 17 |
20 main() { | 18 main() { |
21 """ + (initial ? | 19 """ + |
| 20 (initial |
| 21 ? """ |
| 22 var theMap = {'a': 2.2, 'b': 3.3, 'c': 4.4, $key: $value}; |
22 """ | 23 """ |
23 var theMap = {'a': 2.2, 'b': 3.3, 'c': 4.4, $key: $value}; | 24 : """ |
24 """ : | |
25 """ | |
26 var theMap = {'a': 2.2, 'b': 3.3, 'c': 4.4}; | 25 var theMap = {'a': 2.2, 'b': 3.3, 'c': 4.4}; |
27 theMap[$key] = $value; | 26 theMap[$key] = $value; |
28 """) + | 27 """) + |
29 """ | 28 """ |
30 for (var key in theMap.keys) { | 29 for (var key in theMap.keys) { |
31 aDouble = theMap[key]; | 30 aDouble = theMap[key]; |
32 } | 31 } |
33 // We have to reference it somewhere, so that it always gets resolved. | 32 // We have to reference it somewhere, so that it always gets resolved. |
34 consume(aList); | 33 consume(aList); |
35 } | 34 } |
36 """; | 35 """; |
37 } | 36 } |
38 | 37 |
39 void main() { | 38 void main() { |
40 // Test using keys without the list floating in | 39 // Test using keys without the list floating in |
41 doTest(); | 40 doTest(); |
42 // Test using keys with the list floating in as key | 41 // Test using keys with the list floating in as key |
43 doTest(key: "aList", bail: true); | 42 doTest(key: "aList", bail: true); |
44 // Test using keys with the list floating in as value | 43 // Test using keys with the list floating in as value |
45 doTest(value: "aList"); | 44 doTest(value: "aList"); |
46 // And the above where we add the list as part of the map literal. | 45 // And the above where we add the list as part of the map literal. |
47 doTest(initial: true); | 46 doTest(initial: true); |
48 doTest(key: "aList", bail: true, initial: true); | 47 doTest(key: "aList", bail: true, initial: true); |
49 doTest(value: "aList", initial: true); | 48 doTest(value: "aList", initial: true); |
50 } | 49 } |
51 | 50 |
52 void doTest({String key: "'d'", String value: "5.5", bool bail: false, | 51 void doTest( |
53 bool initial: false}) { | 52 {String key: "'d'", |
| 53 String value: "5.5", |
| 54 bool bail: false, |
| 55 bool initial: false}) { |
54 Uri uri = new Uri(scheme: 'source'); | 56 Uri uri = new Uri(scheme: 'source'); |
55 var compiler = compilerFor(generateTest(key, value, initial), uri, | 57 var compiler = compilerFor(generateTest(key, value, initial), uri, |
56 expectedErrors: 0, expectedWarnings: 0); | 58 expectedErrors: 0, expectedWarnings: 0); |
57 asyncTest(() => compiler.run(uri).then((_) { | 59 asyncTest(() => compiler.run(uri).then((_) { |
58 var commonMasks = compiler.commonMasks; | 60 var commonMasks = compiler.commonMasks; |
59 var typesInferrer = compiler.globalInference.typesInferrer; | 61 var typesInferrer = compiler.globalInference.typesInferrer; |
60 var aDoubleType = | 62 var aDoubleType = |
61 typesInferrer.getTypeOfElement(findElement(compiler, 'aDouble')); | 63 typesInferrer.getTypeOfElement(findElement(compiler, 'aDouble')); |
62 var aListType = | 64 var aListType = |
63 typesInferrer.getTypeOfElement(findElement(compiler, 'aList')); | 65 typesInferrer.getTypeOfElement(findElement(compiler, 'aList')); |
64 | 66 |
65 Expect.equals(aDoubleType, commonMasks.doubleType); | 67 Expect.equals(aDoubleType, commonMasks.doubleType); |
66 Expect.isTrue(aListType is ContainerTypeMask); | 68 Expect.isTrue(aListType is ContainerTypeMask); |
67 ContainerTypeMask container = aListType; | 69 ContainerTypeMask container = aListType; |
68 TypeMask elementType = container.elementType; | 70 TypeMask elementType = container.elementType; |
69 if (bail) { | 71 if (bail) { |
70 Expect.equals(elementType, commonMasks.dynamicType); | 72 Expect.equals(elementType, commonMasks.dynamicType); |
71 } else { | 73 } else { |
72 Expect.equals(elementType, commonMasks.uint31Type); | 74 Expect.equals(elementType, commonMasks.uint31Type); |
73 } | 75 } |
74 })); | 76 })); |
75 } | 77 } |
OLD | NEW |