In progress: [  Issue 27  ]  Minimum proposed index for enum literals should be zero
https://code.google.com/p/protobuf-dt/issues/detail?id=27
diff --git a/com.google.eclipse.protobuf.ui.test/.classpath b/com.google.eclipse.protobuf.ui.test/.classpath
new file mode 100644
index 0000000..64c5e31
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/com.google.eclipse.protobuf.ui.test/.project b/com.google.eclipse.protobuf.ui.test/.project
new file mode 100644
index 0000000..7a0efba
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>com.google.eclipse.protobuf.ui.test</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/com.google.eclipse.protobuf.ui.test/.settings/org.eclipse.jdt.core.prefs b/com.google.eclipse.protobuf.ui.test/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..e2a4e69
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Mon Apr 25 11:34:13 PDT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..80f3db8
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Tests for com.google.eclipse.protobuf.ui
+Bundle-SymbolicName: com.google.eclipse.protobuf.ui.test
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Google
+Fragment-Host: com.google.eclipse.protobuf.ui;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: com.google.eclipse.protobuf.test.lib;bundle-version="1.0.0"
diff --git a/com.google.eclipse.protobuf.ui.test/build.properties b/com.google.eclipse.protobuf.ui.test/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/EContainerStub.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/EContainerStub.java
new file mode 100644
index 0000000..80b9349
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/EContainerStub.java
@@ -0,0 +1,19 @@
+/*
+ * 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.stubs;
+
+import org.eclipse.emf.ecore.InternalEObject;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public interface EContainerStub extends InternalEObject {
+
+  void add(EObjectStub...children);
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/EObjectStub.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/EObjectStub.java
new file mode 100644
index 0000000..aa377af
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/EObjectStub.java
@@ -0,0 +1,19 @@
+/*
+ * 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.stubs;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public interface EObjectStub extends EObject {
+
+  void setContainer(EContainerStub eContainer);
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/EnumStub.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/EnumStub.java
new file mode 100644
index 0000000..1883f46
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/EnumStub.java
@@ -0,0 +1,38 @@
+/*
+ * 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.stubs;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+
+import com.google.eclipse.protobuf.protobuf.impl.EnumImpl;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class EnumStub extends EnumImpl implements EContainerStub {
+
+  private EList<EObject> contents = new BasicEList<EObject>();
+
+  public EnumStub(String name) {
+    this.name = name;
+  }
+
+  public void add(EObjectStub...children) {
+    for (EObjectStub child : children) {
+      contents.add(child);
+      child.setContainer(this);
+    }
+  }
+  
+  @Override public EList<EObject> eContents() {
+    return contents;
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/LiteralStub.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/LiteralStub.java
new file mode 100644
index 0000000..117bb70
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/stubs/LiteralStub.java
@@ -0,0 +1,25 @@
+/*
+ * 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.stubs;
+
+import com.google.eclipse.protobuf.protobuf.impl.LiteralImpl;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class LiteralStub extends LiteralImpl implements EObjectStub {
+
+  public LiteralStub(String name) {
+    this.name = name;
+  }
+
+  public void setContainer(EContainerStub container) {
+    this.eContainer = container;
+  }
+}
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
new file mode 100644
index 0000000..afdb7d4
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
@@ -0,0 +1,52 @@
+/*
+ * 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.util;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.eclipse.protobuf.protobuf.Literal;
+import com.google.eclipse.protobuf.stubs.EnumStub;
+import com.google.eclipse.protobuf.stubs.LiteralStub;
+
+/**
+ * Tests for <code>{@link Literals#calculateIndexOf(Literal)}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class Literals_calculateIndexOf_Test {
+
+  private EnumStub anEnum;
+
+  private Literals literals;
+  
+  @Before public void setUp() {
+    anEnum = new EnumStub("PhoneType");
+    literals = new Literals();
+  }
+  
+  @Test public void should_return_zero_for_first_literal() {
+    LiteralStub literal = new LiteralStub("HOME");
+    anEnum.add(literal);
+    int index = literals.calculateIndexOf(literal);
+    assertThat(index).isZero();
+  }
+  
+  @Test public void should_return_max_index_value_plus_one_for_new_literal() {
+    int maxIndexValue = 1;
+    LiteralStub literal1 = new LiteralStub("HOME");
+    literal1.setIndex(maxIndexValue);
+    LiteralStub literal2 = new LiteralStub("WORK");
+    anEnum.add(literal1, literal2);
+    int index = literals.calculateIndexOf(literal2);
+    assertThat(index).isEqualTo(maxIndexValue + 1);
+  }
+}