Chromium Code Reviews| 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:uri'); | 5 #import('dart:uri'); |
| 6 #import('parser_helper.dart'); | 6 #import('parser_helper.dart'); |
| 7 #import("../../../lib/compiler/compiler.dart"); | 7 #import("../../../lib/compiler/compiler.dart"); |
| 8 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 8 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| 9 | 9 |
| 10 testUnparse(String statement) { | 10 testUnparse(String statement) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 56 } |
| 57 compile( | 57 compile( |
| 58 scriptUri, | 58 scriptUri, |
| 59 fileUri('libraryRoot'), | 59 fileUri('libraryRoot'), |
| 60 fileUri('packageRoot'), | 60 fileUri('packageRoot'), |
| 61 provider, | 61 provider, |
| 62 handler, | 62 handler, |
| 63 const ['--output-type=dart', '--unparse-validation']).then(continuation); | 63 const ['--output-type=dart', '--unparse-validation']).then(continuation); |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | |
| 67 * Library name is assumed to be 'mylib' in 'mylib.dart' file. | |
| 68 */ | |
| 69 testDart2DartWithLibrary(String srcMain, String srcLibrary, [void continuation(S tring s)]) { | |
| 70 fileUri(path) => new Uri(scheme: 'file', path: path); | |
|
Anton Muhin
2012/07/23 11:23:10
looks like a lot of code duplication w/ testDart2D
Roman
2012/07/23 15:34:15
Done.
| |
| 71 | |
| 72 final scriptUri = fileUri('script.dart'); | |
| 73 final libUri = fileUri('mylib.dart'); | |
| 74 | |
| 75 provider(uri) { | |
| 76 if (uri == scriptUri) return new Future.immediate(srcMain); | |
| 77 if (uri.toString() == libUri.toString()) return new Future.immediate(srcLibr ary); | |
| 78 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); | |
| 79 return new Future.immediate(''); | |
| 80 } | |
| 81 | |
| 82 handler(uri, begin, end, message, kind) { | |
| 83 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { | |
| 84 Expect.fail('$uri: $begin-$end: $message [$kind]'); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 compile( | |
| 89 scriptUri, | |
| 90 fileUri('libraryRoot'), | |
| 91 fileUri('packageRoot'), | |
| 92 provider, | |
| 93 handler, | |
| 94 const ['--output-type=dart', '--unparse-validation']).then(continuation); | |
| 95 } | |
| 96 | |
| 66 testGenericTypes() { | 97 testGenericTypes() { |
| 67 testUnparse('var x=new List<List<int>>();'); | 98 testUnparse('var x=new List<List<int>>();'); |
| 68 testUnparse('var x=new List<List<List<int>>>();'); | 99 testUnparse('var x=new List<List<List<int>>>();'); |
| 69 testUnparse('var x=new List<List<List<List<int>>>>();'); | 100 testUnparse('var x=new List<List<List<List<int>>>>();'); |
| 70 testUnparse('var x=new List<List<List<List<List<int>>>>>();'); | 101 testUnparse('var x=new List<List<List<List<List<int>>>>>();'); |
| 71 } | 102 } |
| 72 | 103 |
| 73 testForLoop() { | 104 testForLoop() { |
| 74 testUnparse('for(;i<100;i++){}'); | 105 testUnparse('for(;i<100;i++){}'); |
| 75 testUnparse('for(i=0;i<100;i++){}'); | 106 testUnparse('for(i=0;i<100;i++){}'); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 testDart2Dart('main(){new A.fromFoo(5);}' | 218 testDart2Dart('main(){new A.fromFoo(5);}' |
| 188 'class A{A(this.f);A.fromFoo(foo):this("f");final String f;}'); | 219 'class A{A(this.f);A.fromFoo(foo):this("f");final String f;}'); |
| 189 // Now even more complicated, with interface and default factory. | 220 // Now even more complicated, with interface and default factory. |
| 190 testDart2Dart('main(){new A.fromFoo(5); new I.fromFoo();}' | 221 testDart2Dart('main(){new A.fromFoo(5); new I.fromFoo();}' |
| 191 'class IFactory{factory I.fromFoo()=> new A(5);}' | 222 'class IFactory{factory I.fromFoo()=> new A(5);}' |
| 192 'interface I default IFactory{I.fromFoo();}' | 223 'interface I default IFactory{I.fromFoo();}' |
| 193 'class A implements I{A(this.f);A.fromFoo(foo):this("f");' | 224 'class A implements I{A(this.f);A.fromFoo(foo):this("f");' |
| 194 'final String f;}'); | 225 'final String f;}'); |
| 195 } | 226 } |
| 196 | 227 |
| 228 testConflictLibraryClassRename() { | |
| 229 var librarySrc = ''' | |
| 230 #library('mylib'); | |
| 231 | |
| 232 topfoo() {} | |
| 233 | |
| 234 class A { | |
| 235 foo(){} | |
| 236 } | |
| 237 '''; | |
| 238 var mainSrc = ''' | |
| 239 #import('mylib.dart', prefix: 'mylib'); | |
| 240 | |
| 241 | |
| 242 topfoo() {var x = 5;} | |
| 243 | |
| 244 class A{ | |
| 245 num foo() {} | |
| 246 A.fromFoo() {} | |
| 247 mylib.A myliba; | |
| 248 List<A> mylist; | |
| 249 } | |
| 250 | |
| 251 mylib.A getA() { | |
|
Anton Muhin
2012/07/23 11:23:10
nit: => syntax, please
Roman
2012/07/23 15:34:15
Done.
| |
| 252 return null; | |
| 253 } | |
| 254 | |
| 255 main() { | |
| 256 var a = new mylib.A(); | |
| 257 a.foo(); | |
| 258 var b = new A.fromFoo(); | |
| 259 b.foo(); | |
| 260 var GREATVAR = b.myliba; | |
| 261 b.mylist; | |
| 262 a = getA(); | |
| 263 topfoo(); | |
| 264 mylib.topfoo(); | |
| 265 } | |
| 266 '''; | |
| 267 var expectedResult = 'topfoo(){}_topfoo(){var x=5;}A getA(){return null;}' | |
| 268 'main(){var a=new A(); a.foo(); var b=new _A.fromFoo(); b.foo(); ' | |
| 269 'var GREATVAR=b.myliba; b.mylist; a=getA(); _topfoo(); topfoo();}' | |
| 270 'class _A{_A.fromFoo(){}List<List> mylist;num foo(){}A myliba;}' | |
| 271 'class A{foo(){}}'; | |
| 272 testDart2DartWithLibrary(mainSrc, librarySrc, | |
| 273 (String result) { Expect.equals(expectedResult, result); }); | |
| 274 } | |
| 275 | |
| 197 main() { | 276 main() { |
| 198 testGenericTypes(); | 277 testGenericTypes(); |
| 199 testForLoop(); | 278 testForLoop(); |
| 200 testEmptyList(); | 279 testEmptyList(); |
| 201 testClosure(); | 280 testClosure(); |
| 202 testIndexedOperatorDecl(); | 281 testIndexedOperatorDecl(); |
| 203 testNativeMethods(); | 282 testNativeMethods(); |
| 204 testPrefixIncrements(); | 283 testPrefixIncrements(); |
| 205 testConstModifier(); | 284 testConstModifier(); |
| 206 testSimpleFileUnparse(); | 285 testSimpleFileUnparse(); |
| 207 testSimpleObjectInstantiation(); | 286 testSimpleObjectInstantiation(); |
| 208 testSimpleTopLevelClass(); | 287 testSimpleTopLevelClass(); |
| 209 testClassWithSynthesizedConstructor(); | 288 testClassWithSynthesizedConstructor(); |
| 210 testClassWithMethod(); | 289 testClassWithMethod(); |
| 211 testVariableDefinitions(); | 290 testVariableDefinitions(); |
| 212 testGetSet(); | 291 testGetSet(); |
| 213 testFactoryConstructor(); | 292 testFactoryConstructor(); |
| 214 testTopLevelField(); | 293 testTopLevelField(); |
| 294 testConflictLibraryClassRename(); | |
| 215 } | 295 } |
| OLD | NEW |