-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
29 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
23 changes: 23 additions & 0 deletions
23
app/src/test/kotlin/dogacel/kotlinx/protobuf/gen/CodeGeneratorTest.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,23 @@ | ||
package dogacel.kotlinx.protobuf.gen | ||
|
||
import messages.MessageNoFieldsOuterClass.MessageNoFields | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class CodeGeneratorTest { | ||
|
||
@Test | ||
fun hasAnyFieldShouldWork() { | ||
val codeGenerator = CodeGenerator() | ||
|
||
val messageNoFields = MessageNoFields.getDescriptor() | ||
val messageSomeFields1 = MessageNoFields.SubMessageNoFields.getDescriptor() | ||
val messageSomeFields2 = MessageNoFields.SubMessageNoFields.SubMessageNoFieldsExtend.getDescriptor() | ||
val messageSomeFieldsOneof = MessageNoFields.SubMessageOneofFields.getDescriptor() | ||
|
||
assertEquals(true, codeGenerator.hasNoField(messageNoFields)) | ||
assertEquals(false, codeGenerator.hasNoField(messageSomeFields1)) | ||
assertEquals(false, codeGenerator.hasNoField(messageSomeFields2)) | ||
assertEquals(false, codeGenerator.hasNoField(messageSomeFieldsOneof)) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
generated-code-tests/src/main/kotlin/testgen/messages/message_no_fields.proto.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,51 @@ | ||
package testgen.messages | ||
|
||
import kotlin.Any | ||
import kotlin.Boolean | ||
import kotlin.Int | ||
import kotlin.String | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.protobuf.ProtoNumber | ||
|
||
@Serializable | ||
public class MessageNoFields() { | ||
override fun toString(): String = "MessageNoFields" | ||
|
||
override fun hashCode(): Int = 70_682_849 | ||
|
||
override fun equals(other: Any?): Boolean = other is MessageNoFields | ||
|
||
@Serializable | ||
public data class SubMessageNoFields( | ||
@ProtoNumber(number = 1) | ||
public val subHello: SubMessageNoFields? = null, | ||
) { | ||
@Serializable | ||
public data class SubMessageNoFieldsExtend( | ||
@ProtoNumber(number = 1) | ||
public val type: Type = testgen.messages.MessageNoFields.Type.UNKNOWN, | ||
) | ||
} | ||
|
||
@Serializable | ||
public data class SubMessageOneofFields( | ||
@ProtoNumber(number = 1) | ||
public val someValue: Int? = null, | ||
) { | ||
init { | ||
require( | ||
listOfNotNull( | ||
someValue, | ||
).size <= 1 | ||
) { "Should only contain one of some_oneof." } | ||
} | ||
} | ||
|
||
@Serializable | ||
public enum class Type { | ||
@ProtoNumber(number = 0) | ||
UNKNOWN, | ||
@ProtoNumber(number = 1) | ||
KNOWN, | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
syntax = "proto3"; | ||
|
||
package messages; | ||
|
||
message MessageNoFields { | ||
enum Type { | ||
UNKNOWN = 0; | ||
KNOWN = 1; | ||
} | ||
message SubMessageNoFields { | ||
message SubMessageNoFieldsExtend { | ||
Type type = 1; | ||
} | ||
optional SubMessageNoFields subHello = 1; | ||
} | ||
|
||
message SubMessageOneofFields { | ||
oneof some_oneof { | ||
int32 some_value = 1; | ||
} | ||
} | ||
} |