diff --git a/analysis/import/TokeiImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/tokeiimporter/ParserDialog.kt b/analysis/import/TokeiImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/tokeiimporter/ParserDialog.kt index bab8c73bfd..df2de4591f 100644 --- a/analysis/import/TokeiImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/tokeiimporter/ParserDialog.kt +++ b/analysis/import/TokeiImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/tokeiimporter/ParserDialog.kt @@ -22,28 +22,28 @@ class ParserDialog { message = "What is the name of the output file?", hint = "output.cc.json", allowEmptyInput = true, - onInputReady = outFileCallback() + onInputReady = testCallback() ) val rootName = session.myPromptInput( message = "Which root folder was specified when executing tokei?", hint = ".", allowEmptyInput = false, - onInputReady = rootCallback() + onInputReady = testCallback() ) var pathSeparator = session.myPromptInput( message = "Which path separator is used? Leave empty for auto-detection", hint = "", allowEmptyInput = true, - onInputReady = pathCallback() + onInputReady = testCallback() ) if (pathSeparator == "\\") pathSeparator = "\\\\" val isCompressed = (outputFileName.isEmpty()) || session.myPromptConfirm( message = "Do you want to compress the output file?", - onInputReady = compressCallback() + onInputReady = testCallback() ) return listOfNotNull( @@ -56,13 +56,5 @@ class ParserDialog { } internal fun testCallback(): suspend RunScope.() -> Unit = {} - - internal fun outFileCallback(): suspend RunScope.() -> Unit = {} - - internal fun rootCallback(): suspend RunScope.() -> Unit = {} - - internal fun pathCallback(): suspend RunScope.() -> Unit = {} - - internal fun compressCallback(): suspend RunScope.() -> Unit = {} } } diff --git a/analysis/import/TokeiImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/tokeiimporter/ParserDialogTest.kt b/analysis/import/TokeiImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/tokeiimporter/ParserDialogTest.kt index af60cc2217..4607f743cb 100644 --- a/analysis/import/TokeiImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/tokeiimporter/ParserDialogTest.kt +++ b/analysis/import/TokeiImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/tokeiimporter/ParserDialogTest.kt @@ -1,6 +1,7 @@ package de.maibornwolff.codecharta.importer.tokeiimporter import com.varabyte.kotter.foundation.input.Keys +import com.varabyte.kotter.runtime.RunScope import com.varabyte.kotter.runtime.terminal.inmemory.press import com.varabyte.kotter.runtime.terminal.inmemory.type import com.varabyte.kotterx.test.foundation.testSession @@ -30,29 +31,40 @@ class ParserDialogTest { mockkObject(ParserDialog.Companion) testSession { terminal -> - every { ParserDialog.Companion.testCallback() } returns { + val fileCallback: suspend RunScope.() -> Unit = { terminal.type(inputFileName) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.outFileCallback() } returns { + + val outFileCallback: suspend RunScope.() -> Unit = { terminal.type(outputFileName) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.rootCallback() } returns { + + val rootCallback: suspend RunScope.() -> Unit = { terminal.type(rootFolder) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.pathCallback() } returns { + + val pathCallback: suspend RunScope.() -> Unit = { terminal.type(pathSeparator) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.compressCallback() } returns { + + val compressCallback: suspend RunScope.() -> Unit = { terminal.press(Keys.RIGHT) terminal.press(Keys.ENTER) } - val parserArguments = collectParserArgs(this) + every { ParserDialog.testCallback() } returnsMany listOf( + fileCallback, + outFileCallback, + rootCallback, + pathCallback, + compressCallback + ) + val parserArguments = collectParserArgs(this) val cmdLine = CommandLine(TokeiImporter()) val parseResult = cmdLine.parseArgs(*parserArguments.toTypedArray()) @@ -67,37 +79,49 @@ class ParserDialogTest { @Test fun `should output correct arguments when output file is not provided`() { val pathSeparator = "/" + val defaultOutputFileName = "out.cc.json" mockkObject(ParserDialog.Companion) testSession { terminal -> - every { ParserDialog.Companion.testCallback() } returns { + val fileCallback: suspend RunScope.() -> Unit = { terminal.type(inputFileName) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.outFileCallback() } returns { - terminal.press(Keys.ENTER) + + val outFileCallback: suspend RunScope.() -> Unit = { + terminal.press(Keys.ENTER) // User skips providing output file } - every { ParserDialog.Companion.rootCallback() } returns { + + val rootCallback: suspend RunScope.() -> Unit = { terminal.type(rootFolder) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.pathCallback() } returns { + + val pathCallback: suspend RunScope.() -> Unit = { terminal.type(pathSeparator) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.compressCallback() } returns { + + val compressCallback: suspend RunScope.() -> Unit = { terminal.press(Keys.RIGHT) terminal.press(Keys.ENTER) } - val parserArguments = collectParserArgs(this) + every { ParserDialog.testCallback() } returnsMany listOf( + fileCallback, + outFileCallback, + rootCallback, + pathCallback, + compressCallback + ) + val parserArguments = collectParserArgs(this) val cmdLine = CommandLine(TokeiImporter()) val parseResult = cmdLine.parseArgs(*parserArguments.toTypedArray()) assertThat(parseResult.matchedPositional(0).getValue().name).isEqualTo(File(inputFileName).name) - assertThat(parseResult.matchedOption("output-file").getValue().equals("out.cc.json")) + assertThat(parseResult.matchedOption("output-file").getValue().equals(defaultOutputFileName)) assertThat(parseResult.matchedOption("not-compressed")).isNull() assertThat(parseResult.matchedOption("root-name").getValue()).isEqualTo(rootFolder) assertThat(parseResult.matchedOption("path-separator").getValue()).isEqualTo(pathSeparator) @@ -113,36 +137,51 @@ class ParserDialogTest { mockkObject(ParserDialog.Companion) testSession { terminal -> - every { ParserDialog.Companion.testCallback() } returns { + val fileCallback: suspend RunScope.() -> Unit = { terminal.type(inputFileName) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.outFileCallback() } returns { + + val outFileCallback: suspend RunScope.() -> Unit = { terminal.type(outputFileName) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.rootCallback() } returns { + + val rootCallback: suspend RunScope.() -> Unit = { terminal.type(rootFolder) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.pathCallback() } returns { + + val pathCallback: suspend RunScope.() -> Unit = { terminal.type(pathSeparator) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.compressCallback() } returns { + + val compressCallback: suspend RunScope.() -> Unit = { terminal.press(Keys.RIGHT) terminal.press(Keys.ENTER) } - val parserArguments = collectParserArgs(this) + every { ParserDialog.testCallback() } returnsMany listOf( + fileCallback, + outFileCallback, + rootCallback, + pathCallback, + compressCallback + ) + val parserArguments = collectParserArgs(this) val cmdLine = CommandLine(TokeiImporter()) val parseResult = cmdLine.parseArgs(*parserArguments.toTypedArray()) - assertThat(parseResult.matchedPositional(0).getValue().name).isEqualTo(File(inputFileName).name) - assertThat(parseResult.matchedOption("output-file").getValue().equals(outputFileName)) - assertThat(parseResult.matchedOption("not-compressed").getValue()).isEqualTo(isCompressed) - assertThat(parseResult.matchedOption("root-name").getValue()).isEqualTo(rootFolder) + assertThat(parseResult.matchedPositional(0).getValue().name) + .isEqualTo(File(inputFileName).name) + assertThat(parseResult.matchedOption("output-file").getValue()) + .isEqualTo(outputFileName) + assertThat(parseResult.matchedOption("not-compressed").getValue()) + .isEqualTo(isCompressed) + assertThat(parseResult.matchedOption("root-name").getValue()) + .isEqualTo(rootFolder) assertThat(parseResult.matchedOption("path-separator").getValue()) .isEqualTo(pathSeparatorEscaped) } @@ -156,37 +195,53 @@ class ParserDialogTest { mockkObject(ParserDialog.Companion) testSession { terminal -> - every { ParserDialog.Companion.testCallback() } returns { + val fileCallback: suspend RunScope.() -> Unit = { terminal.type(inputFileName) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.outFileCallback() } returns { + + val outFileCallback: suspend RunScope.() -> Unit = { terminal.type(outputFileName) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.rootCallback() } returns { + + val rootCallback: suspend RunScope.() -> Unit = { terminal.type(rootFolder) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.pathCallback() } returns { + + val pathCallback: suspend RunScope.() -> Unit = { terminal.type(pathSeparator) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.compressCallback() } returns { + + val compressCallback: suspend RunScope.() -> Unit = { terminal.press(Keys.RIGHT) terminal.press(Keys.ENTER) } - val parserArguments = collectParserArgs(this) + every { ParserDialog.testCallback() } returnsMany listOf( + fileCallback, + outFileCallback, + rootCallback, + pathCallback, + compressCallback + ) + val parserArguments = collectParserArgs(this) val cmdLine = CommandLine(TokeiImporter()) val parseResult = cmdLine.parseArgs(*parserArguments.toTypedArray()) - assertThat(parseResult.matchedPositional(0).getValue().name).isEqualTo(File(inputFileName).name) - assertThat(parseResult.matchedOption("output-file").getValue().equals(outputFileName)) - assertThat(parseResult.matchedOption("not-compressed").getValue()).isEqualTo(isCompressed) - assertThat(parseResult.matchedOption("root-name").getValue()).isEqualTo(rootFolder) - assertThat(parseResult.matchedOption("path-separator").getValue()).isEqualTo(pathSeparator) + assertThat(parseResult.matchedPositional(0).getValue().name) + .isEqualTo(File(inputFileName).name) + assertThat(parseResult.matchedOption("output-file").getValue()) + .isEqualTo(outputFileName) + assertThat(parseResult.matchedOption("not-compressed").getValue()) + .isEqualTo(isCompressed) + assertThat(parseResult.matchedOption("root-name").getValue()) + .isEqualTo(rootFolder) + assertThat(parseResult.matchedOption("path-separator").getValue()) + .isEqualTo(pathSeparator) } } @@ -198,30 +253,42 @@ class ParserDialogTest { mockkObject(ParserDialog.Companion) testSession { terminal -> - every { ParserDialog.Companion.testCallback() } returns { + val fileCallback: suspend RunScope.() -> Unit = { terminal.type(invalidFileName) terminal.press(Keys.ENTER) terminal.press(Keys.BACKSPACE, Keys.BACKSPACE, Keys.BACKSPACE) terminal.type(inputFileName) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.outFileCallback() } returns { + + val outFileCallback: suspend RunScope.() -> Unit = { terminal.type(outputFileName) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.rootCallback() } returns { + + val rootCallback: suspend RunScope.() -> Unit = { terminal.type(rootFolder) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.pathCallback() } returns { + + val pathCallback: suspend RunScope.() -> Unit = { terminal.type(pathSeparator) terminal.press(Keys.ENTER) } - every { ParserDialog.Companion.compressCallback() } returns { + + val compressCallback: suspend RunScope.() -> Unit = { terminal.press(Keys.RIGHT) terminal.press(Keys.ENTER) } + every { ParserDialog.testCallback() } returnsMany listOf( + fileCallback, + outFileCallback, + rootCallback, + pathCallback, + compressCallback + ) + val parserArguments = collectParserArgs(this) val cmdLine = CommandLine(TokeiImporter())