abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r611697 - in /incubator/abdera/java/trunk/dependencies/i18n/src: main/java/org/apache/abdera/i18n/text/ test/java/org/apache/abdera/i18n/test/iri/
Date Mon, 14 Jan 2008 02:28:50 GMT
Author: jmsnell
Date: Sun Jan 13 18:28:49 2008
New Revision: 611697

URL: http://svn.apache.org/viewvc?rev=611697&view=rev
Log:
Additional test cases and a couple of minor code changes

Added:
    incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIO.java
    incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestText.java
Modified:
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Codepoint.java
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Sanitizer.java
    incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestSuite.java

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Codepoint.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Codepoint.java?rev=611697&r1=611696&r2=611697&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Codepoint.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Codepoint.java
Sun Jan 13 18:28:49 2008
@@ -166,4 +166,13 @@
     }
   }
   
+  public Codepoint next() {
+    if (value == 0x10ffff) throw new IndexOutOfBoundsException();
+    return new Codepoint(value + 1);
+  }
+  
+  public Codepoint previous() {
+    if (value == 0) throw new IndexOutOfBoundsException();
+    return new Codepoint(value - 1);
+  }
 }

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Sanitizer.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Sanitizer.java?rev=611697&r1=611696&r2=611697&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Sanitizer.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/Sanitizer.java
Sun Jan 13 18:28:49 2008
@@ -86,7 +86,7 @@
   private static final Filter PathNoDelimFilter = 
     new Filter() {
       public boolean accept(int c) {
-        return CharUtils.isAlphaDigit(c) || 
+        return !(CharUtils.isAlphaDigit(c) || 
                c == '-' || 
                c == '.' ||
                c == '_' ||
@@ -97,7 +97,7 @@
                c == '$' || 
                c == ',' ||
                c == ';' ||
-               c == '%';
+               c == '%');
       }
     };
 }

