Loading codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt +4 −3 Original line number Diff line number Diff line Loading @@ -167,9 +167,10 @@ private fun transformTemplate(template: String, scope: Array<out Pair<String, An val templateType = matchResult.groupValues[2].ifEmpty { ":T" } if (!scope.toMap().keys.contains(keyName)) { throw CodegenException( "Rust block template expected `$keyName` but was not present in template.\n hint: Template contains: ${ scope.map { it.first } }", """ Rust block template expected `$keyName` but was not present in template. Hint: Template contains: ${scope.map { "`${it.first}`" }} """.trimIndent(), ) } "#{${keyName.lowercase()}$templateType}" Loading codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt +19 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import io.kotest.matchers.string.shouldContainOnlyOnce import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.SetShape import software.amazon.smithy.model.shapes.StringShape Loading Loading @@ -161,6 +163,23 @@ class RustWriterTest { sut.toString().shouldContain("inner: hello, regular: http::foo") } @Test fun `missing template parameters are enclosed in backticks in the exception message`() { val sut = RustWriter.forModule("lib") val exception = assertThrows<CodegenException> { sut.rustTemplate( "#{Foo} #{Bar}", "Foo Bar" to CargoDependency.Http.toType().resolve("foo"), "Baz" to CargoDependency.Http.toType().resolve("foo"), ) } exception.message shouldBe """ Rust block template expected `Foo` but was not present in template. Hint: Template contains: [`Foo Bar`, `Baz`] """.trimIndent() } @Test fun `can handle file paths properly when determining module`() { val sut = RustWriter.forModule("src/module_name") Loading Loading
codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt +4 −3 Original line number Diff line number Diff line Loading @@ -167,9 +167,10 @@ private fun transformTemplate(template: String, scope: Array<out Pair<String, An val templateType = matchResult.groupValues[2].ifEmpty { ":T" } if (!scope.toMap().keys.contains(keyName)) { throw CodegenException( "Rust block template expected `$keyName` but was not present in template.\n hint: Template contains: ${ scope.map { it.first } }", """ Rust block template expected `$keyName` but was not present in template. Hint: Template contains: ${scope.map { "`${it.first}`" }} """.trimIndent(), ) } "#{${keyName.lowercase()}$templateType}" Loading
codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt +19 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import io.kotest.matchers.string.shouldContainOnlyOnce import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.SetShape import software.amazon.smithy.model.shapes.StringShape Loading Loading @@ -161,6 +163,23 @@ class RustWriterTest { sut.toString().shouldContain("inner: hello, regular: http::foo") } @Test fun `missing template parameters are enclosed in backticks in the exception message`() { val sut = RustWriter.forModule("lib") val exception = assertThrows<CodegenException> { sut.rustTemplate( "#{Foo} #{Bar}", "Foo Bar" to CargoDependency.Http.toType().resolve("foo"), "Baz" to CargoDependency.Http.toType().resolve("foo"), ) } exception.message shouldBe """ Rust block template expected `Foo` but was not present in template. Hint: Template contains: [`Foo Bar`, `Baz`] """.trimIndent() } @Test fun `can handle file paths properly when determining module`() { val sut = RustWriter.forModule("src/module_name") Loading