mirror of https://github.com/smithy-lang/smithy-rs
Fix RustWrite.withModule bug (#13)
* withModule needs to set the parent dependencies * Fix ktlin style
This commit is contained in:
parent
9983057a4b
commit
787d317850
|
@ -93,6 +93,7 @@ class RustWriter private constructor(private val filename: String, val namespace
|
|||
rustBlock("$visibility mod $moduleName") {
|
||||
write(innerWriter.toString())
|
||||
}
|
||||
innerWriter.dependencies.forEach { addDependency(it) }
|
||||
}
|
||||
|
||||
// TODO: refactor both of these methods & add a parent method to for_each across any field type
|
||||
|
|
|
@ -5,14 +5,17 @@
|
|||
|
||||
package software.amazon.smithy.rust.lang
|
||||
|
||||
import io.kotest.matchers.collections.shouldContain
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import org.junit.jupiter.api.Test
|
||||
import software.amazon.smithy.codegen.core.SymbolProvider
|
||||
import software.amazon.smithy.model.Model
|
||||
import software.amazon.smithy.model.shapes.SetShape
|
||||
import software.amazon.smithy.model.shapes.StringShape
|
||||
import software.amazon.smithy.rust.codegen.lang.RustDependency
|
||||
import software.amazon.smithy.rust.codegen.lang.RustWriter
|
||||
import software.amazon.smithy.rust.codegen.lang.rustBlock
|
||||
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
|
||||
import software.amazon.smithy.rust.codegen.smithy.SymbolVisitor
|
||||
import software.amazon.smithy.rust.testutil.quickTest
|
||||
import software.amazon.smithy.rust.testutil.shouldCompile
|
||||
|
@ -28,6 +31,18 @@ class RustWriterTest {
|
|||
sut.toString().shouldMatchResource(javaClass, "empty.rs")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `inner modules correctly handle dependencies`() {
|
||||
val sut = RustWriter.forModule("lib")
|
||||
val requestBuilder = RuntimeType.HttpRequestBuilder
|
||||
sut.withModule("inner") {
|
||||
rustBlock("fn build(builer: \$T)", requestBuilder) {
|
||||
}
|
||||
}
|
||||
val httpDep = RustDependency.Http.dependencies[0]
|
||||
sut.dependencies shouldContain httpDep
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `manually created struct`() {
|
||||
val sut = RustWriter.forModule("lib")
|
||||
|
|
Loading…
Reference in New Issue