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

Downcase value when comparing if the source is plural or singular. #52

Merged
merged 1 commit into from
Sep 22, 2020

Conversation

abuiles
Copy link
Contributor

@abuiles abuiles commented Sep 21, 2020

While generating protocol 14 XDRs, I noticed a weird output for CAP33 related enums and ops.

The following:

 beginSponsoringFutureReserf: 16,
 endSponsoringFutureReserf: 17,

Should have been

 beginSponsoringFutureReserves: 16,
 endSponsoringFutureReserves: 17,

After investigating, I found a bug in this library, which was comparing the pluralized version of the name with the original, the problem is that it didn't keep into account the letter casing - leading to incorrect results in scenarios like this one

"BEGIN_SPONSORING_FUTURE_RESERVEs" == "BEGIN_SPONSORING_FUTURE_RESERVES"

This PR fixes this issue, making both values down case.

base = named.name.underscore.classify
result = plural ? base.pluralize : base

"#{parent}#{result}"
end

def const_name(named)
# NOTE: classify will strip plurality, so we restore it if necessary
plural = named.name.pluralize == named.name
base = named.name.underscore.upcase
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't pluralize base, so this check is actually unnecessary.

@abuiles abuiles merged commit 351531e into master Sep 22, 2020
@abuiles abuiles deleted the fix-pluralize-comparison branch September 22, 2020 15:40
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.

2 participants