directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r490542 - /directory/sandbox/elecharny/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/PrepareStringTest.java
Date Wed, 27 Dec 2006 17:25:06 GMT
Author: elecharny
Date: Wed Dec 27 09:25:05 2006
New Revision: 490542

URL: http://svn.apache.org/viewvc?view=rev&rev=490542
Log:
Added some tests

Modified:
    directory/sandbox/elecharny/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/PrepareStringTest.java

Modified: directory/sandbox/elecharny/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/PrepareStringTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/elecharny/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/PrepareStringTest.java?view=diff&rev=490542&r1=490541&r2=490542
==============================================================================
--- directory/sandbox/elecharny/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/PrepareStringTest.java
(original)
+++ directory/sandbox/elecharny/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/PrepareStringTest.java
Wed Dec 27 09:25:05 2006
@@ -19,6 +19,8 @@
  */
 package org.apache.directory.shared.ldap.schema;
 
+import org.apache.directory.shared.ldap.util.unicode.InvalidCharacterException;
+
 import junit.framework.TestCase;
 
 /**
@@ -29,28 +31,164 @@
  */
 public class PrepareStringTest extends TestCase
 {
-    public void testInsignifiantSpacesStringNull()
+    public void testInsignifiantSpacesStringNull() throws InvalidCharacterException
     {
         assertEquals( "  ", PrepareString.insignifiantSpacesString( (String)null ) );
     }
     
-    public void testInsignifiantSpacesStringEmpty()
+    public void testInsignifiantSpacesStringEmpty() throws InvalidCharacterException
     {
         assertEquals( "  ", PrepareString.insignifiantSpacesString( "" ) );
     }
     
-    public void testInsignifiantSpacesStringOneSpace()
+    public void testInsignifiantSpacesStringOneSpace() throws InvalidCharacterException
     {
         assertEquals( "  ", PrepareString.insignifiantSpacesString( " " ) );
     }
     
-    public void testInsignifiantSpacesStringTwoSpaces()
+    public void testInsignifiantSpacesStringTwoSpaces() throws InvalidCharacterException
     {
         assertEquals( "  ", PrepareString.insignifiantSpacesString( "  " ) );
     }
     
-    public void testInsignifiantSpacesStringNSpaces()
+    public void testInsignifiantSpacesStringNSpaces() throws InvalidCharacterException
     {
         assertEquals( "  ", PrepareString.insignifiantSpacesString( "      " ) );
+    }
+
+    public void testInsignifiantSpacesStringOneChar() throws InvalidCharacterException
+    {
+        assertEquals( " a ", PrepareString.insignifiantSpacesString( "a" ) );
+    }
+
+    public void testInsignifiantSpacesStringTwoChars() throws InvalidCharacterException
+    {
+        assertEquals( " aa ", PrepareString.insignifiantSpacesString( "aa" ) );
+    }
+
+    public void testInsignifiantSpacesStringNChars() throws InvalidCharacterException
+    {
+        assertEquals( " aaaaa ", PrepareString.insignifiantSpacesString( "aaaaa" ) );
+    }
+
+    public void testInsignifiantSpacesStringOneCombining() throws InvalidCharacterException
+    {
+        char[] chars = new char[]{ ' ', 0x0310 };
+        char[] expected = new char[]{ ' ', ' ', 0x0310, ' ' };
+        assertEquals( new String( expected ), PrepareString.insignifiantSpacesString( new
String( chars ) ) );
+    }
+
+    public void testInsignifiantSpacesStringNCombining() throws InvalidCharacterException
+    {
+        char[] chars = new char[]{ ' ', 0x0310, ' ', 0x0311, ' ', 0x0312 };
+        char[] expected = new char[]{ ' ', ' ', 0x0310, ' ', 0x0311, ' ', 0x0312, ' ' };
+        assertEquals( new String( expected ), PrepareString.insignifiantSpacesString( new
String( chars ) ) );
+    }
+    
+    public void testInsignifiantSpacesStringCharsSpaces() throws InvalidCharacterException
+    {
+        assertEquals( " a ", PrepareString.insignifiantSpacesString( " a" ) );
+        assertEquals( " a ", PrepareString.insignifiantSpacesString( "a " ) );
+        assertEquals( " a ", PrepareString.insignifiantSpacesString( " a " ) );
+        assertEquals( " a a ", PrepareString.insignifiantSpacesString( "a a" ) );
+        assertEquals( " a a ", PrepareString.insignifiantSpacesString( " a a" ) );
+        assertEquals( " a a ", PrepareString.insignifiantSpacesString( "a a " ) );
+        assertEquals( " a a ", PrepareString.insignifiantSpacesString( "a  a" ) );
+        assertEquals( " a a ", PrepareString.insignifiantSpacesString( " a   a " ) );
+        assertEquals( " aaa aaa aaa ", PrepareString.insignifiantSpacesString( "  aaa   aaa
  aaa  " ) );
+    }
+
+    public void testInsignifiantSpacesStringCharsCombiningSpaces() throws InvalidCharacterException
+    {
+        char[] chars = new char[]{ ' ', 0x0310, 'a', 'a', ' ', ' ',  0x0311, ' ', ' ', 'a',
0x0311, 0x0312 };
+        char[] expected = new char[]{ ' ', ' ', 0x0310, 'a', 'a', ' ', ' ',  0x0311, ' ',
'a', 0x0311, 0x0312, ' ' };
+        assertEquals( new String( expected ), PrepareString.insignifiantSpacesString( new
String( chars ) ) );
+    }
+
+    public void testMapNull()
+    {
+        assertNull( PrepareString.map( (String)null ) );
+    }
+
+    public void testMapEmpty()
+    {
+        assertEquals( "", PrepareString.map( "" ) );
+    }
+
+    public void testMapString()
+    {
+        assertEquals( "abcd", PrepareString.map( "abcd" ) );
+    }
+
+    public void testMapToLower()
+    {
+        assertEquals( "abcdefghijklmnopqrstuvwxyz", PrepareString.map( "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
) );
+    }
+
+    public void testMapToSpace()
+    {
+        char[] chars = new char[]{ 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0085, 0x00A0, 0x1680,

+            0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009,
0x200A,
+            0x2028, 0x2029, 0x202F, 0x205F };
+        assertEquals( "                       ", PrepareString.map( new String( chars ) )
);
+    }
+
+    public void testMapToIgnore()
+    {
+        char[] chars = new char[58];
+            
+        int pos = 0;
+        
+        for ( char c = 0x0000; c < 0x0008; c++ )
+        {
+            chars[pos++] = c;
+        }
+
+        for ( char c = 0x000E; c < 0x001F; c++ )
+        {
+            chars[pos++] = c;
+        }
+        
+        for ( char c = 0x007F; c < 0x0084; c++ )
+        {
+            chars[pos++] = c;
+        }
+        
+        for ( char c = 0x0086; c < 0x009F; c++ )
+        {
+            chars[pos++] = c;
+        }
+        
+        chars[pos++] = 0x00AD;
+
+        assertEquals( "", PrepareString.map( new String( chars ) ) );
+    }
+    
+    public void testInsignifiantSpacesHandleNumericStringNull()
+    {
+        assertNull( PrepareString.insignifiantCharNumericString( (String )null ) );
+    }
+
+    public void testInsignifiantSpacesHandleNumericStringEmpty()
+    {
+        assertEquals( "", PrepareString.insignifiantCharNumericString( "" ) );
+    }
+
+    public void testInsignifiantSpacesHandleNumericStringSpacesOnly()
+    {
+        assertEquals( "", PrepareString.insignifiantCharNumericString( " " ) );
+        assertEquals( "", PrepareString.insignifiantCharNumericString( "   " ) );
+        assertEquals( "", PrepareString.insignifiantCharNumericString( "    " ) );
+        assertEquals( "", PrepareString.insignifiantCharNumericString( "      " ) );
+    }
+
+    public void testInsignifiantSpacesHandleNumericString()
+    {
+        assertEquals( "1", PrepareString.insignifiantCharNumericString( "1" ) );
+        assertEquals( "123456789", PrepareString.insignifiantCharNumericString( "123456789"
) );
+        assertEquals( "111", PrepareString.insignifiantCharNumericString( "   111" ) );
+        assertEquals( "111", PrepareString.insignifiantCharNumericString( "111  " ) );
+        assertEquals( "11", PrepareString.insignifiantCharNumericString( "1 1" ) );
+        assertEquals( "111", PrepareString.insignifiantCharNumericString( "1 1 1" ) );
     }
 }



Mime
View raw message