From 0ed072cd740447f67888eba9e7b3b785ee3cf9c7 Mon Sep 17 00:00:00 2001 From: Marian Puscasu Date: Thu, 3 Mar 2022 22:41:18 +0200 Subject: [PATCH 1/2] Switch parser readLine trim to trimEnd --- .../kotlin/digital/capsa/core/fileparser/FileParserDsl.kt | 2 +- .../capsa/core/fileparser/FileParserBasicDslTest.kt | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/capsa-core/src/main/kotlin/digital/capsa/core/fileparser/FileParserDsl.kt b/capsa-core/src/main/kotlin/digital/capsa/core/fileparser/FileParserDsl.kt index 49be7e7..de2970f 100644 --- a/capsa-core/src/main/kotlin/digital/capsa/core/fileparser/FileParserDsl.kt +++ b/capsa-core/src/main/kotlin/digital/capsa/core/fileparser/FileParserDsl.kt @@ -112,7 +112,7 @@ class RecordParser( from: Int, toExclusive: Int ): String { - return if (line.length >= toExclusive) line.substring(from, toExclusive).trim() else "" + return if (line.length >= toExclusive) line.substring(from, toExclusive).trimEnd() else "" } } diff --git a/capsa-core/src/test/kotlin/digital/capsa/core/fileparser/FileParserBasicDslTest.kt b/capsa-core/src/test/kotlin/digital/capsa/core/fileparser/FileParserBasicDslTest.kt index 2f85cfb..473f3a3 100644 --- a/capsa-core/src/test/kotlin/digital/capsa/core/fileparser/FileParserBasicDslTest.kt +++ b/capsa-core/src/test/kotlin/digital/capsa/core/fileparser/FileParserBasicDslTest.kt @@ -21,7 +21,7 @@ class FileParserBasicDslTest { StringReader( """ aaa 23 2021-03-09 - bbb cc 23 2021-04-19 + bbb c 23 2021-04-19 d e f1 34 2021-05-22 """.trimIndent() ) @@ -50,7 +50,7 @@ class FileParserBasicDslTest { var item = parser.getRecords()[1].value as Item Assertions.assertEquals("bbb", item.string1) - Assertions.assertEquals("cc", item.string2) + Assertions.assertEquals(" c", item.string2) Assertions.assertEquals(23, item.int1) Assertions.assertEquals(LocalDate.parse("2021-04-19"), item.date1) @@ -121,7 +121,4 @@ class FileParserBasicDslTest { Assertions.assertEquals("Line length should be 18 but was 17", parser.getRecords()[0].issues[0].message) Assertions.assertEquals("Line length should be 22 but was 20", parser.getRecords()[1].issues[0].message) } - } - - From c8e9f5b197905ed191e9fde2f8f3cdd0a71bd624 Mon Sep 17 00:00:00 2001 From: Marian Puscasu Date: Thu, 3 Mar 2022 22:44:08 +0200 Subject: [PATCH 2/2] Add more assertion to parser tests --- .../capsa/core/fileparser/FileParserBasicDslTest.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/capsa-core/src/test/kotlin/digital/capsa/core/fileparser/FileParserBasicDslTest.kt b/capsa-core/src/test/kotlin/digital/capsa/core/fileparser/FileParserBasicDslTest.kt index 473f3a3..bb7226a 100644 --- a/capsa-core/src/test/kotlin/digital/capsa/core/fileparser/FileParserBasicDslTest.kt +++ b/capsa-core/src/test/kotlin/digital/capsa/core/fileparser/FileParserBasicDslTest.kt @@ -43,6 +43,10 @@ class FileParserBasicDslTest { ) } } + Assertions.assertEquals(0, parser.getRecords()[0].issues.count()) + Assertions.assertEquals(0, parser.getRecords()[1].issues.count()) + Assertions.assertEquals(0, parser.getRecords()[2].issues.count()) + val header = parser.getRecords()[0].value as Header Assertions.assertEquals("aaa", header.string1) Assertions.assertEquals(23, header.int1) @@ -118,7 +122,12 @@ class FileParserBasicDslTest { ) } } + Assertions.assertEquals(1, parser.getRecords()[0].issues.count()) + Assertions.assertEquals(1, parser.getRecords()[1].issues.count()) + Assertions.assertEquals(1, parser.getRecords()[2].issues.count()) + Assertions.assertEquals("Line length should be 18 but was 17", parser.getRecords()[0].issues[0].message) Assertions.assertEquals("Line length should be 22 but was 20", parser.getRecords()[1].issues[0].message) + Assertions.assertEquals("Line length should be 22 but was 20", parser.getRecords()[2].issues[0].message) } }