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

Side by Side Diff: pkg/smoke/test/codegen/recorder_test.dart

Issue 802703004: remove smoke from the repo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library smoke.test.codegen.recorder_test;
6
7 import 'package:analyzer/src/generated/element.dart';
8 import 'package:smoke/codegen/generator.dart';
9 import 'package:smoke/codegen/recorder.dart';
10 import 'package:unittest/unittest.dart';
11
12 import 'common.dart' show checkResults;
13 import 'testing_resolver_utils.dart' show initAnalyzer;
14
15 main() {
16 var provider = initAnalyzer(_SOURCES);
17 var generator;
18 var recorder;
19 setUp(() {
20 generator = new SmokeCodeGenerator();
21 recorder = new Recorder(generator, resolveImportUrl);
22 });
23
24 group('parents', () {
25 test('simple subclassing', () {
26 var lib = provider.libraryFor('/a.dart');
27 recorder.lookupParent(lib.getType('A'));
28 recorder.lookupParent(lib.getType('C'));
29
30 checkResults(generator,
31 imports: [
32 "import '/a.dart' as smoke_0;",
33 "import '/b.dart' as smoke_1;",
34 ],
35 initCall:
36 'useGeneratedCode(new StaticConfiguration(\n'
37 ' checkedMode: false,\n'
38 ' parents: {\n'
39 ' smoke_0.A: smoke_1.B,\n'
40 ' smoke_0.C: smoke_0.A,\n'
41 ' }));\n');
42 });
43
44 test('single mixin', () {
45 var lib = provider.libraryFor('/a.dart');
46 recorder.lookupParent(lib.getType('E'));
47
48 checkResults(generator,
49 imports: [
50 "import '/a.dart' as smoke_0;",
51 ],
52 topLevel: 'abstract class _M0 {} // A & D1\n',
53 initCall:
54 'useGeneratedCode(new StaticConfiguration(\n'
55 ' checkedMode: false,\n'
56 ' parents: {\n'
57 ' smoke_0.E: _M0,\n'
58 ' _M0: smoke_0.A,\n'
59 ' }));\n');
60 });
61
62 test('multiple mixins', () {
63 var lib = provider.libraryFor('/a.dart');
64 recorder.lookupParent(lib.getType('F'));
65
66 checkResults(generator,
67 imports: [
68 "import '/a.dart' as smoke_0;",
69 ],
70 topLevel:
71 'abstract class _M0 {} // A & D1\n'
72 'abstract class _M1 {} // _M0 & D2\n'
73 'abstract class _M2 {} // _M1 & D3\n',
74 initCall:
75 'useGeneratedCode(new StaticConfiguration(\n'
76 ' checkedMode: false,\n'
77 ' parents: {\n'
78 ' smoke_0.F: _M2,\n'
79 ' _M0: smoke_0.A,\n'
80 ' _M1: _M0,\n'
81 ' _M2: _M1,\n'
82 ' }));\n');
83 });
84
85 test('same as common_test', () {
86 var lib = provider.libraryFor('/common.dart');
87 recorder.lookupParent(lib.getType('Annot'));
88 recorder.lookupParent(lib.getType('AnnotB'));
89 recorder.lookupParent(lib.getType('A'));
90 recorder.lookupParent(lib.getType('B'));
91 recorder.lookupParent(lib.getType('C'));
92 recorder.lookupParent(lib.getType('D'));
93 recorder.lookupParent(lib.getType('E'));
94 recorder.lookupParent(lib.getType('E2'));
95 recorder.lookupParent(lib.getType('F'));
96 recorder.lookupParent(lib.getType('F2'));
97 recorder.lookupParent(lib.getType('G'));
98 recorder.lookupParent(lib.getType('H'));
99 var coreLib = lib.visibleLibraries.firstWhere(
100 (l) => l.displayName == 'dart.core');
101 recorder.lookupParent(coreLib.getType('int'));
102 recorder.lookupParent(coreLib.getType('num'));
103
104 checkResults(generator,
105 imports: [
106 "import '/common.dart' as smoke_0;",
107 ],
108 topLevel:
109 'abstract class _M0 {} // C & A\n',
110 initCall:
111 'useGeneratedCode(new StaticConfiguration(\n'
112 ' checkedMode: false,\n'
113 ' parents: {\n'
114 ' smoke_0.AnnotB: smoke_0.Annot,\n'
115 ' smoke_0.D: _M0,\n'
116 ' smoke_0.E2: smoke_0.E,\n'
117 ' smoke_0.F2: smoke_0.F,\n'
118 ' smoke_0.H: smoke_0.G,\n'
119 ' int: num,\n'
120 ' _M0: smoke_0.C,\n'
121 ' }));\n');
122 });
123 });
124
125 test('add static method, no declaration', () {
126 var lib = provider.libraryFor('/common.dart');
127 recorder.addStaticMethod(lib.getType('A'), 'sM');
128 checkResults(generator,
129 imports: [
130 "import '/common.dart' as smoke_0;",
131 ],
132 initCall:
133 'useGeneratedCode(new StaticConfiguration(\n'
134 ' checkedMode: false,\n'
135 ' staticMethods: {\n'
136 ' smoke_0.A: {\n'
137 ' #sM: smoke_0.A.sM,\n'
138 ' },\n'
139 ' }));\n');
140 });
141
142 group('lookup member', () {
143 var lib;
144 setUp(() {
145 lib = provider.libraryFor('/common.dart');
146 });
147
148 test('missing declaration', () {
149 recorder.lookupMember(lib.getType('A'), 'q', includeAccessors: false);
150 checkResults(generator,
151 imports: [
152 "import '/common.dart' as smoke_0;",
153 ],
154 initCall:
155 'useGeneratedCode(new StaticConfiguration(\n'
156 ' checkedMode: false,\n'
157 ' declarations: {\n'
158 ' smoke_0.A: {},\n'
159 ' }));\n');
160 });
161
162 test('field declaration', () {
163 recorder.lookupMember(lib.getType('A'), 'i', includeAccessors: false);
164 checkResults(generator,
165 imports: [
166 "import '/common.dart' as smoke_0;",
167 ],
168 initCall:
169 'useGeneratedCode(new StaticConfiguration(\n'
170 ' checkedMode: false,\n'
171 ' declarations: {\n'
172 ' smoke_0.A: {\n'
173 ' #i: const Declaration(#i, int),\n'
174 ' },\n'
175 ' }));\n');
176 });
177
178 test('sattic field declaration', () {
179 recorder.lookupMember(lib.getType('A'), 'sI', includeAccessors: false);
180 checkResults(generator,
181 imports: [
182 "import '/common.dart' as smoke_0;",
183 ],
184 initCall:
185 'useGeneratedCode(new StaticConfiguration(\n'
186 ' checkedMode: false,\n'
187 ' declarations: {\n'
188 ' smoke_0.A: {\n'
189 ' #sI: const Declaration(#sI, int, isStatic: true),\n'
190 ' },\n'
191 ' }));\n');
192 });
193
194 test('property declaration', () {
195 recorder.lookupMember(lib.getType('A'), 'j2', includeAccessors: false);
196 checkResults(generator,
197 imports: [
198 "import '/common.dart' as smoke_0;",
199 ],
200 initCall:
201 'useGeneratedCode(new StaticConfiguration(\n'
202 ' checkedMode: false,\n'
203 ' declarations: {\n'
204 ' smoke_0.A: {\n'
205 ' #j2: const Declaration(#j2, int, kind: PROPERTY),\n'
206 ' },\n'
207 ' }));\n');
208 });
209
210 test('static property declaration', () {
211 recorder.lookupMember(lib.getType('A'), 'sJ', includeAccessors: false);
212 final details = 'kind: PROPERTY, isFinal: true, isStatic: true';
213 checkResults(generator,
214 imports: [
215 "import '/common.dart' as smoke_0;",
216 ],
217 initCall:
218 'useGeneratedCode(new StaticConfiguration(\n'
219 ' checkedMode: false,\n'
220 ' declarations: {\n'
221 ' smoke_0.A: {\n'
222 ' #sJ: const Declaration(#sJ, int, $details),\n'
223 ' },\n'
224 ' }));\n');
225 });
226
227 test('field and property of dynamic type', () {
228 recorder.lookupMember(lib.getType('I'), 'i1', includeAccessors: false);
229 recorder.lookupMember(lib.getType('I'), 'i2', includeAccessors: false);
230 checkResults(generator,
231 imports: [
232 "import '/common.dart' as smoke_0;",
233 ],
234 initCall:
235 'useGeneratedCode(new StaticConfiguration(\n'
236 ' checkedMode: false,\n'
237 ' declarations: {\n'
238 ' smoke_0.I: {\n'
239 ' #i1: const Declaration(#i1, dynamic),\n'
240 ' #i2: const Declaration(#i2, dynamic, kind: PROPERTY),\n'
241 ' },\n'
242 ' }));\n');
243 });
244
245 test('property of concrete type', () {
246 recorder.lookupMember(lib.getType('I'), 'i3', includeAccessors: false);
247 checkResults(generator,
248 imports: [
249 "import '/common.dart' as smoke_0;",
250 ],
251 initCall:
252 'useGeneratedCode(new StaticConfiguration(\n'
253 ' checkedMode: false,\n'
254 ' declarations: {\n'
255 ' smoke_0.I: {\n'
256 ' #i3: const Declaration(#i3, smoke_0.G, kind: PROPERTY, '
257 'isFinal: true),\n'
258 ' },\n'
259 ' }));\n');
260 });
261
262 test('method declaration', () {
263 recorder.lookupMember(lib.getType('A'), 'inc0', includeAccessors: false);
264 checkResults(generator,
265 imports: [
266 "import '/common.dart' as smoke_0;",
267 ],
268 initCall:
269 'useGeneratedCode(new StaticConfiguration(\n'
270 ' checkedMode: false,\n'
271 ' declarations: {\n'
272 ' smoke_0.A: {\n'
273 ' #inc0: const Declaration(#inc0, Function, kind: METHOD),\n'
274 ' },\n'
275 ' }));\n');
276 });
277
278 test('static method declaration', () {
279 recorder.lookupMember(lib.getType('A'), 'sM', includeAccessors: false);
280 const details = 'kind: METHOD, isStatic: true';
281 checkResults(generator,
282 imports: [
283 "import '/common.dart' as smoke_0;",
284 ],
285 initCall:
286 'useGeneratedCode(new StaticConfiguration(\n'
287 ' checkedMode: false,\n'
288 ' declarations: {\n'
289 ' smoke_0.A: {\n'
290 ' #sM: const Declaration(#sM, Function, $details),\n'
291 ' },\n'
292 ' }));\n');
293 });
294
295 test('inherited field - not recursive', () {
296 recorder.lookupMember(lib.getType('D'), 'i', includeAccessors: false);
297 checkResults(generator,
298 imports: [
299 "import '/common.dart' as smoke_0;",
300 ],
301 initCall:
302 'useGeneratedCode(new StaticConfiguration(\n'
303 ' checkedMode: false,\n'
304 ' declarations: {\n'
305 ' smoke_0.D: {},\n'
306 ' }));\n');
307 });
308
309 test('inherited field - recursive', () {
310 recorder.lookupMember(lib.getType('D'), 'i', recursive: true,
311 includeAccessors: false);
312 checkResults(generator,
313 imports: [
314 "import '/common.dart' as smoke_0;",
315 ],
316 topLevel: 'abstract class _M0 {} // C & A\n',
317 initCall:
318 'useGeneratedCode(new StaticConfiguration(\n'
319 ' checkedMode: false,\n'
320 ' parents: {\n'
321 ' smoke_0.D: _M0,\n'
322 ' _M0: smoke_0.C,\n'
323 ' },\n'
324 ' declarations: {\n'
325 ' smoke_0.D: {},\n'
326 ' _M0: {\n'
327 ' #i: const Declaration(#i, int),\n'
328 ' },\n'
329 ' }));\n');
330 });
331
332 test('inherited field - recursive deep', () {
333 recorder.lookupMember(lib.getType('J3'), 'i', recursive: true,
334 includeAccessors: false);
335 checkResults(generator,
336 imports: [
337 "import '/common.dart' as smoke_0;",
338 ],
339 initCall:
340 'useGeneratedCode(new StaticConfiguration(\n'
341 ' checkedMode: false,\n'
342 ' parents: {\n'
343 ' smoke_0.J2: smoke_0.J1,\n'
344 ' smoke_0.J3: smoke_0.J2,\n'
345 ' },\n'
346 ' declarations: {\n'
347 ' smoke_0.J1: {\n'
348 ' #i: const Declaration(#i, int),\n'
349 ' },\n'
350 ' smoke_0.J2: {},\n'
351 ' smoke_0.J3: {},\n'
352 ' }));\n');
353 });
354
355 test('inherited field - recursive - includeUpTo', () {
356 recorder.lookupMember(lib.getType('J3'), 'i', recursive: true,
357 includeAccessors: false, includeUpTo: lib.getType('J1'));
358 checkResults(generator,
359 imports: [
360 "import '/common.dart' as smoke_0;",
361 ],
362 initCall:
363 'useGeneratedCode(new StaticConfiguration(\n'
364 ' checkedMode: false,\n'
365 ' parents: {\n'
366 ' smoke_0.J2: smoke_0.J1,\n'
367 ' smoke_0.J3: smoke_0.J2,\n'
368 ' },\n'
369 ' declarations: {\n'
370 ' smoke_0.J2: {},\n'
371 ' smoke_0.J3: {},\n'
372 ' }));\n');
373 });
374 });
375
376 group('query', () {
377 test('default query', () {
378 var options = new QueryOptions();
379 var lib = provider.libraryFor('/common.dart');
380 recorder.runQuery(lib.getType('A'), options, includeAccessors: false);
381 checkResults(generator,
382 imports: [
383 "import '/common.dart' as smoke_0;",
384 ],
385 initCall:
386 'useGeneratedCode(new StaticConfiguration(\n'
387 ' checkedMode: false,\n'
388 ' declarations: {\n'
389 ' smoke_0.A: {\n'
390 ' #i: const Declaration(#i, int),\n'
391 ' #j: const Declaration(#j, int),\n'
392 ' #j2: const Declaration(#j2, int, kind: PROPERTY),\n'
393 ' },\n'
394 ' }));\n');
395
396 });
397
398 test('only fields', () {
399 var options = new QueryOptions(includeProperties: false);
400 var lib = provider.libraryFor('/common.dart');
401 recorder.runQuery(lib.getType('A'), options, includeAccessors: false);
402 checkResults(generator,
403 imports: [
404 "import '/common.dart' as smoke_0;",
405 ],
406 initCall:
407 'useGeneratedCode(new StaticConfiguration(\n'
408 ' checkedMode: false,\n'
409 ' declarations: {\n'
410 ' smoke_0.A: {\n'
411 ' #i: const Declaration(#i, int),\n'
412 ' #j: const Declaration(#j, int),\n'
413 ' },\n'
414 ' }));\n');
415
416 });
417
418 test('only properties', () {
419 var options = new QueryOptions(includeFields: false);
420 var lib = provider.libraryFor('/common.dart');
421 recorder.runQuery(lib.getType('A'), options, includeAccessors: false);
422 checkResults(generator,
423 imports: [
424 "import '/common.dart' as smoke_0;",
425 ],
426 initCall:
427 'useGeneratedCode(new StaticConfiguration(\n'
428 ' checkedMode: false,\n'
429 ' declarations: {\n'
430 ' smoke_0.A: {\n'
431 ' #j2: const Declaration(#j2, int, kind: PROPERTY),\n'
432 ' },\n'
433 ' }));\n');
434
435 });
436
437 test('fields, properties, and and methods', () {
438 var options = new QueryOptions(includeMethods: true);
439 var lib = provider.libraryFor('/common.dart');
440 recorder.runQuery(lib.getType('A'), options, includeAccessors: false);
441 checkResults(generator,
442 imports: [
443 "import '/common.dart' as smoke_0;",
444 ],
445 initCall:
446 'useGeneratedCode(new StaticConfiguration(\n'
447 ' checkedMode: false,\n'
448 ' declarations: {\n'
449 ' smoke_0.A: {\n'
450 ' #i: const Declaration(#i, int),\n'
451 ' #inc0: const Declaration(#inc0, Function, kind: METHOD),\n'
452 ' #inc1: const Declaration(#inc1, Function, kind: METHOD),\n'
453 ' #inc2: const Declaration(#inc2, Function, kind: METHOD),\n'
454 ' #j: const Declaration(#j, int),\n'
455 ' #j2: const Declaration(#j2, int, kind: PROPERTY),\n'
456 ' },\n'
457 ' }));\n');
458 });
459
460 test('exclude inherited', () {
461 var options = new QueryOptions(includeInherited: false);
462 var lib = provider.libraryFor('/common.dart');
463 recorder.runQuery(lib.getType('D'), options, includeAccessors: false);
464 checkResults(generator,
465 imports: [
466 "import '/common.dart' as smoke_0;",
467 ],
468 initCall:
469 'useGeneratedCode(new StaticConfiguration(\n'
470 ' checkedMode: false,\n'
471 ' declarations: {\n'
472 ' smoke_0.D: {\n'
473 ' #i2: const Declaration(#i2, int, kind: PROPERTY, '
474 'isFinal: true),\n'
475 ' #x2: const Declaration(#x2, int, kind: PROPERTY, '
476 'isFinal: true),\n'
477 ' },\n'
478 ' }));\n');
479 });
480
481 test('include inherited', () {
482 var options = new QueryOptions(includeInherited: true);
483 var lib = provider.libraryFor('/common.dart');
484 recorder.runQuery(lib.getType('D'), options, includeAccessors: false);
485 checkResults(generator,
486 imports: [
487 "import '/common.dart' as smoke_0;",
488 ],
489 topLevel: 'abstract class _M0 {} // C & A\n',
490 initCall:
491 'useGeneratedCode(new StaticConfiguration(\n'
492 ' checkedMode: false,\n'
493 ' parents: {\n'
494 ' smoke_0.D: _M0,\n'
495 ' _M0: smoke_0.C,\n'
496 ' },\n'
497 ' declarations: {\n'
498 ' smoke_0.C: {\n'
499 ' #b: const Declaration(#b, smoke_0.B),\n'
500 ' #x: const Declaration(#x, int),\n'
501 ' #y: const Declaration(#y, String),\n'
502 ' },\n'
503 ' smoke_0.D: {\n'
504 ' #i2: const Declaration(#i2, int, kind: PROPERTY, '
505 'isFinal: true),\n'
506 ' #x2: const Declaration(#x2, int, kind: PROPERTY, '
507 'isFinal: true),\n'
508 ' },\n'
509 ' _M0: {\n'
510 ' #i: const Declaration(#i, int),\n'
511 ' #j: const Declaration(#j, int),\n'
512 ' #j2: const Declaration(#j2, int, kind: PROPERTY),\n'
513 ' },\n'
514 ' }));\n');
515 });
516
517 test('exact annotation', () {
518 var lib = provider.libraryFor('/common.dart');
519 var vars = lib.definingCompilationUnit.topLevelVariables;
520 expect(vars[0].name, 'a1');
521 var options = new QueryOptions(includeInherited: true,
522 withAnnotations: [vars[0]]);
523 recorder.runQuery(lib.getType('H'), options, includeAccessors: false);
524 final annot = 'annotations: const [smoke_0.a1]';
525 checkResults(generator,
526 imports: [
527 "import '/common.dart' as smoke_0;",
528 ],
529 initCall:
530 'useGeneratedCode(new StaticConfiguration(\n'
531 ' checkedMode: false,\n'
532 ' parents: {\n'
533 ' smoke_0.H: smoke_0.G,\n'
534 ' },\n'
535 ' declarations: {\n'
536 ' smoke_0.G: {\n'
537 ' #b: const Declaration(#b, int, $annot),\n'
538 ' },\n'
539 ' smoke_0.H: {\n'
540 ' #f: const Declaration(#f, int, $annot),\n'
541 ' #g: const Declaration(#g, int, $annot),\n'
542 ' },\n'
543 ' }));\n');
544 });
545
546 test('type annotation', () {
547 var lib = provider.libraryFor('/common.dart');
548 var options = new QueryOptions(includeInherited: true,
549 withAnnotations: [lib.getType('Annot')]);
550 recorder.runQuery(lib.getType('H'), options, includeAccessors: false);
551 final a1Annot = 'annotations: const [smoke_0.a1]';
552 final a3Annot = 'annotations: const [smoke_0.a3]';
553 final exprAnnot = 'annotations: const [const smoke_0.Annot(1)]';
554 checkResults(generator,
555 imports: [
556 "import '/common.dart' as smoke_0;",
557 ],
558 initCall:
559 'useGeneratedCode(new StaticConfiguration(\n'
560 ' checkedMode: false,\n'
561 ' parents: {\n'
562 ' smoke_0.H: smoke_0.G,\n'
563 ' },\n'
564 ' declarations: {\n'
565 ' smoke_0.G: {\n'
566 ' #b: const Declaration(#b, int, $a1Annot),\n'
567 ' },\n'
568 ' smoke_0.H: {\n'
569 ' #f: const Declaration(#f, int, $a1Annot),\n'
570 ' #g: const Declaration(#g, int, $a1Annot),\n'
571 ' #i: const Declaration(#i, int, $a3Annot),\n'
572 ' #j: const Declaration(#j, int, $exprAnnot),\n'
573 ' },\n'
574 ' }));\n');
575 });
576
577 test('type annotation with named arguments', () {
578 var lib = provider.libraryFor('/common.dart');
579 var options = new QueryOptions(includeInherited: true,
580 withAnnotations: [lib.getType('AnnotC')]);
581 recorder.runQuery(lib.getType('K'), options, includeAccessors: false);
582 final kAnnot = 'annotations: const [const smoke_0.AnnotC(named: true)]';
583 final k2Annot = 'annotations: const [const smoke_0.AnnotC()]';
584 checkResults(generator,
585 imports: [
586 "import '/common.dart' as smoke_0;",
587 ],
588 initCall:
589 'useGeneratedCode(new StaticConfiguration(\n'
590 ' checkedMode: false,\n'
591 ' declarations: {\n'
592 ' smoke_0.K: {\n'
593 ' #k: const Declaration(#k, int, $kAnnot),\n'
594 ' #k2: const Declaration(#k2, int, $k2Annot),\n'
595 ' },\n'
596 ' }));\n');
597 });
598 });
599
600 group('with accessors', () {
601 test('lookup member', () {
602 var lib = provider.libraryFor('/common.dart');
603 recorder.lookupMember(lib.getType('I'), 'i1');
604 recorder.lookupMember(lib.getType('I'), 'i2');
605 recorder.lookupMember(lib.getType('I'), 'i3');
606 recorder.lookupMember(lib.getType('I'), 'm4');
607 checkResults(generator,
608 imports: [
609 "import '/common.dart' as smoke_0;",
610 ],
611 initCall:
612 'useGeneratedCode(new StaticConfiguration(\n'
613 ' checkedMode: false,\n'
614 ' getters: {\n'
615 ' #i1: (o) => o.i1,\n'
616 ' #i2: (o) => o.i2,\n'
617 ' #i3: (o) => o.i3,\n'
618 ' #m4: (o) => o.m4,\n'
619 ' },\n'
620 ' setters: {\n' // #i3 is final
621 ' #i1: (o, v) { o.i1 = v; },\n'
622 ' #i2: (o, v) { o.i2 = v; },\n'
623 ' },\n'
624 ' declarations: {\n'
625 ' smoke_0.I: {\n'
626 ' #i1: const Declaration(#i1, dynamic),\n'
627 ' #i2: const Declaration(#i2, dynamic, kind: PROPERTY),\n'
628 ' #i3: const Declaration(#i3, smoke_0.G, kind: PROPERTY, '
629 'isFinal: true),\n'
630 ' #m4: const Declaration(#m4, Function, kind: METHOD),\n'
631 ' },\n'
632 ' },\n'
633 ' names: {\n'
634 ' #i1: r\'i1\',\n'
635 ' #i2: r\'i2\',\n'
636 ' #i3: r\'i3\',\n'
637 ' #m4: r\'m4\',\n'
638 ' }));\n');
639 });
640
641 test('static members', () {
642 var lib = provider.libraryFor('/common.dart');
643 recorder.lookupMember(lib.getType('A'), 'sI');
644 recorder.lookupMember(lib.getType('A'), 'sJ');
645 recorder.lookupMember(lib.getType('A'), 'sM');
646 final pDetails = 'kind: PROPERTY, isFinal: true, isStatic: true';
647 const mDetails = 'kind: METHOD, isStatic: true';
648 checkResults(generator,
649 imports: [
650 "import '/common.dart' as smoke_0;",
651 ],
652 initCall:
653 'useGeneratedCode(new StaticConfiguration(\n'
654 ' checkedMode: false,\n'
655 ' declarations: {\n'
656 ' smoke_0.A: {\n'
657 ' #sI: const Declaration(#sI, int, isStatic: true),\n'
658 ' #sJ: const Declaration(#sJ, int, $pDetails),\n'
659 ' #sM: const Declaration(#sM, Function, $mDetails),\n'
660 ' },\n'
661 ' },\n'
662 ' staticMethods: {\n'
663 ' smoke_0.A: {\n'
664 ' #sM: smoke_0.A.sM,\n'
665 ' },\n'
666 ' },\n'
667 ' names: {\n'
668 ' #sM: r\'sM\',\n'
669 ' }));\n');
670 });
671
672 test('query', () {
673 var lib = provider.libraryFor('/common.dart');
674 var options = new QueryOptions(includeInherited: true,
675 withAnnotations: [lib.getType('Annot')]);
676 recorder.runQuery(lib.getType('H'), options);
677 final a1Annot = 'annotations: const [smoke_0.a1]';
678 final a3Annot = 'annotations: const [smoke_0.a3]';
679 final exprAnnot = 'annotations: const [const smoke_0.Annot(1)]';
680 checkResults(generator,
681 imports: [
682 "import '/common.dart' as smoke_0;",
683 ],
684 initCall:
685 'useGeneratedCode(new StaticConfiguration(\n'
686 ' checkedMode: false,\n'
687 ' getters: {\n'
688 ' #b: (o) => o.b,\n'
689 ' #f: (o) => o.f,\n'
690 ' #g: (o) => o.g,\n'
691 ' #i: (o) => o.i,\n'
692 ' #j: (o) => o.j,\n'
693 ' },\n'
694 ' setters: {\n' // #i3 is final
695 ' #b: (o, v) { o.b = v; },\n'
696 ' #f: (o, v) { o.f = v; },\n'
697 ' #g: (o, v) { o.g = v; },\n'
698 ' #i: (o, v) { o.i = v; },\n'
699 ' #j: (o, v) { o.j = v; },\n'
700 ' },\n'
701 ' parents: {\n'
702 ' smoke_0.H: smoke_0.G,\n'
703 ' },\n'
704 ' declarations: {\n'
705 ' smoke_0.G: {\n'
706 ' #b: const Declaration(#b, int, $a1Annot),\n'
707 ' },\n'
708 ' smoke_0.H: {\n'
709 ' #f: const Declaration(#f, int, $a1Annot),\n'
710 ' #g: const Declaration(#g, int, $a1Annot),\n'
711 ' #i: const Declaration(#i, int, $a3Annot),\n'
712 ' #j: const Declaration(#j, int, $exprAnnot),\n'
713 ' },\n'
714 ' },\n'
715 ' names: {\n'
716 ' #b: r\'b\',\n'
717 ' #f: r\'f\',\n'
718 ' #g: r\'g\',\n'
719 ' #i: r\'i\',\n'
720 ' #j: r\'j\',\n'
721 ' }));\n');
722 });
723 });
724 }
725
726 const _SOURCES = const {
727 '/a.dart': '''
728 library a;
729 import '/b.dart';
730
731 class Annot { const Annot(); }
732 const annot = const Annot();
733
734 class A extends B {}
735 class C extends A {}
736 class D1 {
737 int d1;
738 }
739 class D2 {
740 int d2;
741 }
742 class D3 {
743 int d3;
744 }
745 class E extends A with D1 {
746 int e1;
747 }
748 class F extends A with D1, D2, D3 {
749 int f1;
750 }
751 ''',
752
753 '/b.dart': '''
754 library b;
755
756 class B {}
757 ''',
758 '/common.dart': '''
759 library common;
760
761 class A {
762 int i = 42;
763 int j = 44;
764 int get j2 => j;
765 void set j2(int v) { j = v; }
766 void inc0() { i++; }
767 void inc1(int v) { i = i + (v == null ? -10 : v); }
768 void inc2([int v]) { i = i + (v == null ? -10 : v); }
769 static int sI;
770 static int get sJ => 0;
771 static void sM() {}
772 }
773
774 class B {
775 final int f = 3;
776 int _w;
777 int get w => _w;
778 set w(int v) { _w = v; }
779
780 String z;
781 A a;
782
783 B(this._w, this.z, this.a);
784 }
785
786 class C {
787 int x;
788 String y;
789 B b;
790
791 inc(int n) {
792 x = x + n;
793 }
794 dec(int n) {
795 x = x - n;
796 }
797
798 C(this.x, this.y, this.b);
799 }
800
801
802 class D extends C with A {
803 int get x2 => x;
804 int get i2 => i;
805
806 D(x, y, b) : super(x, y, b);
807 }
808
809 class E {
810 set x(int v) { }
811 int get y => 1;
812
813 noSuchMethod(i) => y;
814 }
815
816 class E2 extends E {}
817
818 class F {
819 static int staticMethod(A a) => a.i;
820 }
821
822 class F2 extends F {}
823
824 class Annot { const Annot(int ignore); }
825 class AnnotB extends Annot { const AnnotB(); }
826 class AnnotC { const AnnotC({bool named: false}); }
827 const a1 = const Annot(0);
828 const a2 = 32;
829 const a3 = const AnnotB();
830
831
832 class G {
833 int a;
834 @a1 int b;
835 int c;
836 @a2 int d;
837 }
838
839 class H extends G {
840 int e;
841 @a1 int f;
842 @a1 int g;
843 @a2 int h;
844 @a3 int i;
845 @Annot(1) int j;
846 }
847
848 class I {
849 dynamic i1;
850 get i2 => null;
851 set i2(v) {}
852 G get i3;
853 G m4() {};
854 }
855
856 class J1 {
857 int i;
858 }
859 class J2 extends J1 {
860 }
861 class J3 extends J2 {
862 }
863
864 class K {
865 @AnnotC(named: true) int k;
866 @AnnotC() int k2;
867 }
868 '''
869 };
870
871 resolveImportUrl(LibraryElement lib) =>
872 lib.isDartCore ? 'dart:core' : '/${lib.displayName}.dart';
OLDNEW
« no previous file with comments | « pkg/smoke/test/codegen/generator_test.dart ('k') | pkg/smoke/test/codegen/testing_resolver_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698