Skip to content

Commit

Permalink
Merge pull request #12 from telus/trim_end
Browse files Browse the repository at this point in the history
fix: Parser - trim only trailing spaces
  • Loading branch information
stan-porter-telus-com authored Mar 3, 2022
2 parents 7cdbad5 + c8e9f5b commit 94847f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand All @@ -43,14 +43,18 @@ 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)
Assertions.assertEquals(LocalDate.parse("2021-03-09"), header.date1)

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)

Expand Down Expand Up @@ -118,10 +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)
}

}


0 comments on commit 94847f1

Please sign in to comment.