Skip to content

Commit

Permalink
Regenerate tests to have immutable maps and lists
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Aug 1, 2020
1 parent 9dcbd5d commit 590f89b
Show file tree
Hide file tree
Showing 78 changed files with 2,553 additions and 1,677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.squareup.wire.ProtoReader
import com.squareup.wire.ProtoWriter
import com.squareup.wire.Syntax.PROTO_2
import com.squareup.wire.WireField
import com.squareup.wire.internal.immutableCopyOf
import com.squareup.wire.internal.redactElements
import kotlin.Any
import kotlin.AssertionError
Expand All @@ -26,14 +27,16 @@ import okio.ByteString
* Not used in the RPC. Instead, this is here for the form serialized to disk.
*/
class FeatureDatabase(
feature: List<Feature> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<FeatureDatabase, Nothing>(ADAPTER, unknownFields) {
@field:WireField(
tag = 1,
adapter = "routeguide.Feature#ADAPTER",
label = WireField.Label.REPEATED
)
val feature: List<Feature> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<FeatureDatabase, Nothing>(ADAPTER, unknownFields) {
val feature: List<Feature> = immutableCopyOf("feature", feature)

@Deprecated(
message = "Shouldn't be used in Kotlin",
level = DeprecationLevel.HIDDEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.squareup.wire.ProtoWriter
import com.squareup.wire.Syntax.PROTO_2
import com.squareup.wire.WireField
import com.squareup.wire.internal.checkElementsNotNull
import com.squareup.wire.internal.immutableCopyOf
import com.squareup.wire.internal.sanitize
import com.squareup.wire.proto2.geology.javainteropkotlin.Period
import kotlin.Any
Expand All @@ -32,16 +33,7 @@ class Dinosaur(
)
@JvmField
val name: String? = null,
/**
* URLs with images of this dinosaur.
*/
@field:WireField(
tag = 2,
adapter = "com.squareup.wire.ProtoAdapter#STRING",
label = WireField.Label.REPEATED
)
@JvmField
val picture_urls: List<String> = emptyList(),
picture_urls: List<String> = emptyList(),
@field:WireField(
tag = 3,
adapter = "com.squareup.wire.ProtoAdapter#DOUBLE"
Expand All @@ -62,6 +54,17 @@ class Dinosaur(
val period: Period? = null,
unknownFields: ByteString = ByteString.EMPTY
) : Message<Dinosaur, Dinosaur.Builder>(ADAPTER, unknownFields) {
/**
* URLs with images of this dinosaur.
*/
@field:WireField(
tag = 2,
adapter = "com.squareup.wire.ProtoAdapter#STRING",
label = WireField.Label.REPEATED
)
@JvmField
val picture_urls: List<String> = immutableCopyOf("picture_urls", picture_urls)

override fun newBuilder(): Builder {
val builder = Builder()
builder.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.squareup.wire.ProtoReader
import com.squareup.wire.ProtoWriter
import com.squareup.wire.Syntax.PROTO_2
import com.squareup.wire.WireField
import com.squareup.wire.internal.immutableCopyOf
import com.squareup.wire.internal.sanitize
import com.squareup.wire.proto2.geology.kotlin.Period
import kotlin.Any
Expand All @@ -34,15 +35,7 @@ class Dinosaur(
adapter = "com.squareup.wire.ProtoAdapter#STRING"
)
val name: String? = null,
/**
* URLs with images of this dinosaur.
*/
@field:WireField(
tag = 2,
adapter = "com.squareup.wire.ProtoAdapter#STRING",
label = WireField.Label.REPEATED
)
val picture_urls: List<String> = emptyList(),
picture_urls: List<String> = emptyList(),
@field:WireField(
tag = 3,
adapter = "com.squareup.wire.ProtoAdapter#DOUBLE"
Expand All @@ -60,6 +53,16 @@ class Dinosaur(
val period: Period? = null,
unknownFields: ByteString = ByteString.EMPTY
) : Message<Dinosaur, Nothing>(ADAPTER, unknownFields) {
/**
* URLs with images of this dinosaur.
*/
@field:WireField(
tag = 2,
adapter = "com.squareup.wire.ProtoAdapter#STRING",
label = WireField.Label.REPEATED
)
val picture_urls: List<String> = immutableCopyOf("picture_urls", picture_urls)

@Deprecated(
message = "Shouldn't be used in Kotlin",
level = DeprecationLevel.HIDDEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.squareup.wire.ProtoWriter
import com.squareup.wire.Syntax.PROTO_2
import com.squareup.wire.WireField
import com.squareup.wire.internal.checkElementsNotNull
import com.squareup.wire.internal.immutableCopyOf
import com.squareup.wire.internal.missingRequiredFields
import com.squareup.wire.internal.sanitize
import kotlin.Any
Expand Down Expand Up @@ -39,24 +40,28 @@ class KeywordKotlin(
)
@JvmField
val when_: Int,
fun_: Map<String, String> = emptyMap(),
return_: List<Boolean> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<KeywordKotlin, KeywordKotlin.Builder>(ADAPTER, unknownFields) {
@field:WireField(
tag = 3,
keyAdapter = "com.squareup.wire.ProtoAdapter#STRING",
adapter = "com.squareup.wire.ProtoAdapter#STRING",
declaredName = "fun"
)
@JvmField
val fun_: Map<String, String> = emptyMap(),
val fun_: Map<String, String> = immutableCopyOf("fun_", fun_)

@field:WireField(
tag = 4,
adapter = "com.squareup.wire.ProtoAdapter#BOOL",
label = WireField.Label.REPEATED,
declaredName = "return"
)
@JvmField
val return_: List<Boolean> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<KeywordKotlin, KeywordKotlin.Builder>(ADAPTER, unknownFields) {
val return_: List<Boolean> = immutableCopyOf("return_", return_)

override fun newBuilder(): Builder {
val builder = Builder()
builder.object_ = object_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.squareup.wire.ProtoWriter
import com.squareup.wire.Syntax.PROTO_2
import com.squareup.wire.WireField
import com.squareup.wire.internal.checkElementsNotNull
import com.squareup.wire.internal.immutableCopyOf
import com.squareup.wire.internal.sanitize
import com.squareup.wire.proto2.geology.javainteropkotlin.Period
import kotlin.Any
Expand All @@ -32,16 +33,7 @@ class Dinosaur(
)
@JvmField
val name: String? = null,
/**
* URLs with images of this dinosaur.
*/
@field:WireField(
tag = 2,
adapter = "com.squareup.wire.ProtoAdapter#STRING",
label = WireField.Label.REPEATED
)
@JvmField
val picture_urls: List<String> = emptyList(),
picture_urls: List<String> = emptyList(),
@field:WireField(
tag = 3,
adapter = "com.squareup.wire.ProtoAdapter#DOUBLE"
Expand All @@ -62,6 +54,17 @@ class Dinosaur(
val period: Period? = null,
unknownFields: ByteString = ByteString.EMPTY
) : Message<Dinosaur, Dinosaur.Builder>(ADAPTER, unknownFields) {
/**
* URLs with images of this dinosaur.
*/
@field:WireField(
tag = 2,
adapter = "com.squareup.wire.ProtoAdapter#STRING",
label = WireField.Label.REPEATED
)
@JvmField
val picture_urls: List<String> = immutableCopyOf("picture_urls", picture_urls)

override fun newBuilder(): Builder {
val builder = Builder()
builder.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.squareup.wire.ProtoReader
import com.squareup.wire.ProtoWriter
import com.squareup.wire.Syntax.PROTO_2
import com.squareup.wire.WireField
import com.squareup.wire.internal.immutableCopyOf
import com.squareup.wire.internal.sanitize
import com.squareup.wire.proto2.geology.kotlin.Period
import kotlin.Any
Expand All @@ -34,15 +35,7 @@ class Dinosaur(
adapter = "com.squareup.wire.ProtoAdapter#STRING"
)
val name: String? = null,
/**
* URLs with images of this dinosaur.
*/
@field:WireField(
tag = 2,
adapter = "com.squareup.wire.ProtoAdapter#STRING",
label = WireField.Label.REPEATED
)
val picture_urls: List<String> = emptyList(),
picture_urls: List<String> = emptyList(),
@field:WireField(
tag = 3,
adapter = "com.squareup.wire.ProtoAdapter#DOUBLE"
Expand All @@ -60,6 +53,16 @@ class Dinosaur(
val period: Period? = null,
unknownFields: ByteString = ByteString.EMPTY
) : Message<Dinosaur, Nothing>(ADAPTER, unknownFields) {
/**
* URLs with images of this dinosaur.
*/
@field:WireField(
tag = 2,
adapter = "com.squareup.wire.ProtoAdapter#STRING",
label = WireField.Label.REPEATED
)
val picture_urls: List<String> = immutableCopyOf("picture_urls", picture_urls)

@Deprecated(
message = "Shouldn't be used in Kotlin",
level = DeprecationLevel.HIDDEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.squareup.wire.Syntax.PROTO_2
import com.squareup.wire.WireEnum
import com.squareup.wire.WireField
import com.squareup.wire.internal.checkElementsNotNull
import com.squareup.wire.internal.immutableCopyOf
import com.squareup.wire.internal.missingRequiredFields
import com.squareup.wire.internal.redactElements
import com.squareup.wire.internal.sanitize
Expand Down Expand Up @@ -59,6 +60,9 @@ class Person(
)
@JvmField
val email: String? = null,
phone: List<PhoneNumber> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<Person, Person.Builder>(ADAPTER, unknownFields) {
/**
* A list of the customer's phone numbers.
*/
Expand All @@ -68,9 +72,8 @@ class Person(
label = WireField.Label.REPEATED
)
@JvmField
val phone: List<PhoneNumber> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<Person, Person.Builder>(ADAPTER, unknownFields) {
val phone: List<PhoneNumber> = immutableCopyOf("phone", phone)

override fun newBuilder(): Builder {
val builder = Builder()
builder.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.squareup.wire.Syntax
import com.squareup.wire.Syntax.PROTO_2
import com.squareup.wire.WireEnum
import com.squareup.wire.WireField
import com.squareup.wire.internal.immutableCopyOf
import com.squareup.wire.internal.missingRequiredFields
import com.squareup.wire.internal.redactElements
import com.squareup.wire.internal.sanitize
Expand Down Expand Up @@ -59,6 +60,9 @@ class Person(
adapter = "com.squareup.wire.ProtoAdapter#STRING"
)
val email: String? = null,
phone: List<PhoneNumber> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<Person, Nothing>(ADAPTER, unknownFields) {
/**
* A list of the customer's phone numbers.
*/
Expand All @@ -67,9 +71,8 @@ class Person(
adapter = "com.squareup.wire.proto2.person.kotlin.Person${'$'}PhoneNumber#ADAPTER",
label = WireField.Label.REPEATED
)
val phone: List<PhoneNumber> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<Person, Nothing>(ADAPTER, unknownFields) {
val phone: List<PhoneNumber> = immutableCopyOf("phone", phone)

@Deprecated(
message = "Shouldn't be used in Kotlin",
level = DeprecationLevel.HIDDEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.squareup.wire.ProtoWriter
import com.squareup.wire.Syntax.PROTO_2
import com.squareup.wire.WireField
import com.squareup.wire.internal.checkElementsNotNull
import com.squareup.wire.internal.immutableCopyOf
import com.squareup.wire.internal.missingRequiredFields
import com.squareup.wire.internal.sanitize
import kotlin.Any
Expand Down Expand Up @@ -39,24 +40,28 @@ class KeywordKotlin(
)
@JvmField
val when_: Int,
fun_: Map<String, String> = emptyMap(),
return_: List<Boolean> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<KeywordKotlin, KeywordKotlin.Builder>(ADAPTER, unknownFields) {
@field:WireField(
tag = 3,
keyAdapter = "com.squareup.wire.ProtoAdapter#STRING",
adapter = "com.squareup.wire.ProtoAdapter#STRING",
declaredName = "fun"
)
@JvmField
val fun_: Map<String, String> = emptyMap(),
val fun_: Map<String, String> = immutableCopyOf("fun_", fun_)

@field:WireField(
tag = 4,
adapter = "com.squareup.wire.ProtoAdapter#BOOL",
label = WireField.Label.REPEATED,
declaredName = "return"
)
@JvmField
val return_: List<Boolean> = emptyList(),
unknownFields: ByteString = ByteString.EMPTY
) : Message<KeywordKotlin, KeywordKotlin.Builder>(ADAPTER, unknownFields) {
val return_: List<Boolean> = immutableCopyOf("return_", return_)

override fun newBuilder(): Builder {
val builder = Builder()
builder.object_ = object_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import okio.ByteString.Companion.decodeHex
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.fail

class KotlinMapTest {
private val adapter = Mappy.ADAPTER
Expand All @@ -39,6 +40,22 @@ class KotlinMapTest {
assertNotNull(empty.things)
}

@Test fun mapsAreImmutable() {
val map = mutableMapOf("one" to Thing("One"))

val mappy = Mappy(things = map)
try {
(mappy.things as MutableMap<*, *>).clear()
fail()
} catch (_: UnsupportedOperationException) {
// Mutation failed as expected.
}

// Mutate the values used to create the map. Wire should have defensive copies.
map.clear()
assertEquals(mapOf("one" to Thing("One")), mappy.things)
}

companion object {
private val BYTES =
"0a0c0a036f6e6512050a034f6e650a0c0a0374776f12050a0354776f0a100a05746872656512070a055468726565".decodeHex()
Expand Down
Loading

0 comments on commit 590f89b

Please sign in to comment.