commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1300516 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/UnicodeUnescapeReader.java test/java/org/apache/commons/csv/CharBufferTest.java test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java
Date Wed, 14 Mar 2012 12:45:16 GMT
On 14 March 2012 12:01,  <ebourg@apache.org> wrote:
> Author: ebourg
> Date: Wed Mar 14 12:01:47 2012
> New Revision: 1300516
>
> URL: http://svn.apache.org/viewvc?rev=1300516&view=rev
> Log:
> Improved test coverage
>
> Modified:
>    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/UnicodeUnescapeReader.java
>    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java
>    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java
>
> Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/UnicodeUnescapeReader.java
> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/UnicodeUnescapeReader.java?rev=1300516&r1=1300515&r2=1300516&view=diff
> ==============================================================================
> --- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/UnicodeUnescapeReader.java
(original)
> +++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/UnicodeUnescapeReader.java
Wed Mar 14 12:01:47 2012
> @@ -50,12 +50,7 @@ class UnicodeUnescapeReader extends Read
>
>             if (c == '\\') {
>                 int l = reader.read(sequence);
> -                if (l == sequence.length
> -                        && 'u' == sequence[0]
> -                        && isHexadecimal(sequence[1])
> -                        && isHexadecimal(sequence[2])
> -                        && isHexadecimal(sequence[3])
> -                        && isHexadecimal(sequence[4])) {
> +                if (l == sequence.length && isUnicodeSequence(sequence))
{
>                     // unicode escape found
>                     c = Integer.parseInt(new String(sequence, 1, 4), 16);
>
> @@ -71,7 +66,15 @@ class UnicodeUnescapeReader extends Read
>
>         return count;
>     }
> -
> +
> +    private boolean isUnicodeSequence(char[] sequence) {
> +        return 'u' == sequence[0]
> +                && isHexadecimal(sequence[1])
> +                && isHexadecimal(sequence[2])
> +                && isHexadecimal(sequence[3])
> +                && isHexadecimal(sequence[4]);
> +    }

What if the sequence is not exactly 5 characters long?

> +
>     private boolean isHexadecimal(char c) {
>         return ('0' <= c && c <= '9') || ('a' <= c && c
<= 'f') || ('A' <= c && c <= 'F');
>     }
>
> Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java?rev=1300516&r1=1300515&r2=1300516&view=diff
> ==============================================================================
> --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java
(original)
> +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java
Wed Mar 14 12:01:47 2012
> @@ -164,4 +164,16 @@ public class CharBufferTest extends Test
>         buffer.ensureCapacity(8);
>         assertTrue(buffer.capacity() >= 8);
>     }
> +
> +    public void testTrim() throws Exception {
> +        CharBuffer buffer = new CharBuffer();
> +        buffer.append("          ");
> +        buffer.trimTrailingWhitespace();
> +        assertEquals(0, buffer.length());
> +
> +        buffer = new CharBuffer();
> +        buffer.append("Hello World!    ");
> +        buffer.trimTrailingWhitespace();
> +        assertEquals("Hello World!", buffer.toString());
> +    }
>  }
>
> Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java?rev=1300516&r1=1300515&r2=1300516&view=diff
> ==============================================================================
> --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java
(original)
> +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java
Wed Mar 14 12:01:47 2012
> @@ -14,6 +14,7 @@
>  * See the License for the specific language governing permissions and
>  * limitations under the License.
>  */
> +
>  package org.apache.commons.csv;
>
>  import java.io.StringReader;
> @@ -21,15 +22,19 @@ import java.util.Arrays;
>
>  import junit.framework.TestCase;
>
> -/**
> - * ExtendedBufferedReaderTest
> - */
>  public class ExtendedBufferedReaderTest extends TestCase {
>
> -    public void testReadLookahead1() throws Exception {
> +    public void testEmptyInput() throws Exception {
> +        ExtendedBufferedReader br = getBufferedReader("");
> +        assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.read());
> +        assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.lookAhead());
> +        assertEquals(ExtendedBufferedReader.END_OF_STREAM, br.readAgain());
> +        assertNull(br.readLine());
> +        assertEquals(0, br.read(new char[10], 0, 0));
> +    }
>
> -        assertEquals(ExtendedBufferedReader.END_OF_STREAM, getEBR("").read());
> -        ExtendedBufferedReader br = getEBR("1\n2\r3\n");
> +    public void testReadLookahead1() throws Exception {
> +        ExtendedBufferedReader br = getBufferedReader("1\n2\r3\n");
>         assertEquals('1', br.lookAhead());
>         assertEquals(ExtendedBufferedReader.UNDEFINED, br.readAgain());
>         assertEquals('1', br.read());
> @@ -82,12 +87,8 @@ public class ExtendedBufferedReaderTest
>     public void testReadLookahead2() throws Exception {
>         char[] ref = new char[5];
>         char[] res = new char[5];
> -
> -        ExtendedBufferedReader br = getEBR("");
> -        assertEquals(0, br.read(res, 0, 0));
> -        assertTrue(Arrays.equals(res, ref));
> -
> -        br = getEBR("abcdefg");
> +
> +        ExtendedBufferedReader br = getBufferedReader("abcdefg");
>         ref[0] = 'a';
>         ref[1] = 'b';
>         ref[2] = 'c';
> @@ -100,18 +101,17 @@ public class ExtendedBufferedReaderTest
>         assertEquals(1, br.read(res, 4, 1));
>         assertTrue(Arrays.equals(res, ref));
>         assertEquals('d', br.readAgain());
> -
>     }
>
>     public void testReadLine() throws Exception {
> -        ExtendedBufferedReader br = getEBR("");
> +        ExtendedBufferedReader br = getBufferedReader("");
>         assertTrue(br.readLine() == null);
>
> -        br = getEBR("\n");
> +        br = getBufferedReader("\n");
>         assertTrue(br.readLine().equals(""));
>         assertTrue(br.readLine() == null);
>
> -        br = getEBR("foo\n\nhello");
> +        br = getBufferedReader("foo\n\nhello");
>         assertEquals(0, br.getLineNumber());
>         assertTrue(br.readLine().equals("foo"));
>         assertEquals(1, br.getLineNumber());
> @@ -122,7 +122,7 @@ public class ExtendedBufferedReaderTest
>         assertTrue(br.readLine() == null);
>         assertEquals(3, br.getLineNumber());
>
> -        br = getEBR("foo\n\nhello");
> +        br = getBufferedReader("foo\n\nhello");
>         assertEquals('f', br.read());
>         assertEquals('o', br.lookAhead());
>         assertTrue(br.readLine().equals("oo"));
> @@ -136,7 +136,7 @@ public class ExtendedBufferedReaderTest
>         assertEquals(3, br.getLineNumber());
>
>
> -        br = getEBR("foo\rbaar\r\nfoo");
> +        br = getBufferedReader("foo\rbaar\r\nfoo");
>         assertTrue(br.readLine().equals("foo"));
>         assertEquals('b', br.lookAhead());
>         assertTrue(br.readLine().equals("baar"));
> @@ -145,7 +145,7 @@ public class ExtendedBufferedReaderTest
>         assertTrue(br.readLine() == null);
>     }
>
> -    private ExtendedBufferedReader getEBR(String s) {
> +    private ExtendedBufferedReader getBufferedReader(String s) {
>         return new ExtendedBufferedReader(new StringReader(s));
>     }
>  }
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message