-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f225d3e
commit 4a8e2a5
Showing
2 changed files
with
76 additions
and
61 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/commonTest/kotlin/com/github/doyaaaaaken/kotlincsv/parser/CsvParserTest.kt
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,76 @@ | ||
package com.github.doyaaaaaken.kotlincsv.parser | ||
|
||
import com.github.doyaaaaaken.kotlincsv.util.MalformedCSVException | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
import kotlin.test.assertNull | ||
|
||
class CsvParserTest { | ||
|
||
private val parser = CsvParser('"', ',', '"') | ||
|
||
private val lineTerminators = listOf("\n", "\u2028", "\u2029", "\u0085", "\r", "\r\n") | ||
|
||
@Test | ||
fun `parseRow method should parseEmptyRow`() { | ||
assertEquals(parser.parseRow(""), emptyList()) | ||
} | ||
|
||
@Test | ||
fun `parseRow method should return null if line is on the way of csv row`() { | ||
assertNull(parser.parseRow("a,\"b")) | ||
} | ||
|
||
@Test | ||
fun `ParseStateMachine logic should parse delimiter at the start of row`() { | ||
assertEquals(parser.parseRow(",a"), listOf("", "a")) | ||
} | ||
|
||
@Test | ||
fun `ParseStateMachine logic should parse line terminator at the start of row`() { | ||
lineTerminators.forEach { lt -> | ||
assertEquals(parser.parseRow(lt), listOf("")) | ||
} | ||
} | ||
|
||
@Test | ||
fun `ParseStateMachine logic should parse row with delimiter at the end`() { | ||
assertEquals(parser.parseRow("a,"), listOf("a", "")) | ||
} | ||
|
||
@Test | ||
fun `ParseStateMachine logic should parse line terminator after quote end`() { | ||
lineTerminators.forEach { lt -> | ||
assertEquals(parser.parseRow("""a,"b"$lt"""), listOf("a", "b")) | ||
} | ||
} | ||
|
||
@Test | ||
fun `ParseStateMachine logic should parse line terminator after delimiter`() { | ||
lineTerminators.forEach { lt -> | ||
assertEquals(parser.parseRow("a,$lt"), listOf("a", "")) | ||
} | ||
} | ||
|
||
@Test | ||
fun `ParseStateMachine logic should parse line terminator after field`() { | ||
lineTerminators.forEach { lt -> | ||
assertEquals(parser.parseRow("a$lt"), listOf("a")) | ||
} | ||
} | ||
|
||
@Test | ||
fun `ParseStateMachine logic should parse escape character after field`() { | ||
assertEquals(parser.parseRow("a\"\""), listOf("a\"")) | ||
} | ||
|
||
@Test | ||
fun `ParseStateMachine logic should throw exception when parsing 2 rows`() { | ||
lineTerminators.forEach { lt -> | ||
assertFailsWith(MalformedCSVException::class) { | ||
parser.parseRow("a${lt}b") | ||
} | ||
} | ||
} | ||
} |
61 changes: 0 additions & 61 deletions
61
src/jvmTest/kotlin/com/github/doyaaaaaken/kotlincsv/parser/CsvParserTest.kt
This file was deleted.
Oops, something went wrong.