From 3d2718090326bc2fa8102d6e5f17301621a969e0 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Wed, 27 Jan 2016 01:52:29 -0500 Subject: [PATCH] Reserved is actually available for proto2 syntax. --- .../schema/internal/parser/ProtoParser.java | 3 -- .../internal/parser/ProtoParserTest.java | 33 ++----------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/wire-schema/src/main/java/com/squareup/wire/schema/internal/parser/ProtoParser.java b/wire-schema/src/main/java/com/squareup/wire/schema/internal/parser/ProtoParser.java index e9d8c71e4c..8392c5330a 100644 --- a/wire-schema/src/main/java/com/squareup/wire/schema/internal/parser/ProtoParser.java +++ b/wire-schema/src/main/java/com/squareup/wire/schema/internal/parser/ProtoParser.java @@ -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); diff --git a/wire-schema/src/test/java/com/squareup/wire/schema/internal/parser/ProtoParserTest.java b/wire-schema/src/test/java/com/squareup/wire/schema/internal/parser/ProtoParserTest.java index a3a348918a..923555397c 100644 --- a/wire-schema/src/test/java/com/squareup/wire/schema/internal/parser/ProtoParserTest.java +++ b/wire-schema/src/test/java/com/squareup/wire/schema/internal/parser/ProtoParserTest.java @@ -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.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)