Author: j...@google.com
Date: Fri Mar 13 11:37:14 2009
New Revision: 5013

Added:
    changes/jat/ihm/user/test/com/google/gwt/dev/util/
    changes/jat/ihm/user/test/com/google/gwt/dev/util/NameTest.java    
(contents, props changed)
Modified:
    changes/jat/ihm/dev/core/src/com/google/gwt/dev/util/Name.java

Log:
Cleanup Name, add tests.


Modified: changes/jat/ihm/dev/core/src/com/google/gwt/dev/util/Name.java
==============================================================================
--- changes/jat/ihm/dev/core/src/com/google/gwt/dev/util/Name.java       
(original)
+++ changes/jat/ihm/dev/core/src/com/google/gwt/dev/util/Name.java      Fri Mar 
 
13 11:37:14 2009
@@ -1,5 +1,5 @@
  /*
- * Copyright 2008 Google Inc.
+ * Copyright 2009 Google Inc.
   *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
   * use this file except in compliance with the License. You may obtain a  
copy of
@@ -51,7 +51,7 @@
        }
        return name.equals(((BinaryName) obj).name);
      }
-
+
      public String getClassName() {
        int lastDot = name.lastIndexOf('.');
        if (lastDot < 0) {
@@ -82,7 +82,7 @@

      public String getShortClassName() {
        String className = getClassName();
-      int lastDollar = className.lastIndexOf('$');
+      int lastDollar = className.lastIndexOf('$', className.length() - 2);
        if (lastDollar < 0) {
          return className;
        }
@@ -101,7 +101,7 @@

      @Override
      public SourceName toSourceName() {
-      return sourceName(name.replace('$', '.'));
+      return sourceName(name.replaceAll("[$/](\\w)", ".$1"));
      }

      @Override
@@ -121,7 +121,7 @@
      protected DottedName(String name) {
        super(name);
      }
-
+
      public abstract SourceName toSourceName();
    }

@@ -153,7 +153,7 @@
        }
        return name.equals(((InternalName) obj).name);
      }
-
+
      public String getClassName() {
        int lastSlash = name.lastIndexOf('/');
        if (lastSlash < 0) {
@@ -184,7 +184,7 @@

      public String getShortClassName() {
        String className = getClassName();
-      int lastDollar = className.lastIndexOf('$');
+      int lastDollar = className.lastIndexOf('$', className.length() - 2);
        if (lastDollar < 0) {
          return className;
        }
@@ -202,7 +202,7 @@
      }

      public SourceName toSourceName() {
-      return sourceName(name.replaceAll("[$/]", "."));
+      return sourceName(name.replaceAll("[$/](\\w)", ".$1"));
      }

      @Override
@@ -391,7 +391,7 @@
      if (name == null) {
        return null;
      }
-    assert !name.contains("/") : "Binary names should not contain /";
+    assert !name.contains("/") : "Source names should not contain /";
      assert !name.contains("$") || name.endsWith("$")
          : "Source names should not contain $";
      return new SourceName(name);

Added: changes/jat/ihm/user/test/com/google/gwt/dev/util/NameTest.java
==============================================================================
--- (empty file)
+++ changes/jat/ihm/user/test/com/google/gwt/dev/util/NameTest.java     Fri Mar 
 
13 11:37:14 2009
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+ * use this file except in compliance with the License. You may obtain a  
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.dev.util;
+
+import com.google.gwt.dev.util.Name.BinaryName;
+import com.google.gwt.dev.util.Name.InternalName;
+import com.google.gwt.dev.util.Name.SourceName;
+
+import junit.framework.TestCase;
+
+/**
+ * Test for various Name implementations.
+ */
+public class NameTest extends TestCase {
+  // TODO(jat): add more tests
+
+  private static final String INTERNAL_ENDS_WITH_DOLLAR  
= "org/example/Foo$";
+  private static final String SOURCE_BINARY_ENDS_WITH_DOLLAR  
= "org.example.Foo$";
+
+  private static final String TEST_SOURCE_NAME = "org.example.Foo.Bar";
+  private static final String TEST_BINARY_NAME = "org.example.Foo$Bar";
+  private static final String TEST_INTERNAL_NAME = "org/example/Foo$Bar";
+
+  public void testBinaryName() {
+    BinaryName name = Name.binaryName(TEST_BINARY_NAME);
+    assertEquals(TEST_BINARY_NAME, name.toString());
+    assertEquals(TEST_SOURCE_NAME, name.toSourceName().toString());
+    assertEquals(TEST_INTERNAL_NAME, name.toInternalName().toString());
+    Throwable caught = null;
+    try {
+      name = Name.binaryName(TEST_INTERNAL_NAME);
+    } catch (AssertionError expected) {
+      caught = expected;
+    }
+    assert caught != null || !NameTest.class.desiredAssertionStatus();
+    name = Name.binaryName(SOURCE_BINARY_ENDS_WITH_DOLLAR);
+    assertEquals(SOURCE_BINARY_ENDS_WITH_DOLLAR, name.toString());
+    assertEquals(INTERNAL_ENDS_WITH_DOLLAR,  
name.toInternalName().toString());
+  }
+
+  public void testInternalName() {
+    InternalName name = Name.internalName(TEST_INTERNAL_NAME);
+    assertEquals(TEST_INTERNAL_NAME, name.toString());
+    assertEquals(TEST_SOURCE_NAME, name.toSourceName().toString());
+    assertEquals(TEST_BINARY_NAME, name.toBinaryName().toString());
+    Throwable caught = null;
+    try {
+      name = Name.internalName(TEST_SOURCE_NAME);
+    } catch (AssertionError expected) {
+      caught = expected;
+    }
+    assert caught != null || !NameTest.class.desiredAssertionStatus();
+    name = Name.internalName(INTERNAL_ENDS_WITH_DOLLAR);
+    assertEquals(INTERNAL_ENDS_WITH_DOLLAR, name.toString());
+    assertEquals(SOURCE_BINARY_ENDS_WITH_DOLLAR,  
name.toBinaryName().toString());
+    assertEquals(SOURCE_BINARY_ENDS_WITH_DOLLAR,  
name.toSourceName().toString());
+  }
+
+  public void testSourceName() {
+    SourceName name = Name.sourceName(TEST_SOURCE_NAME);
+    assertEquals(TEST_SOURCE_NAME, name.toString());
+    Throwable caught = null;
+    try {
+      name = Name.sourceName(TEST_BINARY_NAME);
+    } catch (AssertionError expected) {
+      caught = expected;
+    }
+    assert caught != null || !NameTest.class.desiredAssertionStatus();
+    caught = null;
+    try {
+      name = Name.sourceName(TEST_INTERNAL_NAME);
+    } catch (AssertionError expected) {
+      caught = expected;
+    }
+    assert caught != null || !NameTest.class.desiredAssertionStatus();
+    name = Name.sourceName(SOURCE_BINARY_ENDS_WITH_DOLLAR);
+    assertEquals(SOURCE_BINARY_ENDS_WITH_DOLLAR, name.toString());
+  }
+}

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to