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

Better handing of proto identifiers that start with underscores and numbers #947

Merged
merged 10 commits into from
Feb 6, 2020

Conversation

thomasvl
Copy link
Collaborator

@thomasvl thomasvl commented Feb 4, 2020

Code changes and docs to better document what input some methods during generation have to deal with based on the restrictions protoc enforces when parsing proto files.

There are no changes to what was generated before (and compiled), but there is one case (extensions at the root of a file) that can still fail to generate. But, that was already failing to generate (trips a precondition), so there is no change in behavior. That will get looked at next, but does as a follow up PR to keep it more self contained.

Fixes #931

Update test cases to have more failures and use the argument.
- Document what the input set it.
- Handing leading underscores followed by a number which used to result in the
  generation of an invalid Swift identifier starting with a number.
- Expand the testcases to cover the improved code and cover handling of
  repeated underscores (they just go away).
This is just a compile test.

Tests/SwiftProtobufPluginLibraryTests/Test_NamingUtils.swift also covers this
behavior but making a full compile test to be safe.
- Rename the UnicodeScalar helpers to to make it clear they only takes ASC.
- Stop exporting the camelcase helpers from the plugin lib, make a new
  temporary api that will better supported in followup.
Document the inputs to toUpper|LowerCamelCase (splitIdentifier), and dea;
with input that would have resulted in a leading number which isn't valid.

This fixes the field name issues in apple#931 as well as the naming of the generated
oneof enums.
This is just a compile test.

Tests/SwiftProtobufPluginLibraryTests/Test_NamingUtils.swift also covers this
behavior but making a full compile test to be safe.
For enum prefix stripping, some validation was happening after the stripping,
move that into the stripper so it won't return a stripped value that isn't
something that should be used to generate a swift name from.

Add some basic test cases to ensure it is working as expected.
This is just a compile test.

Tests/SwiftProtobufPluginLibraryTests/Test_NamingUtils.swift also covers this
behavior but making a full compile test to be safe.
@thomasvl thomasvl requested review from allevato and tbkka February 4, 2020 18:11
Copy link
Collaborator

@allevato allevato left a comment

Choose a reason for hiding this comment

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

Great improvements!

@thomasvl thomasvl merged commit b5efba4 into apple:master Feb 6, 2020
@thomasvl thomasvl deleted the ensure_valid_identifiers branch February 6, 2020 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Camel case naming of field variables and enum cases results in invalid Swift
2 participants