Added: incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIO.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIO.java?rev=611697&view=auto
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIO.java
(added)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIO.java
Sun Jan 13 18:28:49 2008
@@ -0,0 +1,178 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* 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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.i18n.test.iri;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.StringReader;
+
+import junit.framework.TestCase;
+
+import org.apache.abdera.i18n.text.Filter;
+import org.apache.abdera.i18n.text.io.CharsetSniffingInputStream;
+import org.apache.abdera.i18n.text.io.DynamicPushbackInputStream;
+import org.apache.abdera.i18n.text.io.FilteredCharReader;
+import org.apache.abdera.i18n.text.io.PeekAheadInputStream;
+import org.apache.abdera.i18n.text.io.PipeChannel;
+import org.apache.abdera.i18n.text.io.RewindableInputStream;
+
+public class TestIO extends TestCase {
+
+  public static void testCharsetDetection() throws Exception {
+    
+    byte[] utf32be = {0x00,0x00,0xFFFFFFFE,0xFFFFFFFF, 0x01, 0x02, 0x03};
+    byte[] utf32le = {0xFFFFFFFF,0xFFFFFFFE,0x00,0x00, 0x01, 0x02, 0x03};
+    byte[] utf16be = {0xFFFFFFFE,0xFFFFFFFF, 0x01, 0x02, 0x03};
+    byte[] utf16le = {0xFFFFFFFF,0xFFFFFFFE, 0x01, 0x02, 0x03};
+    byte[] utf8 =    {0xFFFFFFEF,0xFFFFFFBB,0xFFFFFFBF, 0x01, 0x02, 0x03};
+    
+    byte[] nobom_utf32be = {0x00,0x00,0x00,0x3C, 0x01, 0x02, 0x03};
+    byte[] nobom_utf32le = {0x3C,0x00,0x00,0x00, 0x01, 0x02, 0x03};
+    byte[] nobom_utf16be = {0x00,0x3C,0x00,0x3F, 0x01, 0x02, 0x03};
+    byte[] nobom_utf16le = {0x3C,0x00,0x3F,0x00, 0x01, 0x02, 0x03};
+    
+    ByteArrayInputStream in = new ByteArrayInputStream(utf32be);
+    CharsetSniffingInputStream csis = new CharsetSniffingInputStream(in);
+    assertEquals(csis.getEncoding(),"UTF-32");
+    assertTrue(csis.isBomSet());
+    
+    in = new ByteArrayInputStream(utf32le);
+    csis = new CharsetSniffingInputStream(in);
+    assertEquals(csis.getEncoding(),"UTF-32");
+    assertTrue(csis.isBomSet());
+
+    in = new ByteArrayInputStream(utf16be);
+    csis = new CharsetSniffingInputStream(in);
+    assertEquals(csis.getEncoding(),"UTF-16");
+    assertTrue(csis.isBomSet());
+    
+    in = new ByteArrayInputStream(utf16le);
+    csis = new CharsetSniffingInputStream(in);
+    assertEquals(csis.getEncoding(),"UTF-16");
+    assertTrue(csis.isBomSet());
+    
+    in = new ByteArrayInputStream(utf8);
+    csis = new CharsetSniffingInputStream(in);
+    assertEquals(csis.getEncoding(),"UTF-8");
+    assertTrue(csis.isBomSet());
+    
+
+    in = new ByteArrayInputStream(nobom_utf32be);
+    csis = new CharsetSniffingInputStream(in);
+    assertEquals(csis.getEncoding(),"UTF-32be");
+    assertFalse(csis.isBomSet());
+    
+    in = new ByteArrayInputStream(nobom_utf32le);
+    csis = new CharsetSniffingInputStream(in);
+    assertEquals(csis.getEncoding(),"UTF-32le");
+    assertFalse(csis.isBomSet());
+
+    in = new ByteArrayInputStream(nobom_utf16be);
+    csis = new CharsetSniffingInputStream(in);
+    assertEquals(csis.getEncoding(),"UTF-16be");
+    assertFalse(csis.isBomSet());
+    
+    in = new ByteArrayInputStream(nobom_utf16le);
+    csis = new CharsetSniffingInputStream(in);
+    assertEquals(csis.getEncoding(),"UTF-16le");
+    assertFalse(csis.isBomSet());
+  }
+  
+  public static void testDynamicPushbackInputStream() throws Exception {
+    ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {0x01,0x02,0x03,0x04});
+    DynamicPushbackInputStream dpis = new DynamicPushbackInputStream(in);
+    int r = dpis.read();
+    dpis.unread(r);
+    int e = dpis.read();
+    assertEquals(r,e);
+    dpis.unread(e);
+    dpis.clear();
+    r = dpis.read();
+    assertFalse(e == r);
+  }
+  
+  public static void testFilteredCharReader() throws Exception {
+    String string = "abcdefg";
+    FilteredCharReader fcr = 
+      new FilteredCharReader(
+        new StringReader(string),
+        new Filter() {
+          public boolean accept(int c) {
+            return c != 'c' &&
+                   c != 'd' && 
+                   c != 'e';
+          }});
+    char[] buf = new char[7];
+    int r = fcr.read(buf);
+    assertEquals(r,4);
+    assertEquals(new String(buf,0,r),"abfg");
+  }
+  
+  public static void testPeekAheadInputStream() throws Exception {
+    ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {0x01,0x02,0x03,0x04});
+    PeekAheadInputStream pais = new PeekAheadInputStream(in);
+    byte[] peek = new byte[2];
+    byte[] read = new byte[2];
+    pais.peek(peek);
+    pais.read(read);
+    assertEquals(peek[0],read[0]);
+    assertEquals(peek[1],read[1]);
+    byte[] newread = new byte[2];
+    assertFalse(read[0] == newread[0]);
+    assertFalse(read[1] == newread[1]);    
+  }
+  
+  public static void testRewindableInputStream() throws Exception {
+    ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {0x01,0x02,0x03,0x04});
+    RewindableInputStream ris = new RewindableInputStream(in);
+    byte[] buf1 = new byte[4];
+    byte[] buf2 = new byte[4];
+    ris.read(buf1);
+    ris.rewind();
+    ris.read(buf2);
+    for (int n = 0; n < 4; n++)
+      assertEquals(buf1[n],buf2[n]);
+  }
+  
+  public static void testPipeChannel() throws Exception {
+    PipeChannel pc = new PipeChannel();
+    assertTrue(pc.isWritable());
+    assertFalse(pc.isReadable());
+    OutputStream out = pc.getOutputStream();
+    out.write(0x01);
+    out.write(0x02);
+    out.write(0x03);
+    out.write(0x04);
+    out.close();
+    assertFalse(pc.isWritable());
+    assertTrue(pc.isReadable());    
+    InputStream in = pc.getInputStream();
+    byte[] buf = new byte[4];
+    in.read(buf);
+    assertEquals(buf[0],0x1);
+    assertEquals(buf[1],0x2);
+    assertEquals(buf[2],0x3);
+    assertEquals(buf[3],0x4);
+    in.close();
+    assertTrue(pc.isWritable());
+    assertFalse(pc.isReadable());
+  }
+}
+
+

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestSuite.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestSuite.java?rev=611697&r1=611696&r2=611697&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestSuite.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestSuite.java
Sun Jan 13 18:28:49 2008
@@ -31,5 +31,7 @@
     addTestSuite(TestNFKC.class);
     addTestSuite(TestPunycode.class);
     addTestSuite(TestTemplate.class);
