Skip to content

Commit

Permalink
Fix platform issue when determining module name from file
Browse files Browse the repository at this point in the history
  • Loading branch information
kiiadi committed Jun 28, 2022
1 parent 424d736 commit e6f92e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import software.amazon.smithy.rust.codegen.smithy.isOptional
import software.amazon.smithy.rust.codegen.smithy.rustType
import software.amazon.smithy.rust.codegen.util.orNull
import software.amazon.smithy.utils.AbstractCodeWriter
import java.io.File
import java.util.function.BiFunction

/**
Expand Down Expand Up @@ -393,7 +394,7 @@ class RustWriter private constructor(
}

fun module(): String? = if (filename.startsWith("src") && filename.endsWith(".rs")) {
filename.removeSuffix(".rs").split('/').last()
filename.removeSuffix(".rs").substringAfterLast(File.separatorChar)
} else null

fun safeName(prefix: String = "var"): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,10 @@ class RustWriterTest {
)
sut.toString().shouldContain("inner: hello, regular: http::foo")
}

@Test
fun `can handle file paths properly when determining module`() {
val sut = RustWriter.forModule("src/module_name")
sut.module().shouldBe("module_name")
}
}

0 comments on commit e6f92e5

Please sign in to comment.