Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/util/Strings.kt +2 −2 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ package software.amazon.smithy.rust.codegen.util fun String.doubleQuote(): String = "\"$this\"" fun String.singleQuote(): String = "\'$this\'" fun String.doubleQuote(): String = "\"${this.slashEscape('"')}\"" fun String.slashEscape(char: Char) = this.replace(char.toString(), """\$char""") /** * Double quote a string, eg. "abc" -> "\"abc\"" Loading codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/util/StringsTest.kt 0 → 100644 +13 −0 Original line number Diff line number Diff line package software.amazon.smithy.rust.codegen.util import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test internal class StringsTest { @Test fun doubleQuote() { "abc".doubleQuote() shouldBe "\"abc\"" """{"some": "json"}""".doubleQuote() shouldBe """"{\"some\": \"json\"}"""" } } Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/util/Strings.kt +2 −2 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ package software.amazon.smithy.rust.codegen.util fun String.doubleQuote(): String = "\"$this\"" fun String.singleQuote(): String = "\'$this\'" fun String.doubleQuote(): String = "\"${this.slashEscape('"')}\"" fun String.slashEscape(char: Char) = this.replace(char.toString(), """\$char""") /** * Double quote a string, eg. "abc" -> "\"abc\"" Loading
codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/util/StringsTest.kt 0 → 100644 +13 −0 Original line number Diff line number Diff line package software.amazon.smithy.rust.codegen.util import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test internal class StringsTest { @Test fun doubleQuote() { "abc".doubleQuote() shouldBe "\"abc\"" """{"some": "json"}""".doubleQuote() shouldBe """"{\"some\": \"json\"}"""" } }