Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: tests/compiler/dart2js/dart_backend_test.dart

Issue 11368150: Updated tests/compiler/* to use new library syntax. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 'mock_compiler.dart'; 7 import 'mock_compiler.dart';
8 import '../../../sdk/lib/_internal/compiler/compiler.dart'; 8 import '../../../sdk/lib/_internal/compiler/compiler.dart';
9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' as l eg; 9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' as l eg;
10 import '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_bac kend.dart'; 10 import '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_bac kend.dart';
11 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t'; 11 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t';
12 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; 12 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart';
13 13
14 const coreLib = r''' 14 const coreLib = r'''
15 #library('corelib'); 15 library corelib;
16 class Object {} 16 class Object {}
17 interface bool {} 17 interface bool {}
18 interface num {} 18 interface num {}
19 interface int extends num {} 19 interface int extends num {}
20 interface double extends num {} 20 interface double extends num {}
21 interface String {} 21 interface String {}
22 interface Function {} 22 interface Function {}
23 interface List {} 23 interface List {}
24 interface Map {} 24 interface Map {}
25 interface Closure {} 25 interface Closure {}
26 interface Dynamic_ {} 26 interface Dynamic_ {}
27 interface Null {} 27 interface Null {}
28 interface TypeError {} 28 interface TypeError {}
29 class Type {} 29 class Type {}
30 class Math { 30 class Math {
31 static double parseDouble(String s) => 1.0; 31 static double parseDouble(String s) => 1.0;
32 } 32 }
33 print(x) {} 33 print(x) {}
34 '''; 34 ''';
35 35
36 const ioLib = r''' 36 const ioLib = r'''
37 #library('io'); 37 library io;
38 class Platform { 38 class Platform {
39 static int operatingSystem; 39 static int operatingSystem;
40 } 40 }
41 '''; 41 ''';
42 42
43 const htmlLib = r''' 43 const htmlLib = r'''
44 #library('html'); 44 library html;
45 Window __window; 45 Window __window;
46 Window get window => __window; 46 Window get window => __window;
47 abstract class Window { 47 abstract class Window {
48 Navigator get navigator; 48 Navigator get navigator;
49 } 49 }
50 abstract class Navigator { 50 abstract class Navigator {
51 String get userAgent; 51 String get userAgent;
52 } 52 }
53 '''; 53 ''';
54 54
55 const helperLib = r''' 55 const helperLib = r'''
56 #library('js_helper'); 56 library js_helper;
57 class JSInvocationMirror {} 57 class JSInvocationMirror {}
58 '''; 58 ''';
59 59
60 testDart2Dart(String src, {void continuation(String s), bool minify: false, 60 testDart2Dart(String src, {void continuation(String s), bool minify: false,
61 bool stripTypes: false}) { 61 bool stripTypes: false}) {
62 // If continuation is not provided, check that source string remains the same. 62 // If continuation is not provided, check that source string remains the same.
63 if (continuation === null) { 63 if (continuation === null) {
64 continuation = (s) { Expect.equals(src, s); }; 64 continuation = (s) { Expect.equals(src, s); };
65 } 65 }
66 testDart2DartWithLibrary(src, '', continuation: continuation, minify: minify, 66 testDart2DartWithLibrary(src, '', continuation: continuation, minify: minify,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 testAbstractClass() { 177 testAbstractClass() {
178 testDart2Dart('main(){A.foo;}abstract class A{final static num foo;}'); 178 testDart2Dart('main(){A.foo;}abstract class A{final static num foo;}');
179 } 179 }
180 180
181 testConflictSendsRename() { 181 testConflictSendsRename() {
182 // Various Send-s to current library and external library. Verify that 182 // Various Send-s to current library and external library. Verify that
183 // everything is renamed correctly in conflicting class names and global 183 // everything is renamed correctly in conflicting class names and global
184 // functions. 184 // functions.
185 var librarySrc = ''' 185 var librarySrc = '''
186 #library("mylib.dart"); 186 library mylib;
187 187
188 globalfoo() {} 188 globalfoo() {}
189 var globalVar; 189 var globalVar;
190 var globalVarInitialized = 6, globalVarInitialized2 = 7; 190 var globalVarInitialized = 6, globalVarInitialized2 = 7;
191 191
192 class A { 192 class A {
193 A(){} 193 A(){}
194 A.fromFoo(){} 194 A.fromFoo(){}
195 static staticfoo(){} 195 static staticfoo(){}
196 foo(){} 196 foo(){}
197 static const field = 5; 197 static const field = 5;
198 } 198 }
199 '''; 199 ''';
200 var mainSrc = ''' 200 var mainSrc = '''
201 #import("mylib.dart", prefix: "mylib"); 201 import 'mylib.dart' as mylib;
202 202
203 globalfoo() {} 203 globalfoo() {}
204 var globalVar; 204 var globalVar;
205 var globalVarInitialized = 6, globalVarInitialized2 = 7; 205 var globalVarInitialized = 6, globalVarInitialized2 = 7;
206 206
207 class A { 207 class A {
208 A(){} 208 A(){}
209 A.fromFoo(){} 209 A.fromFoo(){}
210 static staticfoo(){} 210 static staticfoo(){}
211 foo(){} 211 foo(){}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 'A.field;A.staticfoo();' 251 'A.field;A.staticfoo();'
252 'new A();new A.fromFoo();new A().foo();}'; 252 'new A();new A.fromFoo();new A().foo();}';
253 testDart2DartWithLibrary(mainSrc, librarySrc, 253 testDart2DartWithLibrary(mainSrc, librarySrc,
254 continuation: (String result) { Expect.equals(expectedResult, result); }); 254 continuation: (String result) { Expect.equals(expectedResult, result); });
255 } 255 }
256 256
257 testNoConflictSendsRename() { 257 testNoConflictSendsRename() {
258 // Various Send-s to current library and external library. Nothing should be 258 // Various Send-s to current library and external library. Nothing should be
259 // renamed here, only library prefixes must be cut. 259 // renamed here, only library prefixes must be cut.
260 var librarySrc = ''' 260 var librarySrc = '''
261 #library("mylib.dart"); 261 library mylib;
262 262
263 globalfoo() {} 263 globalfoo() {}
264 264
265 class A { 265 class A {
266 A(){} 266 A(){}
267 A.fromFoo(){} 267 A.fromFoo(){}
268 static staticfoo(){} 268 static staticfoo(){}
269 foo(){} 269 foo(){}
270 static const field = 5; 270 static const field = 5;
271 } 271 }
272 '''; 272 ''';
273 var mainSrc = ''' 273 var mainSrc = '''
274 #import("mylib.dart", prefix: "mylib"); 274 import 'mylib.dart' as mylib;
275 275
276 myglobalfoo() {} 276 myglobalfoo() {}
277 277
278 class MyA { 278 class MyA {
279 MyA(){} 279 MyA(){}
280 MyA.myfromFoo(){} 280 MyA.myfromFoo(){}
281 static mystaticfoo(){} 281 static mystaticfoo(){}
282 myfoo(){} 282 myfoo(){}
283 static const myfield = 5; 283 static const myfield = 5;
284 } 284 }
(...skipping 23 matching lines...) Expand all
308 'static const myfield=5;}' 308 'static const myfield=5;}'
309 'main(){myglobalfoo();MyA.myfield;MyA.mystaticfoo();new MyA();' 309 'main(){myglobalfoo();MyA.myfield;MyA.mystaticfoo();new MyA();'
310 'new MyA.myfromFoo();new MyA().myfoo();globalfoo();A.field;' 310 'new MyA.myfromFoo();new MyA().myfoo();globalfoo();A.field;'
311 'A.staticfoo();new A();new A.fromFoo();new A().foo();}'; 311 'A.staticfoo();new A();new A.fromFoo();new A().foo();}';
312 testDart2DartWithLibrary(mainSrc, librarySrc, 312 testDart2DartWithLibrary(mainSrc, librarySrc,
313 continuation: (String result) { Expect.equals(expectedResult, result); }); 313 continuation: (String result) { Expect.equals(expectedResult, result); });
314 } 314 }
315 315
316 testConflictLibraryClassRename() { 316 testConflictLibraryClassRename() {
317 var librarySrc = ''' 317 var librarySrc = '''
318 #library('mylib'); 318 library mylib;
319 319
320 topfoo() {} 320 topfoo() {}
321 321
322 class A { 322 class A {
323 foo(){} 323 foo(){}
324 } 324 }
325 '''; 325 ''';
326 var mainSrc = ''' 326 var mainSrc = '''
327 #import('mylib.dart', prefix: 'mylib'); 327 import 'mylib.dart' as mylib;
328 328
329 329
330 topfoo() {var x = 5;} 330 topfoo() {var x = 5;}
331 331
332 class A{ 332 class A{
333 num foo() {} 333 num foo() {}
334 A.fromFoo() {} 334 A.fromFoo() {}
335 mylib.A myliba; 335 mylib.A myliba;
336 List<A> mylist; 336 List<A> mylist;
337 } 337 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 'class A<T extends Object>{}' 373 'class A<T extends Object>{}'
374 'class B<T extends Object> extends A<T>{}'); 374 'class B<T extends Object> extends A<T>{}');
375 } 375 }
376 376
377 testStaticInvocation() { 377 testStaticInvocation() {
378 testDart2Dart('main(){var x=Math.parseDouble("1");}'); 378 testDart2Dart('main(){var x=Math.parseDouble("1");}');
379 } 379 }
380 380
381 testLibraryGetSet() { 381 testLibraryGetSet() {
382 var librarySrc = ''' 382 var librarySrc = '''
383 #library('mylib'); 383 library mylib;
384 384
385 get topgetset => 5; 385 get topgetset => 5;
386 set topgetset(arg) {} 386 set topgetset(arg) {}
387 '''; 387 ''';
388 var mainSrc = ''' 388 var mainSrc = '''
389 #import('mylib.dart', prefix: 'mylib'); 389 import 'mylib.dart' as mylib;
390 390
391 get topgetset => 6; 391 get topgetset => 6;
392 set topgetset(arg) {} 392 set topgetset(arg) {}
393 393
394 main() { 394 main() {
395 topgetset; 395 topgetset;
396 topgetset = 6; 396 topgetset = 6;
397 397
398 mylib.topgetset; 398 mylib.topgetset;
399 mylib.topgetset = 5; 399 mylib.topgetset = 5;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 // Check that 'C' in default clause of I gets into placeholders. 471 // Check that 'C' in default clause of I gets into placeholders.
472 Expect.isTrue(collector.elementNodes[classElement].contains(defaultTypeNode)); 472 Expect.isTrue(collector.elementNodes[classElement].contains(defaultTypeNode));
473 } 473 }
474 474
475 testTypeVariablesAreRenamed() { 475 testTypeVariablesAreRenamed() {
476 // Somewhat a hack: we require all the references of the identifier 476 // Somewhat a hack: we require all the references of the identifier
477 // to be renamed in the same way for the whole library. Hence 477 // to be renamed in the same way for the whole library. Hence
478 // if we have a class and type variable with the same name, they 478 // if we have a class and type variable with the same name, they
479 // both should be renamed. 479 // both should be renamed.
480 var librarySrc = ''' 480 var librarySrc = '''
481 #library('mylib'); 481 library mylib;
482 typedef void MyFunction<T extends num>(T arg); 482 typedef void MyFunction<T extends num>(T arg);
483 class T {} 483 class T {}
484 class B<T> {} 484 class B<T> {}
485 class A<T> extends B<T> { T f; } 485 class A<T> extends B<T> { T f; }
486 '''; 486 ''';
487 var mainSrc = ''' 487 var mainSrc = '''
488 #import('mylib.dart', prefix: 'mylib'); 488 import 'mylib.dart' as mylib;
489 typedef void MyFunction<T extends num>(T arg); 489 typedef void MyFunction<T extends num>(T arg);
490 class T {} 490 class T {}
491 class B<T> {} 491 class B<T> {}
492 class A<T> extends B<T> { T f; } 492 class A<T> extends B<T> { T f; }
493 493
494 main() { 494 main() {
495 MyFunction myf1; 495 MyFunction myf1;
496 mylib.MyFunction myf2; 496 mylib.MyFunction myf2;
497 new A<int>().f; 497 new A<int>().f;
498 new T(); 498 new T();
(...skipping 12 matching lines...) Expand all
511 'class p_B<p_T>{}' 511 'class p_B<p_T>{}'
512 'class p_A<p_T> extends p_B<p_T>{p_T f;}' 512 'class p_A<p_T> extends p_B<p_T>{p_T f;}'
513 'main(){p_MyFunction myf1;MyFunction myf2;new p_A<int>().f;' 513 'main(){p_MyFunction myf1;MyFunction myf2;new p_A<int>().f;'
514 'new p_T();new A<int>().f;new T();}'; 514 'new p_T();new A<int>().f;new T();}';
515 testDart2DartWithLibrary(mainSrc, librarySrc, 515 testDart2DartWithLibrary(mainSrc, librarySrc,
516 continuation: (String result) { Expect.equals(expectedResult, result); }); 516 continuation: (String result) { Expect.equals(expectedResult, result); });
517 } 517 }
518 518
519 testClassTypeArgumentBound() { 519 testClassTypeArgumentBound() {
520 var librarySrc = ''' 520 var librarySrc = '''
521 #library('mylib'); 521 library mylib;
522 522
523 interface I {} 523 interface I {}
524 class A<T extends I> {} 524 class A<T extends I> {}
525 525
526 '''; 526 ''';
527 var mainSrc = ''' 527 var mainSrc = '''
528 #import('mylib.dart', prefix: 'mylib'); 528 import 'mylib.dart' as mylib;
529 529
530 interface I {} 530 interface I {}
531 class A<T extends I> {} 531 class A<T extends I> {}
532 532
533 main() { 533 main() {
534 new A(); 534 new A();
535 new mylib.A(); 535 new mylib.A();
536 } 536 }
537 '''; 537 ''';
538 var expectedResult = 538 var expectedResult =
539 'interface I{}' 539 'interface I{}'
540 'class A<T extends I>{}' 540 'class A<T extends I>{}'
541 'interface p_I{}' 541 'interface p_I{}'
542 'class p_A<p_T extends p_I>{}' 542 'class p_A<p_T extends p_I>{}'
543 'main(){new p_A();new A();}'; 543 'main(){new p_A();new A();}';
544 testDart2DartWithLibrary(mainSrc, librarySrc, 544 testDart2DartWithLibrary(mainSrc, librarySrc,
545 continuation: (String result) { Expect.equals(expectedResult, result); }); 545 continuation: (String result) { Expect.equals(expectedResult, result); });
546 } 546 }
547 547
548 testDoubleMains() { 548 testDoubleMains() {
549 var librarySrc = ''' 549 var librarySrc = '''
550 #library('mylib'); 550 library mylib;
551 main() {} 551 main() {}
552 '''; 552 ''';
553 var mainSrc = ''' 553 var mainSrc = '''
554 #import('mylib.dart', prefix: 'mylib'); 554 import 'mylib.dart' as mylib;
555 main() { 555 main() {
556 mylib.main(); 556 mylib.main();
557 } 557 }
558 '''; 558 ''';
559 var expectedResult = 559 var expectedResult =
560 'p_main(){}' 560 'p_main(){}'
561 'main(){p_main();}'; 561 'main(){p_main();}';
562 testDart2DartWithLibrary(mainSrc, librarySrc, 562 testDart2DartWithLibrary(mainSrc, librarySrc,
563 continuation: (String result) { Expect.equals(expectedResult, result); }); 563 continuation: (String result) { Expect.equals(expectedResult, result); });
564 } 564 }
565 565
566 testStaticAccessIoLib() { 566 testStaticAccessIoLib() {
567 var src = ''' 567 var src = '''
568 #import('dart:io'); 568 import 'dart:io';
569 569
570 main() { 570 main() {
571 Platform.operatingSystem; 571 Platform.operatingSystem;
572 } 572 }
573 '''; 573 ''';
574 var expectedResult = 'import "dart:io" as p;' 574 var expectedResult = 'import "dart:io" as p;'
575 'main(){p.Platform.operatingSystem;}'; 575 'main(){p.Platform.operatingSystem;}';
576 testDart2Dart(src, 576 testDart2Dart(src,
577 continuation: (String result) { Expect.equals(expectedResult, result); }); 577 continuation: (String result) { Expect.equals(expectedResult, result); });
578 } 578 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 '''; 651 ''';
652 var expectedResult = 652 var expectedResult =
653 ' foo( arg){}main(){var localvar;foo("5");}'; 653 ' foo( arg){}main(){var localvar;foo("5");}';
654 testDart2Dart(src, 654 testDart2Dart(src,
655 continuation: (String result) { Expect.equals(expectedResult, result); }, 655 continuation: (String result) { Expect.equals(expectedResult, result); },
656 stripTypes: true); 656 stripTypes: true);
657 } 657 }
658 658
659 testPlatformLibraryMemberNamesAreFixed() { 659 testPlatformLibraryMemberNamesAreFixed() {
660 var src = ''' 660 var src = '''
661 #import('dart:html'); 661 import 'dart:html';
662 662
663 class A { 663 class A {
664 static String get userAgent => window.navigator.userAgent; 664 static String get userAgent => window.navigator.userAgent;
665 } 665 }
666 666
667 main() { 667 main() {
668 A.userAgent; 668 A.userAgent;
669 } 669 }
670 '''; 670 ''';
671 var expectedResult = 'import "dart:html" as p;' 671 var expectedResult = 'import "dart:html" as p;'
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 testDoubleMains(); 716 testDoubleMains();
717 testStaticAccessIoLib(); 717 testStaticAccessIoLib();
718 testLocalFunctionPlaceholder(); 718 testLocalFunctionPlaceholder();
719 testMinification(); 719 testMinification();
720 testClosureLocalsMinified(); 720 testClosureLocalsMinified();
721 testParametersMinified(); 721 testParametersMinified();
722 testDeclarationTypePlaceholders(); 722 testDeclarationTypePlaceholders();
723 testPlatformLibraryMemberNamesAreFixed(); 723 testPlatformLibraryMemberNamesAreFixed();
724 testConflictsWithCoreLib(); 724 testConflictsWithCoreLib();
725 } 725 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/constant_folding_test.dart ('k') | tests/compiler/dart2js/dead_phi_eliminator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698