+    addTestSuite(TestIO.class);
+    addTestSuite(TestText.class);
   }
 }

Added: incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestText.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestText.java?rev=611697&view=auto
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestText.java
(added)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestText.java
Sun Jan 13 18:28:49 2008
@@ -0,0 +1,126 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* 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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.i18n.test.iri;
+
+import junit.framework.TestCase;
+
+import org.apache.abdera.i18n.text.CharUtils;
+import org.apache.abdera.i18n.text.Codepoint;
+import org.apache.abdera.i18n.text.CodepointIterator;
+import org.apache.abdera.i18n.text.Normalizer;
+import org.apache.abdera.i18n.text.Sanitizer;
+
+public class TestText extends TestCase {
+
+  public static void testCodepoints() throws Exception {
+    StringBuilder buf = new StringBuilder();
+    CharUtils.append(buf, 0x10000);
+    assertEquals(buf.length(),2);
+    assertEquals(buf.charAt(0), CharUtils.getHighSurrogate(0x10000));
+    assertEquals(buf.charAt(1), CharUtils.getLowSurrogate(0x10000));
+    assertTrue(CharUtils.isSurrogatePair(buf.charAt(0), buf.charAt(1)));
+    Codepoint codepoint = CharUtils.codepointAt(buf, 0);
+    assertEquals(codepoint.getValue(),0x10000);
+    assertEquals(codepoint.getCharCount(),2);
+    assertTrue(codepoint.isSupplementary());
+    CharUtils.insert(buf, 0, codepoint.next());
+    assertEquals(buf.length(),4);
+    assertEquals(codepoint.next(),CharUtils.codepointAt(buf, 0));
+  }
+  
+  public static void testSetChecks() throws Exception {
+    assertTrue(CharUtils.inRange(new char[]{'a','b','c'}, 'a', 'c'));
+    assertFalse(CharUtils.inRange(new char[]{'a','b','c'}, 'm', 'z'));
+    
+    assertTrue(CharUtils.inRange(new char[]{'a','b','c'}, (int)'a', (int)'c'));
+    assertFalse(CharUtils.inRange(new char[]{'a','b','c'}, (int)'m', (int)'z'));
+    
+    assertTrue(CharUtils.isBidi(CharUtils.LRE));
+    assertTrue(CharUtils.isBidi(CharUtils.LRM));
+    assertTrue(CharUtils.isBidi(CharUtils.LRO));
+    assertTrue(CharUtils.isBidi(CharUtils.PDF));
+    assertTrue(CharUtils.isBidi(CharUtils.RLE));
+    assertTrue(CharUtils.isBidi(CharUtils.RLM));
+    assertTrue(CharUtils.isBidi(CharUtils.RLO));
+    
+    // TODO: other checks
+  }
+  
+  public static void testBidi() throws Exception {
+    String s = "abc";
+    String lre = CharUtils.wrapBidi(s, CharUtils.LRE);
+    String lro = CharUtils.wrapBidi(s, CharUtils.LRO);
+    String lrm = CharUtils.wrapBidi(s, CharUtils.LRM);
+    String rle = CharUtils.wrapBidi(s, CharUtils.RLE);
+    String rlo = CharUtils.wrapBidi(s, CharUtils.RLO);
+    String rlm = CharUtils.wrapBidi(s, CharUtils.RLM);
+    
+    assertEquals(lre.charAt(0),CharUtils.LRE);
+    assertEquals(lre.charAt(lre.length()-1),CharUtils.PDF);
+    
+    assertEquals(lro.charAt(0),CharUtils.LRO);
+    assertEquals(lro.charAt(lro.length()-1),CharUtils.PDF);
+    
+    assertEquals(lrm.charAt(0),CharUtils.LRM);
+    assertEquals(lrm.charAt(lrm.length()-1),CharUtils.LRM);
+
+    assertEquals(rle.charAt(0),CharUtils.RLE);
+    assertEquals(rle.charAt(rle.length()-1),CharUtils.PDF);
+    
+    assertEquals(rlo.charAt(0),CharUtils.RLO);
+    assertEquals(rlo.charAt(rlo.length()-1),CharUtils.PDF);
+    
+    assertEquals(rlm.charAt(0),CharUtils.RLM);
+    assertEquals(rlm.charAt(rlm.length()-1),CharUtils.RLM);
+    
+    assertEquals(s, CharUtils.stripBidi(lre));
+    assertEquals(s, CharUtils.stripBidi(lro));
+    assertEquals(s, CharUtils.stripBidi(lrm));
+    assertEquals(s, CharUtils.stripBidi(rle));
+    assertEquals(s, CharUtils.stripBidi(rlo));
+    assertEquals(s, CharUtils.stripBidi(rlm));
+    
+    s = new String(new char[] {'a',CharUtils.LRM,'b',CharUtils.LRM,'c'});
+    assertEquals(s.length(),5);
+    s = CharUtils.stripBidiInternal(s);
+    assertEquals(s.length(),3);
+    assertEquals(s,"abc");
+  }
+  
+  public static void testVerify() throws Exception {
+    CharUtils.verify(new char[] {'a','b','c','d'}, CharUtils.Profile.ALPHA);
+    CharUtils.verifyNot(new char [] {'1','2','3','4','-'}, CharUtils.Profile.ALPHA);
+  }
+  
+  public static void testCodepointIterator() throws Exception {
+    String s = "abcdefghijklmnop";
+    CodepointIterator ci = CodepointIterator.forCharSequence(s);
+    while(ci.hasNext()) {
+      Codepoint cp = ci.next();
+    }
+  }
+  
+  public static void testSanitizer() throws Exception {
+    String s = "\u0074\u0068\u00ed\u0073\u0020\u00ed\u0073\u0020\u00e0\u0020\u0074\u00e9\u0073\u0074";
+    String t = Sanitizer.sanitize(s);
+    assertEquals(t,"th%C3%ADs_%C3%ADs_%C3%A0_t%C3%A9st");
+    t = Sanitizer.sanitize(s, "", true, Normalizer.Form.D);
+    assertEquals(t,"this_is_a_test");
+    
+  }
+}



Mime
View raw message