Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[go_router_builder] Generate replace method in RouteExtension #2838

Merged
merged 3 commits into from
Feb 21, 2023

Conversation

omensight
Copy link
Contributor

@omensight omensight commented Nov 21, 2022

The problem is described here flutter/flutter#115789
The method replace is added to the route_config.dart file

List which issues are fixed by this PR. You must list at least one issue.
The replace method is needed in the generated class

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@omensight omensight changed the title [go_router_build] Generate replace method in RouteExtension [go_router_builder] Generate replace method in RouteExtension Nov 21, 2022
@omensight
Copy link
Contributor Author

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

The test

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

The ShouldGenerate annotation method have been edited in the line 93 of the file "_go_router_builder_test_input.dart" before to edit the lib code

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should probably need run code gen in the example/ folder. I am surprise this does not trigger ci failure. The test/ensure_build_test.dart should have failed. @kevmoo Since you wrote the package that enabled this test, do you know why this is the case

@kevmoo
Copy link
Contributor

kevmoo commented Nov 28, 2022 via email

@chunhtai
Copy link
Contributor

lol it looks like the presubmit-only tag is not working properly

@kevmoo
Copy link
Contributor

kevmoo commented Nov 28, 2022

lol it looks like the presubmit-only tag is not working properly

You need to pass a flag to the test command to include the ensure bits.

See https://github.com/google/json_serializable.dart/blob/master/.github/workflows/dart.yml#L335

@chunhtai
Copy link
Contributor

This will requires flutter_plugin_tools to support adding -t to the test command. another question may be whether this this test really needs this tag, Is there a reason why this need to be presubmit only?

@kevmoo
Copy link
Contributor

kevmoo commented Nov 29, 2022

@chunhtai – it runs a build and checks for a git delta. Can be annoying during normal development.

We could certainly drop it in the short run!

@omensight
Copy link
Contributor Author

Contributor

What should I do for it to be accepted?

@chunhtai chunhtai self-requested a review December 8, 2022 22:58
@chunhtai
Copy link
Contributor

We should wait for #2846 (comment) because we are going to rename this to pushReplacement

@chunhtai
Copy link
Contributor

chunhtai commented Jan 4, 2023

can you rebase off latest main and change the name to pushReplacement

@stuartmorgan
Copy link
Contributor

What's the status of this PR? Is it ready for re-review?

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Hixie
Copy link
Contributor

Hixie commented Jan 31, 2023

Should we test that the generated files are the files you get when you run the generator? Does that make sense?

@chunhtai
Copy link
Contributor

Should we test that the generated files are the files you get when you run the generator? Does that make sense?

Yes there is a test that makes sure of that https://github.com/flutter/packages/blob/main/packages/go_router_builder/example/test/ensure_build_test.dart

@Hixie
Copy link
Contributor

Hixie commented Feb 1, 2023

test-exempt: is tested

Copy link
Contributor

@hangyujin hangyujin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chunhtai
Copy link
Contributor

chunhtai commented Feb 8, 2023

hi @omensight can you fix the merge conflict?

@omensight
Copy link
Contributor Author

hi @omensight can you fix the merge conflict?

I did it, thanks for waiting.

@chunhtai
Copy link
Contributor

chunhtai commented Feb 16, 2023

@omensight it looks like there are some test failures

@omensight
Copy link
Contributor Author

@omensight it looks like there are some test failures

I'm sorry but I'm not understanding what the problem is.

@chunhtai
Copy link
Contributor

This is the test failure

test/builder_test.dart: DefaultValueRoute                                                                                                                                                    
00:34 
+2
 -1
