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

Side by Side Diff: frog/tests/leg/src/ResolverTest.dart

Issue 10091037: Clean up handling of types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove debug code. Created 8 years, 8 months 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("../../../../lib/compiler/implementation/leg.dart"); 5 #import("../../../../lib/compiler/implementation/leg.dart");
6 #import("../../../../lib/compiler/implementation/elements/elements.dart"); 6 #import("../../../../lib/compiler/implementation/elements/elements.dart");
7 #import("../../../../lib/compiler/implementation/tree/tree.dart"); 7 #import("../../../../lib/compiler/implementation/tree/tree.dart");
8 #import("../../../../lib/compiler/implementation/util/util.dart"); 8 #import("../../../../lib/compiler/implementation/util/util.dart");
9 #import("mock_compiler.dart"); 9 #import("mock_compiler.dart");
10 #import("parser_helper.dart"); 10 #import("parser_helper.dart");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 testLocalsOne(); 52 testLocalsOne();
53 testLocalsTwo(); 53 testLocalsTwo();
54 testLocalsThree(); 54 testLocalsThree();
55 testLocalsFour(); 55 testLocalsFour();
56 testLocalsFive(); 56 testLocalsFive();
57 testParametersOne(); 57 testParametersOne();
58 testFor(); 58 testFor();
59 testTypeAnnotation(); 59 testTypeAnnotation();
60 testSuperclass(); 60 testSuperclass();
61 // testVarSuperclass(); // The parser crashes with 'class Foo extends var'. 61 // testVarSuperclass(); // The parser crashes with 'class Foo extends var'.
62 // testOneInterface(); // The parser does not handle interfaces. 62 // testOneInterface(); // Generates unexpected error message.
63 // testTwoInterfaces(); // The parser does not handle interfaces. 63 // testTwoInterfaces(); // Generates unexpected error message.
64 testFunctionExpression(); 64 testFunctionExpression();
65 testNewExpression(); 65 testNewExpression();
66 testTopLevelFields(); 66 testTopLevelFields();
67 testClassHierarchy(); 67 testClassHierarchy();
68 testInitializers(); 68 testInitializers();
69 testThis(); 69 testThis();
70 testSuperCalls(); 70 testSuperCalls();
71 testTypeVariables(); 71 testTypeVariables();
72 } 72 }
73 73
74 testTypeVariables() { 74 testTypeVariables() {
75 testTypeResolving(visitor, text, name, expectedElements) { 75 matchResolvedTypes(visitor, text, name, expectedElements) {
76 VariableDefinitions definition = parseStatement(text); 76 VariableDefinitions definition = parseStatement(text);
77 visitor.visit(definition.type); 77 visitor.visit(definition.type);
78 InterfaceType type = visitor.mapping.getType(definition.type); 78 InterfaceType type = visitor.mapping.getType(definition.type);
79 Expect.equals(definition.type.typeArguments.length(), 79 Expect.equals(definition.type.typeArguments.length(),
80 length(type.arguments)); 80 length(type.arguments));
81 int index = 0; 81 int index = 0;
82 Link<Type> arguments = type.arguments; 82 Link<Type> arguments = type.arguments;
83 while (!arguments.isEmpty()) { 83 while (!arguments.isEmpty()) {
84 Expect.equals(true, index < expectedElements.length);
84 Expect.equals(expectedElements[index], arguments.head.element); 85 Expect.equals(expectedElements[index], arguments.head.element);
85 index++; 86 index++;
86 arguments = arguments.tail; 87 arguments = arguments.tail;
87 } 88 }
89 Expect.equals(index, expectedElements.length);
88 } 90 }
89 91
90 MockCompiler compiler = new MockCompiler(); 92 MockCompiler compiler = new MockCompiler();
91 ResolverVisitor visitor = compiler.resolverVisitor(); 93 ResolverVisitor visitor = compiler.resolverVisitor();
92 compiler.parseScript('class Foo<T, U> {}'); 94 compiler.parseScript('class Foo<T, U> {}');
93 visitor.visit(parseStatement('Foo foo;'));
94 ClassElement foo = compiler.mainApp.find(buildSourceString('Foo')); 95 ClassElement foo = compiler.mainApp.find(buildSourceString('Foo'));
95 testTypeResolving(visitor, 'Foo<int, String> x;', 'Foo', 96 matchResolvedTypes(visitor, 'Foo<int, String> x;', 'Foo',
96 [compiler.intClass, compiler.stringClass]); 97 [compiler.intClass, compiler.stringClass]);
97 testTypeResolving(visitor, 'Foo<Foo, Foo> x;', 'Foo', 98 matchResolvedTypes(visitor, 'Foo<Foo, Foo> x;', 'Foo',
98 [foo, foo]); 99 [foo, foo]);
99 100
100 compiler = new MockCompiler(); 101 compiler = new MockCompiler();
101 compiler.parseScript('class Foo<T, U> {}'); 102 compiler.parseScript('class Foo<T, U> {}');
102 compiler.resolveStatement('Foo<notype, int> x;'); 103 compiler.resolveStatement('Foo<notype, int> x;');
103 Expect.equals(1, compiler.warnings.length); 104 Expect.equals(1, compiler.warnings.length);
104 Expect.equals(MessageKind.CANNOT_RESOLVE_TYPE, 105 Expect.equals(MessageKind.CANNOT_RESOLVE_TYPE,
105 compiler.warnings[0].message.kind); 106 compiler.warnings[0].message.kind);
106 Expect.equals(0, compiler.errors.length); 107 Expect.equals(0, compiler.errors.length);
107 108
108 compiler = new MockCompiler(); 109 compiler = new MockCompiler();
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 script = """class A { 663 script = """class A {
663 int i; 664 int i;
664 A(i); 665 A(i);
665 } 666 }
666 class B extends A { 667 class B extends A {
667 B() : super(0), super(1); 668 B() : super(0), super(1);
668 }"""; 669 }""";
669 resolveConstructor(script, "B b = new B();", "B", "B", 2, 670 resolveConstructor(script, "B b = new B();", "B", "B", 2,
670 [], [MessageKind.DUPLICATE_SUPER_INITIALIZER]); 671 [], [MessageKind.DUPLICATE_SUPER_INITIALIZER]);
671 672
672 script = "class Object { Object() : super(); }"; 673 script = "";
674 final String CORELIB_WITH_INVALID_OBJECT =
675 '''print(var obj) {}
676 class int {}
677 class double {}
678 class bool {}
679 class String {}
680 class num {}
681 class Function {}
682 class List {}
683 class Closure {}
684 class Null {}
685 class Dynamic {}
686 class Object { Object() : super(); }''';
673 resolveConstructor(script, "Object o = new Object();", "Object", "Object", 1, 687 resolveConstructor(script, "Object o = new Object();", "Object", "Object", 1,
674 [], [MessageKind.SUPER_INITIALIZER_IN_OBJECT], 688 [], [MessageKind.SUPER_INITIALIZER_IN_OBJECT],
675 corelib: ""); 689 corelib: CORELIB_WITH_INVALID_OBJECT);
676 } 690 }
677 691
678 map(ResolverVisitor visitor) { 692 map(ResolverVisitor visitor) {
679 TreeElementMapping elements = visitor.mapping; 693 TreeElementMapping elements = visitor.mapping;
680 return elements.map; 694 return elements.map;
681 } 695 }
682 696
683 length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1; 697 length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1;
684 698
685 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); 699 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1);
686 700
687 List<String> asSortedStrings(Link link) { 701 List<String> asSortedStrings(Link link) {
688 List<String> result = <String>[]; 702 List<String> result = <String>[];
689 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString()); 703 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString());
690 result.sort((s1, s2) => s1.compareTo(s2)); 704 result.sort((s1, s2) => s1.compareTo(s2));
691 return result; 705 return result;
692 } 706 }
OLDNEW
« no previous file with comments | « no previous file | frog/tests/leg/src/TypeCheckerTest.dart » ('j') | lib/compiler/implementation/typechecker.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698