Skip to content

Commit ae509e0

Browse files
authored
Adds test for recursive enum (#485)
1 parent 35d41e8 commit ae509e0

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

smithy-swift-codegen/src/test/kotlin/UnionGeneratorTests.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,45 @@ class UnionGeneratorTests {
9999
contents.shouldContain(expectedGeneratedEnum)
100100
}
101101

102+
@Test
103+
fun `it renders recursive union shape`() {
104+
val simpleUnionShapeBuilder = createUnionShapeBuilderWithMembers(
105+
MemberShape.builder().id("smithy.example#MyUnion\$foo").target("smithy.example#MyUnion").build(),
106+
MemberShape.builder().id("smithy.example#MyUnion\$baz").target("smithy.api#Integer").build(),
107+
MemberShape.builder().id("smithy.example#MyUnion\$bar")
108+
.target("smithy.api#PrimitiveInteger")
109+
.addTrait(DocumentationTrait("Documentation for bar"))
110+
.build()
111+
)
112+
val simpleUnionShape = simpleUnionShapeBuilder.build()
113+
val model = createModelFromShapes(simpleUnionShape)
114+
val settings = model.defaultSettings()
115+
val provider: SymbolProvider = SwiftCodegenPlugin.createSymbolProvider(model, settings)
116+
val writer = SwiftWriter("MockPackage")
117+
118+
val generator = UnionGenerator(model, provider, writer, simpleUnionShape, settings)
119+
generator.render()
120+
121+
val contents = writer.toString()
122+
123+
contents.shouldContain(SwiftWriter.staticHeader)
124+
125+
val expectedGeneratedEnum =
126+
"""
127+
/// Really long multi-line Documentation for MyUnion
128+
public indirect enum MyUnion: Swift.Equatable {
129+
/// Really long multi-line Documentation for MyUnion
130+
case foo(MyUnion)
131+
case baz(Swift.Int)
132+
/// Documentation for bar
133+
case bar(Swift.Int)
134+
case sdkUnknown(Swift.String)
135+
}
136+
""".trimIndent()
137+
138+
contents.shouldContain(expectedGeneratedEnum)
139+
}
140+
102141
private fun createUnionShapeBuilderWithMembers(vararg memberShapes: MemberShape): UnionShape.Builder {
103142
val unionShapeBuilder = UnionShape.builder()
104143
unionShapeBuilder.id("smithy.example#MyUnion").addTrait(

0 commit comments

Comments
 (0)