Tests now specify proto code to specify as comments below the test
method, instead of using a StringBuilder.
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_fieldFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_fieldFrom_Test.java
index 6300ea8..a4d9291 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_fieldFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_fieldFrom_Test.java
@@ -10,22 +10,16 @@
import static com.google.eclipse.protobuf.junit.core.Setups.integrationTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-import static com.google.eclipse.protobuf.junit.model.find.FieldOptionFinder.findFieldOption;
+import static com.google.eclipse.protobuf.junit.model.find.FieldOptionFinder.findCustomFieldOption;
import static com.google.eclipse.protobuf.junit.model.find.Name.name;
import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
-import com.google.eclipse.protobuf.junit.core.*;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.FieldOptions;
-import com.google.eclipse.protobuf.protobuf.CustomFieldOption;
-import com.google.eclipse.protobuf.protobuf.Property;
-import com.google.eclipse.protobuf.protobuf.Protobuf;
+import org.junit.*;
/**
* Tests for <code>{@link FieldOptions#fieldFrom(CustomFieldOption)}</code>.
@@ -36,29 +30,29 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
+ private Protobuf root;
private FieldOptions fieldOptions;
@Before public void setUp() {
+ root = xtext.root();
fieldOptions = xtext.getInstanceOf(FieldOptions.class);
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // message Custom {
+ // optional int32 count = 1;
+ // }
+ //
+ // extend google.protobuf.FieldOptions {
+ // optional Custom custom = 1000;
+ // }
+ //
+ // message Person {
+ // optional boolean active = 1 [(custom).count = 6];
+ // }
@Test public void should_return_property_field() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto'; ")
- .append(" ")
- .append("message Custom { ")
- .append(" optional int32 count = 1; ")
- .append("} ")
- .append(" ")
- .append("extend google.protobuf.FieldOptions { ")
- .append(" optional Custom custom = 1000; ")
- .append("} ")
- .append(" ")
- .append("message Person { ")
- .append(" optional boolean active = 1 [(custom).count = 6];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
- CustomFieldOption option = (CustomFieldOption) findFieldOption(name("custom"), in(root));
+ CustomFieldOption option = findCustomFieldOption(name("custom"), in(root));
Property p = fieldOptions.fieldFrom(option);
assertThat(p.getName(), equalTo("count"));
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_isDefaultValueOption_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_isDefaultValueOption_Test.java
index dfbf2a8..89c1702 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_isDefaultValueOption_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_isDefaultValueOption_Test.java
@@ -16,13 +16,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.FieldOptions;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link FieldOptions#isDefaultValueOption(FieldOption)}</code>.
*
@@ -32,24 +30,26 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private FieldOptions fieldOptions;
private Protobuf root;
+ private FieldOptions fieldOptions;
@Before public void setUp() {
+ root = xtext.root();
fieldOptions = xtext.getInstanceOf(FieldOptions.class);
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional boolean active = 1 [default = true, deprecated = false];")
- .append("} ");
- root = xtext.parseText(proto);
}
+ // message Person {
+ // optional boolean active = 1 [default = true, deprecated = false];
+ // }
@Test public void should_return_true_if_FieldOption_is_default_value_one() {
FieldOption option = findFieldOption(name("default"), in(root));
boolean result = fieldOptions.isDefaultValueOption(option);
assertThat(result, equalTo(true));
}
+ // message Person {
+ // optional boolean active = 1 [default = true, deprecated = false];
+ // }
@Test public void should_return_false_if_FieldOption_is_not_default_value_one() {
FieldOption option = findFieldOption(name("deprecated"), in(root));
boolean result = fieldOptions.isDefaultValueOption(option);
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_nameOf_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_nameOf_Test.java
index e95ae28..034ce14 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_nameOf_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_nameOf_Test.java
@@ -16,13 +16,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.FieldOptions;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link FieldOptions#nameOf(FieldOption)}</code>.
*
@@ -32,35 +30,33 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
+ private Protobuf root;
private FieldOptions fieldOptions;
@Before public void setUp() {
+ root = xtext.root();
fieldOptions = xtext.getInstanceOf(FieldOptions.class);
}
+ // message Person {
+ // optional boolean active = 1 [deprecated = false];
+ // }
@Test public void should_return_name_of_native_field_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional boolean active = 1 [deprecated = false];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
FieldOption option = findFieldOption(name("deprecated"), in(root));
String name = fieldOptions.nameOf(option);
assertThat(name, equalTo("deprecated"));
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // extend google.protobuf.FieldOptions {
+ // optional string encoding = 1000;
+ // }
+ //
+ // message Person {
+ // optional boolean active = 1 [(encoding) = 'UTF-8'];
+ // }
@Test public void should_return_name_of_custom_field_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto'; ")
- .append(" ")
- .append("extend google.protobuf.FieldOptions { ")
- .append(" optional string encoding = 1000; ")
- .append("} ")
- .append(" ")
- .append("message Person { ")
- .append(" optional boolean active = 1 [(encoding) = 'UTF-8'];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
FieldOption option = findFieldOption(name("encoding"), in(root));
String name = fieldOptions.nameOf(option);
assertThat(name, equalTo("encoding"));
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java
index 6db834f..9f222f0 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java
@@ -16,13 +16,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.FieldOptions;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link FieldOptions#propertyFrom(FieldOption)}</code>.
*
@@ -32,35 +30,33 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
+ private Protobuf root;
private FieldOptions fieldOptions;
@Before public void setUp() {
+ root = xtext.root();
fieldOptions = xtext.getInstanceOf(FieldOptions.class);
}
+ // message Person {
+ // optional boolean active = 1 [deprecated = false];
+ // }
@Test public void should_return_property_of_native_field_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional boolean active = 1 [deprecated = false];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
FieldOption option = findFieldOption(name("deprecated"), in(root));
Property p = fieldOptions.propertyFrom(option);
assertThat(p.getName(), equalTo("deprecated"));
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // extend google.protobuf.FieldOptions {
+ // optional string encoding = 1000;
+ // }
+ //
+ // message Person {
+ // optional boolean active = 1 [(encoding) = 'UTF-8'];
+ // }
@Test public void should_return_property_of_custom_field_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto'; ")
- .append(" ")
- .append("extend google.protobuf.FieldOptions { ")
- .append(" optional string encoding = 1000; ")
- .append("} ")
- .append(" ")
- .append("message Person { ")
- .append(" optional boolean active = 1 [(encoding) = 'UTF-8'];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
FieldOption option = findFieldOption(name("encoding"), in(root));
Property p = fieldOptions.propertyFrom(option);
assertThat(p.getName(), equalTo("encoding"));
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_fieldFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_fieldFrom_Test.java
index 1fc8f46..c7cda66 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_fieldFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_fieldFrom_Test.java
@@ -16,16 +16,10 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.Options;
-import com.google.eclipse.protobuf.protobuf.CustomOption;
-import com.google.eclipse.protobuf.protobuf.Property;
-import com.google.eclipse.protobuf.protobuf.Protobuf;
+import com.google.eclipse.protobuf.protobuf.*;
+
+import org.junit.*;
/**
* Tests for <code>{@link Options#fieldFrom(CustomOption)}</code>.
@@ -36,26 +30,26 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
+ private Protobuf root;
private Options options;
@Before public void setUp() {
+ root = xtext.root();
options = xtext.getInstanceOf(Options.class);
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // message Custom {
+ // optional int32 count = 1;
+ // }
+ //
+ // extend google.protobuf.FileOptions {
+ // optional Custom custom = 1000;
+ // }
+ //
+ // option (custom).count = 6;
@Test public void should_return_property_field() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto';")
- .append(" ")
- .append("message Custom { ")
- .append(" optional int32 count = 1; ")
- .append("} ")
- .append(" ")
- .append("extend google.protobuf.FileOptions { ")
- .append(" optional Custom custom = 1000; ")
- .append("} ")
- .append(" ")
- .append("option (custom).count = 6;");
- Protobuf root = xtext.parseText(proto);
CustomOption option = (CustomOption) findOption(name("custom"), in(root));
Property p = options.fieldFrom(option);
assertThat(p.getName(), equalTo("count"));
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_isExtendingOptionMessage_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_isExtendingOptionMessage_Test.java
index 7df81b6..57c8869 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_isExtendingOptionMessage_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_isExtendingOptionMessage_Test.java
@@ -19,7 +19,6 @@
import static org.mockito.Mockito.mock;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.model.OptionType;
import com.google.eclipse.protobuf.protobuf.*;
@@ -35,20 +34,20 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
+ private Protobuf root;
private Options options;
@Before public void setUp() {
+ root = xtext.root();
options = xtext.getInstanceOf(Options.class);
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // extend google.protobuf.FileOptions {
+ // optional string encoding = 1000;
+ // }
@Test public void should_return_true_if_name_of_extended_message_is_equal_to_message_name_in_OptionType() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto';")
- .append(" ")
- .append("extend google.protobuf.FileOptions { ")
- .append(" optional string encoding = 1000; ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
ExtendMessage extend = findExtendMessage(name("FileOptions"), in(root));
boolean result = options.isExtendingOptionMessage(extend, FILE);
assertThat(result, equalTo(true));
@@ -60,14 +59,12 @@
assertThat(result, equalTo(false));
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // extend google.protobuf.FieldOptions {
+ // optional string encoding = 1000;
+ // }
@Test public void should_return_false_if_name_of_extended_message_is_not_equal_to_message_name_in_OptionType() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto';")
- .append(" ")
- .append("extend google.protobuf.FieldOptions { ")
- .append(" optional string encoding = 1000; ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
ExtendMessage extend = findExtendMessage(name("FieldOptions"), in(root));
boolean result = options.isExtendingOptionMessage(extend, FILE);
assertThat(result, equalTo(false));
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java
index e27234f..2bbd2a9 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java
@@ -16,13 +16,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.Options;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link Options#propertyFrom(Option)}</code>.
*
@@ -32,31 +30,29 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
+ private Protobuf root;
private Options options;
@Before public void setUp() {
+ root = xtext.root();
options = xtext.getInstanceOf(Options.class);
}
+ // option java_package = 'com.google.eclipse.protobuf.tests';
@Test public void should_return_property_of_native_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("option java_package = 'com.google.eclipse.protobuf.tests';");
- Protobuf root = xtext.parseText(proto);
Option option = findOption(name("java_package"), in(root));
Property p = options.propertyFrom(option);
assertThat(p.getName(), equalTo("java_package"));
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // extend google.protobuf.FileOptions {
+ // optional string encoding = 1000;
+ // }
+ //
+ // option (encoding) = 'UTF-8';
@Test public void should_return_property_of_custom_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto';")
- .append(" ")
- .append("extend google.protobuf.FileOptions { ")
- .append(" optional string encoding = 1000; ")
- .append("} ")
- .append(" ")
- .append("option (encoding) = 'UTF-8'; ");
- Protobuf root = xtext.parseText(proto);
Option option = findOption(name("encoding"), in(root));
Property p = options.propertyFrom(option);
assertThat(p.getName(), equalTo("encoding"));
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralRef_literal_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralRef_literal_Test.java
index bf3872b..b9dd454 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralRef_literal_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralRef_literal_Test.java
@@ -28,7 +28,6 @@
import org.junit.Test;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.protobuf.Enum;
import com.google.eclipse.protobuf.protobuf.FieldOption;
import com.google.eclipse.protobuf.protobuf.LiteralRef;
@@ -50,77 +49,73 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
+ private Protobuf root;
private ProtobufScopeProvider provider;
@Before public void setUp() {
+ root = xtext.root();
provider = xtext.getInstanceOf(ProtobufScopeProvider.class);
}
+ // enum Type {
+ // ONE = 0;
+ // TWO = 1;
+ // }
+ //
+ // message Person {
+ // optional Type type = 1 [default = ONE];
+ // }
@Test public void should_provide_Literals_for_default_value() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("enum Type { ")
- .append(" ONE = 0; ")
- .append(" TWO = 1; ")
- .append("} ")
- .append(" ")
- .append("message Person { ")
- .append(" optional Type type = 1 [default = ONE];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
FieldOption option = findFieldOption(name("default"), in(root));
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
Enum typeEnum = findEnum(name("Type"), in(root));
assertThat(descriptionsIn(scope), containAllLiteralsIn(typeEnum));
}
+ // option optimize_for = SPEED;
@Test public void should_provide_Literals_for_native_option() {
- Protobuf root = xtext.parseText("option optimize_for = SPEED;");
Option option = findOption(name("optimize_for"), in(root));
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
Enum optimizeModeEnum = descriptor().enumByName("OptimizeMode");
assertThat(descriptionsIn(scope), containAllLiteralsIn(optimizeModeEnum));
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // enum Type {
+ // ONE = 0;
+ // TWO = 1;
+ // }
+ //
+ // extend google.protobuf.FileOptions {
+ // optional Type type = 1000;
+ // }
+ //
+ // option (type) = ONE;
@Test public void should_provide_Literals_for_custom_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto';")
- .append(" ")
- .append("enum Type { ")
- .append(" ONE = 0; ")
- .append(" TWO = 1; ")
- .append("} ")
- .append(" ")
- .append("extend google.protobuf.FileOptions { ")
- .append(" optional Type type = 1000; ")
- .append("} ")
- .append(" ")
- .append("option (type) = ONE; ");
- Protobuf root = xtext.parseText(proto);
Option option = findOption(name("type"), in(root));
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
Enum typeEnum = findEnum(name("Type"), in(root));
assertThat(descriptionsIn(scope), containAllLiteralsIn(typeEnum));
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // enum Type {
+ // ONE = 0;
+ // TWO = 1;
+ // }
+ //
+ // message Info {
+ // optional Type type = 1;
+ // }
+ //
+ // extend google.protobuf.FileOptions {
+ // optional Info info = 1000;
+ // }
+ //
+ // option (info).type = ONE;
@Test public void should_provide_Literals_for_property_of_custom_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto';")
- .append(" ")
- .append("enum Type { ")
- .append(" ONE = 0; ")
- .append(" TWO = 1; ")
- .append("} ")
- .append(" ")
- .append("message Info { ")
- .append(" optional Type type = 1; ")
- .append("} ")
- .append(" ")
- .append("extend google.protobuf.FileOptions { ")
- .append(" optional Info info = 1000; ")
- .append("} ")
- .append(" ")
- .append("option (info).type = ONE; ");
- Protobuf root = xtext.parseText(proto);
Option option = findOption(name("info"), in(root));
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
Enum typeEnum = findEnum(name("Type"), in(root));
@@ -131,12 +126,10 @@
return (LiteralRef) option.getValue();
}
+ // message Person {
+ // optional Type type = 1 [ctype = STRING];
+ // }
@Test public void should_provide_Literals_for_native_field_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional Type type = 1 [ctype = STRING];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
FieldOption option = findFieldOption(name("ctype"), in(root));
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
Enum cTypeEnum = descriptor().enumByName("CType");
@@ -148,50 +141,46 @@
return descriptorProvider.primaryDescriptor();
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // enum Type {
+ // ONE = 0;
+ // TWO = 1;
+ // }
+ //
+ // extend google.protobuf.FieldOptions {
+ // optional Type type = 1000;
+ // }
+ //
+ // message Person {
+ // optional boolean active = 1 [(type) = ONE];
+ // }
@Test public void should_provide_Literals_for_custom_field_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto'; ")
- .append(" ")
- .append("enum Type { ")
- .append(" ONE = 0; ")
- .append(" TWO = 1; ")
- .append("} ")
- .append(" ")
- .append("extend google.protobuf.FieldOptions { ")
- .append(" optional Type type = 1000; ")
- .append("} ")
- .append(" ")
- .append("message Person { ")
- .append(" optional boolean active = 1 [(type) = ONE];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
FieldOption option = findFieldOption(name("type"), in(root));
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
Enum typeEnum = findEnum(name("Type"), in(root));
assertThat(descriptionsIn(scope), containAllLiteralsIn(typeEnum));
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // enum Type {
+ // ONE = 0;
+ // TWO = 1;
+ // }
+ //
+ // message Info {
+ // optional Type type = 1;
+ // }
+ //
+ // extend google.protobuf.FieldOptions {
+ // optional Info info = 1000;
+ // }
+ //
+ // message Person {
+ // optional boolean active = 1 [(info).type = ONE];
+ // }
@Test public void should_provide_Literals_for_property_of_custom_field_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto'; ")
- .append(" ")
- .append("enum Type { ")
- .append(" ONE = 0; ")
- .append(" TWO = 1; ")
- .append("} ")
- .append(" ")
- .append("message Info { ")
- .append(" optional Type type = 1; ")
- .append("} ")
- .append(" ")
- .append("extend google.protobuf.FieldOptions { ")
- .append(" optional Info info = 1000; ")
- .append("} ")
- .append(" ")
- .append("message Person { ")
- .append(" optional boolean active = 1 [(info).type = ONE];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
FieldOption option = findFieldOption(name("info"), in(root));
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
Enum typeEnum = findEnum(name("Type"), in(root));
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java
index 8324cd1..2593c9e 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java
@@ -22,7 +22,6 @@
import static org.mockito.Mockito.mock;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.protobuf.*;
import org.eclipse.emf.ecore.EReference;
@@ -46,26 +45,26 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
+ private Protobuf root;
private ProtobufScopeProvider provider;
@Before public void setUp() {
+ root = xtext.root();
provider = xtext.getInstanceOf(ProtobufScopeProvider.class);
}
+ // option optimize_for = SPEED;
@Test public void should_provide_Property_fields_for_native_option() {
- Protobuf root = xtext.parseText("option optimize_for = SPEED;");
Option option = findOption(name("optimize_for"), in(root));
IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
Collection<Property> fileOptions = descriptor().optionsOfType(FILE);
assertThat(descriptionsIn(scope), containAll(fileOptions));
}
+ // message Person {
+ // optional Type type = 1 [ctype = STRING];
+ // }
@Test public void should_provide_Property_fields_for_native_field_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional Type type = 1 [ctype = STRING];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
NativeFieldOption option = findNativeFieldOption(name("ctype"), in(root));
IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
Collection<Property> fieldOptions = descriptor().optionsOfType(FIELD);
@@ -77,18 +76,16 @@
return descriptorProvider.primaryDescriptor();
}
+ // package com.google.proto;
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // extend google.protobuf.FileOptions {
+ // optional int32 code = 1000;
+ // optional int32 info = 1001;
+ // }
+ //
+ // option (code) = 68;
@Test public void should_provide_Property_fields_for_custom_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("package com.google.proto; ")
- .append("import 'google/protobuf/descriptor.proto';")
- .append(" ")
- .append("extend google.protobuf.FileOptions { ")
- .append(" optional int32 code = 1000; ")
- .append(" optional int32 info = 1001; ")
- .append("} ")
- .append(" ")
- .append("option (code) = 68; ");
- Protobuf root = xtext.parseText(proto);
Option option = findOption(name("code"), in(root));
IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
assertThat(descriptionsIn(scope), containAll("code", "proto.code", "google.proto.code", "com.google.proto.code",
@@ -97,14 +94,12 @@
".com.google.proto.info"));
}
+ // package com.google.proto;
+ //
+ // import 'protos/custom-options.proto';
+ //
+ // option (code) = 68;
@Test public void should_provide_imported_Property_fields_for_custom_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("package com.google.proto; ")
- .append(" ")
- .append("import 'protos/custom-options.proto';") // file is in this project.
- .append(" ")
- .append("option (code) = 68; ");
- Protobuf root = xtext.parseText(proto);
Option option = findOption(name("code"), in(root));
IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
assertThat(descriptionsIn(scope), containAll("code", "test.code", "google.test.code", "com.google.test.code",
@@ -113,20 +108,18 @@
".com.google.test.info"));
}
+ // package com.google.proto;
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // extend google.protobuf.FieldOptions {
+ // optional int32 code = 1000;
+ // optional int32 info = 1001;
+ // }
+ //
+ // message Person {
+ // optional boolean active = 1 [(code) = 68];
+ // }
@Test public void should_provide_Property_fields_for_custom_field_option() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("package com.google.proto; ")
- .append("import 'google/protobuf/descriptor.proto'; ")
- .append(" ")
- .append("extend google.protobuf.FieldOptions { ")
- .append(" optional int32 code = 1000; ")
- .append(" optional int32 info = 1001; ")
- .append("} ")
- .append(" ")
- .append("message Person { ")
- .append(" optional boolean active = 1 [(code) = 68];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
CustomFieldOption option = findCustomFieldOption(name("code"), in(root));
IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
assertThat(descriptionsIn(scope), containAll("code", "proto.code", "google.proto.code", "com.google.proto.code",
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_SimplePropertyRef_property_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_SimplePropertyRef_property_Test.java
index e1a4aca..82d0b49 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_SimplePropertyRef_property_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_SimplePropertyRef_property_Test.java
@@ -21,7 +21,6 @@
import static org.mockito.Mockito.mock;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.protobuf.*;
import org.eclipse.emf.ecore.EReference;
@@ -42,51 +41,49 @@
}
@Rule public XtextRule xtext = createWith(integrationTestSetup());
-
+
+ private Protobuf root;
private ProtobufScopeProvider provider;
@Before public void setUp() {
+ root = xtext.root();
provider = xtext.getInstanceOf(ProtobufScopeProvider.class);
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // message Type {
+ // optional int32 code = 1;
+ // optional string name = 2;
+ // }
+ //
+ // extend google.protobuf.FileOptions {
+ // optional Type type = 1000;
+ // }
+ //
+ // option (type).code = 68;
@Test public void should_provide_Property_fields_for_custom_option_field() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto';")
- .append(" ")
- .append("message Type { ")
- .append(" optional int32 code = 1; ")
- .append(" optional string name = 2; ")
- .append("} ")
- .append(" ")
- .append("extend google.protobuf.FileOptions { ")
- .append(" optional Type type = 1000; ")
- .append("} ")
- .append(" ")
- .append("option (type).code = 68; ");
- Protobuf root = xtext.parseText(proto);
CustomOption option = findCustomOption(name("type"), in(root));
IScope scope = provider.scope_SimplePropertyRef_property(option.getPropertyField(), reference);
Message typeMessage = findMessage(name("Type"), in(root));
assertThat(descriptionsIn(scope), containAllPropertiesIn(typeMessage));
}
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // message Type {
+ // optional int32 code = 1;
+ // optional string name = 2;
+ // }
+ //
+ // extend google.protobuf.FieldOptions {
+ // optional Type type = 1000;
+ // }
+ //
+ // message Person {
+ // optional boolean active = 1 [(type).code = 68];
+ // }
@Test public void should_provide_Property_fields_for_custom_field_option_field() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import 'google/protobuf/descriptor.proto'; ")
- .append(" ")
- .append("message Type { ")
- .append(" optional int32 code = 1; ")
- .append(" optional string name = 2; ")
- .append("} ")
- .append(" ")
- .append("extend google.protobuf.FieldOptions { ")
- .append(" optional Type type = 1000; ")
- .append("} ")
- .append(" ")
- .append("message Person { ")
- .append(" optional boolean active = 1 [(type).code = 68];")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
CustomFieldOption option = findCustomFieldOption(name("type"), in(root));
IScope scope = provider.scope_SimplePropertyRef_property(option.getPropertyField(), reference);
Message typeMessage = findMessage(name("Type"), in(root));
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue91AddSupportForUTF16Strings.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue91AddSupportForUTF16Strings.java
index ef56d2e..c7785eb 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue91AddSupportForUTF16Strings.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue91AddSupportForUTF16Strings.java
@@ -10,9 +10,11 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
+import com.google.eclipse.protobuf.protobuf.Protobuf;
import org.junit.*;
@@ -24,12 +26,17 @@
public class Issue91AddSupportForUTF16Strings {
@Rule public XtextRule xtext = createWith(unitTestSetup());
+
+ private Protobuf root;
+ @Before public void setUp() {
+ root = xtext.root();
+ }
+
+ // message Foo {
+ // optional string bar = 1 [default="\\302\\265"];
+ // }
@Test public void should_recognize_UTF16_strings() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Foo { ")
- .append(" optional string bar = 1 [default=\"\\302\\265\"];")
- .append("} ");
- xtext.parseText(proto);
+ assertThat(root, notNullValue());
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestSourceReader.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestSourceReader.java
new file mode 100644
index 0000000..d07f5c7
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestSourceReader.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.junit.core;
+
+import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
+
+import org.junit.runners.model.FrameworkMethod;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+class TestSourceReader {
+
+ private final Map<String, MultiLineTextBuilder> comments = new HashMap<String, MultiLineTextBuilder>();
+ private final Object lock = new Object();
+ private boolean initialized;
+
+ private String testName(String line) {
+ if (!line.startsWith("@Test")) return null;
+ int indexOfShould = line.indexOf("should");
+ return (indexOfShould == -1) ? null : line.substring(indexOfShould, line.indexOf("("));
+ }
+
+ String commentsIn(FrameworkMethod method) {
+ synchronized (lock) {
+ ensureCommentsAreRead(method.getMethod().getDeclaringClass());
+ MultiLineTextBuilder text = comments.get(method.getName());
+ return (text == null) ? null : text.toString();
+ }
+ }
+
+ private void ensureCommentsAreRead(Class<?> testClass) {
+ if (initialized) return;
+ doReadComments(testClass);
+ initialized = true;
+ }
+
+ private void doReadComments(Class<?> testClass) {
+ String fqn = testClass.getName().replace('.', '/');
+ fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$"));
+ String classFile = fqn + ".java";
+ File file = new File("src" + File.separator + classFile);
+ BufferedReader reader = null;
+ MultiLineTextBuilder text = new MultiLineTextBuilder();
+ try {
+ reader = new BufferedReader(new FileReader(file));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ line = line.replaceFirst("^\\s*", "");
+ if (line.startsWith("//")) {
+ text.append(line.substring(2));
+ continue;
+ }
+ if (text.isEmpty()) continue;
+ String testName = testName(line);
+ if (testName != null) {
+ comments.put(testName, text);
+ text = new MultiLineTextBuilder();
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {}
+ }
+ }
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
index 2dc9e1d..cd0d72d 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
@@ -1,9 +1,10 @@
/*
* Copyright (c) 2011 Google Inc.
- *
- * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
- * Public License v1.0 which accompanies this distribution, and is available at
- *
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.junit.core;
@@ -12,6 +13,7 @@
import static org.eclipse.emf.common.util.URI.createURI;
import static org.eclipse.emf.ecore.util.EcoreUtil.resolveAll;
import static org.eclipse.xtext.util.CancelIndicator.NullImpl;
+import static org.eclipse.xtext.util.Strings.isEmpty;
import java.io.*;
@@ -21,32 +23,40 @@
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.resource.*;
-import org.eclipse.xtext.util.StringInputStream;
+import org.eclipse.xtext.util.*;
import org.junit.rules.MethodRule;
import org.junit.runners.model.*;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.protobuf.Protobuf;
import com.google.inject.Injector;
/**
* Rule that performs configuration of a standalone Xtext environment.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class XtextRule implements MethodRule {
private final Injector injector;
+ private final TestSourceReader reader;
+
+ private Protobuf root;
public static XtextRule createWith(ISetup setup) {
return new XtextRule(setup);
}
-
+
private XtextRule(ISetup setup) {
injector = setup.createInjectorAndDoEMFRegistration();
+ reader = new TestSourceReader();
}
public Statement apply(Statement base, FrameworkMethod method, Object target) {
+ root = null;
+ String comments = reader.commentsIn(method);
+ if (!isEmpty(comments)) {
+ root = parseText(comments);
+ }
return base;
}
@@ -54,11 +64,7 @@
return injector;
}
- public Protobuf parseText(MultiLineTextBuilder text) {
- return parseText(text.toString());
- }
-
- public Protobuf parseText(String text) {
+ private Protobuf parseText(String text) {
XtextResource resource = resourceFrom(new StringInputStream(text));
IParseResult parseResult = resource.getParseResult();
if (!parseResult.hasSyntaxErrors()) return (Protobuf) parseResult.getRootASTElement();
@@ -94,4 +100,8 @@
public <T> T getInstanceOf(Class<T> type) {
return injector.getInstance(type);
}
+
+ public Protobuf root() {
+ return root;
+ }
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/util/MultiLineTextBuilder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/util/MultiLineTextBuilder.java
index 6d8e19c..75dc8f4 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/util/MultiLineTextBuilder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/util/MultiLineTextBuilder.java
@@ -22,6 +22,10 @@
return this;
}
+ public boolean isEmpty() {
+ return builder.length() == 0;
+ }
+
@Override public String toString() {
return builder.toString();
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_enumTypeOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_enumTypeOf_Test.java
index f5d2a3b..e51a116 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_enumTypeOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_enumTypeOf_Test.java
@@ -17,14 +17,12 @@
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.ModelFinder;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
+import org.junit.*;
+
/**
* Tests for <code>{@link ModelFinder#enumTypeOf(Property)}</code>.
*
@@ -34,35 +32,33 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private ModelFinder finder;
@Before public void setUp() {
+ root = xtext.root();
finder = xtext.getInstanceOf(ModelFinder.class);
}
+ // enum PhoneType {
+ // MOBILE = 0;
+ // HOME = 1;
+ // WORK = 2;
+ // }
+ //
+ // message PhoneNumber {
+ // optional PhoneType type = 1;
+ // }
@Test public void should_return_enum_if_property_type_is_enum() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("enum PhoneType { ")
- .append(" MOBILE = 0; ")
- .append(" HOME = 1; ")
- .append(" WORK = 2; ")
- .append("} ")
- .append(" ")
- .append("message PhoneNumber { ")
- .append(" optional PhoneType type = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property type = findProperty(name("type"), in(root));
Enum phoneType = finder.enumTypeOf(type);
assertThat(phoneType.getName(), equalTo("PhoneType"));
}
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_return_null_if_property_type_is_not_enum() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property name = findProperty(name("name"), in(root));
Enum anEnum = finder.enumTypeOf(name);
assertThat(anEnum, nullValue());
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_importsIn_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_importsIn_Test.java
index d9fd082..d951ef1 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_importsIn_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_importsIn_Test.java
@@ -13,14 +13,12 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import java.util.List;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
import org.junit.*;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.ModelFinder;
-import com.google.eclipse.protobuf.protobuf.*;
+import java.util.List;
/**
* Tests for <code>{@link ModelFinder#importsIn(Protobuf)}</code>.
@@ -31,31 +29,29 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private ModelFinder finder;
@Before public void setUp() {
+ root = xtext.root();
finder = xtext.getInstanceOf(ModelFinder.class);
}
+ // import "luke.proto";
+ // import "leia.proto";
@Test public void should_return_all_imports() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("import \"luke.proto\";")
- .append("import \"leia.proto\";");
- Protobuf root = xtext.parseText(proto);
List<Import> allImports = finder.importsIn(root);
assertThat(allImports.size(), equalTo(2));
assertThat(allImports.get(0).getImportURI(), equalTo("luke.proto"));
assertThat(allImports.get(1).getImportURI(), equalTo("leia.proto"));
}
+ // enum PhoneType {
+ // MOBILE = 0;
+ // HOME = 1;
+ // WORK = 2;
+ // }
@Test public void should_return_empty_if_no_imports_found() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("enum PhoneType {")
- .append(" MOBILE = 0; ")
- .append(" HOME = 1; ")
- .append(" WORK = 2; ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
List<Import> allImports = finder.importsIn(root);
assertThat(allImports.size(), equalTo(0));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_packageOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_packageOf_Test.java
index 7076c1c..f1e4ffb 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_packageOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_packageOf_Test.java
@@ -17,15 +17,13 @@
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
-import org.eclipse.emf.ecore.EObject;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.ModelFinder;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Package;
+import org.eclipse.emf.ecore.EObject;
+import org.junit.*;
+
/**
* Tests for <code>{@link ModelFinder#packageOf(EObject)}</code>.
*
@@ -35,31 +33,29 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private ModelFinder finder;
@Before public void setUp() {
+ root = xtext.root();
finder = xtext.getInstanceOf(ModelFinder.class);
}
+ // package person.test;
+ //
+ // message Person {
+ // optional int32 id = 1;
+ // }
@Test public void should_return_package_if_proto_has_one() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("package person.test; ")
- .append(" ")
- .append("message Person { ")
- .append(" optional int32 id = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property id = findProperty(name("id"), in(root));
Package aPackage = finder.packageOf(id);
assertThat(aPackage.getName(), equalTo("person.test"));
}
+ // message Person {
+ // optional int32 id = 1;
+ // }
@Test public void should_return_null_if_proto_does_not_have_package() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional int32 id = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property id = findProperty(name("id"), in(root));
Package aPackage = finder.packageOf(id);
assertThat(aPackage, nullValue());
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_rootOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_rootOf_Test.java
index d641ef7..3e96f8b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_rootOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_rootOf_Test.java
@@ -16,14 +16,12 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+
import org.eclipse.emf.ecore.EObject;
import org.junit.*;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.ModelFinder;
-import com.google.eclipse.protobuf.protobuf.*;
-
/**
* Tests for <code>{@link ModelFinder#rootOf(EObject)}</code>.
*
@@ -33,18 +31,18 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private ModelFinder finder;
@Before public void setUp() {
+ root = xtext.root();
finder = xtext.getInstanceOf(ModelFinder.class);
}
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_return_root_of_proto() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property name = findProperty(name("name"), in(root));
assertThat(finder.rootOf(name), sameInstance(root));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_scalarTypeOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_scalarTypeOf_Test.java
index 8222cd3..6bb79b5 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_scalarTypeOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_scalarTypeOf_Test.java
@@ -17,13 +17,11 @@
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.ModelFinder;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link ModelFinder#scalarTypeOf(Property)}</code>.
*
@@ -33,35 +31,33 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private ModelFinder finder;
@Before public void setUp() {
+ root = xtext.root();
finder = xtext.getInstanceOf(ModelFinder.class);
}
+ // message Person {
+ // optional int32 id = 1;
+ // }
@Test public void should_return_scalar_if_property_type_is_scalar() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional int32 id = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property id = findProperty(name("id"), in(root));
ScalarType int32 = finder.scalarTypeOf(id);
assertThat(int32.getName(), equalTo("int32"));
}
+ // enum PhoneType {
+ // MOBILE = 0;
+ // HOME = 1;
+ // WORK = 2;
+ // }
+ //
+ // message PhoneNumber {
+ // optional PhoneType type = 1;
+ // }
@Test public void should_return_null_if_property_type_is_not_scalar() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("enum PhoneType { ")
- .append(" MOBILE = 0; ")
- .append(" HOME = 1; ")
- .append(" WORK = 2; ")
- .append("} ")
- .append(" ")
- .append("message PhoneNumber { ")
- .append(" optional PhoneType type = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property type = findProperty(name("type"), in(root));
ScalarType scalar = finder.scalarTypeOf(type);
assertThat(scalar, nullValue());
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelNodes_firstNodeForFeature_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelNodes_firstNodeForFeature_Test.java
index 167f631..565fd7c 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelNodes_firstNodeForFeature_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelNodes_firstNodeForFeature_Test.java
@@ -17,15 +17,13 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+
import org.eclipse.emf.ecore.*;
import org.eclipse.xtext.nodemodel.INode;
import org.junit.*;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.INodes;
-import com.google.eclipse.protobuf.protobuf.*;
-
/**
* Tests for <code>{@link INodes#firstNodeForFeature(EObject, EStructuralFeature)}</code>
*
@@ -35,18 +33,18 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private INodes nodes;
@Before public void setUp() {
+ root = xtext.root();
nodes = xtext.getInstanceOf(INodes.class);
}
+ // message Person {
+ // optional bool active = 1;
+ // }
@Test public void should_return_first_node_for_feature() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional bool active = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property active = findProperty(name("active"), in(root));
INode node = nodes.firstNodeForFeature(active, FIELD__NAME);
assertThat(node.getText().trim(), equalTo("active"));
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isBool_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isBool_Test.java
index 9cf3492..69cf8f6 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isBool_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isBool_Test.java
@@ -16,13 +16,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.Properties;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link Properties#isBool(Property)}</code>.
*
@@ -32,28 +30,26 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private Properties properties;
@Before public void setUp() {
+ root = xtext.root();
properties = xtext.getInstanceOf(Properties.class);
}
+ // message Person {
+ // optional bool active = 1;
+ // }
@Test public void should_return_true_if_property_is_bool() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional bool active = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property active = findProperty(name("active"), in(root));
assertThat(properties.isBool(active), equalTo(true));
}
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_return_false_if_property_is_not_bool() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property name = findProperty(name("name"), in(root));
assertThat(properties.isBool(name), equalTo(false));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isPrimitive_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isPrimitive_Test.java
index 2515ab9..3f4ef6b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isPrimitive_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isPrimitive_Test.java
@@ -14,13 +14,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.Properties;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link Properties#isPrimitive(Property)}</code>.
*
@@ -30,43 +28,41 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private Properties properties;
@Before public void setUp() {
+ root = xtext.root();
properties = xtext.getInstanceOf(Properties.class);
}
+ // message Primitives {
+ // optional float float_1 = 1;
+ // optional int32 int32_1 = 2;
+ // optional int64 int64_1 = 3;
+ // optional uint32 uint32_1 = 4;
+ // optional uint64 uint64_1 = 5;
+ // optional sint32 sint32_1 = 6;
+ // optional sint64 sint64_1 = 7;
+ // optional fixed32 fixed32_1 = 8;
+ // optional fixed64 fixed64_1 = 9;
+ // optional bool bool_1 = 10;
+ // }
@Test public void should_return_true_if_property_is_primitive() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Primitives { ")
- .append(" optional float float_1 = 1; ")
- .append(" optional int32 int32_1 = 2; ")
- .append(" optional int64 int64_1 = 3; ")
- .append(" optional uint32 uint32_1 = 4; ")
- .append(" optional uint64 uint64_1 = 5; ")
- .append(" optional sint32 sint32_1 = 6; ")
- .append(" optional sint64 sint64_1 = 7; ")
- .append(" optional fixed32 fixed32_1 = 8;")
- .append(" optional fixed64 fixed64_1 = 9;")
- .append(" optional bool bool_1 = 10; ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
for (Property p : allPropertiesIn(root))
assertThat(properties.isPrimitive(p), equalTo(true));
}
+ // message Types {
+ // optional string string_1 = 1;
+ // optional bytes bytes_1 = 2;
+ // optional Person person = 3;
+ // }
+ //
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_return_false_if_property_is_not_primitive() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Types { ")
- .append(" optional string string_1 = 1; ")
- .append(" optional bytes bytes_1 = 2; ")
- .append(" optional Person person = 3; ")
- .append("} ")
- .append(" ")
- .append("message Person { ")
- .append(" optional string name = 1; ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
for (Property p : allPropertiesIn(root))
assertThat(properties.isPrimitive(p), equalTo(false));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isString_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isString_Test.java
index fcf253d..ee51bde 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isString_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isString_Test.java
@@ -16,13 +16,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.Properties;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link Properties#isString(Property)}</code>.
*
@@ -32,28 +30,26 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private Properties properties;
@Before public void setUp() {
+ root = xtext.root();
properties = xtext.getInstanceOf(Properties.class);
}
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_return_true_if_property_is_string() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property name = findProperty(name("name"), in(root));
assertThat(properties.isString(name), equalTo(true));
}
+ // message Person {
+ // optional bool active = 1;
+ // }
@Test public void should_return_false_if_property_is_not_string() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional bool active = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property active = findProperty(name("active"), in(root));
assertThat(properties.isString(active), equalTo(false));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_typeNameOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_typeNameOf_Test.java
index 5383276..5b36387 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_typeNameOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_typeNameOf_Test.java
@@ -16,13 +16,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.model.util.Properties;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link Properties#typeNameOf(Property)}</code>.
*
@@ -32,33 +30,31 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private Properties properties;
@Before public void setUp() {
+ root = xtext.root();
properties = xtext.getInstanceOf(Properties.class);
}
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_return_name_of_scalar() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property name = findProperty(name("name"), in(root));
assertThat(properties.typeNameOf(name), equalTo("string"));
}
+ // message Person {
+ // optional string name = 1;
+ // optional PhoneNumber number = 2;
+ //
+ // message PhoneNumber {
+ // optional string value = 1;
+ // }
+ // }
@Test public void should_return_name_of_type() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional string name = 1; ")
- .append(" optional PhoneNumber number = 2;")
- .append(" ")
- .append(" message PhoneNumber { ")
- .append(" optional string value = 1; ")
- .append(" } ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property number = findProperty(name("number"), in(root));
assertThat(properties.typeNameOf(number), equalTo("PhoneNumber"));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java
index ff8ac5c..c45494b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java
@@ -17,13 +17,12 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+
import org.eclipse.xtext.naming.*;
import org.junit.*;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.protobuf.*;
-
/**
* Tests for <code>{@link ProtobufQualifiedNameProvider}</code>.
*
@@ -33,55 +32,49 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private ProtobufQualifiedNameProvider provider;
@Before public void setUp() {
+ root = xtext.root();
provider = (ProtobufQualifiedNameProvider) xtext.getInstanceOf(IQualifiedNameProvider.class);
}
+ // package fqn.test;
+ //
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_include_existing_package_name_as_part_of_message_FQN() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("package fqn.test; ")
- .append(" ")
- .append("message Person { ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Message person = findMessage(name("Person"), in(root));
QualifiedName fqn = provider.getFullyQualifiedName(person);
assertThat(fqn.toString(), equalTo("fqn.test.Person"));
}
+ // package fqn.test;
+ //
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_include_existing_package_name_as_part_of_property_FQN() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("package fqn.test; ")
- .append(" ")
- .append("message Person { ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property name = findProperty(name("name"), in(root));
QualifiedName fqn = provider.getFullyQualifiedName(name);
assertThat(fqn.toString(), equalTo("fqn.test.Person.name"));
}
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_not_include_package_name_as_part_of_message_FQN_if_package_is_not_specified() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Message person = findMessage(name("Person"), in(root));
QualifiedName fqn = provider.getFullyQualifiedName(person);
assertThat(fqn.toString(), equalTo("Person"));
}
+ // message Person {
+ // optional string name = 1;
+ // }
@Test public void should_not_include_package_name_as_part_of_property_FQN_if_package_is_not_specified() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property name = findProperty(name("name"), in(root));
QualifiedName fqn = provider.getFullyQualifiedName(name);
assertThat(fqn.toString(), equalTo("Person.name"));
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider_namesOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider_namesOf_Test.java
index 34d5769..b5d5a62 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider_namesOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider_namesOf_Test.java
@@ -16,16 +16,15 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import java.util.List;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.protobuf.Enum;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.QualifiedName;
import org.junit.*;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.protobuf.*;
-import com.google.eclipse.protobuf.protobuf.Enum;
+import java.util.List;
/**
* Tests for <code>{@link LocalNamesProvider#namesOf(EObject)}</code>.
@@ -36,27 +35,27 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private LocalNamesProvider namesProvider;
@Before public void setUp() {
+ root = xtext.root();
namesProvider = xtext.getInstanceOf(LocalNamesProvider.class);
}
+ // package test.alternative.names;
+ //
+ // message Person {
+ // message PhoneNumber {
+ // optional PhoneType type = 1 [default = HOME];
+ //
+ // enum PhoneType {
+ // HOME = 0;
+ // WORK = 1;
+ // }
+ // }
+ // }
@Test public void should_return_all_possible_local_names() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("package test.alternative.names; ");
- proto.append(" ");
- proto.append("message Person { ");
- proto.append(" message PhoneNumber { ");
- proto.append(" optional PhoneType type = 1 [default = HOME];");
- proto.append(" ");
- proto.append(" enum PhoneType { ");
- proto.append(" HOME = 0; ");
- proto.append(" WORK = 1; ");
- proto.append(" } ");
- proto.append(" } ");
- proto.append("} ");
- Protobuf root = xtext.parseText(proto);
Enum phoneType = findEnum(name("PhoneType"), in(root));
List<QualifiedName> names = namesProvider.namesOf(phoneType);
assertThat(names.get(0).toString(), equalTo("PhoneType"));
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java
index a3561f1..df0368f 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java
@@ -19,7 +19,6 @@
import static org.mockito.Mockito.*;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Package;
@@ -35,30 +34,28 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private ValidationMessageAcceptor messageAcceptor;
private ProtobufJavaValidator validator;
@Before public void setUp() {
+ root = xtext.root();
messageAcceptor = mock(ValidationMessageAcceptor.class);
validator = xtext.getInstanceOf(ProtobufJavaValidator.class);
validator.setMessageAcceptor(messageAcceptor);
}
+ // package com.google.protobuf;
+ // package com.google.eclipse;
@Test public void should_create_error_if_there_are_more_than_one_package_definitions() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("package com.google.protobuf;")
- .append("package com.google.eclipse; ");
- Protobuf root = xtext.parseText(proto);
Package p = findPackage(name("com.google.eclipse"), in(root));
validator.checkOnlyOnePackageDefinition(p);
String message = "Multiple package definitions.";
verify(messageAcceptor).acceptError(message, p, PACKAGE__NAME, INSIGNIFICANT_INDEX, MORE_THAN_ONE_PACKAGE_ERROR);
}
+ // package com.google.eclipse;
@Test public void should_not_create_error_if_there_is_only_one_package_definition() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("package com.google.eclipse; ");
- Protobuf root = xtext.parseText(proto);
Package p = findPackage(name("com.google.eclipse"), in(root));
validator.checkOnlyOnePackageDefinition(p);
verifyZeroInteractions(messageAcceptor);
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java
index b3e2f9e..732dc18 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java
@@ -19,7 +19,6 @@
import static org.mockito.Mockito.*;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.protobuf.*;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
@@ -34,45 +33,41 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private ValidationMessageAcceptor messageAcceptor;
private ProtobufJavaValidator validator;
@Before public void setUp() {
+ root = xtext.root();
messageAcceptor = mock(ValidationMessageAcceptor.class);
validator = xtext.getInstanceOf(ProtobufJavaValidator.class);
validator.setMessageAcceptor(messageAcceptor);
}
+ // message Person {
+ // optional long id = 0;
+ // }
@Test public void should_create_error_if_field_index_is_zero() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional long id = 0;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property p = findProperty(name("id"), in(root));
validator.checkTagNumberIsGreaterThanZero(p);
String message = "Field numbers must be positive integers.";
verify(messageAcceptor).acceptError(message, p, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
}
+ // message Person {
+ // optional long id = -1;
+ // }
@Test public void should_create_error_if_field_index_is_negative() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional long id = -1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property p = findProperty(name("id"), in(root));
validator.checkTagNumberIsGreaterThanZero(p);
String message = "Expected field number.";
verify(messageAcceptor).acceptError(message, p, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
}
+ // message Person {
+ // optional long id = 1;
+ // }
@Test public void should_not_create_error_if_field_index_is_greater_than_zero() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional long id = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property p = findProperty(name("id"), in(root));
validator.checkTagNumberIsGreaterThanZero(p);
verifyZeroInteractions(messageAcceptor);
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java
index d23a8a3..5df4839 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java
@@ -19,7 +19,6 @@
import static org.mockito.Mockito.*;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.protobuf.*;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
@@ -33,36 +32,34 @@
public class ProtobufJavaValidator_checkTagNumberIsUnique_Test {
@Rule public XtextRule xtext = createWith(unitTestSetup());
-
+
+ private Protobuf root;
private ValidationMessageAcceptor messageAcceptor;
private ProtobufJavaValidator validator;
@Before public void setUp() {
+ root = xtext.root();
messageAcceptor = mock(ValidationMessageAcceptor.class);
validator = xtext.getInstanceOf(ProtobufJavaValidator.class);
validator.setMessageAcceptor(messageAcceptor);
}
+ // message Person {
+ // optional long id = 1;
+ // optional string name = 1;
+ // }
@Test public void should_create_error_if_field_does_not_have_unique_tag_number() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional long id = 1; ")
- .append(" optional string name = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property p = findProperty(name("name"), in(root));
validator.checkTagNumberIsUnique(p);
String message = "Field number 1 has already been used in \"Person\" by field \"id\".";
verify(messageAcceptor).acceptError(message, p, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
}
+ // message Person {
+ // optional long id = 1;
+ // optional string name = 2;
+ // }
@Test public void should_not_create_error_if_field_has_unique_tag_number() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional long id = 1; ")
- .append(" optional string name = 2;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property p = findProperty(name("name"), in(root));
validator.checkTagNumberIsUnique(p);
verifyZeroInteractions(messageAcceptor);
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder_matchingCommentNode_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder_matchingCommentNode_Test.java
index 7ae790f..c679d8d 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder_matchingCommentNode_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder_matchingCommentNode_Test.java
@@ -17,16 +17,15 @@
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.assertThat;
-import java.util.regex.Matcher;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.util.Pair;
import org.junit.*;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.protobuf.*;
+import java.util.regex.Matcher;
/**
* Tests for <code>{@link CommentNodesFinder#matchingCommentNode(EObject, String...)}</code>.
@@ -37,47 +36,43 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private CommentNodesFinder finder;
@Before public void setUp() {
+ root = xtext.root();
finder = xtext.getInstanceOf(CommentNodesFinder.class);
}
+ // message Person {
+ // // Next Id: 6
+ // optional bool active = 1;
+ // }
@Test public void should_return_matching_single_line_comment_of_element() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" // Next Id: 6 ")
- .append(" optional bool active = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property active = findProperty(name("active"), in(root));
Pair<INode, Matcher> match = finder.matchingCommentNode(active, "next id: [\\d]+");
INode node = match.getFirst();
assertThat(node.getText().trim(), equalTo("// Next Id: 6"));
}
+ // message Person {
+ // /*
+ // * Next Id: 6
+ // */
+ // optional bool active = 1;
+ // }
@Test public void should_return_matching_multi_line_comment_of_element() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" /* ")
- .append(" * Next Id: 6 ")
- .append(" */ ")
- .append(" optional bool active = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property active = findProperty(name("active"), in(root));
Pair<INode, Matcher> match = finder.matchingCommentNode(active, "NEXT ID: [\\d]+");
INode node = match.getFirst();
assertThat(node, notNullValue());
}
+ // message Person {
+ // // Next Id: 6
+ // optional bool active = 1;
+ // }
@Test public void should_return_null_if_no_matching_node_found() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" // Next Id: 6 ")
- .append(" optional bool active = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property active = findProperty(name("active"), in(root));
Pair<INode, Matcher> match = finder.matchingCommentNode(active, "Hello");
assertThat(match, nullValue());
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/SingleLineCommentDocumentationProvider_getDocumentation_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/SingleLineCommentDocumentationProvider_getDocumentation_Test.java
index e8f988f..74d5b2a 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/SingleLineCommentDocumentationProvider_getDocumentation_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/SingleLineCommentDocumentationProvider_getDocumentation_Test.java
@@ -16,13 +16,12 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+
import org.eclipse.emf.ecore.EObject;
import org.junit.*;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.protobuf.*;
-
/**
* Tests for <code>{@link SingleLineCommentDocumentationProvider#getDocumentation(EObject)}</code>
*
@@ -32,30 +31,28 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private SingleLineCommentDocumentationProvider provider;
@Before public void setUp() {
+ root = xtext.root();
provider = xtext.getInstanceOf(SingleLineCommentDocumentationProvider.class);
}
+ // message Person {
+ // // Indicates whether the person is active or not.
+ // optional bool active = 1;
+ // }
@Test public void should_return_single_line_comment_of_element() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" // Indicates whether the person is active or not.")
- .append(" optional bool active = 1; ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property active = findProperty(name("active"), in(root));
String documentation = provider.getDocumentation(active);
assertThat(documentation, equalTo("Indicates whether the person is active or not."));
}
+ // message Person {
+ // optional bool active = 1;
+ // }
@Test public void should_return_empty_String_if_element_does_not_have_single_line_comment() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" optional bool active = 1;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property active = findProperty(name("active"), in(root));
String documentation = provider.getDocumentation(active);
assertThat(documentation, equalTo(""));
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
index c1c5651..2dd366c 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
@@ -16,12 +16,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link Fields#calculateTagNumberOf(Field)}</code>.
*
@@ -31,30 +30,28 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private Fields fields;
@Before public void setUp() {
+ root = xtext.root();
fields = xtext.getInstanceOf(Fields.class);
}
+ // message Person {
+ // required string name = 2;
+ // }
@Test public void should_return_one_for_first_and_only_property() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" required string name = 2;")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property name = findProperty(name("name"), in(root));
long index = fields.calculateTagNumberOf(name);
assertThat(index, equalTo(1L));
}
+ // message Person {
+ // required string name = 6;
+ // required int32 id = 8;
+ // }
@Test public void should_return_max_tag_number_value_plus_one_for_new_property() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("message Person { ")
- .append(" required string name = 6;")
- .append(" required int32 id = 8; ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Property id = findProperty(name("id"), in(root));
long index = fields.calculateTagNumberOf(id);
assertThat(index, equalTo(7L));
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
index 45262db..0d87374 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
@@ -16,12 +16,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.*;
-
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
import com.google.eclipse.protobuf.protobuf.*;
+import org.junit.*;
+
/**
* Tests for <code>{@link Literals#calculateIndexOf(Literal)}</code>.
*
@@ -31,31 +30,29 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
+ private Protobuf root;
private Literals literals;
@Before public void setUp() {
+ root = xtext.root();
literals = xtext.getInstanceOf(Literals.class);
}
+ // enum PhoneType {
+ // MOBILE = 1;
+ // }
@Test public void should_return_zero_for_first_and_only_literal() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("enum PhoneType {")
- .append(" MOBILE = 1; ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Literal mobile = findLiteral(name("MOBILE"), in(root));
long index = literals.calculateIndexOf(mobile);
assertThat(index, equalTo(0L));
}
+ // enum PhoneType {
+ // MOBILE = 1;
+ // HOME = 5;
+ // WORK = 9;
+ // }
@Test public void should_return_max_index_value_plus_one_for_new_literal() {
- MultiLineTextBuilder proto = new MultiLineTextBuilder();
- proto.append("enum PhoneType {")
- .append(" MOBILE = 1; ")
- .append(" HOME = 5; ")
- .append(" WORK = 9; ")
- .append("} ");
- Protobuf root = xtext.parseText(proto);
Literal work = findLiteral(name("WORK"), in(root));
long index = literals.calculateIndexOf(work);
assertThat(index, equalTo(6L));