Fix RustWrite.withModule bug (#13)

* withModule needs to set the parent dependencies

* Fix ktlin style
This commit is contained in:
Russell Cohen 2020-11-02 15:37:29 -05:00 committed by GitHub
parent 9983057a4b
commit 787d317850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -93,6 +93,7 @@ class RustWriter private constructor(private val filename: String, val namespace
rustBlock("$visibility mod $moduleName") { rustBlock("$visibility mod $moduleName") {
write(innerWriter.toString()) 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 // TODO: refactor both of these methods & add a parent method to for_each across any field type

View File

@ -5,14 +5,17 @@
package software.amazon.smithy.rust.lang package software.amazon.smithy.rust.lang
import io.kotest.matchers.collections.shouldContain
import io.kotest.matchers.string.shouldContain import io.kotest.matchers.string.shouldContain
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.codegen.core.SymbolProvider
import software.amazon.smithy.model.Model import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.SetShape import software.amazon.smithy.model.shapes.SetShape
import software.amazon.smithy.model.shapes.StringShape 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.RustWriter
import software.amazon.smithy.rust.codegen.lang.rustBlock 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.codegen.smithy.SymbolVisitor
import software.amazon.smithy.rust.testutil.quickTest import software.amazon.smithy.rust.testutil.quickTest
import software.amazon.smithy.rust.testutil.shouldCompile import software.amazon.smithy.rust.testutil.shouldCompile
@ -28,6 +31,18 @@ class RustWriterTest {
sut.toString().shouldMatchResource(javaClass, "empty.rs") 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 @Test
fun `manually created struct`() { fun `manually created struct`() {
val sut = RustWriter.forModule("lib") val sut = RustWriter.forModule("lib")