Skip to content

Commit

Permalink
test(analysis): increase tokei test cov again #3483
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktMehl committed Feb 28, 2025
1 parent f336fcb commit e6f5795
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 = {}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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())

Expand All @@ -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<File>().name).isEqualTo(File(inputFileName).name)
assertThat(parseResult.matchedOption("output-file").getValue<String>().equals("out.cc.json"))
assertThat(parseResult.matchedOption("output-file").getValue<String>().equals(defaultOutputFileName))
assertThat(parseResult.matchedOption("not-compressed")).isNull()
assertThat(parseResult.matchedOption("root-name").getValue<String>()).isEqualTo(rootFolder)
assertThat(parseResult.matchedOption("path-separator").getValue<String>()).isEqualTo(pathSeparator)
Expand All @@ -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<File>().name).isEqualTo(File(inputFileName).name)
assertThat(parseResult.matchedOption("output-file").getValue<String>().equals(outputFileName))
assertThat(parseResult.matchedOption("not-compressed").getValue<Boolean>()).isEqualTo(isCompressed)
assertThat(parseResult.matchedOption("root-name").getValue<String>()).isEqualTo(rootFolder)
assertThat(parseResult.matchedPositional(0).getValue<File>().name)
.isEqualTo(File(inputFileName).name)
assertThat(parseResult.matchedOption("output-file").getValue<String>())
.isEqualTo(outputFileName)
assertThat(parseResult.matchedOption("not-compressed").getValue<Boolean>())
.isEqualTo(isCompressed)
assertThat(parseResult.matchedOption("root-name").getValue<String>())
.isEqualTo(rootFolder)
assertThat(parseResult.matchedOption("path-separator").getValue<String>())
.isEqualTo(pathSeparatorEscaped)
}
Expand All @@ -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<File>().name).isEqualTo(File(inputFileName).name)
assertThat(parseResult.matchedOption("output-file").getValue<String>().equals(outputFileName))
assertThat(parseResult.matchedOption("not-compressed").getValue<Boolean>()).isEqualTo(isCompressed)
assertThat(parseResult.matchedOption("root-name").getValue<String>()).isEqualTo(rootFolder)
assertThat(parseResult.matchedOption("path-separator").getValue<String>()).isEqualTo(pathSeparator)
assertThat(parseResult.matchedPositional(0).getValue<File>().name)
.isEqualTo(File(inputFileName).name)
assertThat(parseResult.matchedOption("output-file").getValue<String>())
.isEqualTo(outputFileName)
assertThat(parseResult.matchedOption("not-compressed").getValue<Boolean>())
.isEqualTo(isCompressed)
assertThat(parseResult.matchedOption("root-name").getValue<String>())
.isEqualTo(rootFolder)
assertThat(parseResult.matchedOption("path-separator").getValue<String>())
.isEqualTo(pathSeparator)
}
}

Expand All @@ -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())
Expand Down

0 comments on commit e6f5795

Please sign in to comment.