Skip to content

Commit 29d654f

Browse files
committed
Trailing comments support on windows
1 parent 459b722 commit 29d654f

File tree

2 files changed

+49
-4
lines changed
  • wire-schema/src

2 files changed

+49
-4
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,7 @@ class ProtoParser internal constructor(
659659
companion object {
660660
/** Parse a named `.proto` schema. */
661661
fun parse(location: Location, data: String): ProtoFileElement {
662-
// TODO Migrate to data.toCharArray() once stable in common code.
663-
val chars = CharArray(data.length, data::get)
662+
val chars = data.toCharArray()
664663
return ProtoParser(location, chars).readProtoFile()
665664
}
666665
}

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

+48-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.squareup.wire.schema.internal.MAX_TAG_VALUE
3030
import com.squareup.wire.schema.internal.parser.OptionElement.Kind
3131
import kotlin.test.Test
3232
import kotlin.test.fail
33+
import kotlinx.datetime.Clock
3334

3435
class ProtoParserTest {
3536
internal var location = Location.get("file.proto")
@@ -437,13 +438,13 @@ class ProtoParserTest {
437438
}
438439

439440
@Test
440-
fun messageFieldTrailingComment() {
441+
fun messageFieldTrailingCommentWithCarriageReturn() {
441442
// Trailing message field comment.
442443
val proto = """
443444
|message Test {
444445
| optional string name = 1; // Test all the things!
445446
|}
446-
""".trimMargin()
447+
""".trimMargin().replace("\n", "\r\n")
447448
val parsed = ProtoParser.parse(location, proto)
448449
val message = parsed.types[0] as MessageElement
449450
val field = message.fields[0]
@@ -3066,6 +3067,51 @@ class ProtoParserTest {
30663067
assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected)
30673068
}
30683069

3070+
@Test fun parsingTrailingComments() {
3071+
val proto = """
3072+
|enum ImageState {
3073+
| IMAGE_STATE_UNSPECIFIED = 0;
3074+
| IMAGE_STATE_READONLY = 1; /* unlocked */
3075+
| IMAGE_STATE_MUSTLOCK = 2; /* must be locked */
3076+
|}
3077+
""".trimMargin()
3078+
val expected = ProtoFileElement(
3079+
location = location,
3080+
types = listOf(
3081+
EnumElement(
3082+
location = location.at(1, 1),
3083+
name = "ImageState",
3084+
documentation = "",
3085+
options = listOf(),
3086+
constants = listOf(
3087+
EnumConstantElement(
3088+
location = location.at(2, 5),
3089+
name = "IMAGE_STATE_UNSPECIFIED",
3090+
tag = 0,
3091+
documentation = "",
3092+
options = listOf(),
3093+
),
3094+
EnumConstantElement(
3095+
location = location.at(3, 5),
3096+
name = "IMAGE_STATE_READONLY",
3097+
tag = 1,
3098+
documentation = "unlocked",
3099+
options = listOf(),
3100+
),
3101+
EnumConstantElement(
3102+
location = location.at(4, 5),
3103+
name = "IMAGE_STATE_MUSTLOCK",
3104+
tag = 2,
3105+
documentation = "must be locked",
3106+
options = listOf(),
3107+
),
3108+
),
3109+
),
3110+
),
3111+
)
3112+
assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected)
3113+
}
3114+
30693115
@Test fun forbidMultipleSyntaxDefinitions() {
30703116
val proto = """
30713117
| syntax = "proto2";

0 commit comments

Comments
 (0)