OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library test.src.serialization.elements_test; | 5 library test.src.serialization.elements_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
8 import 'package:analyzer/src/generated/engine.dart'; | 8 import 'package:analyzer/src/generated/engine.dart'; |
9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
10 import 'package:analyzer/src/summary/base.dart'; | 10 import 'package:analyzer/src/summary/base.dart'; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 compareCompilationUnitElements(resynthesized.parts[i], original.parts[i]); | 54 compareCompilationUnitElements(resynthesized.parts[i], original.parts[i]); |
55 } | 55 } |
56 expect(resynthesized.imports.length, original.imports.length); | 56 expect(resynthesized.imports.length, original.imports.length); |
57 for (int i = 0; i < resynthesized.imports.length; i++) { | 57 for (int i = 0; i < resynthesized.imports.length; i++) { |
58 compareImportElements(resynthesized.imports[i], original.imports[i], | 58 compareImportElements(resynthesized.imports[i], original.imports[i], |
59 'import ${original.imports[i].uri}'); | 59 'import ${original.imports[i].uri}'); |
60 } | 60 } |
61 expect(resynthesized.exports.length, original.exports.length); | 61 expect(resynthesized.exports.length, original.exports.length); |
62 for (int i = 0; i < resynthesized.exports.length; i++) { | 62 for (int i = 0; i < resynthesized.exports.length; i++) { |
63 compareExportElements(resynthesized.exports[i], original.exports[i], | 63 compareExportElements(resynthesized.exports[i], original.exports[i], |
64 'export ${original.exports[i].name}'); | 64 'export ${original.exports[i].uri}'); |
65 } | 65 } |
| 66 expect(resynthesized.nameLength, original.nameLength); |
66 // TODO(paulberry): test entryPoint, exportNamespace, publicNamespace, | 67 // TODO(paulberry): test entryPoint, exportNamespace, publicNamespace, |
67 // and metadata. | 68 // and metadata. |
68 } | 69 } |
69 | 70 |
70 void compareClassElements( | 71 void compareClassElements( |
71 ClassElementImpl resynthesized, ClassElementImpl original, String desc) { | 72 ClassElementImpl resynthesized, ClassElementImpl original, String desc) { |
72 compareElements(resynthesized, original, desc); | 73 compareElements(resynthesized, original, desc); |
73 expect(resynthesized.fields.length, original.fields.length, | 74 expect(resynthesized.fields.length, original.fields.length, |
74 reason: '$desc fields.length'); | 75 reason: '$desc fields.length'); |
75 for (int i = 0; i < resynthesized.fields.length; i++) { | 76 for (int i = 0; i < resynthesized.fields.length; i++) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 compareExecutableElements(resynthesized, original, desc); | 183 compareExecutableElements(resynthesized, original, desc); |
183 // TODO(paulberry): test redirectedConstructor and constantInitializers | 184 // TODO(paulberry): test redirectedConstructor and constantInitializers |
184 } | 185 } |
185 | 186 |
186 void compareElements( | 187 void compareElements( |
187 ElementImpl resynthesized, ElementImpl original, String desc) { | 188 ElementImpl resynthesized, ElementImpl original, String desc) { |
188 expect(resynthesized, isNotNull); | 189 expect(resynthesized, isNotNull); |
189 expect(resynthesized.kind, original.kind); | 190 expect(resynthesized.kind, original.kind); |
190 expect(resynthesized.location, original.location, reason: desc); | 191 expect(resynthesized.location, original.location, reason: desc); |
191 expect(resynthesized.name, original.name); | 192 expect(resynthesized.name, original.name); |
| 193 expect(resynthesized.nameOffset, original.nameOffset, reason: desc); |
192 for (Modifier modifier in Modifier.values) { | 194 for (Modifier modifier in Modifier.values) { |
193 if (modifier == Modifier.MIXIN) { | 195 if (modifier == Modifier.MIXIN) { |
194 // Skipping for now. TODO(paulberry): fix. | 196 // Skipping for now. TODO(paulberry): fix. |
195 continue; | 197 continue; |
196 } | 198 } |
197 bool got = resynthesized.hasModifier(modifier); | 199 bool got = resynthesized.hasModifier(modifier); |
198 bool want = original.hasModifier(modifier); | 200 bool want = original.hasModifier(modifier); |
199 expect(got, want, | 201 expect(got, want, |
200 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); | 202 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); |
201 } | 203 } |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 test_imports() { | 895 test_imports() { |
894 addLibrarySource('/a.dart', 'library a; class C {}'); | 896 addLibrarySource('/a.dart', 'library a; class C {}'); |
895 addLibrarySource('/b.dart', 'library b; class D {}'); | 897 addLibrarySource('/b.dart', 'library b; class D {}'); |
896 checkLibrary('import "a.dart"; import "b.dart"; C c; D d;'); | 898 checkLibrary('import "a.dart"; import "b.dart"; C c; D d;'); |
897 } | 899 } |
898 | 900 |
899 test_library() { | 901 test_library() { |
900 checkLibrary(''); | 902 checkLibrary(''); |
901 } | 903 } |
902 | 904 |
| 905 test_library_name_with_spaces() { |
| 906 checkLibrary('library foo . bar ;'); |
| 907 } |
| 908 |
903 test_library_named() { | 909 test_library_named() { |
904 checkLibrary('library foo.bar;'); | 910 checkLibrary('library foo.bar;'); |
905 } | 911 } |
906 | 912 |
907 test_method_parameter_parameters() { | 913 test_method_parameter_parameters() { |
908 checkLibrary('class C { f(g(x, y)) {} }'); | 914 checkLibrary('class C { f(g(x, y)) {} }'); |
909 } | 915 } |
910 | 916 |
911 test_method_parameter_parameters_in_generic_class() { | 917 test_method_parameter_parameters_in_generic_class() { |
912 checkLibrary('class C<A, B> { f(A g(B x)) {} }'); | 918 checkLibrary('class C<A, B> { f(A g(B x)) {} }'); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 } | 1182 } |
1177 | 1183 |
1178 test_variable_implicit_type() { | 1184 test_variable_implicit_type() { |
1179 checkLibrary('var x;'); | 1185 checkLibrary('var x;'); |
1180 } | 1186 } |
1181 | 1187 |
1182 test_variables() { | 1188 test_variables() { |
1183 checkLibrary('int i; int j;'); | 1189 checkLibrary('int i; int j;'); |
1184 } | 1190 } |
1185 } | 1191 } |
OLD | NEW |