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

Side by Side Diff: dart/tests/try/poi/serialize_test.dart

Issue 396803003: Serialize scopes according to semantic structure. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r39136 Created 6 years, 4 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
« no previous file with comments | « dart/tests/try/poi/data/subclass.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// Test that poi.dart can serialize a scope. 5 /// Test that poi.dart can serialize a scope.
6 6
7 library trydart.serialize_test; 7 library trydart.serialize_test;
8 8
9 import 'dart:io' show 9 import 'dart:io' show
10 Platform; 10 Platform;
11 11
12 import 'dart:async' show 12 import 'dart:async' show
13 Future; 13 Future;
14 14
15 import 'dart:convert' show 15 import 'dart:convert' show
16 JSON; 16 JSON;
17 17
18 import 'package:try/poi/poi.dart' as poi; 18 import 'package:try/poi/poi.dart' as poi;
19 19
20 import 'package:async_helper/async_helper.dart'; 20 import 'package:async_helper/async_helper.dart';
21 21
22 import 'package:expect/expect.dart'; 22 import 'package:expect/expect.dart';
23 23
24 import 'package:compiler/implementation/elements/elements.dart' show 24 import 'package:compiler/implementation/elements/elements.dart' show
25 Element; 25 Element;
26 26
27 import 'package:compiler/implementation/source_file_provider.dart' show 27 import 'package:compiler/implementation/source_file_provider.dart' show
28 FormattingDiagnosticHandler; 28 FormattingDiagnosticHandler;
29 29
30 Future testPoi() { 30 Future testInteresting() {
31 Uri script = Platform.script.resolve('data/interesting.dart'); 31 Uri script = Platform.script.resolve('data/interesting.dart');
32 FormattingDiagnosticHandler handler = new FormattingDiagnosticHandler(); 32 FormattingDiagnosticHandler handler = new FormattingDiagnosticHandler();
33 33
34 int position = 263; 34 int position = 263;
35 35
36 Future future = poi.runPoi(script, position, handler.provider, handler); 36 Future future = poi.runPoi(script, position, handler.provider, handler);
37 return future.then((Element element) { 37 return future.then((Element element) {
38 Uri foundScript = element.compilationUnit.script.resourceUri; 38 Uri foundScript = element.compilationUnit.script.resourceUri;
39 Expect.stringEquals('$script', '$foundScript'); 39 Expect.stringEquals('$script', '$foundScript');
40 Expect.stringEquals('fisk', element.name); 40 Expect.stringEquals('fisk', element.name);
41 41
42 String scope = poi.scopeInformation(element, position); 42 String scope = poi.scopeInformation(element, position);
43 Expect.stringEquals( 43 Expect.stringEquals(
44 JSON.encode(expected), JSON.encode(JSON.decode(scope)), scope); 44 JSON.encode(expectedInteresting), JSON.encode(JSON.decode(scope)),
45 scope);
46 return testSubclass(handler);
47 });
48 }
49
50 Future testSubclass(FormattingDiagnosticHandler handler) {
51 int position = 506;
52
53 Uri script = Platform.script.resolve('data/subclass.dart');
54
55 Future future = poi.runPoi(script, position, handler.provider, handler);
56 return future.then((Element element) {
57 Uri foundScript = element.compilationUnit.script.resourceUri;
58 Expect.stringEquals('$script', '$foundScript');
59 Expect.stringEquals('instanceMethod2', element.name);
60
61 String scope = poi.scopeInformation(element, position);
62 Expect.stringEquals(
63 JSON.encode(expectedSubclass), JSON.encode(JSON.decode(scope)), scope);
45 }); 64 });
46 } 65 }
47 66
48 void main() { 67 void main() {
49 asyncTest(testPoi); 68 asyncTest(testInteresting);
50 } 69 }
51 70
52 final expected = { 71 final expectedInteresting = {
53 "name": "fisk", 72 "name": "fisk",
54 "kind": "function", 73 "kind": "function",
55 "type": "() -> dynamic", 74 "type": "() -> dynamic",
56 "enclosing": { 75 "enclosing": {
57 "name": "Foo", 76 "name": "Foo",
58 "kind": "class", 77 "kind": "class",
59 "members": [ 78 "members": [
79 ],
80 "enclosing": {
81 "name": "this(Foo)",
82 "kind": "class",
83 "members": [
84 {
85 "name": "fisk",
86 "kind": "function",
87 "type": "() -> dynamic"
88 },
89 {
90 "name": "hest",
91 "kind": "function",
92 "type": "() -> dynamic"
93 },
94 {
95 "kind": "generative_constructor",
96 "type": "() -> Foo"
97 }
98 ],
99 "enclosing": {
100 "name": "interesting",
101 "kind": "library",
102 "members": [
103 {
104 "name": "Foo",
105 "kind": "class"
106 },
107 {
108 "name": "main",
109 "kind": "function",
110 "type": "() -> dynamic"
111 }
112 ],
113 "enclosing": {
114 "kind": "imports",
115 "members": coreImports,
116 "enclosing": object,
117 }
118 }
119 }
120 }
121 };
122
123 final expectedSubclass = {
124 "name": "instanceMethod2",
125 "kind": "function",
126 "type": "() -> dynamic",
127 "enclosing": {
128 "name": "C",
129 "kind": "class",
130 "members": [
60 { 131 {
61 "name": "fisk", 132 "name": "staticMethod1",
62 "kind": "function", 133 "kind": "function",
63 "type": "() -> dynamic" 134 "type": "() -> dynamic"
64 }, 135 },
65 { 136 {
66 "name": "hest", 137 "name": "staticMethod2",
67 "kind": "function", 138 "kind": "function",
68 "type": "() -> dynamic" 139 "type": "() -> dynamic"
69 },
70 {
71 "name": "",
72 "kind": "generative_constructor",
73 "type": "() -> Foo"
74 } 140 }
75 ], 141 ],
76 "enclosing": { 142 "enclosing": {
77 "name": "interesting", 143 "name": "this(C)",
78 "kind": "library", 144 "kind": "class",
79 "members": [ 145 "members": [
80 { 146 {
81 "name": "main", 147 "name": "instanceMethod1",
82 "kind": "function", 148 "kind": "function",
83 "type": "() -> dynamic" 149 "type": "() -> dynamic"
84 }, 150 },
85 { 151 {
86 "name": "Foo", 152 "name": "instanceMethod2",
87 "kind": "class" 153 "kind": "function",
154 "type": "() -> dynamic"
155 },
156 {
157 "kind": "generative_constructor",
158 "type": "() -> C"
88 } 159 }
89 ] 160 ],
161 "enclosing": {
162 "name": "subclass",
163 "kind": "library",
164 "members": [
165 {
166 "name": "S",
167 "kind": "class"
168 },
169 {
170 "name": "C",
171 "kind": "class"
172 },
173 {
174 "name": "main",
175 "kind": "function",
176 "type": "() -> dynamic"
177 },
178 {
179 "name": "p",
180 "kind": "prefix"
181 }
182 ],
183 "enclosing": {
184 "kind": "imports",
185 "members": [
186 {
187 "name": "Foo",
188 "kind": "class"
189 },
190 {
191 "name": "main",
192 "kind": "function",
193 "type": "() -> dynamic"
194 },
195 ]..addAll(coreImports),
196 "enclosing": {
197 "name": "this(S)",
198 "kind": "class",
199 "members": [
200 {
201 "name": "superMethod1",
202 "kind": "function",
203 "type": "() -> dynamic"
204 },
205 {
206 "name": "superMethod2",
207 "kind": "function",
208 "type": "() -> dynamic"
209 },
210 {
211 "kind": "generative_constructor",
212 "type": "() -> S"
213 }
214 ],
215 "enclosing": {
216 "name": "this(P)",
217 "kind": "class",
218 "members": [
219 {
220 "name": "pMethod1",
221 "kind": "function",
222 "type": "() -> dynamic"
223 },
224 {
225 "name": "pMethod2",
226 "kind": "function",
227 "type": "() -> dynamic"
228 },
229 {
230 "name": "_pMethod1",
231 "kind": "function",
232 "type": "() -> dynamic"
233 },
234 {
235 "name": "_pMethod2",
236 "kind": "function",
237 "type": "() -> dynamic"
238 },
239 {
240 "kind": "generative_constructor",
241 "type": "() -> P"
242 }
243 ],
244 "enclosing": object,
245 }
246 }
247 }
248 }
90 } 249 }
91 } 250 }
92 }; 251 };
252
253 final coreImports = [
254 {
255 "name": "Deprecated",
256 "kind": "class"
257 },
258 {
259 "name": "deprecated",
260 "kind": "field",
261 "type": "Deprecated"
262 },
263 {
264 "name": "override",
265 "kind": "field",
266 "type": "Object"
267 },
268 {
269 "name": "proxy",
270 "kind": "field",
271 "type": "Object"
272 },
273 {
274 "name": "bool",
275 "kind": "class"
276 },
277 {
278 "name": "Comparator",
279 "kind": "typedef"
280 },
281 {
282 "name": "Comparable",
283 "kind": "class"
284 },
285 {
286 "name": "DateTime",
287 "kind": "class"
288 },
289 {
290 "name": "double",
291 "kind": "class"
292 },
293 {
294 "name": "Duration",
295 "kind": "class"
296 },
297 {
298 "name": "Error",
299 "kind": "class"
300 },
301 {
302 "name": "AssertionError",
303 "kind": "class"
304 },
305 {
306 "name": "TypeError",
307 "kind": "class"
308 },
309 {
310 "name": "CastError",
311 "kind": "class"
312 },
313 {
314 "name": "NullThrownError",
315 "kind": "class"
316 },
317 {
318 "name": "ArgumentError",
319 "kind": "class"
320 },
321 {
322 "name": "RangeError",
323 "kind": "class"
324 },
325 {
326 "name": "FallThroughError",
327 "kind": "class"
328 },
329 {
330 "name": "AbstractClassInstantiationError",
331 "kind": "class"
332 },
333 {
334 "name": "NoSuchMethodError",
335 "kind": "class"
336 },
337 {
338 "name": "UnsupportedError",
339 "kind": "class"
340 },
341 {
342 "name": "UnimplementedError",
343 "kind": "class"
344 },
345 {
346 "name": "StateError",
347 "kind": "class"
348 },
349 {
350 "name": "ConcurrentModificationError",
351 "kind": "class"
352 },
353 {
354 "name": "OutOfMemoryError",
355 "kind": "class"
356 },
357 {
358 "name": "StackOverflowError",
359 "kind": "class"
360 },
361 {
362 "name": "CyclicInitializationError",
363 "kind": "class"
364 },
365 {
366 "name": "Exception",
367 "kind": "class"
368 },
369 {
370 "name": "FormatException",
371 "kind": "class"
372 },
373 {
374 "name": "IntegerDivisionByZeroException",
375 "kind": "class"
376 },
377 {
378 "name": "Expando",
379 "kind": "class"
380 },
381 {
382 "name": "Function",
383 "kind": "class"
384 },
385 {
386 "name": "identical",
387 "kind": "function",
388 "type": "(Object, Object) -> bool"
389 },
390 {
391 "name": "identityHashCode",
392 "kind": "function",
393 "type": "(Object) -> int"
394 },
395 {
396 "name": "int",
397 "kind": "class"
398 },
399 {
400 "name": "Invocation",
401 "kind": "class"
402 },
403 {
404 "name": "Iterable",
405 "kind": "class"
406 },
407 {
408 "name": "BidirectionalIterator",
409 "kind": "class"
410 },
411 {
412 "name": "Iterator",
413 "kind": "class"
414 },
415 {
416 "name": "List",
417 "kind": "class"
418 },
419 {
420 "name": "Map",
421 "kind": "class"
422 },
423 {
424 "name": "Null",
425 "kind": "class"
426 },
427 {
428 "name": "num",
429 "kind": "class"
430 },
431 {
432 "name": "Object",
433 "kind": "class"
434 },
435 {
436 "name": "Pattern",
437 "kind": "class"
438 },
439 {
440 "name": "print",
441 "kind": "function",
442 "type": "(Object) -> void"
443 },
444 {
445 "name": "Match",
446 "kind": "class"
447 },
448 {
449 "name": "RegExp",
450 "kind": "class"
451 },
452 {
453 "name": "Set",
454 "kind": "class"
455 },
456 {
457 "name": "Sink",
458 "kind": "class"
459 },
460 {
461 "name": "StackTrace",
462 "kind": "class"
463 },
464 {
465 "name": "Stopwatch",
466 "kind": "class"
467 },
468 {
469 "name": "String",
470 "kind": "class"
471 },
472 {
473 "name": "Runes",
474 "kind": "class"
475 },
476 {
477 "name": "RuneIterator",
478 "kind": "class"
479 },
480 {
481 "name": "StringBuffer",
482 "kind": "class"
483 },
484 {
485 "name": "StringSink",
486 "kind": "class"
487 },
488 {
489 "name": "Symbol",
490 "kind": "class"
491 },
492 {
493 "name": "Type",
494 "kind": "class"
495 },
496 {
497 "name": "Uri",
498 "kind": "class"
499 }
500 ];
501
502 final object = {
503 "name": "this(Object)",
504 "kind": "class",
505 "members": [
506 {
507 "kind": "generative_constructor",
508 "type": "() -> dynamic"
509 },
510 {
511 "name": "==",
512 "kind": "function",
513 "type": "(dynamic) -> bool"
514 },
515 {
516 "name": "hashCode",
517 "kind": "getter"
518 },
519 {
520 "name": "toString",
521 "kind": "function",
522 "type": "() -> String"
523 },
524 {
525 "name": "noSuchMethod",
526 "kind": "function",
527 "type": "(Invocation) -> dynamic"
528 },
529 {
530 "name": "runtimeType",
531 "kind": "getter"
532 }
533 ]
534 };
OLDNEW
« no previous file with comments | « dart/tests/try/poi/data/subclass.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698