Skip to content

Commit

Permalink
Do not override extension for explicit file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbrooks committed Oct 12, 2024
1 parent a0b8795 commit eb07ebf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
13 changes: 9 additions & 4 deletions vgo/src/main/kotlin/com/jzbrooks/vgo/Vgo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import kotlin.io.path.isDirectory
import kotlin.io.path.isRegularFile
import kotlin.io.path.isSameFileAs
import kotlin.io.path.nameWithoutExtension
import kotlin.io.path.pathString
import kotlin.math.absoluteValue
import kotlin.math.roundToInt

Expand Down Expand Up @@ -154,10 +155,14 @@ class Vgo(
}

val output =
when (this.options.format) {
"vd" -> outputPath.resolveSibling("${outputPath.nameWithoutExtension}.xml")
"svg" -> outputPath.resolveSibling("${outputPath.nameWithoutExtension}.svg")
else -> outputPath
if (input.path == outputPath.pathString) {
when (this.options.format) {
"vd" -> outputPath.resolveSibling("${outputPath.nameWithoutExtension}.xml")
"svg" -> outputPath.resolveSibling("${outputPath.nameWithoutExtension}.svg")
else -> outputPath
}
} else {
outputPath
}.toFile()

if (output.parentFile?.exists() == false) output.parentFile.mkdirs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import assertk.assertions.contains
import assertk.assertions.doesNotContain
import assertk.assertions.exists
import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -14,7 +15,7 @@ import java.io.File
import java.io.PrintStream
import java.nio.file.Paths

class InPlaceModificationTest {
class VgoTests {
private lateinit var systemOutput: ByteArrayOutputStream

@BeforeEach
Expand Down Expand Up @@ -47,7 +48,7 @@ class InPlaceModificationTest {
}

@Test
fun `individual file statistics are reported with a directory input`(info: TestInfo) {
fun `in-place individual file statistics are reported with a directory input`(info: TestInfo) {
val options =
Vgo.Options(
printStats = true,
Expand All @@ -60,7 +61,7 @@ class InPlaceModificationTest {
}

@Test
fun `non-vector files are not mentioned in statistics reporting with a directory input`(info: TestInfo) {
fun `in-place non-vector files are not mentioned in statistics reporting with a directory input`(info: TestInfo) {
val options =
Vgo.Options(
printStats = true,
Expand All @@ -74,7 +75,7 @@ class InPlaceModificationTest {
}

@Test
fun `only modified files appear in statistics reporting`(info: TestInfo) {
fun `in-place only modified files appear in statistics reporting`(info: TestInfo) {
val options =
Vgo.Options(
printStats = true,
Expand All @@ -88,7 +89,7 @@ class InPlaceModificationTest {
}

@Test
fun `non-vector files are not modified`(info: TestInfo) {
fun `in-place non-vector files are not modified`(info: TestInfo) {
val input = File("build/test-results/inPlaceModification/${info.displayName}/non_vector.xml")
val before = input.readText()

Expand All @@ -103,7 +104,7 @@ class InPlaceModificationTest {
}

@Test
fun `format option results in new file extension`(info: TestInfo) {
fun `in-place format option results in new file extension`(info: TestInfo) {
val options =
Vgo.Options(
format = "svg",
Expand All @@ -114,4 +115,22 @@ class InPlaceModificationTest {

assertThat(File("build/test-results/inPlaceModification/${info.displayName}/avocado_example.svg")).exists()
}

@Test
fun `output-specified file extension is not overwritten by conversion format`(info: TestInfo) {
val options =
Vgo.Options(
format = "svg",
input = listOf("build/test-results/inPlaceModification/${info.displayName}/avocado_example.xml"),
output = listOf("build/test-results/inPlaceModification/${info.displayName}/avocado_example.vec"),
)

Vgo(options).run()

assertThat(File("build/test-results/inPlaceModification/${info.displayName}/avocado_example.vec")).exists()
assertThat(File("build/test-results/inPlaceModification/${info.displayName}/avocado_example.svg"))
.transform("exists") {
it.exists()
}.isFalse() // todo: replace this with doesNotExists() when assertk is updated
}
}

0 comments on commit eb07ebf

Please sign in to comment.