Skip to content

Commit

Permalink
Merge pull request #263 from statisticsnorway/RecordLengthFix
Browse files Browse the repository at this point in the history
Record length fix
  • Loading branch information
jonolehagemo authored Sep 27, 2023
2 parents a47c1b8 + 6bbcbe8 commit af9ce4f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class KotlinArguments(
}

fun getInputContentAsStringList(delimiter: String = DEFAULT_LINEBREAK_CHAR): List<String> =
inputFileContent.split(delimiter)
inputFileContent.split(delimiter).map { it.trim('\r') }

fun getInputContentAsInputStream(): InputStream = inputFileContent.byteInputStream(Charsets.ISO_8859_1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Rule001RecordLength(
.map {
createValidationReportEntry(
messageText = """Korrigér filen slik at alle records er på $length tegn.<br/>
Fant record med lengde på ${it.value.length} tegn.<br/>
Mellomrom brukes for alle blanke posisjoner og avslutter med linjeskift.<br/>
Denne feilen hindrer de andre kontrollene i å bli kjørt""".trimIndent(),
lineNumbers = listOf(it.index + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,29 @@ class KotlinArgumentsTest : BehaviorSpec({
}
}
}

Given("KotlinArguments#getInputContentAsStringList()") {

forAll(
row("empty content", "", listOf("")),
row("content with new line", "a\nb", listOf("a", "b")),
row("content with carriage return and new line", "a\r\nb", listOf("a", "b")),
row("content with carriage return and new line plus blank line at end", "a\r\nb\n", listOf("a", "b", "")),
) { description, content, expectedList ->
When(description) {
val kotlinArguments = KotlinArguments(
skjema = "15",
aargang = Year.now().value.toString(),
region = "030100",
inputFileContent = content
)

val contentAsStringList = kotlinArguments.getInputContentAsStringList()

Then("getInputContentAsStringList() should produce the expectedList") {
contentAsStringList shouldBe expectedList
}
}
}
}
})

0 comments on commit af9ce4f

Please sign in to comment.