-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcodegen_test.dart
More file actions
1244 lines (1045 loc) · 63.7 KB
/
codegen_test.dart
File metadata and controls
1244 lines (1045 loc) · 63.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016 Workiva Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
@TestOn('vm')
library impl_generation_test;
import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:mocktail/mocktail.dart';
import 'package:over_react/src/builder/parsing.dart';
import 'package:over_react/src/builder/codegen.dart';
import 'package:source_span/source_span.dart';
import 'package:test/test.dart';
import './util.dart';
main() {
group('ImplGenerator', () {
ImplGenerator? implGenerator;
late MockLogger logger;
late SourceFile sourceFile;
CompilationUnit unit;
late List<BoilerplateDeclaration> declarations;
tearDown(() {
implGenerator = null;
});
void setUpAndParse(String source) {
logger = MockLogger();
sourceFile = SourceFile.fromString(source);
unit = parseString(content: source).unit;
final errorCollector = ErrorCollector.log(sourceFile, logger);
declarations = parseAndValidateDeclarations(unit, errorCollector);
// FIXME(null-safety) add tests for both cases FED-1720
implGenerator = ImplGenerator(logger, sourceFile, nullSafety: false);
}
void setUpAndGenerate(String source) {
setUpAndParse(source);
// FIXME(null-safety) add tests for both cases FED-1720
implGenerator = ImplGenerator(logger, sourceFile, nullSafety: false);
declarations.forEach(implGenerator!.generate);
}
void verifyNoErrorLogs() {
verifyNever(() => logger.warning(any()));
verifyNever(() => logger.severe(any()));
}
void verifyImplGenerationIsValid() {
var buildOutput = implGenerator!.outputContentsBuffer.toString();
final result = parseString(content: buildOutput, throwIfDiagnostics: false);
expect(result.errors, isEmpty, reason: 'transformed source should parse without errors:\n');
}
void generateFromSource(String source) {
setUpAndParse(source);
declarations.forEach(implGenerator!.generate);
}
group('generates an implementation that parses correctly', () {
tearDown(() {
// Verify that there were no errors other than the ones we explicitly verified.
verifyNoErrorLogs();
verifyImplGenerationIsValid();
});
void testImplGeneration(String groupName, {bool backwardsCompatible = true}) {
group(groupName, () {
test('stateful components', () {
generateFromSource(OverReactSrc.state(backwardsCompatible: backwardsCompatible).source);
});
test('component', () {
generateFromSource(OverReactSrc.props(backwardsCompatible: backwardsCompatible).source);
});
group('that subtypes another component, referencing the component class via', () {
test('a simple identifier', () {
generateFromSource(OverReactSrc.props(backwardsCompatible: backwardsCompatible, componentAnnotationArg: 'subtypeOf: BarComponent').source);
expect(implGenerator!.outputContentsBuffer.toString(), contains('parentType: \$BarComponentFactory'));
});
test('a prefixed identifier', () {
generateFromSource(OverReactSrc.props(backwardsCompatible: backwardsCompatible, componentAnnotationArg: 'subtypeOf: baz.BarComponent').source);
expect(implGenerator!.outputContentsBuffer.toString(), contains('parentType: baz.\$BarComponentFactory'));
});
});
group('and includes concrete accessors class for', () {
void testAccessorGeneration(String testName, OverReactSrc ors) {
group(testName, () {
late bool isProps;
late String className;
late String descriptorType;
setUp(() {
generateFromSource(ors.source);
isProps = ors.isProps(ors.annotation);
className = isProps ? ors.propsClassName : ors.stateClassName;
descriptorType = '${isProps ? 'Prop' : 'State'}Descriptor';
});
test('with proper accessors mixin declaration, retaining type parameters', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
'mixin _\$${className}AccessorsMixin${ors.typeParamSrc} '
'implements _\$$className${ors.typeParamSrcWithoutBounds} {'));
});
test('with abstract props/state getter', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains('@override Map get ${isProps ? 'props' : 'state'};'));
});
test('contains props or state descriptors for all fields', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' static const $descriptorType _\$prop__someField___\$$className = $descriptorType(_\$key__someField___\$$className);\n'
' static const $descriptorType _\$prop__foo___\$$className = $descriptorType(_\$key__foo___\$$className);\n'
' static const $descriptorType _\$prop__bar___\$$className = $descriptorType(_\$key__bar___\$$className);\n'
' static const $descriptorType _\$prop__baz___\$$className = $descriptorType(_\$key__baz___\$$className);\n'));
});
test('contains string keys', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' static const String _\$key__someField___\$$className = \'$className.someField\';\n'
' static const String _\$key__foo___\$$className = \'$className.foo\';\n'
' static const String _\$key__bar___\$$className = \'$className.bar\';\n'
' static const String _\$key__baz___\$$className = \'$className.baz\';\n'));
});
test('contains list of descriptors', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' static const List<$descriptorType> ${ors.constantListName} = '
'[_\$prop__someField___\$$className, '
'_\$prop__foo___\$$className, '
'_\$prop__bar___\$$className, '
'_\$prop__baz___\$$className];\n'));
});
test('contains list of keys', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' static const List<String> ${ors.keyListName} = '
'[_\$key__someField___\$$className, '
'_\$key__foo___\$$className, '
'_\$key__bar___\$$className, '
'_\$key__baz___\$$className];\n'));
});
group('with concrete implementations', () {
test('', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(' String get someField => (${isProps ? 'props' : 'state'}[_\$key__someField___\$$className] ?? null) as String;'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' set someField(String value) => ${isProps ? 'props' : 'state'}[_\$key__someField___\$$className] = value'));
});
test('for multiple fields declared on same line', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(' bool get foo => (${isProps ? 'props' : 'state'}[_\$key__foo___\$$className] ?? null) as bool;'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' set foo(bool value) => ${isProps ? 'props' : 'state'}[_\$key__foo___\$$className] = value'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' bool get bar => (${isProps ? 'props' : 'state'}[_\$key__bar___\$$className] ?? null) as bool;'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' set bar(bool value) => ${isProps ? 'props' : 'state'}[_\$key__bar___\$$className] = value'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' bool get baz => (${isProps ? 'props' : 'state'}[_\$key__baz___\$$className] ?? null) as bool;'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' set baz(bool value) => ${isProps ? 'props' : 'state'}[_\$key__baz___\$$className] = value'));
});
test('containing links to source', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(' /// <!-- Generated from [_\$$className.someField] -->\n'));
});
test('that carry over annotations', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @deprecated()\n'
' String get someField => '));
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @deprecated()\n'
' set someField(String value) => '));
});
test('but does not create implementations for non-fields', () {
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains('abstractGetter')));
});
});
});
}
void testAccessorGenerationForMixins(String testName, OverReactSrc ors) {
group(testName, () {
late bool isProps;
late String className;
late String consumableClassName;
setUp(() {
generateFromSource(ors.source);
isProps = ors.isProps(ors.annotation);
final nameBuilder = isProps ? ors.propsMixinClassName : ors.stateMixinClassName;
consumableClassName = '${backwardsCompatible ? '\$' : ''}$nameBuilder';
className = '${backwardsCompatible ? '' : '_\$'}$nameBuilder';
});
test('with proper accessors mixin declaration, retaining type parameters', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
'mixin $consumableClassName${ors.typeParamSrc} '
'implements $className${ors.typeParamSrcWithoutBounds} {'));
});
test('with abstract props/state getter', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains('@override Map get ${isProps ? 'props' : 'state'};'));
});
group('with concrete implementations', () {
test('', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(' String get someField => (${isProps ? 'props' : 'state'}[_\$key__someField__$className] ?? null) as String;'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' set someField(String value) => ${isProps ? 'props' : 'state'}[_\$key__someField__$className] = value'));
});
test('for multiple fields declared on same line', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(' bool get foo => (${isProps ? 'props' : 'state'}[_\$key__foo__$className] ?? null) as bool;'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' set foo(bool value) => ${isProps ? 'props' : 'state'}[_\$key__foo__$className] = value'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' bool get bar => (${isProps ? 'props' : 'state'}[_\$key__bar__$className] ?? null) as bool;'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' set bar(bool value) => ${isProps ? 'props' : 'state'}[_\$key__bar__$className] = value'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' bool get baz => (${isProps ? 'props' : 'state'}[_\$key__baz__$className] ?? null) as bool;'));
expect(implGenerator!.outputContentsBuffer.toString(), contains(' set baz(bool value) => ${isProps ? 'props' : 'state'}[_\$key__baz__$className] = value'));
});
test('containing links to source', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(' /// <!-- Generated from [$className.someField] -->\n'));
});
test('that carry over annotations', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @deprecated()\n'
' String get someField => '));
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @deprecated()\n'
' set someField(String value) => '));
});
test('but does not create implementations for non-fields', () {
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains('abstractGetter => ')));
});
test('and copies over non-field implementations', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains('String get abstractGetter;'));
});
test('and copies over fields marked with `@Accessor(doNotGenerate: true)`', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains('String _someNonGeneratedField;'));
});
});
});
}
const body = '\n/// Doc comments\n'
'@deprecated()\n'
'String someField;\n'
'bool foo, bar, baz;\n'
'String get abstractGetter;\n'
'@Accessor(doNotGenerate: true)\n'
'String _someNonGeneratedField;\n';
testAccessorGeneration('abstract props classes which are public without type parameters', OverReactSrc.abstractProps(backwardsCompatible: backwardsCompatible, body: body));
testAccessorGeneration('abstract props classes which are private without type parameters', OverReactSrc.abstractProps(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true));
testAccessorGeneration('abstract props classes which are public with type parameters', OverReactSrc.abstractProps(backwardsCompatible: backwardsCompatible, body: body, typeParameters: true));
testAccessorGeneration('abstract props classes which are private with type parameters', OverReactSrc.abstractProps(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true, typeParameters: true));
testAccessorGeneration('abstract state classes which are public without type parameters', OverReactSrc.abstractState(backwardsCompatible: backwardsCompatible, body: body));
testAccessorGeneration('abstract state classes which are private without type parameters', OverReactSrc.abstractState(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true));
testAccessorGeneration('abstract state classes which are public with type parameters', OverReactSrc.abstractState(backwardsCompatible: backwardsCompatible, body: body, typeParameters: true));
testAccessorGeneration('abstract state classes which are private with type parameters', OverReactSrc.abstractState(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true, typeParameters: true));
testAccessorGeneration('props classes which are public without type parameters', OverReactSrc.props(backwardsCompatible: backwardsCompatible, body: body));
testAccessorGeneration('props classes which are private without type parameters', OverReactSrc.props(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true));
testAccessorGeneration('props classes which are public with type parameters', OverReactSrc.props(backwardsCompatible: backwardsCompatible, body: body, typeParameters: true));
testAccessorGeneration('props classes which are private with type parameters', OverReactSrc.props(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true, typeParameters: true));
testAccessorGeneration('state classes which are public without type parameters', OverReactSrc.state(backwardsCompatible: backwardsCompatible, body: body));
testAccessorGeneration('state classes which are private without type parameters', OverReactSrc.state(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true));
testAccessorGeneration('state classes which are public with type parameters', OverReactSrc.state(backwardsCompatible: backwardsCompatible, body: body, typeParameters: true));
testAccessorGeneration('state classes which are private with type parameters', OverReactSrc.state(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true, typeParameters: true));
testAccessorGenerationForMixins('props mixins which are public without type parameters', OverReactSrc.propsMixin(backwardsCompatible: backwardsCompatible, body: body));
testAccessorGenerationForMixins('props mixins which are private without type parameters', OverReactSrc.propsMixin(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true));
testAccessorGenerationForMixins('props mixins which are public with type parameters', OverReactSrc.propsMixin(backwardsCompatible: backwardsCompatible, body: body, typeParameters: true));
testAccessorGenerationForMixins('props mixins which are private with type parameters', OverReactSrc.propsMixin(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true, typeParameters: true));
testAccessorGenerationForMixins('state mixins which are public without type parameters', OverReactSrc.stateMixin(backwardsCompatible: backwardsCompatible, body: body));
testAccessorGenerationForMixins('state mixins which are private without type parameters', OverReactSrc.stateMixin(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true));
testAccessorGenerationForMixins('state mixins which are public with type parameters', OverReactSrc.stateMixin(backwardsCompatible: backwardsCompatible, body: body, typeParameters: true));
testAccessorGenerationForMixins('state mixins which are private with type parameters', OverReactSrc.stateMixin(backwardsCompatible: backwardsCompatible, body: body, isPrivate: true, typeParameters: true));
});
group('and includes the react component factory implementation', () {
void testReactComponentFactory(String testName, OverReactSrc ors) {
test(testName, () {
setUpAndGenerate(ors.source);
final baseName = ors.prefixedBaseName;
expect(implGenerator!.outputContentsBuffer.toString(), contains(
'final \$${baseName}ComponentFactory = registerComponent(\n'
' () => _\$${baseName}Component(),\n'
' builderFactory: _\$$baseName,\n'
' componentClass: ${baseName}Component,\n'
' isWrapper: false,\n'
' parentType: null,\n'
');\n'));
});
}
testReactComponentFactory('for a public concrete component class with only props', OverReactSrc.props(backwardsCompatible: backwardsCompatible));
testReactComponentFactory('for a private concrete component class with only props', OverReactSrc.props(backwardsCompatible: backwardsCompatible, isPrivate: true));
testReactComponentFactory('for a public concrete component class with props and state', OverReactSrc.state(backwardsCompatible: backwardsCompatible));
testReactComponentFactory('for a private concrete component class with props and state', OverReactSrc.state(backwardsCompatible: backwardsCompatible, isPrivate: true));
});
group('and creates factory initializer implementation', () {
void testReactComponentFactory(String testName, OverReactSrc ors) {
test(testName, () {
setUpAndGenerate(ors.source);
final baseName = ors.prefixedBaseName;
expect(implGenerator!.outputContentsBuffer.toString(), contains(
'_\$\$${baseName}Props ${ors.factoryInitializer}([Map backingProps]) => _\$\$${baseName}Props(backingProps);\n'));
});
}
testReactComponentFactory('for a public concrete component class with only props', OverReactSrc.props(backwardsCompatible: backwardsCompatible));
testReactComponentFactory('for a private concrete component class with only props', OverReactSrc.props(backwardsCompatible: backwardsCompatible, isPrivate: true));
testReactComponentFactory('for a public concrete component class with props and state', OverReactSrc.state(backwardsCompatible: backwardsCompatible));
testReactComponentFactory('for a private concrete component class with props and state', OverReactSrc.state(backwardsCompatible: backwardsCompatible, isPrivate: true));
});
group('and creates concrete props implementation', () {
void testConcretePropsGeneration(String testName, OverReactSrc ors) {
group(testName, () {
setUp(() {
generateFromSource(ors.source);
});
test('with the correct class declaration', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
'class _\$\$${ors.prefixedBaseName}Props${ors.typeParamSrc} '
'extends _\$${ors.propsClassName}${ors.typeParamSrcWithoutBounds} '
'with _\$${ors.propsClassName}AccessorsMixin${ors.typeParamSrcWithoutBounds} '
'implements ${ors.propsClassName}${ors.typeParamSrcWithoutBounds} {'));
});
test('with the correct constructor', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' _\$\$${ors.prefixedBaseName}Props([Map backingMap]) : this.props = backingMap ?? JsBackedMap();'));
});
test('with props backing map impl', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @override\n'
' final Map props;'));
});
test('overrides `\$isClassGenerated` to return `true`', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @override\n'
' bool get \$isClassGenerated => true;\n'));
});
test('overrides `componentFactory` to return the correct component factory', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @override\n'
' ReactComponentFactoryProxy get componentFactory => super.componentFactory ?? \$${ors.prefixedBaseName}ComponentFactory;\n'));
});
test('sets the default prop key namespace', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @override\n'
' String get propKeyNamespace => \'${ors.propsClassName}.\';\n'));
});
});
}
testConcretePropsGeneration('for a public props class without type parameters when no state class is declared', OverReactSrc.props(backwardsCompatible: backwardsCompatible));
testConcretePropsGeneration('for a public props class with type parameters when no state class is declared', OverReactSrc.props(backwardsCompatible: backwardsCompatible, typeParameters: true));
testConcretePropsGeneration('for a private props class without type parameters when no state class is declared', OverReactSrc.props(backwardsCompatible: backwardsCompatible, isPrivate: true));
testConcretePropsGeneration('for a private props class with type parameters when no state class is declared', OverReactSrc.props(backwardsCompatible: backwardsCompatible, isPrivate: true, typeParameters: true));
testConcretePropsGeneration('for a public props class without type parameters when a state class is declared', OverReactSrc.state(backwardsCompatible: backwardsCompatible));
testConcretePropsGeneration('for a public props class with type parameters when a state class is declared', OverReactSrc.state(backwardsCompatible: backwardsCompatible, typeParameters: true));
testConcretePropsGeneration('for a private props class without type parameters when a state class is declared', OverReactSrc.state(backwardsCompatible: backwardsCompatible, isPrivate: true));
testConcretePropsGeneration('for a private props class with type parameters when a state class is declared', OverReactSrc.state(backwardsCompatible: backwardsCompatible, isPrivate: true, typeParameters: true));
});
test('does not include react component factory implementation for abstract component', () {
setUpAndGenerate(OverReactSrc.abstractProps(backwardsCompatible: backwardsCompatible, needsComponent: true).source);
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains('registerComponent(()')));
});
test('for covariant keywords', () {
final ors = OverReactSrc.abstractProps(backwardsCompatible: backwardsCompatible, body: 'covariant String foo;');
generateFromSource(ors.source);
expect(implGenerator!.outputContentsBuffer.toString(), contains('String get foo => (props[_\$key__foo___\$${ors.propsClassName}] ?? null) as String;'));
expect(implGenerator!.outputContentsBuffer.toString(), contains('set foo(covariant String value) => props[_\$key__foo___\$${ors.propsClassName}] = value;'));
});
group('and creates concrete state implementation', () {
void testConcretePropsGeneration(String testName, OverReactSrc ors) {
group(testName, () {
setUp(() {
generateFromSource(ors.source);
});
test('with the correct class declaration', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
'class _\$\$${ors.prefixedBaseName}State${ors.typeParamSrc} '
'extends _\$${ors.stateClassName}${ors.typeParamSrcWithoutBounds} '
'with _\$${ors.stateClassName}AccessorsMixin${ors.typeParamSrcWithoutBounds} '
'implements ${ors.stateClassName}${ors.typeParamSrcWithoutBounds} {'));
});
test('with the correct constructor', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' _\$\$${ors.prefixedBaseName}State([Map backingMap]) : this.state = backingMap ?? JsBackedMap();'));
});
test('with state backing map impl', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @override\n'
' final Map state;'));
});
test('overrides `\$isClassGenerated` to return `true`', () {
expect(implGenerator!.outputContentsBuffer.toString(), contains(
' @override\n'
' bool get \$isClassGenerated => true;\n'));
});
});
}
testConcretePropsGeneration('for a public state class without type parameters', OverReactSrc.state(backwardsCompatible: backwardsCompatible));
testConcretePropsGeneration('for a public state class with type parameters', OverReactSrc.state(backwardsCompatible: backwardsCompatible, typeParameters: true));
testConcretePropsGeneration('for a private state class without type parameters', OverReactSrc.state(backwardsCompatible: backwardsCompatible, isPrivate: true));
testConcretePropsGeneration('for a private state class with type parameters', OverReactSrc.state(backwardsCompatible: backwardsCompatible, isPrivate: true, typeParameters: true));
});
});
}
testImplGeneration(', with backwards compatible boilerplate,', backwardsCompatible: true);
testImplGeneration(', with Dart 2 only boilerplate,', backwardsCompatible: false);
group('and generated consumable companion class with Dart 2 only boilerplate', () {
@isTest
void testConsumableCompanionGeneration(String testName, OverReactSrc ors) {
test(testName, () {
setUpAndGenerate(ors.source);
final className = ors.isProps(ors.annotation) ? ors.propsClassName : ors.stateClassName;
final metaStructName = ors.isProps(ors.annotation) ? 'PropsMeta' : 'StateMeta';
expect(implGenerator!.outputContentsBuffer.toString(), contains(
'class $className extends _\$$className with _\$${className}AccessorsMixin {\n'
' static const $metaStructName meta = _\$metaFor$className;\n'
'}\n'));
});
}
testConsumableCompanionGeneration('for props classes', OverReactSrc.props(backwardsCompatible: false));
testConsumableCompanionGeneration('for abstract props classes', OverReactSrc.abstractProps(backwardsCompatible: false));
testConsumableCompanionGeneration('for state classes', OverReactSrc.state(backwardsCompatible: false));
testConsumableCompanionGeneration('for abstract state classes', OverReactSrc.abstractState(backwardsCompatible: false));
});
group('and copies over static fields with Dart 2 only boilerplate', () {
final fieldDeclarations = [
'static const String some_string_const = \'some_string_prop\';',
'static final SomeMapView defaultProps = ',
'new SomeMapView({})',
'..item1 = 1',
'..item2 = \'some_prop\';'
];
const uselessMetaField = 'static const String meta = \'some_string\';';
const uselessMetaMethod = 'static String get meta => \'some_string\';';
final fieldDeclarationsWithMetaField = List.from(fieldDeclarations)..add(uselessMetaField);
final fieldDeclarationsWithMetaMethod = List.from(fieldDeclarations)..add(uselessMetaMethod);
void testStaticFieldCopying(OverReactSrc ors) {
setUpAndGenerate(ors.source);
fieldDeclarations.forEach((piece) {
expect(implGenerator!.outputContentsBuffer.toString().trim(), contains(piece));
});
}
group('for a props class', () {
test('', () {
testStaticFieldCopying(OverReactSrc.props(backwardsCompatible: false, body: fieldDeclarations.join('\n')));
});
test(', except for static `meta` field', () {
testStaticFieldCopying(OverReactSrc.props(backwardsCompatible: false, body: fieldDeclarationsWithMetaField.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaField)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
test(', except for static `meta` method', () {
testStaticFieldCopying(OverReactSrc.props(backwardsCompatible: false, body: fieldDeclarationsWithMetaMethod.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaMethod)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
});
group('for a state class', () {
test('', () {
testStaticFieldCopying(OverReactSrc.state(backwardsCompatible: false, body: fieldDeclarations.join('\n')));
});
test(', except for static `meta` field', () {
testStaticFieldCopying(OverReactSrc.state(backwardsCompatible: false, body: fieldDeclarationsWithMetaField.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaField)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
test(', except for static `meta` method', () {
testStaticFieldCopying(OverReactSrc.state(backwardsCompatible: false, body: fieldDeclarationsWithMetaMethod.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaMethod)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
});
group('for a abstract props class', () {
test('', () {
testStaticFieldCopying(OverReactSrc.abstractProps(backwardsCompatible: false, body: fieldDeclarations.join('\n')));
});
test(', except for static `meta` field', () {
testStaticFieldCopying(OverReactSrc.abstractProps(backwardsCompatible: false, body: fieldDeclarationsWithMetaField.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaField)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
test(', except for static `meta` method', () {
testStaticFieldCopying(OverReactSrc.abstractProps(backwardsCompatible: false, body: fieldDeclarationsWithMetaMethod.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaMethod)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
});
group('for a abstract state class', () {
test('', () {
testStaticFieldCopying(OverReactSrc.abstractState(backwardsCompatible: false, body: fieldDeclarations.join('\n')));
});
test(', except for static `meta` field', () {
testStaticFieldCopying(OverReactSrc.abstractState(backwardsCompatible: false, body: fieldDeclarationsWithMetaField.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaField)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
test(', except for static `meta` method', () {
testStaticFieldCopying(OverReactSrc.abstractState(backwardsCompatible: false, body: fieldDeclarationsWithMetaMethod.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaMethod)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
});
group('for a props mixin class', () {
test('', () {
testStaticFieldCopying(OverReactSrc.propsMixin(backwardsCompatible: false, body: fieldDeclarations.join('\n')));
});
test(', except for static `meta` field', () {
testStaticFieldCopying(OverReactSrc.propsMixin(backwardsCompatible: false, body: fieldDeclarationsWithMetaField.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaField)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
test(', except for static `meta` method', () {
testStaticFieldCopying(OverReactSrc.propsMixin(backwardsCompatible: false, body: fieldDeclarationsWithMetaMethod.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaMethod)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
});
group('for a state mixin class', () {
test('', () {
testStaticFieldCopying(OverReactSrc.stateMixin(backwardsCompatible: false, body: fieldDeclarations.join('\n')));
});
test(', except for static `meta` field', () {
testStaticFieldCopying(OverReactSrc.stateMixin(backwardsCompatible: false, body: fieldDeclarationsWithMetaField.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaField)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
test(', except for static `meta` method', () {
testStaticFieldCopying(OverReactSrc.stateMixin(backwardsCompatible: false, body: fieldDeclarationsWithMetaMethod.join('\n')));
expect(implGenerator!.outputContentsBuffer.toString(), isNot(contains(uselessMetaMethod)));
// clear the warning coming from declaration parsing about having static meta
verify(() => logger.warning(startsWith('Static class member `meta`')));
});
});
});
group('static meta field', () {
void testStaticMetaField(String testName, OverReactSrc ors) {
test(testName, () {
setUpAndGenerate(ors.source);
final accessorsClassName = testName.contains('mixin')
? '\$${ors.propsOrStateOrMixinClassName}'
: '_\$${ors
.propsOrStateOrMixinClassName}AccessorsMixin';
final propsOrStateOrMixinClassName = ors.propsOrStateOrMixinClassName;
final annotatedPropsOrStateOrMixinClassName = testName.contains('mixin') ? propsOrStateOrMixinClassName : '_\$$propsOrStateOrMixinClassName';
final expectedAccessorsMixin = 'mixin $accessorsClassName implements $annotatedPropsOrStateOrMixinClassName';
final metaStructName = ors.metaStructName(ors.annotation);
final expectedMetaForInstance = (StringBuffer()
..writeln('const $metaStructName _\$metaFor$propsOrStateOrMixinClassName = $metaStructName(')
..writeln(' fields: $accessorsClassName.${ors.constantListName},')
..writeln(' keys: $accessorsClassName.${ors.keyListName},')
..writeln(');')
).toString();
expect(implGenerator!.outputContentsBuffer.toString(), contains(expectedAccessorsMixin));
expect(implGenerator!.outputContentsBuffer.toString(), contains(expectedMetaForInstance));
});
}
testStaticMetaField('props class', OverReactSrc.props());
testStaticMetaField('state class', OverReactSrc.state());
testStaticMetaField('props mixin', OverReactSrc.propsMixin());
testStaticMetaField('state mixin', OverReactSrc.stateMixin());
testStaticMetaField('abstract props', OverReactSrc.abstractProps());
testStaticMetaField('abstract state', OverReactSrc.abstractState());
});
group('and generates props config for function components constructed with', () {
String generatedConfig(String propsName, String factoryName) {
return 'final UiFactoryConfig<_\$\$$propsName> '
'_\$${factoryName}Config = UiFactoryConfig(\n'
'propsFactory: PropsFactory(\n'
'map: (map) => _\$\$$propsName(map),\n'
'jsMap: (map) => _\$\$$propsName(map),),\n'
'displayName: \'$factoryName\');\n\n'
'@Deprecated(r\'Use the private variable, _\$${factoryName}Config, instead \'\n'
'\'and update the `over_react` lower bound to version 4.1.0. \'\n'
'\'For information on why this is deprecated, see https://github.com/Workiva/over_react/pull/650\')\n'
'final UiFactoryConfig<_\$\$$propsName> '
'\$${factoryName}Config = _\$${factoryName}Config;\n\n';
}
String generatedPropsMapForConfig(String propsName) {
// No need to validate the whole implementation; that's tedious to reconstruct here, and it's tested elsewhere.
return '@Deprecated(\'This API is for use only within generated code.\'\' Do not reference it in your code, as it may change at any time.\')\n'
'class _\$\$$propsName extends UiProps with';
}
void sharedUiConfigGenerationTests(String wrapperFunction) {
test('with multiple props mixins and function components in file', () {
setUpAndGenerate('''
mixin FooPropsMixin on UiProps {}
class FooProps = UiProps with FooPropsMixin;
mixin BarPropsMixin on UiProps {}
UiFactory<BarPropsMixin> Bar = $wrapperFunction(
(props) {
return Dom.div()();
},
_\$BarConfig, // ignore: undefined_identifier
);
UiFactory<BarPropsMixin> Foo = $wrapperFunction(
(props) {
return Dom.div()();
},
_\$FooConfig, // ignore: undefined_identifier
);
UiFactory<FooProps> Baz = $wrapperFunction(
(props) {
return Dom.div()();
},
_\$BazConfig, // ignore: undefined_identifier
);
mixin UnusedPropsMixin on UiProps {}
''');
expect(implGenerator!.outputContentsBuffer.toString().contains(generatedPropsMapForConfig('UnusedPropsMixin')), isFalse);
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedPropsMapForConfig('BarPropsMixin')));
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedPropsMapForConfig('FooProps')));
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedConfig('BarPropsMixin', 'Bar')));
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedConfig('BarPropsMixin', 'Foo')));
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedConfig('FooProps', 'Baz')));
});
test('wrapped in an hoc', () {
setUpAndGenerate('''
UiFactory<FooPropsMixin> Foo = someHOC($wrapperFunction(
(props) {
return Dom.div()();
},
_\$FooConfig, // ignore: undefined_identifier
));
mixin FooPropsMixin on UiProps {}
''');
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedPropsMapForConfig('FooPropsMixin')));
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedConfig('FooPropsMixin', 'Foo')));
});
test('with public generated config', () {
setUpAndGenerate('''
UiFactory<FooProps> Foo = $wrapperFunction(
(props) {
return Dom.div()();
},
\$FooConfig, // ignore: undefined_identifier
);
mixin FooProps on UiProps {}
''');
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedPropsMapForConfig('FooProps')));
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedConfig('FooProps', 'Foo')));
});
}
group('uiFunction', () {
sharedUiConfigGenerationTests('uiFunction');
});
group('uiForwardRef', () {
// Note: this doesn't test any of the ref forwarding capabilities of `uiForwardRef`,
// and just tests the generation of the UiFactoryConfig for `uiForwardRef`
// explicitly.
sharedUiConfigGenerationTests('uiForwardRef');
test('when the config does not need to be generated', () {
setUpAndGenerate(r'''
UiFactory<FooProps> ForwardRefFoo = uiForwardRef((props, ref) {
return (Foo()
..ref = ref
)();
}, Foo.asForwardRefConfig());
''');
expect(implGenerator!.outputContentsBuffer.toString().contains(generatedConfig('FooProps', 'ForwardRefFoo')), isFalse);
});
test('when the config does need to be generated but mixes in an already consumed props class', () {
setUpAndGenerate(r'''
UiFactory<FooProps> Foo = _$Foo;
mixin FooProps on UiProps {}
class FooComponent extends UiComponent2<FooProps>{
@override
render() => null;
}
class UiForwardRefFooProps = UiProps with FooProps;
UiFactory<UiForwardRefFooProps> UiForwardRefFoo = uiForwardRef(
(props, ref) {
return (Foo()
..ref = ref
)();
},
_$UiForwardRefFooConfig,
);
''');
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedPropsMapForConfig('UiForwardRefFooProps')));
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedConfig('UiForwardRefFooProps', 'UiForwardRefFoo')));
});
});
// The builder should support generation of UiFactoryConfig's whenever
// it recognizes that a generated config is being referenced
group('arbitrary HOC', () {
sharedUiConfigGenerationTests('anArbitraryHOC');
});
test('unless function component is generic or does not have a props config', () {
setUpAndGenerate(r'''
mixin FooPropsMixin on UiProps {}
UiFactory<FooPropsMixin> FooForwarded = forwardRef<FooPropsMixin>((props, ref) {
return (Foo()
..ref = ref
)();
})(Foo);
UiFactory<FooPropsMixin> ArbitraryFoo = anArbitraryHoc(
(props) {
return (Foo()
..ref = ref
)();
},
UiFactoryConfig(
propsFactory: PropsFactory.fromUiFactory(Foo)
)
);
final Bar = uiFunction<UiProps>(
(props) {
return Dom.div()();
},
UiFactoryConfig(),
);
final Foo = uiFunction<FooPropsMixin>(
(props) {
return Dom.div()();
},
_$FooConfig, // ignore: undefined_identifier
);
final Baz = uiFunction<FooPropsMixin>(
(props) {
return Dom.div()();
},
UiFactoryConfig(
propsFactory: PropsFactory.fromUiFactory(Foo),
)
);
''');
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedPropsMapForConfig('FooPropsMixin')));
expect(implGenerator!.outputContentsBuffer.toString().contains(generatedConfig('UiProps', 'Bar')), isFalse, reason: '2');
expect(implGenerator!.outputContentsBuffer.toString().contains(generatedConfig('FooPropsMixin', 'ArbitraryFoo')), isFalse, reason: '2');
expect(implGenerator!.outputContentsBuffer.toString(), contains(generatedConfig('FooPropsMixin', 'Foo')), reason: '1');
expect(implGenerator!.outputContentsBuffer.toString().contains(generatedConfig('FooPropsMixin', 'Baz')), isFalse, reason: '3');
});
});
group('usages of converter annotations', () {
// A utility to both share getter/setter expectations and to verify only one set of getter/setters is generated at a time.
void expectGettersAndSetters({bool convertProp = false, bool jsMap = false, bool jsRef = false}) {
Matcher maybeContains(String match, bool shouldContain) => shouldContain ? contains(match) : isNot(contains(match));
// @ConvertProp getter / setter
expect(
implGenerator!.outputContentsBuffer.toString(),
maybeContains(
'String get foo => getConverter((props[_\$key__foo___\$AbstractFooProps] ?? null) as int);', convertProp));
expect(
implGenerator!.outputContentsBuffer.toString(),
maybeContains(
'set foo(String value) => props[_\$key__foo___\$AbstractFooProps] = setConverter(value);', convertProp));
// @convertJsMapProp getter / setter
expect(
implGenerator!.outputContentsBuffer.toString(),
maybeContains(
'Map? get foo => unjsifyMapProp((props[_\$key__foo___\$AbstractFooProps] ?? null) as JsMap?);', jsMap));
expect(
implGenerator!.outputContentsBuffer.toString(),
maybeContains(
'set foo(Map? value) => props[_\$key__foo___\$AbstractFooProps] = jsifyMapProp(value);', jsMap));
// @convertJsRefProp getter / setter
expect(
implGenerator!.outputContentsBuffer.toString(),
maybeContains(
'dynamic get foo => unjsifyRefProp((props[_\$key__foo___\$AbstractFooProps] ?? null) as dynamic);', jsRef));
expect(
implGenerator!.outputContentsBuffer.toString(),
maybeContains(
'set foo(dynamic value) => props[_\$key__foo___\$AbstractFooProps] = jsifyRefProp(value);', jsRef));
}
test('@ConvertProp',() {
const body = '''
@ConvertProp<int, String>(setConverter, getConverter)
late String foo;''';
setUpAndGenerate(
OverReactSrc.abstractProps(backwardsCompatible: false, body: body)
.source);
expectGettersAndSetters(convertProp: true);
});
test('@convertJsMapProp',() {
const body = '''
@convertJsMapProp
Map? foo;''';
setUpAndGenerate(
OverReactSrc.abstractProps(backwardsCompatible: false, body: body)
.source);
expectGettersAndSetters(jsMap: true);
});
test('@convertJsRefProp',() {
const body = '''
@convertJsRefProp
dynamic foo;''';
setUpAndGenerate(
OverReactSrc.abstractProps(backwardsCompatible: false, body: body)
.source);
expectGettersAndSetters(jsRef: true);
});
group('multiple annotations used together - prefer @ConvertProp over',() {
test('@convertJsMapProp',() {
const body = '''
@ConvertProp<int, String>(setConverter, getConverter)
@convertJsMapProp
late String foo;''';
setUpAndGenerate(
OverReactSrc.abstractProps(backwardsCompatible: false, body: body)
.source);
expectGettersAndSetters(convertProp: true);
});
test('@convertJsRefProp',() {
const body = '''
@ConvertProp<int, String>(setConverter, getConverter)
@convertJsRefProp
late String foo;''';
setUpAndGenerate(
OverReactSrc.abstractProps(backwardsCompatible: false, body: body)
.source);
expectGettersAndSetters(convertProp: true);
});
});
});
});
group('logs an error when', () {
group('a component class', () {
test('subtypes itself', () {
setUpAndGenerate(OverReactSrc.props(backwardsCompatible: false, componentAnnotationArg: 'subtypeOf: FooComponent').source);
verify(() => logger.severe(contains('A component cannot be a subtype of itself.')));
});
});
group('a props mixin is', () {
const String expectedPropsGetterError =
'Props mixin classes must declare an abstract props getter `Map get props;` '
'so that they can be statically analyzed properly.';
test('declared without an abstract `props` getter', () {
setUpAndGenerate('''
@PropsMixin()
abstract class _\$FooPropsMixin {
var bar;
}
''');
verify(() => logger.severe(contains(expectedPropsGetterError)));
});
group('declared with a malformed `props` getter:', () {
test('a field', () {
setUpAndGenerate('''
@PropsMixin()
abstract class _\$FooPropsMixin {
Map props;
var bar;
}
''');
verify(() => logger.severe(contains(expectedPropsGetterError)));
});
test('a getter of the wrong type', () {
setUpAndGenerate('''
@PropsMixin()
abstract class _\$FooPropsMixin {
NotAMap get props;