Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenthompson-wk committed Jan 10, 2024
1 parent 9865c08 commit b64a271
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions w_flux_codemod/test/action_v2_suggestor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
w_flux: ^3.0.0
''';

String wFluxInputImport(WFluxImportMode mode) {
String wFluxImport(WFluxImportMode mode) {
switch (mode) {
case WFluxImportMode.none:
return '';
Expand All @@ -30,12 +30,12 @@ String wFluxInputImport(WFluxImportMode mode) {
}
}

String wFluxOutputImport(WFluxImportMode mode) {
String wFluxMigratedImport(WFluxImportMode mode) {
switch (mode) {
case WFluxImportMode.none:
case WFluxImportMode.standard:
case WFluxImportMode.prefixed:
return wFluxInputImport(mode);
return wFluxImport(mode);
case WFluxImportMode.shown:
return "import 'package:w_flux/w_flux.dart' show ActionV2;";
case WFluxImportMode.multipleShown:
Expand Down Expand Up @@ -66,16 +66,16 @@ void main() {
void testSuggestor(String description, Suggestor Function() suggestor,
String before, String after,
{WFluxImportMode importMode = WFluxImportMode.standard,
shouldImport = true}) {
migrateImport = false}) {
test(description, () async {
final context = await pkg.addFile('''
${shouldImport ? wFluxInputImport(importMode) : ''}
${before}
''');
${wFluxImport(importMode)}
${before}
''');
final expectedOutput = '''
${shouldImport ? wFluxOutputImport(importMode) : ''}
${after}
''';
${migrateImport ? wFluxMigratedImport(importMode) : wFluxImport(importMode)}
${after}
''';
expectSuggestorGeneratesPatches(
suggestor(),
context,
Expand All @@ -93,6 +93,7 @@ ${after}
'',
'',
importMode: WFluxImportMode.shown,
migrateImport: true,
);

testSuggestor(
Expand All @@ -101,6 +102,7 @@ ${after}
'',
'',
importMode: WFluxImportMode.multipleShown,
migrateImport: true,
);

testSuggestor(
Expand All @@ -109,6 +111,7 @@ ${after}
'',
'',
importMode: WFluxImportMode.hidden,
migrateImport: true,
);
});

Expand Down Expand Up @@ -165,26 +168,20 @@ ${after}
testSuggestor(
'local invocation of field',
suggestor,
'class C { ActionV2 action; dispatch() => action(); }',
'class C { ActionV2 action; dispatch() => action(null); }',
'class C { Action action; dispatch() => action(); }',
'class C { Action action; dispatch() => action(null); }',
);
testSuggestor(
'external invocation of field',
suggestor,
'class C { ActionV2 action; } void main() { C().action(); }',
'class C { ActionV2 action; } void main() { C().action(null); }',
);
testSuggestor(
'ignores Action type',
suggestor,
'void main() { var a = Action(); a(); }',
'void main() { var a = Action(); a(); }',
'class C { Action action; } void main() { C().action(); }',
'class C { Action action; } void main() { C().action(null); }',
);
testSuggestor(
'nested dispatch',
suggestor,
'''
class A { final ActionV2 action = ActionV2(); }
class A { final Action action = Action(); }
class B { final actions = A(); }
void main() {
B().actions.action();
Expand Down Expand Up @@ -221,16 +218,9 @@ ${after}
testSuggestor(
'ignore Action when hidden from w_flux',
suggestor,
'''
${wFluxOutputImport(WFluxImportMode.hidden)}
'Action<num> action;'
''',
'''
${wFluxOutputImport(WFluxImportMode.hidden)}
'Action<num> action;'
''',
'Action<num> action;',
'Action<num> action;',
importMode: WFluxImportMode.hidden,
shouldImport: false,
);
testSuggestor(
'ignore types not from w_flux',
Expand Down Expand Up @@ -348,12 +338,6 @@ ${after}
'fn(Action action) {}',
'fn(ActionV2 action) {}',
);
testSuggestor(
'SimpleFormalParameter.type (method)',
suggestor,
'class C { m(Action action) {} }',
'class C { m(ActionV2 action) {} }',
);
testSuggestor(
'Parameter type with a generic',
suggestor,
Expand Down Expand Up @@ -401,6 +385,13 @@ ${after}
'class C { Action m() {} }',
'class C { ActionV2 m() {} }',
);

testSuggestor(
'MethodDeclaration SimpleFormalParameter.type',
suggestor,
'class C { m(Action action) {} }',
'class C { m(ActionV2 action) {} }',
);
testSuggestor(
'Return type with a generic',
suggestor,
Expand Down

0 comments on commit b64a271

Please sign in to comment.