: test/builder_test.dart: DefaultValueRoute 
[E]
  Expected: 'GoRoute get $defaultValueRoute => GoRouteData.$route(\n'
              '      path: \'/default-value-route\',\n'
              '      factory: $DefaultValueRouteExtension._fromState,\n'
              '    );\n'
              '\n'
              'extension $DefaultValueRouteExtension on DefaultValueRoute {\n'
              '  static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute(\n'
              '        param: _$convertMapValue(\'param\', state.queryParams, int.parse) ?? 0,\n'
              '      );\n'
              '\n'
              '  String get location => GoRouteData.$location(\n'
              '        \'/default-value-route\',\n'
              '        queryParams: {\n'
              '          if (param != 0) \'param\': param.toString(),\n'
              '        },\n'
              '      );\n'
              '\n'
              '  void go(BuildContext context) => context.go(location, extra: this);\n'
              '\n'
              '  void push(BuildContext context) => context.push(location, extra: this);\n'
              '}\n'
              '\n'
              'T? _$convertMapValue<T>(\n'
              '  String key,\n'
              '  Map<String, String> map,\n'
              '  T Function(String) converter,\n'
              ') {\n'
              '  final value = map[key];\n'
              '  return value == null ? null : converter(value);\n'
              '}\n'
              ''
    Actual: 'GoRoute get $defaultValueRoute => GoRouteData.$route(\n'
              '      path: \'/default-value-route\',\n'
              '      factory: $DefaultValueRouteExtension._fromState,\n'
              '    );\n'
              '\n'
              'extension $DefaultValueRouteExtension on DefaultValueRoute {\n'
              '  static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute(\n'
              '        param: _$convertMapValue(\'param\', state.queryParams, int.parse) ?? 0,\n'
              '      );\n'
              '\n'
              '  String get location => GoRouteData.$location(\n'
              '        \'/default-value-route\',\n'
              '        queryParams: {\n'
              '          if (param != 0) \'param\': param.toString(),\n'
              '        },\n'
              '      );\n'
              '\n'
              '  void go(BuildContext context) => context.go(location, extra: this);\n'
              '\n'
              '  void push(BuildContext context) => context.push(location, extra: this);\n'
              '\n'
              '  void pushReplacement(BuildContext context) =>\n'
              '      context.pushReplacement(location, extra: this);\n'
              '}\n'
              '\n'
              'T? _$convertMapValue<T>(\n'
              '  String key,\n'
              '  Map<String, String> map,\n'
              '  T Function(String) converter,\n'
              ') {\n'
              '  final value = map[key];\n'
              '  return value == null ? null : converter(value);\n'
              '}\n'
              ''
     Which: is different.
            Expected: ... : this);\n}\n\nT? _$ ...
              Actual: ... : this);\n\n  void p ...
                                    ^
             Differ at offset 725
  package:test_api                                               expect
  package:source_gen_test/src/test_annotated_classes.dart 244:7  AnnotatedTest._shouldGenerateTest
ACTUAL CONTENT:
r'''
GoRoute get $defaultValueRoute => GoRouteData.$route(
      path: '/default-value-route',
      factory: $DefaultValueRouteExtension._fromState,
    );
extension $DefaultValueRouteExtension on DefaultValueRoute {
  static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute(
        param: _$convertMapValue('param', state.queryParams, int.parse) ?? 0,
      );
  String get location => GoRouteData.$location(
        '/default-value-route',
        queryParams: {
          if (param != 0) 'param': param.toString(),
        },
      );
  void go(BuildContext context) => context.go(location, extra: this);
  void push(BuildContext context) => context.push(location, extra: this);
  void pushReplacement(BuildContext context) =>
      context.pushReplacement(location, extra: this);
}
T? _$convertMapValue<T>(
  String key,
  Map<String, String> map,
  T Function(String) converter,
) {
  final value = map[key];
  return value == null ? null : converter(value);
}
'''

@omensight
Copy link
Contributor Author

omensight commented Feb 18, 2023

This is the test failure

test/builder_test.dart: DefaultValueRoute                                                                                                                                                    
00:34 
+2
 -1
: test/builder_test.dart: DefaultValueRoute 
[E]
  Expected: 'GoRoute get $defaultValueRoute => GoRouteData.$route(\n'
              '      path: \'/default-value-route\',\n'
              '      factory: $DefaultValueRouteExtension._fromState,\n'
              '    );\n'
              '\n'
              'extension $DefaultValueRouteExtension on DefaultValueRoute {\n'
              '  static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute(\n'
              '        param: _$convertMapValue(\'param\', state.queryParams, int.parse) ?? 0,\n'
              '      );\n'
              '\n'
              '  String get location => GoRouteData.$location(\n'
              '        \'/default-value-route\',\n'
              '        queryParams: {\n'
              '          if (param != 0) \'param\': param.toString(),\n'
              '        },\n'
              '      );\n'
              '\n'
              '  void go(BuildContext context) => context.go(location, extra: this);\n'
              '\n'
              '  void push(BuildContext context) => context.push(location, extra: this);\n'
              '}\n'
              '\n'
              'T? _$convertMapValue<T>(\n'
              '  String key,\n'
              '  Map<String, String> map,\n'
              '  T Function(String) converter,\n'
              ') {\n'
              '  final value = map[key];\n'
              '  return value == null ? null : converter(value);\n'
              '}\n'
              ''
    Actual: 'GoRoute get $defaultValueRoute => GoRouteData.$route(\n'
              '      path: \'/default-value-route\',\n'
              '      factory: $DefaultValueRouteExtension._fromState,\n'
              '    );\n'
              '\n'
              'extension $DefaultValueRouteExtension on DefaultValueRoute {\n'
              '  static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute(\n'
              '        param: _$convertMapValue(\'param\', state.queryParams, int.parse) ?? 0,\n'
              '      );\n'
              '\n'
              '  String get location => GoRouteData.$location(\n'
              '        \'/default-value-route\',\n'
              '        queryParams: {\n'
              '          if (param != 0) \'param\': param.toString(),\n'
              '        },\n'
              '      );\n'
              '\n'
              '  void go(BuildContext context) => context.go(location, extra: this);\n'
              '\n'
              '  void push(BuildContext context) => context.push(location, extra: this);\n'
              '\n'
              '  void pushReplacement(BuildContext context) =>\n'
              '      context.pushReplacement(location, extra: this);\n'
              '}\n'
              '\n'
              'T? _$convertMapValue<T>(\n'
              '  String key,\n'
              '  Map<String, String> map,\n'
              '  T Function(String) converter,\n'
              ') {\n'
              '  final value = map[key];\n'
              '  return value == null ? null : converter(value);\n'
              '}\n'
              ''
     Which: is different.
            Expected: ... : this);\n}\n\nT? _$ ...
              Actual: ... : this);\n\n  void p ...
                                    ^
             Differ at offset 725
  package:test_api                                               expect
  package:source_gen_test/src/test_annotated_classes.dart 244:7  AnnotatedTest._shouldGenerateTest
