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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; |
6 import 'dart:collection'; | 7 import 'dart:collection'; |
7 | 8 |
8 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; | 9 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; |
9 import "compiler_helper.dart"; | 10 import "compiler_helper.dart"; |
10 import "parser_helper.dart"; | 11 import "parser_helper.dart"; |
11 | 12 |
12 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; | 13 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; |
13 | 14 |
14 Node buildIdentifier(String name) => new Identifier(scan(name)); | 15 Node buildIdentifier(String name) => new Identifier(scan(name)); |
15 | 16 |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 777 |
777 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); | 778 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); |
778 | 779 |
779 List<String> asSortedStrings(Link link) { | 780 List<String> asSortedStrings(Link link) { |
780 List<String> result = <String>[]; | 781 List<String> result = <String>[]; |
781 for (; !link.isEmpty; link = link.tail) result.add(link.head.toString()); | 782 for (; !link.isEmpty; link = link.tail) result.add(link.head.toString()); |
782 result.sort((s1, s2) => s1.compareTo(s2)); | 783 result.sort((s1, s2) => s1.compareTo(s2)); |
783 return result; | 784 return result; |
784 } | 785 } |
785 | 786 |
786 compileScript(String source) { | 787 Future compileScript(String source) { |
787 Uri uri = new Uri(scheme: 'source'); | 788 Uri uri = new Uri(scheme: 'source'); |
788 MockCompiler compiler = compilerFor(source, uri); | 789 MockCompiler compiler = compilerFor(source, uri); |
789 compiler.runCompiler(uri); | 790 return compiler.runCompiler(uri).then((_) { |
790 return compiler; | 791 return compiler; |
| 792 }); |
791 } | 793 } |
792 | 794 |
793 checkMemberResolved(compiler, className, memberName) { | 795 checkMemberResolved(compiler, className, memberName) { |
794 Element memberElement = findElement(compiler, className) | 796 Element memberElement = findElement(compiler, className) |
795 .lookupLocalMember(memberName); | 797 .lookupLocalMember(memberName); |
796 Expect.isNotNull(memberElement); | 798 Expect.isNotNull(memberElement); |
797 Expect.isNotNull( | 799 Expect.isNotNull( |
798 compiler.enqueuer.resolution.getCachedElements(memberElement)); | 800 compiler.enqueuer.resolution.getCachedElements(memberElement)); |
799 } | 801 } |
800 | 802 |
801 testToString() { | 803 testToString() { |
802 final script = r"class C { toString() => 'C'; } main() { '${new C()}'; }"; | 804 final script = r"class C { toString() => 'C'; } main() { '${new C()}'; }"; |
803 final compiler = compileScript(script); | 805 compileScript(script).then((compiler) { |
804 | 806 checkMemberResolved(compiler, 'C', buildSourceString('toString')); |
805 checkMemberResolved(compiler, 'C', buildSourceString('toString')); | 807 }); |
806 } | 808 } |
807 | 809 |
808 operatorName(op, isUnary) { | 810 operatorName(op, isUnary) { |
809 return Elements.constructOperatorName(new SourceString(op), isUnary); | 811 return Elements.constructOperatorName(new SourceString(op), isUnary); |
810 } | 812 } |
811 | 813 |
812 testIndexedOperator() { | 814 testIndexedOperator() { |
813 final script = r""" | 815 final script = r""" |
814 class C { | 816 class C { |
815 operator[](ix) => ix; | 817 operator[](ix) => ix; |
816 operator[]=(ix, v) {} | 818 operator[]=(ix, v) {} |
817 } | 819 } |
818 main() { var c = new C(); c[0]++; }"""; | 820 main() { var c = new C(); c[0]++; }"""; |
819 final compiler = compileScript(script); | 821 compileScript(script).then((compiler) { |
820 | 822 checkMemberResolved(compiler, 'C', operatorName('[]', false)); |
821 checkMemberResolved(compiler, 'C', operatorName('[]', false)); | 823 checkMemberResolved(compiler, 'C', operatorName('[]=', false)); |
822 checkMemberResolved(compiler, 'C', operatorName('[]=', false)); | 824 }); |
823 } | 825 } |
824 | 826 |
825 testIncrementsAndDecrements() { | 827 testIncrementsAndDecrements() { |
826 final script = r""" | 828 final script = r""" |
827 class A { operator+(o)=>null; } | 829 class A { operator+(o)=>null; } |
828 class B { operator+(o)=>null; } | 830 class B { operator+(o)=>null; } |
829 class C { operator-(o)=>null; } | 831 class C { operator-(o)=>null; } |
830 class D { operator-(o)=>null; } | 832 class D { operator-(o)=>null; } |
831 main() { | 833 main() { |
832 var a = new A(); | 834 var a = new A(); |
833 a++; | 835 a++; |
834 var b = new B(); | 836 var b = new B(); |
835 ++b; | 837 ++b; |
836 var c = new C(); | 838 var c = new C(); |
837 c--; | 839 c--; |
838 var d = new D(); | 840 var d = new D(); |
839 --d; | 841 --d; |
840 }"""; | 842 }"""; |
841 final compiler = compileScript(script); | 843 compileScript(script).then((compiler) { |
842 | 844 checkMemberResolved(compiler, 'A', operatorName('+', false)); |
843 checkMemberResolved(compiler, 'A', operatorName('+', false)); | 845 checkMemberResolved(compiler, 'B', operatorName('+', false)); |
844 checkMemberResolved(compiler, 'B', operatorName('+', false)); | 846 checkMemberResolved(compiler, 'C', operatorName('-', false)); |
845 checkMemberResolved(compiler, 'C', operatorName('-', false)); | 847 checkMemberResolved(compiler, 'D', operatorName('-', false)); |
846 checkMemberResolved(compiler, 'D', operatorName('-', false)); | 848 }); |
847 } | 849 } |
OLD | NEW |