-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate Kotlin-esque build function for using closures rather than B…
…uilders
- Loading branch information
Ryan O'Neill
committed
Oct 11, 2023
1 parent
b9f6835
commit 094fa67
Showing
14 changed files
with
844 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinBuildTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.squareup.wire | ||
|
||
import com.squareup.wire.protos.kotlin.simple.buildersonly.SimpleMessage | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class KotlinBuildTest { | ||
@Test fun kotlinBuildEquivalentToBuilderResult() { | ||
val bb = 100 | ||
|
||
val kotlinBuildResult = SimpleMessage.build { | ||
required_int32 = 4 | ||
optional_int32 = 5 | ||
optional_nested_msg = SimpleMessage.NestedMessage.build { | ||
this.bb = bb | ||
} | ||
} | ||
val builderResult = SimpleMessage.Builder() | ||
.required_int32(4) | ||
.optional_int32(5) | ||
.optional_nested_msg(SimpleMessage.NestedMessage.Builder() | ||
.bb(bb) | ||
.build() | ||
).build() | ||
|
||
assertEquals(kotlinBuildResult, builderResult) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.