Adding unit tests. Minor code cleanup. Added folder "icons" to the list of files to include in the binary build.
diff --git a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/KeywordHasValueMatcher.java b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/KeywordHasValueMatcher.java
new file mode 100644
index 0000000..be27bce
--- /dev/null
+++ b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/KeywordHasValueMatcher.java
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+import org.eclipse.xtext.Keyword;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+
+/**
+ * Matches that verifies that a value of a <code>{@link Keyword}</code> is equal to the expected value.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class KeywordHasValueMatcher extends BaseMatcher<Keyword> {
+
+ private final String expectedValue;
+
+ public static KeywordHasValueMatcher hasValue(String expected) {
+ return new KeywordHasValueMatcher(expected);
+ }
+
+ private KeywordHasValueMatcher(String expectedValue) {
+ this.expectedValue = expectedValue;
+ }
+
+ public boolean matches(Object arg) {
+ if (!(arg instanceof Keyword)) return false;
+ Keyword keyword = (Keyword) arg;
+ return keyword.getValue().equals(expectedValue);
+ }
+
+ public void describeTo(Description description) {
+ description.appendValue(expectedValue);
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/grammar/CompoundElementsTest.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/grammar/CompoundElementsTest.java
new file mode 100644
index 0000000..9116109
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/grammar/CompoundElementsTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.ui.grammar;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+import org.junit.*;
+
+import com.google.eclipse.protobuf.junit.XtextRule;
+
+/**
+ * Tests for <code>{@link CompoundElements}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class CompoundElementsTest {
+
+ @Rule public XtextRule xtext = new XtextRule();
+
+ private CompoundElements elements;
+
+ @Before public void setUp() {
+ elements = xtext.getInstanceOf(CompoundElements.class);
+ }
+
+ @Test public void should_return_default() {
+ assertThat(elements.defaultValue(), equalTo("default ="));
+ }
+
+ @Test public void should_return_default_in_brackets() {
+ assertThat(elements.defaultValueInBrackets(), equalTo("[default =]"));
+ }
+
+ @Test public void should_return_default_for_string() {
+ assertThat(elements.defaultStringValue(), equalTo("default = \"\""));
+ }
+
+ @Test public void should_return_default_for_string_in_brackets() {
+ assertThat(elements.defaultStringValueInBrackets(), equalTo("[default = \"\"]"));
+ }
+
+ @Test public void should_return_empty_string() {
+ assertThat(elements.emptyString(), equalTo("\"\""));
+ }
+
+ @Test public void should_return_packed() {
+ assertThat(elements.packed(), equalTo("packed = true"));
+ }
+
+ @Test public void should_return_packed_in_brackets() {
+ assertThat(elements.packedInBrackets(), equalTo("[packed = true]"));
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/grammar/KeywordsTest.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/grammar/KeywordsTest.java
new file mode 100644
index 0000000..47bbe46
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/grammar/KeywordsTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.ui.grammar;
+
+import static com.google.eclipse.protobuf.junit.KeywordHasValueMatcher.hasValue;
+import static org.junit.Assert.assertThat;
+
+import org.junit.*;
+
+import com.google.eclipse.protobuf.junit.XtextRule;
+
+/**
+ * Tests for <code>{@link Keywords}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class KeywordsTest {
+
+ @Rule public XtextRule xtext = new XtextRule();
+
+ private Keywords keywords;
+
+ @Before public void setUp() {
+ keywords = xtext.getInstanceOf(Keywords.class);
+ }
+
+ @Test public void should_return_bool() {
+ assertThat(keywords.bool(), hasValue("bool"));
+ }
+
+ @Test public void should_return_true() {
+ assertThat(keywords.boolTrue(), hasValue("true"));
+ }
+
+ @Test public void should_return_false() {
+ assertThat(keywords.boolFalse(), hasValue("false"));
+ }
+
+ @Test public void should_return_bytes() {
+ assertThat(keywords.bytes(), hasValue("bytes"));
+ }
+
+ @Test public void should_return_opening_bracket() {
+ assertThat(keywords.openingBracket(), hasValue("["));
+ }
+
+ @Test public void should_return_closing_bracket() {
+ assertThat(keywords.closingBracket(), hasValue("]"));
+ }
+
+ @Test public void should_return_default() {
+ assertThat(keywords.defaultValue(), hasValue("default"));
+ }
+
+ @Test public void should_return_equal_sign() {
+ assertThat(keywords.equalSign(), hasValue("="));
+ }
+
+ @Test public void should_return_packed() {
+ assertThat(keywords.packed(), hasValue("packed"));
+ }
+
+ @Test public void should_return_semicolon() {
+ assertThat(keywords.semicolon(), hasValue(";"));
+ }
+
+ @Test public void should_return_string() {
+ assertThat(keywords.string(), hasValue("string"));
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui/build.properties b/com.google.eclipse.protobuf.ui/build.properties
index 300fb1a..0d2ea5b 100644
--- a/com.google.eclipse.protobuf.ui/build.properties
+++ b/com.google.eclipse.protobuf.ui/build.properties
@@ -3,4 +3,5 @@
bin.includes = META-INF/,\
.,\
plugin.xml,\
- OSGI-INF/
+ OSGI-INF/,\
+ icons/
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/CompoundElements.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/CompoundElements.java
index a648ecf..a619471 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/CompoundElements.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/CompoundElements.java
@@ -10,9 +10,12 @@
import org.eclipse.xtext.Keyword;
-import com.google.inject.*;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
/**
+ * Common grammar elements composed of one or more keywords.
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton
@@ -29,6 +32,10 @@
private final String packed;
private final String packedInBrackets;
+ /**
+ * Creates a new </code>{@link CompoundElements}</code>.
+ * @param keywords the keywords in our grammar.
+ */
@Inject public CompoundElements(Keywords keywords) {
inBracketsFormat = keywords.openingBracket().getValue() + "%s" + keywords.closingBracket().getValue();
defaultValue = format("%s %s", keywords.defaultValue(), keywords.equalSign());
@@ -53,30 +60,58 @@
return String.format(inBracketsFormat, element);
}
+ /**
+ * Returns 'default ='.
+ * @return 'default ='.
+ */
public String defaultValue() {
return defaultValue;
}
+ /**
+ * Returns '[default =]'.
+ * @return '[default =]'.
+ */
public String defaultValueInBrackets() {
return defaultValueInBrackets;
}
+ /**
+ * Returns 'default = ""'.
+ * @return 'default = ""'.
+ */
public String defaultStringValue() {
return defaultStringValue;
}
+ /**
+ * Returns '[default = ""]'.
+ * @return '[default = ""]'.
+ */
public String defaultStringValueInBrackets() {
return defaultStringValueInBrackets;
}
+ /**
+ * Returns '""'.
+ * @return '""'.
+ */
public String emptyString() {
return EMPTY_STRING;
}
+ /**
+ * Returns 'packed = true'.
+ * @return 'packed = true'.
+ */
public String packed() {
return packed;
}
+ /**
+ * Returns '[packed = true]'.
+ * @return '[packed = true]'.
+ */
public String packedInBrackets() {
return packedInBrackets;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/Keywords.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/Keywords.java
index da6154f..a8695c2 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/Keywords.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/Keywords.java
@@ -19,6 +19,8 @@
import com.google.inject.Singleton;
/**
+ * Common keywords used in the code base.
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton
@@ -36,6 +38,10 @@
private Keyword semicolon;
private Keyword string;
+ /**
+ * Creates a new </code>{@link Keywords}</code>.
+ * @param grammarAccess contains the grammar whose keywords we'll be extracting.
+ */
@Inject public Keywords(IGrammarAccess grammarAccess) {
List<Keyword> allKeywords = containedKeywords(grammarAccess.getGrammar());
for (Keyword k : allKeywords) {
@@ -123,46 +129,90 @@
return expectedValue.equals(k.getValue());
}
+ /**
+ * Returns the representation of the keyword "bool".
+ * @return the representation of the keyword "bool".
+ */
public Keyword bool() {
return bool;
}
+ /**
+ * Returns the representation of the keyword "true".
+ * @return the representation of the keyword "true".
+ */
public Keyword boolTrue() {
return boolTrue;
}
+ /**
+ * Returns the representation of the keyword "false".
+ * @return the representation of the keyword "false".
+ */
public Keyword boolFalse() {
return boolFalse;
}
+ /**
+ * Returns the representation of the keyword "bytes".
+ * @return the representation of the keyword "bytes".
+ */
public Keyword bytes() {
return bytes;
}
+ /**
+ * Returns the representation of the keyword "[".
+ * @return the representation of the keyword "[".
+ */
public Keyword openingBracket() {
return openingBracket;
}
+ /**
+ * Returns the representation of the keyword "]".
+ * @return the representation of the keyword "]".
+ */
public Keyword closingBracket() {
return closingBracket;
}
+ /**
+ * Returns the representation of the keyword "default".
+ * @return the representation of the keyword "default".
+ */
public Keyword defaultValue() {
return defaultValue;
}
+ /**
+ * Returns the representation of the keyword "=".
+ * @return the representation of the keyword "=".
+ */
public Keyword equalSign() {
return equalSign;
}
+ /**
+ * Returns the representation of the keyword "packed".
+ * @return the representation of the keyword "packed".
+ */
public Keyword packed() {
return packed;
}
+ /**
+ * Returns the representation of the keyword ";".
+ * @return the representation of the keyword ";".
+ */
public Keyword semicolon() {
return semicolon;
}
+ /**
+ * Returns the representation of the keyword "string".
+ * @return the representation of the keyword "string".
+ */
public Keyword string() {
return string;
}