Unverified Commit b27ce8b7 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Fix escaping bug (#19)

parent 9707c034
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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\""
+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\"}""""
    }
}