Use hasContent matcher token type is not relevant (correct token type recognition is tested by other tests methods)

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1463210 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benedikt Ritter 2013-04-01 17:15:31 +00:00
parent aef71309b6
commit 09a6e887b8
1 changed files with 16 additions and 8 deletions

View File

@ -29,6 +29,8 @@ import static org.apache.commons.csv.Token.Type.TOKEN;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;
import static org.apache.commons.csv.TokenMatchers.hasContent;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
@ -282,38 +284,38 @@ public class CSVLexerTest {
@Test @Test
public void testEscapedCR() throws Exception { public void testEscapedCR() throws Exception {
final Lexer lexer = getLexer("character\\" + CR + "Escaped", formatWithEscaping); final Lexer lexer = getLexer("character\\" + CR + "Escaped", formatWithEscaping);
assertTokenEquals(EOF, "character" + CR + "Escaped", lexer.nextToken(new Token())); assertThat(lexer.nextToken(new Token()), hasContent("character" + CR + "Escaped"));
} }
@Test @Test
public void testEscapedLF() throws Exception { public void testEscapedLF() throws Exception {
final Lexer lexer = getLexer("character\\" + LF + "Escaped", formatWithEscaping); final Lexer lexer = getLexer("character\\" + LF + "Escaped", formatWithEscaping);
assertTokenEquals(EOF, "character" + LF + "Escaped", lexer.nextToken(new Token())); assertThat(lexer.nextToken(new Token()), hasContent("character" + LF + "Escaped"));
} }
@Test @Test
public void testEscapedTab() throws Exception { public void testEscapedTab() throws Exception {
final Lexer lexer = getLexer("character\\" + TAB + "Escaped", formatWithEscaping); final Lexer lexer = getLexer("character\\" + TAB + "Escaped", formatWithEscaping);
assertTokenEquals(EOF, "character" + TAB + "Escaped", lexer.nextToken(new Token())); assertThat(lexer.nextToken(new Token()), hasContent("character" + TAB + "Escaped"));
} }
@Test @Test
public void testEscapeBackspace() throws Exception { public void testEscapeBackspace() throws Exception {
final Lexer lexer = getLexer("character\\" + BACKSPACE + "Escaped", formatWithEscaping); final Lexer lexer = getLexer("character\\" + BACKSPACE + "Escaped", formatWithEscaping);
assertTokenEquals(EOF, "character" + BACKSPACE + "Escaped", lexer.nextToken(new Token())); assertThat(lexer.nextToken(new Token()), hasContent("character" + BACKSPACE + "Escaped"));
} }
@Test @Test
public void testEscapeFF() throws Exception { public void testEscapeFF() throws Exception {
final Lexer lexer = getLexer("character\\" + FF + "Escaped", formatWithEscaping); final Lexer lexer = getLexer("character\\" + FF + "Escaped", formatWithEscaping);
assertTokenEquals(EOF, "character" + FF + "Escaped", lexer.nextToken(new Token())); assertThat(lexer.nextToken(new Token()), hasContent("character" + FF + "Escaped"));
} }
@Test @Test
public void testEscapedMySqlNullValue() throws Exception { public void testEscapedMySqlNullValue() throws Exception {
// MySQL uses \N to symbolize null values. We have to restore this // MySQL uses \N to symbolize null values. We have to restore this
final Lexer lexer = getLexer("character\\\\NEscaped", formatWithEscaping); final Lexer lexer = getLexer("character\\\\NEscaped", formatWithEscaping);
assertTokenEquals(EOF, "character\\NEscaped", lexer.nextToken(new Token())); assertThat(lexer.nextToken(new Token()), hasContent("character\\NEscaped"));
} }
// FIXME this should work after CSV-58 is resolved. Currently the result will be "characteraEscaped" // FIXME this should work after CSV-58 is resolved. Currently the result will be "characteraEscaped"
@ -321,7 +323,7 @@ public class CSVLexerTest {
@Ignore @Ignore
public void testEscapedCharacter() throws Exception { public void testEscapedCharacter() throws Exception {
final Lexer lexer = getLexer("character\\aEscaped", formatWithEscaping); final Lexer lexer = getLexer("character\\aEscaped", formatWithEscaping);
assertTokenEquals(EOF, "character\\aEscaped", lexer.nextToken(new Token())); assertThat(lexer.nextToken(new Token()), hasContent("character\\aEscaped"));
} }
// FIXME this should work after CSV-58 is resolved. Currently the result will be "characterCREscaped" // FIXME this should work after CSV-58 is resolved. Currently the result will be "characterCREscaped"
@ -330,7 +332,13 @@ public class CSVLexerTest {
public void testEscapedControlCharacter() throws Exception { public void testEscapedControlCharacter() throws Exception {
// we are explicitly using an escape different from \ here, because \r is the character sequence for CR // we are explicitly using an escape different from \ here, because \r is the character sequence for CR
final Lexer lexer = getLexer("character!rEscaped", CSVFormat.newBuilder().withEscape('!').build()); final Lexer lexer = getLexer("character!rEscaped", CSVFormat.newBuilder().withEscape('!').build());
assertTokenEquals(EOF, "character!rEscaped", lexer.nextToken(new Token())); assertThat(lexer.nextToken(new Token()), hasContent("character!rEscaped"));
}
@Test
public void testEscapedControlCharacter2() throws Exception {
final Lexer lexer = getLexer("character\\rEscaped", CSVFormat.newBuilder().withEscape('\\').build());
assertThat(lexer.nextToken(new Token()), hasContent("character"+CR+"Escaped"));
} }
@Test(expected = IOException.class) @Test(expected = IOException.class)