forked from getodk/collect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CSV quoting and escaping of strings
Add tests
- Loading branch information
1 parent
34241ec
commit 2c16a46
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
collect_app/src/test/java/org/odk/collect/android/utilities/CSVUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.odk.collect.android.utilities; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class CSVUtilsTest { | ||
@Test | ||
public void testEscapeDoubleQuote() { | ||
Assert.assertNull(CSVUtils.escapeDoubleQuote(null)); | ||
Assert.assertEquals("", CSVUtils.escapeDoubleQuote("")); | ||
Assert.assertEquals("no quotes", CSVUtils.escapeDoubleQuote("no quotes")); | ||
Assert.assertEquals("string with \"\"quotes\"\"", CSVUtils.escapeDoubleQuote("string with \"quotes\"")); | ||
} | ||
|
||
@Test | ||
public void testQuoteString() { | ||
Assert.assertNull(CSVUtils.quoteString(null)); | ||
Assert.assertEquals("\"\"", CSVUtils.quoteString("")); | ||
Assert.assertEquals("\"string\"", CSVUtils.quoteString("string")); | ||
Assert.assertEquals("\"string with \"quotes\"\"", CSVUtils.quoteString("string with \"quotes\"")); | ||
} | ||
|
||
@Test | ||
public void testGetEscapedValueForCsv() { | ||
Assert.assertNull(CSVUtils.getEscapedValueForCsv(null)); | ||
Assert.assertEquals("\"\"", CSVUtils.getEscapedValueForCsv("")); | ||
Assert.assertEquals("\"string\"", CSVUtils.getEscapedValueForCsv("string")); | ||
Assert.assertEquals("\"string with \"\"quotes\"\"\"", CSVUtils.getEscapedValueForCsv("string with \"quotes\"")); | ||
} | ||
} |