Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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";
Expand Down