OLD | NEW |
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 library smoke.test.codegen.recorder_test; | 5 library smoke.test.codegen.recorder_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
8 import 'package:smoke/codegen/generator.dart'; | 8 import 'package:smoke/codegen/generator.dart'; |
9 import 'package:smoke/codegen/recorder.dart'; | 9 import 'package:smoke/codegen/recorder.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 ' smoke_0.D: _M0,\n' | 115 ' smoke_0.D: _M0,\n' |
116 ' smoke_0.E2: smoke_0.E,\n' | 116 ' smoke_0.E2: smoke_0.E,\n' |
117 ' smoke_0.F2: smoke_0.F,\n' | 117 ' smoke_0.F2: smoke_0.F,\n' |
118 ' smoke_0.H: smoke_0.G,\n' | 118 ' smoke_0.H: smoke_0.G,\n' |
119 ' int: num,\n' | 119 ' int: num,\n' |
120 ' _M0: smoke_0.C,\n' | 120 ' _M0: smoke_0.C,\n' |
121 ' }));\n'); | 121 ' }));\n'); |
122 }); | 122 }); |
123 }); | 123 }); |
124 | 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 |
125 group('lookup member', () { | 142 group('lookup member', () { |
126 var lib; | 143 var lib; |
127 setUp(() { | 144 setUp(() { |
128 lib = provider.libraryFor('/common.dart'); | 145 lib = provider.libraryFor('/common.dart'); |
129 }); | 146 }); |
130 | 147 |
131 test('missing declaration', () { | 148 test('missing declaration', () { |
132 recorder.lookupMember(lib.getType('A'), 'q', includeAccessors: false); | 149 recorder.lookupMember(lib.getType('A'), 'q', includeAccessors: false); |
133 checkResults(generator, | 150 checkResults(generator, |
134 imports: [ | 151 imports: [ |
(...skipping 16 matching lines...) Expand all Loading... |
151 initCall: | 168 initCall: |
152 'useGeneratedCode(new StaticConfiguration(\n' | 169 'useGeneratedCode(new StaticConfiguration(\n' |
153 ' checkedMode: false,\n' | 170 ' checkedMode: false,\n' |
154 ' declarations: {\n' | 171 ' declarations: {\n' |
155 ' smoke_0.A: {\n' | 172 ' smoke_0.A: {\n' |
156 ' #i: const Declaration(#i, int),\n' | 173 ' #i: const Declaration(#i, int),\n' |
157 ' },\n' | 174 ' },\n' |
158 ' }));\n'); | 175 ' }));\n'); |
159 }); | 176 }); |
160 | 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 |
161 test('property declaration', () { | 194 test('property declaration', () { |
162 recorder.lookupMember(lib.getType('A'), 'j2', includeAccessors: false); | 195 recorder.lookupMember(lib.getType('A'), 'j2', includeAccessors: false); |
163 checkResults(generator, | 196 checkResults(generator, |
164 imports: [ | 197 imports: [ |
165 "import '/common.dart' as smoke_0;", | 198 "import '/common.dart' as smoke_0;", |
166 ], | 199 ], |
167 initCall: | 200 initCall: |
168 'useGeneratedCode(new StaticConfiguration(\n' | 201 'useGeneratedCode(new StaticConfiguration(\n' |
169 ' checkedMode: false,\n' | 202 ' checkedMode: false,\n' |
170 ' declarations: {\n' | 203 ' declarations: {\n' |
171 ' smoke_0.A: {\n' | 204 ' smoke_0.A: {\n' |
172 ' #j2: const Declaration(#j2, int, kind: PROPERTY),\n' | 205 ' #j2: const Declaration(#j2, int, kind: PROPERTY),\n' |
173 ' },\n' | 206 ' },\n' |
174 ' }));\n'); | 207 ' }));\n'); |
175 }); | 208 }); |
176 | 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 |
177 test('field and property of dynamic type', () { | 227 test('field and property of dynamic type', () { |
178 recorder.lookupMember(lib.getType('I'), 'i1', includeAccessors: false); | 228 recorder.lookupMember(lib.getType('I'), 'i1', includeAccessors: false); |
179 recorder.lookupMember(lib.getType('I'), 'i2', includeAccessors: false); | 229 recorder.lookupMember(lib.getType('I'), 'i2', includeAccessors: false); |
180 checkResults(generator, | 230 checkResults(generator, |
181 imports: [ | 231 imports: [ |
182 "import '/common.dart' as smoke_0;", | 232 "import '/common.dart' as smoke_0;", |
183 ], | 233 ], |
184 initCall: | 234 initCall: |
185 'useGeneratedCode(new StaticConfiguration(\n' | 235 'useGeneratedCode(new StaticConfiguration(\n' |
186 ' checkedMode: false,\n' | 236 ' checkedMode: false,\n' |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 initCall: | 268 initCall: |
219 'useGeneratedCode(new StaticConfiguration(\n' | 269 'useGeneratedCode(new StaticConfiguration(\n' |
220 ' checkedMode: false,\n' | 270 ' checkedMode: false,\n' |
221 ' declarations: {\n' | 271 ' declarations: {\n' |
222 ' smoke_0.A: {\n' | 272 ' smoke_0.A: {\n' |
223 ' #inc0: const Declaration(#inc0, Function, kind: METHOD),\n' | 273 ' #inc0: const Declaration(#inc0, Function, kind: METHOD),\n' |
224 ' },\n' | 274 ' },\n' |
225 ' }));\n'); | 275 ' }));\n'); |
226 }); | 276 }); |
227 | 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 |
228 test('inherited field - not recursive', () { | 295 test('inherited field - not recursive', () { |
229 recorder.lookupMember(lib.getType('D'), 'i', includeAccessors: false); | 296 recorder.lookupMember(lib.getType('D'), 'i', includeAccessors: false); |
230 checkResults(generator, | 297 checkResults(generator, |
231 imports: [ | 298 imports: [ |
232 "import '/common.dart' as smoke_0;", | 299 "import '/common.dart' as smoke_0;", |
233 ], | 300 ], |
234 initCall: | 301 initCall: |
235 'useGeneratedCode(new StaticConfiguration(\n' | 302 'useGeneratedCode(new StaticConfiguration(\n' |
236 ' checkedMode: false,\n' | 303 ' checkedMode: false,\n' |
237 ' declarations: {\n' | 304 ' declarations: {\n' |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 ' }));\n'); | 531 ' }));\n'); |
465 }); | 532 }); |
466 }); | 533 }); |
467 | 534 |
468 group('with accessors', () { | 535 group('with accessors', () { |
469 test('lookup member', () { | 536 test('lookup member', () { |
470 var lib = provider.libraryFor('/common.dart'); | 537 var lib = provider.libraryFor('/common.dart'); |
471 recorder.lookupMember(lib.getType('I'), 'i1'); | 538 recorder.lookupMember(lib.getType('I'), 'i1'); |
472 recorder.lookupMember(lib.getType('I'), 'i2'); | 539 recorder.lookupMember(lib.getType('I'), 'i2'); |
473 recorder.lookupMember(lib.getType('I'), 'i3'); | 540 recorder.lookupMember(lib.getType('I'), 'i3'); |
| 541 recorder.lookupMember(lib.getType('I'), 'm4'); |
474 checkResults(generator, | 542 checkResults(generator, |
475 imports: [ | 543 imports: [ |
476 "import '/common.dart' as smoke_0;", | 544 "import '/common.dart' as smoke_0;", |
477 ], | 545 ], |
478 initCall: | 546 initCall: |
479 'useGeneratedCode(new StaticConfiguration(\n' | 547 'useGeneratedCode(new StaticConfiguration(\n' |
480 ' checkedMode: false,\n' | 548 ' checkedMode: false,\n' |
481 ' getters: {\n' | 549 ' getters: {\n' |
482 ' #i1: (o) => o.i1,\n' | 550 ' #i1: (o) => o.i1,\n' |
483 ' #i2: (o) => o.i2,\n' | 551 ' #i2: (o) => o.i2,\n' |
484 ' #i3: (o) => o.i3,\n' | 552 ' #i3: (o) => o.i3,\n' |
| 553 ' #m4: (o) => o.m4,\n' |
485 ' },\n' | 554 ' },\n' |
486 ' setters: {\n' // #i3 is final | 555 ' setters: {\n' // #i3 is final |
487 ' #i1: (o, v) { o.i1 = v; },\n' | 556 ' #i1: (o, v) { o.i1 = v; },\n' |
488 ' #i2: (o, v) { o.i2 = v; },\n' | 557 ' #i2: (o, v) { o.i2 = v; },\n' |
489 ' },\n' | 558 ' },\n' |
490 ' declarations: {\n' | 559 ' declarations: {\n' |
491 ' smoke_0.I: {\n' | 560 ' smoke_0.I: {\n' |
492 ' #i1: const Declaration(#i1, dynamic),\n' | 561 ' #i1: const Declaration(#i1, dynamic),\n' |
493 ' #i2: const Declaration(#i2, dynamic, kind: PROPERTY),\n' | 562 ' #i2: const Declaration(#i2, dynamic, kind: PROPERTY),\n' |
494 ' #i3: const Declaration(#i3, smoke_0.G, kind: PROPERTY, ' | 563 ' #i3: const Declaration(#i3, smoke_0.G, kind: PROPERTY, ' |
495 'isFinal: true),\n' | 564 'isFinal: true),\n' |
| 565 ' #m4: const Declaration(#m4, Function, kind: METHOD),\n' |
496 ' },\n' | 566 ' },\n' |
497 ' },\n' | 567 ' },\n' |
498 ' names: {\n' | 568 ' names: {\n' |
499 ' #i1: \'i1\',\n' | 569 ' #i1: r\'i1\',\n' |
500 ' #i2: \'i2\',\n' | 570 ' #i2: r\'i2\',\n' |
501 ' #i3: \'i3\',\n' | 571 ' #i3: r\'i3\',\n' |
| 572 ' #m4: r\'m4\',\n' |
502 ' }));\n'); | 573 ' }));\n'); |
503 }); | 574 }); |
504 | 575 |
| 576 test('static members', () { |
| 577 var lib = provider.libraryFor('/common.dart'); |
| 578 recorder.lookupMember(lib.getType('A'), 'sI'); |
| 579 recorder.lookupMember(lib.getType('A'), 'sJ'); |
| 580 recorder.lookupMember(lib.getType('A'), 'sM'); |
| 581 final pDetails = 'kind: PROPERTY, isFinal: true, isStatic: true'; |
| 582 const mDetails = 'kind: METHOD, isStatic: true'; |
| 583 checkResults(generator, |
| 584 imports: [ |
| 585 "import '/common.dart' as smoke_0;", |
| 586 ], |
| 587 initCall: |
| 588 'useGeneratedCode(new StaticConfiguration(\n' |
| 589 ' checkedMode: false,\n' |
| 590 ' declarations: {\n' |
| 591 ' smoke_0.A: {\n' |
| 592 ' #sI: const Declaration(#sI, int, isStatic: true),\n' |
| 593 ' #sJ: const Declaration(#sJ, int, $pDetails),\n' |
| 594 ' #sM: const Declaration(#sM, Function, $mDetails),\n' |
| 595 ' },\n' |
| 596 ' },\n' |
| 597 ' staticMethods: {\n' |
| 598 ' smoke_0.A: {\n' |
| 599 ' #sM: smoke_0.A.sM,\n' |
| 600 ' },\n' |
| 601 ' },\n' |
| 602 ' names: {\n' |
| 603 ' #sM: r\'sM\',\n' |
| 604 ' }));\n'); |
| 605 }); |
| 606 |
505 test('query', () { | 607 test('query', () { |
506 var lib = provider.libraryFor('/common.dart'); | 608 var lib = provider.libraryFor('/common.dart'); |
507 var options = new QueryOptions(includeInherited: true, | 609 var options = new QueryOptions(includeInherited: true, |
508 withAnnotations: [lib.getType('Annot')]); | 610 withAnnotations: [lib.getType('Annot')]); |
509 recorder.runQuery(lib.getType('H'), options); | 611 recorder.runQuery(lib.getType('H'), options); |
510 final a1Annot = 'annotations: const [smoke_0.a1]'; | 612 final a1Annot = 'annotations: const [smoke_0.a1]'; |
511 final a3Annot = 'annotations: const [smoke_0.a3]'; | 613 final a3Annot = 'annotations: const [smoke_0.a3]'; |
512 final exprAnnot = 'annotations: const [const smoke_0.Annot(1)]'; | 614 final exprAnnot = 'annotations: const [const smoke_0.Annot(1)]'; |
513 checkResults(generator, | 615 checkResults(generator, |
514 imports: [ | 616 imports: [ |
(...skipping 24 matching lines...) Expand all Loading... |
539 ' #b: const Declaration(#b, int, $a1Annot),\n' | 641 ' #b: const Declaration(#b, int, $a1Annot),\n' |
540 ' },\n' | 642 ' },\n' |
541 ' smoke_0.H: {\n' | 643 ' smoke_0.H: {\n' |
542 ' #f: const Declaration(#f, int, $a1Annot),\n' | 644 ' #f: const Declaration(#f, int, $a1Annot),\n' |
543 ' #g: const Declaration(#g, int, $a1Annot),\n' | 645 ' #g: const Declaration(#g, int, $a1Annot),\n' |
544 ' #i: const Declaration(#i, int, $a3Annot),\n' | 646 ' #i: const Declaration(#i, int, $a3Annot),\n' |
545 ' #j: const Declaration(#j, int, $exprAnnot),\n' | 647 ' #j: const Declaration(#j, int, $exprAnnot),\n' |
546 ' },\n' | 648 ' },\n' |
547 ' },\n' | 649 ' },\n' |
548 ' names: {\n' | 650 ' names: {\n' |
549 ' #b: \'b\',\n' | 651 ' #b: r\'b\',\n' |
550 ' #f: \'f\',\n' | 652 ' #f: r\'f\',\n' |
551 ' #g: \'g\',\n' | 653 ' #g: r\'g\',\n' |
552 ' #i: \'i\',\n' | 654 ' #i: r\'i\',\n' |
553 ' #j: \'j\',\n' | 655 ' #j: r\'j\',\n' |
554 ' }));\n'); | 656 ' }));\n'); |
555 }); | 657 }); |
556 }); | 658 }); |
557 } | 659 } |
558 | 660 |
559 const _SOURCES = const { | 661 const _SOURCES = const { |
560 '/a.dart': ''' | 662 '/a.dart': ''' |
561 library a; | 663 library a; |
562 import '/b.dart'; | 664 import '/b.dart'; |
563 | 665 |
(...skipping 28 matching lines...) Expand all Loading... |
592 library common; | 694 library common; |
593 | 695 |
594 class A { | 696 class A { |
595 int i = 42; | 697 int i = 42; |
596 int j = 44; | 698 int j = 44; |
597 int get j2 => j; | 699 int get j2 => j; |
598 void set j2(int v) { j = v; } | 700 void set j2(int v) { j = v; } |
599 void inc0() { i++; } | 701 void inc0() { i++; } |
600 void inc1(int v) { i = i + (v == null ? -10 : v); } | 702 void inc1(int v) { i = i + (v == null ? -10 : v); } |
601 void inc2([int v]) { i = i + (v == null ? -10 : v); } | 703 void inc2([int v]) { i = i + (v == null ? -10 : v); } |
| 704 static int sI; |
| 705 static int get sJ => 0; |
| 706 static void sM() {} |
602 } | 707 } |
603 | 708 |
604 class B { | 709 class B { |
605 final int f = 3; | 710 final int f = 3; |
606 int _w; | 711 int _w; |
607 int get w => _w; | 712 int get w => _w; |
608 set w(int v) { _w = v; } | 713 set w(int v) { _w = v; } |
609 | 714 |
610 String z; | 715 String z; |
611 A a; | 716 A a; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 @a2 int h; | 777 @a2 int h; |
673 @a3 int i; | 778 @a3 int i; |
674 @Annot(1) int j; | 779 @Annot(1) int j; |
675 } | 780 } |
676 | 781 |
677 class I { | 782 class I { |
678 dynamic i1; | 783 dynamic i1; |
679 get i2 => null; | 784 get i2 => null; |
680 set i2(v) {} | 785 set i2(v) {} |
681 G get i3; | 786 G get i3; |
| 787 G m4() {}; |
682 } | 788 } |
683 ''' | 789 ''' |
684 }; | 790 }; |
685 | 791 |
686 resolveImportUrl(LibraryElement lib) => | 792 resolveImportUrl(LibraryElement lib) => |
687 lib.isDartCore ? 'dart:core' : '/${lib.displayName}.dart'; | 793 lib.isDartCore ? 'dart:core' : '/${lib.displayName}.dart'; |
OLD | NEW |