Unverified Commit 08a533ff authored by 82marbag's avatar 82marbag Committed by GitHub
Browse files

RustType renders types with wrong syntax (#3090)



The correct syntax is `HashMap::<T, U>` instead of `HashMap<T, U>` and
so on.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Signed-off-by: default avatarDaniele Ahmed <ahmeddan@amazon.de>
parent 12bed905
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -55,8 +55,8 @@ class FluentClientGeneratorTest {
    fun `generate correct input docs`() {
        val expectations = mapOf(
            "listValue" to "list_value(impl Into<String>)",
            "doubleListValue" to "double_list_value(Vec<String>)",
            "mapValue" to "map_value(impl Into<String>, Vec<String>)",
            "doubleListValue" to "double_list_value(Vec::<String>)",
            "mapValue" to "map_value(impl Into<String>, Vec::<String>)",
            "byteValue" to "byte_value(i8)",
        )
        expectations.forEach { (name, expect) ->
+26 −26
Original line number Diff line number Diff line
@@ -67,10 +67,10 @@ sealed class RustType {
     * | RustType.Integer(32)                               | i32                                                                  |
     * | RustType.Integer(64)                               | i64                                                                  |
     * | RustType.String                                    | std::string::String                                                  |
     * | RustType.Vec(RustType.String)                      | std::vec::Vec<std::string::String>                                  |
     * | RustType.Vec(RustType.String)                      | std::vec::Vec::<std::string::String>                                 |
     * | RustType.Slice(RustType.String)                    | [std::string::String]                                                |
     * | RustType.HashMap(RustType.String, RustType.String) | std::collections::HashMap<std::string::String, std::string::String> |
     * | RustType.HashSet(RustType.String)                  | std::vec::Vec<std::string::String>                                  |
     * | RustType.HashMap(RustType.String, RustType.String) | std::collections::HashMap::<std::string::String, std::string::String>|
     * | RustType.HashSet(RustType.String)                  | std::vec::Vec::<std::string::String>                                 |
     * | RustType.Reference("&", RustType.String)           | &std::string::String                                                 |
     * | RustType.Reference("&mut", RustType.String)        | &mut std::string::String                                             |
     * | RustType.Reference("&'static", RustType.String)    | &'static std::string::String                                         |
@@ -244,10 +244,10 @@ fun RustType.render(fullyQualified: Boolean = true): String {
        is RustType.Float -> this.name
        is RustType.Integer -> this.name
        is RustType.String -> this.name
        is RustType.Vec -> "${this.name}<${this.member.render(fullyQualified)}>"
        is RustType.Vec -> "${this.name}::<${this.member.render(fullyQualified)}>"
        is RustType.Slice -> "[${this.member.render(fullyQualified)}]"
        is RustType.HashMap -> "${this.name}<${this.key.render(fullyQualified)}, ${this.member.render(fullyQualified)}>"
        is RustType.HashSet -> "${this.name}<${this.member.render(fullyQualified)}>"
        is RustType.HashMap -> "${this.name}::<${this.key.render(fullyQualified)}, ${this.member.render(fullyQualified)}>"
        is RustType.HashSet -> "${this.name}::<${this.member.render(fullyQualified)}>"
        is RustType.Reference -> {
            if (this.lifetime == "&") {
                "&${this.member.render(fullyQualified)}"
+5 −5
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ internal class RustTypesTest {
    fun `RustType_Vec_writable produces a template-compatible RuntimeType`() {
        forInputExpectOutput(
            RustType.Vec(RustType.String).writable,
            "'::std::vec::Vec<::std::string::String>'",
            "'::std::vec::Vec::<::std::string::String>'",
        )
    }

@@ -77,7 +77,7 @@ internal class RustTypesTest {
    fun `RustType_HashMap_writable produces a template-compatible RuntimeType`() {
        forInputExpectOutput(
            RustType.HashMap(RustType.String, RustType.String).writable,
            "'::std::collections::HashMap<::std::string::String, ::std::string::String>'",
            "'::std::collections::HashMap::<::std::string::String, ::std::string::String>'",
        )
    }

@@ -87,7 +87,7 @@ internal class RustTypesTest {
            RustType.HashSet(RustType.String).writable,
            // Rust doesn't guarantee that `HashSet`s are insertion ordered, so we use a `Vec` instead.
            // This is called out in a comment in the RustType.HashSet declaration
            "'::std::vec::Vec<::std::string::String>'",
            "'::std::vec::Vec::<::std::string::String>'",
        )
    }

@@ -146,8 +146,8 @@ internal class RustTypesTest {
    @Test
    fun `types render properly`() {
        val type = RustType.Box(RustType.Option(RustType.Reference("a", RustType.Vec(RustType.String))))
        type.render(false) shouldBe "Box<Option<&'a Vec<String>>>"
        type.render(true) shouldBe "::std::boxed::Box<::std::option::Option<&'a ::std::vec::Vec<::std::string::String>>>"
        type.render(false) shouldBe "Box<Option<&'a Vec::<String>>>"
        type.render(true) shouldBe "::std::boxed::Box<::std::option::Option<&'a ::std::vec::Vec::<::std::string::String>>>"
    }

    @Test
+3 −3
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ class SymbolVisitorTest {

        val provider: SymbolProvider = testSymbolProvider(model)
        val setSymbol = provider.toSymbol(set)
        setSymbol.rustType().render(false) shouldBe "${RustType.HashSet.Type}<String>"
        setSymbol.rustType().render(false) shouldBe "${RustType.HashSet.Type}::<String>"
        setSymbol.referenceClosure().map { it.name } shouldBe listOf(RustType.HashSet.Type, "String")
    }

@@ -172,7 +172,7 @@ class SymbolVisitorTest {

        val provider: SymbolProvider = testSymbolProvider(model)
        val setSymbol = provider.toSymbol(set)
        setSymbol.rustType().render(false) shouldBe "Vec<Record>"
        setSymbol.rustType().render(false) shouldBe "Vec::<Record>"
        setSymbol.referenceClosure().map { it.name } shouldBe listOf("Vec", "Record")
    }

@@ -193,7 +193,7 @@ class SymbolVisitorTest {

        val provider: SymbolProvider = testSymbolProvider(model)
        val setSymbol = provider.toSymbol(set)
        setSymbol.rustType().render(false) shouldBe "Vec<Option<Record>>"
        setSymbol.rustType().render(false) shouldBe "Vec::<Option<Record>>"
        setSymbol.referenceClosure().map { it.name } shouldBe listOf("Vec", "Option", "Record")
    }

+1 −1
Original line number Diff line number Diff line
@@ -98,6 +98,6 @@ class UnconstrainedShapeSymbolProviderTest {
        val structureBShape = model.lookup<StructureShape>("test#StructureB")

        unconstrainedShapeSymbolProvider.toSymbol(structureBShape).rustType().render() shouldBe "crate::model::StructureB"
        unconstrainedShapeSymbolProvider.toSymbol(listAShape).rustType().render() shouldBe "::std::vec::Vec<crate::model::StructureB>"
        unconstrainedShapeSymbolProvider.toSymbol(listAShape).rustType().render() shouldBe "::std::vec::Vec::<crate::model::StructureB>"
    }
}