diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoParser.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoParser.kt index 0bf6ec4b05..a3ac1a7893 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoParser.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoParser.kt @@ -659,8 +659,7 @@ class ProtoParser internal constructor( companion object { /** Parse a named `.proto` schema. */ fun parse(location: Location, data: String): ProtoFileElement { - // TODO Migrate to data.toCharArray() once stable in common code. - val chars = CharArray(data.length, data::get) + val chars = data.toCharArray() return ProtoParser(location, chars).readProtoFile() } } diff --git a/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoParserTest.kt b/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoParserTest.kt index 4827397e42..a3e9a9fe20 100644 --- a/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoParserTest.kt +++ b/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoParserTest.kt @@ -437,13 +437,13 @@ class ProtoParserTest { } @Test - fun messageFieldTrailingComment() { + fun messageFieldTrailingCommentWithCarriageReturn() { // Trailing message field comment. val proto = """ |message Test { | optional string name = 1; // Test all the things! |} - """.trimMargin() + """.trimMargin().replace("\n", "\r\n") val parsed = ProtoParser.parse(location, proto) val message = parsed.types[0] as MessageElement val field = message.fields[0] @@ -3066,6 +3066,51 @@ class ProtoParserTest { assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } + @Test fun parsingTrailingComments() { + val proto = """ + |enum ImageState { + | IMAGE_STATE_UNSPECIFIED = 0; + | IMAGE_STATE_READONLY = 1; /* unlocked */ + | IMAGE_STATE_MUSTLOCK = 2; /* must be locked */ + |} + """.trimMargin() + val expected = ProtoFileElement( + location = location, + types = listOf( + EnumElement( + location = location.at(1, 1), + name = "ImageState", + documentation = "", + options = listOf(), + constants = listOf( + EnumConstantElement( + location = location.at(2, 5), + name = "IMAGE_STATE_UNSPECIFIED", + tag = 0, + documentation = "", + options = listOf(), + ), + EnumConstantElement( + location = location.at(3, 5), + name = "IMAGE_STATE_READONLY", + tag = 1, + documentation = "unlocked", + options = listOf(), + ), + EnumConstantElement( + location = location.at(4, 5), + name = "IMAGE_STATE_MUSTLOCK", + tag = 2, + documentation = "must be locked", + options = listOf(), + ), + ), + ), + ), + ) + assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) + } + @Test fun forbidMultipleSyntaxDefinitions() { val proto = """ | syntax = "proto2";