ACTUAL CONTENT:
r'''
GoRoute get $defaultValueRoute => GoRouteData.$route(
      path: '/default-value-route',
      factory: $DefaultValueRouteExtension._fromState,
    );
extension $DefaultValueRouteExtension on DefaultValueRoute {
  static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute(
        param: _$convertMapValue('param', state.queryParams, int.parse) ?? 0,
      );
  String get location => GoRouteData.$location(
        '/default-value-route',
        queryParams: {
          if (param != 0) 'param': param.toString(),
        },
      );
  void go(BuildContext context) => context.go(location, extra: this);
  void push(BuildContext context) => context.push(location, extra: this);
  void pushReplacement(BuildContext context) =>
      context.pushReplacement(location, extra: this);
}
T? _$convertMapValue<T>(
  String key,
  Map<String, String> map,
  T Function(String) converter,
) {
  final value = map[key];
  return value == null ? null : converter(value);
}
'''

I have fixed the error. Sorry, I didn't add the respective lines for the test.

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 21, 2023
@auto-submit auto-submit bot merged commit 69e6dac into flutter:main Feb 21, 2023
ditman added a commit to ditman/flutter-flutter that referenced this pull request Feb 24, 2023
* ad48ee5 [go_router] Fix some broken links in doc (flutter/packages#3288)
* 58ac45e [go_router_builder] Add support for Iterable, List  and Set to TypedGoRoute (flutter/packages#2679)
* 0edae25 Export super types in route_data.dart library (flutter/packages#3286)
* 8ad3fde [go_router] Add `GoRouter.maybeOf` (flutter/packages#3216)
* 13ee644 [flutter_migrate] Skip slow tests (flutter/packages#3270)
* 3cc754a Update .gitignore with missing values from flutter/plugins (flutter/packages#3265)
* c0f0a22 [ci] Re-enable pathified unit tests (flutter/packages#3268)
* 5834b4c [go_router]: implemented helpers for ShellRoute (flutter/packages#2730)
* af5906b [extension_gsi] Update extension to support gsi 5 and 6. (flutter/packages#3235)
* 195f4e8 Merge in plugin README and CONTRIBUTING (flutter/packages#3252)
* fab47af [go_router] Disable logging in tests (flutter/packages#3263)
* 25f0f70 [various] Update flutter/plugins links (flutter/packages#3256)
* 2e16733 Merge flutter/plugins (flutter/packages#3233)
* 324a7f2 Exclude more tests on Windows
* 334b58e Adjust test configs
* 69e6dac [go_router_builder] Generate replace method in RouteExtension (flutter/packages#2838)
* 193e454 Merge repository metadata
* 18715d7 Merge remote-tracking branch 'plugins-packages/main' into merge-flutter-plugins
* f2d802d Roll Flutter from ae8d051 to 7175de4 (4 revisions) (flutter/packages#3232)
* 6f1b1e8 Roll Flutter from 33e4d21 to ae8d051 (6 revisions) (flutter/packages#3229)
* a162a98 Roll Flutter from 0be7c3f to 33e4d21 (5 revisions) (flutter/packages#3227)
* ab5a8c0 [tool] Allow importing packages with NEXT (flutter/packages#3215)
* ce9c61b Roll Flutter from 170539f to 0be7c3f (38 revisions) (flutter/packages#3225)
* 9747469 Fix deprecation message for GoRouterState.namedLocation (flutter/packages#3092)
* 6e4431f [go_router] Bump example `compileSdkVersion` and `package_info_plus` dependency version (flutter/packages#3219)
* 925bea8 [pigeon] Validate generated files in CI (flutter/packages#3224)
* 3094867 Move iOS Swift unit tests back to Cirrus (flutter/packages#3221)
* 763d025 [pigeon] Eliminate some of the test pigeons (flutter/packages#3213)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App needs tests p: go_router_builder
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants