Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 import 'package:expect/expect.dart'; | |
| 6 import "package:async_helper/async_helper.dart"; | |
| 7 | |
| 8 import 'compiler_helper.dart'; | |
| 9 import 'parser_helper.dart'; | |
| 10 | |
| 11 const String TEST = ''' | |
| 12 testFunctionStatement() { | |
| 13 var res; | |
| 14 closure(a) => res = a; | |
| 15 closure(42); | |
| 16 return res; | |
| 17 } | |
| 18 | |
| 19 testFunctionExpression() { | |
| 20 var res; | |
| 21 var closure = (a) => res = a; | |
| 22 closure(42); | |
| 23 return res; | |
| 24 } | |
| 25 | |
| 26 var staticField; | |
| 27 | |
| 28 testStoredInStatic() { | |
| 29 var res; | |
| 30 closure(a) => res = a; | |
| 31 staticField = closure; | |
| 32 staticField(42); | |
| 33 return res; | |
| 34 } | |
| 35 | |
| 36 class A { | |
| 37 var field; | |
| 38 A(this.field); | |
| 39 } | |
| 40 | |
| 41 testStoredInInstance() { | |
| 42 var res; | |
| 43 closure(a) => res = a; | |
| 44 var a = new A(closure); | |
| 45 a.field(42); | |
| 46 return res; | |
| 47 } | |
| 48 | |
| 49 foo(closure) { | |
| 50 closure(42); | |
| 51 } | |
| 52 | |
| 53 testPassedInParameter() { | |
| 54 var res; | |
| 55 closure(a) => res = a; | |
| 56 foo(closure); | |
| 57 return res; | |
| 58 } | |
| 59 | |
| 60 var topLevel1; | |
| 61 foo2(a) => topLevel1 = a; | |
| 62 testStaticClosure1() { | |
| 63 var a = foo2; | |
| 64 a(42); | |
| 65 return topLevel1; | |
| 66 } | |
| 67 | |
| 68 var topLevel2; | |
| 69 bar(a) => topLevel2 = a; | |
| 70 testStaticClosure2() { | |
| 71 var a = bar; | |
| 72 a(42); | |
| 73 var b = bar; | |
| 74 b(2.5); | |
| 75 return topLevel2; | |
| 76 } | |
| 77 | |
| 78 main() { | |
| 79 testFunctionStatement(); | |
| 80 testFunctionExpression(); | |
| 81 testStoredInStatic(); | |
| 82 testStoredInInstance(); | |
| 83 testPassedInParameter(); | |
| 84 testStaticClosure1(); | |
| 85 testStaticClosure2(); | |
|
kasperl
2013/12/19 13:33:34
Add test for static method on class too?
ngeoffray
2013/12/19 13:39:26
Done.
| |
| 86 } | |
| 87 '''; | |
| 88 | |
| 89 void main() { | |
| 90 Uri uri = new Uri(scheme: 'source'); | |
| 91 var compiler = compilerFor(TEST, uri); | |
| 92 asyncTest(() => compiler.runCompiler(uri).then((_) { | |
| 93 var typesTask = compiler.typesTask; | |
| 94 var typesInferrer = typesTask.typesInferrer; | |
| 95 | |
| 96 checkType(String name, type) { | |
| 97 var element = findElement(compiler, name); | |
| 98 var mask = typesInferrer.getReturnTypeOfElement(element); | |
| 99 Expect.equals(type.nullable(), mask.simplify(compiler), name); | |
| 100 } | |
| 101 | |
| 102 checkType('testFunctionStatement', typesTask.uint31Type); | |
| 103 checkType('testFunctionExpression', typesTask.uint31Type); | |
| 104 checkType('testStoredInInstance', typesTask.uint31Type); | |
| 105 checkType('testStoredInStatic', typesTask.uint31Type); | |
| 106 checkType('testPassedInParameter', typesTask.uint31Type); | |
| 107 checkType('testStaticClosure1', typesTask.uint31Type); | |
| 108 checkType('testStaticClosure2', typesTask.numType); | |
| 109 })); | |
| 110 } | |
| OLD | NEW |