Skip to content

Commit

Permalink
Reserved is actually available for proto2 syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Jan 27, 2016
1 parent a2614bb commit 3d27180
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ private Object readDeclaration(String documentation, Context context) {
if (readChar() != ';') throw unexpected("expected ';'");
return result;
} else if (label.equals("reserved")) {
if (syntax != ProtoFile.Syntax.PROTO_3) {
throw unexpected(location, "'reserved' declaration requires proto3");
}
return readReserved(location, documentation);
} else if (label.equals("message")) {
return readMessage(location, documentation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1593,49 +1593,20 @@ public final class ProtoParserTest {

@Test public void reserved() {
String proto = ""
+ "syntax = \"proto3\";\n"
+ "message Foo {\n"
+ " reserved 10, 12 to 14, 'foo';"
+ "}";
TypeElement message = MessageElement.builder(location.at(2, 1))
TypeElement message = MessageElement.builder(location.at(1, 1))
.name("Foo")
.reserveds(ImmutableList.of(ReservedElement.create(location.at(3, 3), "",
.reserveds(ImmutableList.of(ReservedElement.create(location.at(2, 3), "",
ImmutableList.<Object>of(10, Range.closed(12, 14), "foo"))))
.build();
ProtoFileElement expected = ProtoFileElement.builder(location)
.syntax(ProtoFile.Syntax.PROTO_3)
.types(ImmutableList.of(message))
.build();
assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected);
}

@Test public void reservedRequiresProto3() {
// Implicit proto2 syntax.
try {
String proto = ""
+ "message Foo {\n"
+ " reserved 10, 12 to 14, 'foo';"
+ "}";
ProtoParser.parse(location, proto);
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Syntax error in file.proto at 2:3: 'reserved' declaration requires proto3");
}

// Explicit proto2 syntax.
try {
String proto = ""
+ "syntax = \"proto2\";\n"
+ "message Foo {\n"
+ " reserved 10, 12 to 14, 'foo';"
+ "}";
ProtoParser.parse(location, proto);
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Syntax error in file.proto at 3:3: 'reserved' declaration requires proto3");
}
}

@Test public void noWhitespace() {
String proto = "message C {optional A.B ab = 1;}";
ProtoFileElement expected = ProtoFileElement.builder(location)
Expand Down

0 comments on commit 3d27180

Please sign in to comment.