In progress: [Isse 13] Implement a formatter.
* Added extra line between top-level elements.
* Added more tests.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter_Test.java
index 99f3990..5af39c7 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter_Test.java
@@ -10,8 +10,7 @@
import static com.google.eclipse.protobuf.formatting.CommentReaderRule.overrideRuntimeModuleWith;
import static com.google.eclipse.protobuf.junit.core.UnitTestModule.unitTestModule;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
import org.eclipse.xtext.formatting.*;
import org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion;
@@ -92,11 +91,37 @@
assertThatFormattingWorksCorrectly();
}
+ // message Person { optional group address = 1 { optional int32
+ // number = 2; optional string street = 3; } }
+
+ // message Person {
+ // optional group address = 1 {
+ // optional int32 number = 2;
+ // optional string street = 3;
+ // }
+ // }
+ @Test public void should_format_groups() {
+ assertThatFormattingWorksCorrectly();
+ }
+
+ // message Person {}
+ // service PersonService { rpc PersonRpc (Person) returns (Person); }
+
+ // message Person {
+ // }
+ //
+ // service PersonService {
+ // rpc PersonRpc ( Person ) returns ( Person );
+ // }
+ @Test public void should_format_service() {
+ assertThatFormattingWorksCorrectly();
+ }
+
private void assertThatFormattingWorksCorrectly() {
ICompositeNode rootNode = commentReader.rootNode();
IFormattedRegion region = formatter.format(rootNode, 0, rootNode.getText().length());
String formatted = region.getFormattedText();
- assertThat(formatted, equalTo(commentReader.expectedText()));
+ assertEquals(commentReader.expectedText(), formatted);
}
private static class TestModule extends AbstractTestModule {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter.java
index f7d94ba..1d737e4 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter.java
@@ -34,11 +34,13 @@
c.setLinewrap(1).after(g.getWeakImportRule());
c.setLinewrap(1).after(g.getNativeOptionRule());
c.setLinewrap(1).after(g.getCustomOptionRule());
- c.setLinewrap(1).after(g.getGroupRule());
+ c.setLinewrap(2).after(g.getMessageRule());
c.setLinewrap(1).after(g.getMessageFieldRule());
- c.setLinewrap(1).after(g.getEnumRule());
+ c.setLinewrap(1).after(g.getGroupRule());
+ c.setLinewrap(2).after(g.getEnumRule());
c.setLinewrap(1).after(g.getEnumElementRule());
c.setLinewrap(1).after(g.getRpcRule());
+ c.setLinewrap(2).after(g.getServiceRule());
for (Keyword k : g.findKeywords(EQUAL.toString())) {
c.setSpace(space()).around(k);
}
@@ -51,7 +53,7 @@
}
for (Keyword k : g.findKeywords(CLOSING_CURLY_BRACKET.toString())) {
c.setIndentationDecrement().before(k);
- c.setLinewrap(2).after(k);
+ c.setLinewrap(1).after(k);
}
for (Keyword k : g.findKeywords(OPENING_BRACKET.toString())) {
c.setNoSpace().after(k);