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

fix: Kotlin name mangling #1549

Closed
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 @@ -17,4 +17,12 @@ open class GivenStage : Stage<GivenStage>() {
this.message = message
return self()
}

@JvmInline
value class Username(val value: String)

open fun greeting(username: Username): GivenStage {
this.message = "Hello ${username.value}"
return self()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ class JUnit5Test {
whenStage.`when`().handle_message()
thenStage.then().the_result_is("Hello JUnit 5!")
}

@Test
fun `test with value class`() {
givenStage.given().greeting(GivenStage.Username("Foo"))
whenStage.`when`().handle_message()
thenStage.then().the_result_is("Hello Foo 5!")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public String as( As annotation, Method method ) {
}

String methodNameToReadableText( String methodName ) {
// Kotlin mangles the name of some functions; see https://kotlinlang.org/docs/inline-classes.html#mangling
if (methodName.contains("-")) {
methodName = methodName.substring(0, methodName.lastIndexOf('-'));
}

if( methodName.contains( "_" ) ) {
return WordUtil.fromSnakeCase( methodName );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class DefaultAsProviderTest {
"FooBar, foo bar",
"Foo_Bar, Foo Bar",
"foo_bar_Baz, foo bar Baz",
"foo_bar, foo bar"
"foo_bar, foo bar",
"foo bar-lkjw24dsgf, foo bar"
} )
@Test
public void test_method_to_readable_text( String methodName, String expectedText ) {
Expand Down