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

#480 Automatic Coproduct Rename from/to Protobuf GeneratedEnum #489

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ object TransformedNamesComparison {
def namesMatch(fromName: String, toName: String): Boolean = fromName.equalsIgnoreCase(toName)
}

case object GeneratedProtobufEnumEquality extends TransformedNamesComparison {
Copy link
Member

Choose a reason for hiding this comment

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

I would either name it CamelCaseUnderscoreCaseEquality (to e.g. use this with Java enums as well, maybe it should be a default for it? Maybe it should be named JavaEnumAware?) or keep it in chimneyProtobuf module. I wouldn't put some integration-specific conventions in the core package.


def namesMatch(fromName: String, toName: String): Boolean = {
val fromNameWithoutPrefix = fromName.replace("_", "").reverse.toLowerCase
val toNameWithoutPrefix = toName.replace("_", "").reverse.toLowerCase

fromNameWithoutPrefix.startsWith(toNameWithoutPrefix) || toNameWithoutPrefix.startsWith(fromNameWithoutPrefix)
}
}

type FieldDefault = BeanAware.type
val FieldDefault: FieldDefault = BeanAware

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,29 @@ class TransformedNamesComparisonSpec extends ChimneySpec {
TransformedNamesComparison.CaseInsensitiveEquality.namesMatch("SOME_FIELD", "someField") ==> false
}
}

group("TransformedNamesComparison.GeneratedProtobufEnumEquality") {

test("should match identical names") {
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("someField", "someField") ==> true
}

test("should match names which differ in capitalisation, underscores and prefix") {
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("FIELD_SOME", "some") ==> true
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("SOME_FIELD", "Field") ==> true
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("Field", "SOME_FIELD") ==> true
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("FIELD", "some_Field") ==> true
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("someField", "isSomeField") ==> true
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("isSomeField", "someField") ==> true
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("someField", "getSomeField") ==> true
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("getSomeField", "someField") ==> true
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("someField", "setSomeField") ==> true
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("setSomeField", "someField") ==> true
}

test("should not match names converted with different conventions") {
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("someField", "some-field") ==> false
TransformedNamesComparison.GeneratedProtobufEnumEquality.namesMatch("some-field", "someField") ==> false
}
}
}
Loading