diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaTest.kt index a8a1a2499b..6a242907e8 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaTest.kt @@ -2535,6 +2535,74 @@ class SchemaTest { assertThat(schema.protoFile("squareup/domain/message.proto")).isNotNull() } + @Test + fun extensionInProtoPathDontLoad() { + val schema = buildSchema { + add( + "a/original.proto".toPath(), + """ + |syntax = "proto2"; + |package a; + |message A { + | optional string one = 1; + |} + """.trimMargin(), + ) + addProtoPath( + "b/extension.proto".toPath(), + """ + |syntax = "proto2"; + |package b; + |import "a/original.proto"; + |extend a.A { + | optional string two = 2; + |} + """.trimMargin(), + ) + } + val fields = (schema.getType("a.A") as MessageType).fields + assertThat(fields).hasSize(1) + with(fields[0]) { + assertThat(namespaces).isEqualTo(listOf("a", "A")) + assertThat(name).isEqualTo("one") + assertThat(isExtension).isEqualTo(false) + } + } + + @Test + fun extensionInSourceLoadsEvenIfParentMessageIsInProtoPath() { + val schema = buildSchema { + addProtoPath( + "a/original.proto".toPath(), + """ + |syntax = "proto2"; + |package a; + |message A { + | optional string one = 1; + |} + """.trimMargin(), + ) + add( + "b/extension.proto".toPath(), + """ + |syntax = "proto2"; + |package b; + |import "a/original.proto"; + |extend a.A { + | optional string two = 2; + |} + """.trimMargin(), + ) + } + val fields = (schema.getType("a.A") as MessageType).fields + assertThat(fields).hasSize(1) + with(fields[0]) { + assertThat(namespaces).isEqualTo(listOf("b")) + assertThat(name).isEqualTo("two") + assertThat(isExtension).isEqualTo(true) + } + } + @Test fun optionsWithRelativePathUsedInExtensions() { val schema = buildSchema {