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 "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; | 6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; |
| 7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt'; | 7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt'; |
| 8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; | 8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; |
| 9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'; | 9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'; |
| 10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; | 10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 result.string, // a.x = 'abc' | 504 result.string, // a.x = 'abc' |
| 505 result.bool, // a.y = true | 505 result.bool, // a.y = true |
| 506 result.nullType, // dynamic.x = null | 506 result.nullType, // dynamic.x = null |
| 507 result.double]); // dynamic.y = 3.14 | 507 result.double]); // dynamic.y = 3.14 |
| 508 result.checkFieldHasType('A', 'w', | 508 result.checkFieldHasType('A', 'w', |
| 509 [result.int, // new A(..., 42) | 509 [result.int, // new A(..., 42) |
| 510 result.bool, // a.y = true | 510 result.bool, // a.y = true |
| 511 result.double]); // dynamic.y = double | 511 result.double]); // dynamic.y = double |
| 512 } | 512 } |
| 513 | 513 |
| 514 testNamedParameters() { | 514 testOptionalNamedParameters() { |
|
karlklose
2013/01/15 09:54:51
Perhaps you should add a few tests using methods i
polux
2013/01/17 09:14:27
Done.
| |
| 515 final String source = r""" | 515 final String source = r""" |
| 516 class A { | 516 class A { |
| 517 var x, y, z, w; | 517 var x, y, z, w; |
| 518 A(this.x, {this.y, this.z, this.w}); | 518 A(this.x, {this.y, this.z, this.w}); |
| 519 } | 519 } |
| 520 class B { | |
| 521 var x, y; | |
| 522 B(this.x, {this.y}); | |
| 523 } | |
| 524 class C { | |
| 525 var x, y; | |
| 526 C(this.x, {this.y}); | |
| 527 } | |
| 520 main() { | 528 main() { |
| 521 new A(42); | 529 new A(42); |
| 522 new A('abc', w: true, z: 42.0); | 530 new A('abc', w: true, z: 42.0); |
| 531 new B('abc', y: true); | |
| 532 new B(1, 2); // too many positional arguments | |
| 533 new C('abc', y: true); | |
| 534 new C(1, z: 2); // non-existing named parameter | |
| 523 } | 535 } |
| 524 """; | 536 """; |
| 525 AnalysisResult result = analyze(source); | 537 AnalysisResult result = analyze(source); |
| 526 result.checkFieldHasType('A', 'x', [result.int, result.string]); | 538 result.checkFieldHasType('A', 'x', [result.int, result.string]); |
| 527 result.checkFieldHasType('A', 'y', [new NullBaseType()]); | 539 result.checkFieldHasType('A', 'y', [new NullBaseType()]); |
| 528 result.checkFieldHasType('A', 'z', [new NullBaseType(), result.double]); | 540 result.checkFieldHasType('A', 'z', [new NullBaseType(), result.double]); |
| 529 result.checkFieldHasType('A', 'w', [new NullBaseType(), result.bool]); | 541 result.checkFieldHasType('A', 'w', [new NullBaseType(), result.bool]); |
| 542 result.checkFieldHasType('B', 'x', [result.string]); | |
| 543 result.checkFieldHasType('B', 'y', [result.bool]); | |
| 544 result.checkFieldHasType('C', 'x', [result.string]); | |
| 545 result.checkFieldHasType('C', 'y', [result.bool]); | |
| 546 } | |
| 547 | |
| 548 testOptionalPositionalParameters() { | |
| 549 final String source = r""" | |
| 550 class A { | |
| 551 var x, y, z, w; | |
| 552 A(this.x, [this.y, this.z, this.w]); | |
| 553 } | |
| 554 class B { | |
| 555 var x, y; | |
| 556 B(this.x, [this.y]); | |
| 557 } | |
| 558 main() { | |
| 559 new A(42); | |
| 560 new A('abc', true, 42.0); | |
| 561 new B('a', true); | |
| 562 new B(1, 2, 3); // too many arguments | |
| 563 } | |
| 564 """; | |
| 565 AnalysisResult result = analyze(source); | |
| 566 result.checkFieldHasType('A', 'x', [result.int, result.string]); | |
| 567 result.checkFieldHasType('A', 'y', [new NullBaseType(), result.bool]); | |
| 568 result.checkFieldHasType('A', 'z', [new NullBaseType(), result.double]); | |
| 569 result.checkFieldHasType('A', 'w', [new NullBaseType()]); | |
| 570 result.checkFieldHasType('B', 'x', [result.string]); | |
| 571 result.checkFieldHasType('B', 'y', [result.bool]); | |
| 530 } | 572 } |
| 531 | 573 |
| 532 testListLiterals() { | 574 testListLiterals() { |
| 533 final String source = r""" | 575 final String source = r""" |
| 534 class A { | 576 class A { |
| 535 var x; | 577 var x; |
| 536 A(this.x); | 578 A(this.x); |
| 537 } | 579 } |
| 538 main() { | 580 main() { |
| 539 var x = []; | 581 var x = []; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 testNonRecusiveFunction(); | 896 testNonRecusiveFunction(); |
| 855 testRecusiveFunction(); | 897 testRecusiveFunction(); |
| 856 testMutuallyRecusiveFunction(); | 898 testMutuallyRecusiveFunction(); |
| 857 testSimpleSend(); | 899 testSimpleSend(); |
| 858 // testSendToClosureField(); // closures are not yet supported | 900 // testSendToClosureField(); // closures are not yet supported |
| 859 testSendToThis1(); | 901 testSendToThis1(); |
| 860 testSendToThis2(); | 902 testSendToThis2(); |
| 861 testConstructor(); | 903 testConstructor(); |
| 862 testGetters(); | 904 testGetters(); |
| 863 testSetters(); | 905 testSetters(); |
| 864 testNamedParameters(); | 906 testOptionalNamedParameters(); |
| 907 testOptionalPositionalParameters(); | |
| 865 testListLiterals(); | 908 testListLiterals(); |
| 866 testMapLiterals(); | 909 testMapLiterals(); |
| 867 testReturn(); | 910 testReturn(); |
| 868 // testNoReturn(); // right now we infer the empty type instead of null | 911 // testNoReturn(); // right now we infer the empty type instead of null |
| 869 testArithmeticOperators(); | 912 testArithmeticOperators(); |
| 870 testOperators(); | 913 testOperators(); |
| 871 testCompoundOperators1(); | 914 testCompoundOperators1(); |
| 872 testCompoundOperators2(); | 915 testCompoundOperators2(); |
| 873 testSetIndexOperator(); | 916 testSetIndexOperator(); |
| 874 testInequality(); | 917 testInequality(); |
| 875 // testFieldInitialization(); // TODO(polux) | 918 // testFieldInitialization(); // TODO(polux) |
| 876 testSendWithWrongArity(); | 919 testSendWithWrongArity(); |
| 877 testBigTypesWidening1(); | 920 testBigTypesWidening1(); |
| 878 testBigTypesWidening2(); | 921 testBigTypesWidening2(); |
| 879 testDynamicIsAbsorbing(); | 922 testDynamicIsAbsorbing(); |
| 880 } | 923 } |
| OLD | NEW |