Skip to content

Commit 508f9bb

Browse files
committed
Trailing comments support on windows
1 parent ea23dcd commit 508f9bb

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

  • wire-schema/src

wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoParser.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,7 @@ class ProtoParser internal constructor(
680680
companion object {
681681
/** Parse a named `.proto` schema. */
682682
fun parse(location: Location, data: String): ProtoFileElement {
683-
// TODO Migrate to data.toCharArray() once stable in common code.
684-
val chars = CharArray(data.length, data::get)
683+
val chars = data.toCharArray()
685684
return ProtoParser(location, chars).readProtoFile()
686685
}
687686
}

wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoParserTest.kt

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,13 @@ class ProtoParserTest {
441441
}
442442

443443
@Test
444-
fun messageFieldTrailingComment() {
444+
fun messageFieldTrailingCommentWithCarriageReturn() {
445445
// Trailing message field comment.
446446
val proto = """
447447
|message Test {
448448
| optional string name = 1; // Test all the things!
449449
|}
450-
""".trimMargin()
450+
""".trimMargin().replace("\n", "\r\n")
451451
val parsed = ProtoParser.parse(location, proto)
452452
val message = parsed.types[0] as MessageElement
453453
val field = message.fields[0]
@@ -3204,6 +3204,51 @@ class ProtoParserTest {
32043204
assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected)
32053205
}
32063206

3207+
@Test fun parsingTrailingComments() {
3208+
val proto = """
3209+
|enum ImageState {
3210+
| IMAGE_STATE_UNSPECIFIED = 0;
3211+
| IMAGE_STATE_READONLY = 1; /* unlocked */
3212+
| IMAGE_STATE_MUSTLOCK = 2; /* must be locked */
3213+
|}
3214+
""".trimMargin()
3215+
val expected = ProtoFileElement(
3216+
location = location,
3217+
types = listOf(
3218+
EnumElement(
3219+
location = location.at(1, 1),
3220+
name = "ImageState",
3221+
documentation = "",
3222+
options = listOf(),
3223+
constants = listOf(
3224+
EnumConstantElement(
3225+
location = location.at(2, 5),
3226+
name = "IMAGE_STATE_UNSPECIFIED",
3227+
tag = 0,
3228+
documentation = "",
3229+
options = listOf(),
3230+
),
3231+
EnumConstantElement(
3232+
location = location.at(3, 5),
3233+
name = "IMAGE_STATE_READONLY",
3234+
tag = 1,
3235+
documentation = "unlocked",
3236+
options = listOf(),
3237+
),
3238+
EnumConstantElement(
3239+
location = location.at(4, 5),
3240+
name = "IMAGE_STATE_MUSTLOCK",
3241+
tag = 2,
3242+
documentation = "must be locked",
3243+
options = listOf(),
3244+
),
3245+
),
3246+
),
3247+
),
3248+
)
3249+
assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected)
3250+
}
3251+
32073252
@Test fun forbidMultipleSyntaxDefinitions() {
32083253
val proto = """
32093254
| syntax = "proto2";

0 commit comments

Comments
 (0)