Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Sep 21, 2024
1 parent 9561ade commit 65ce5bc
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class IntEnumGenerator(
if (isNestedType) {
val service = model.expectShape<ServiceShape>(settings.service)
writer.openBlock("extension ${service.nestedNamespaceType(symbolProvider)} {", "}") {
writer.write("")
renderEnum()
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class StructureGenerator(
}

private fun generateStruct() {
writer.write("")
writer.writeShapeDocs(shape)
writer.writeAvailableAttribute(model, shape)
val equatableConformance = writer.format(", \$N", SwiftTypes.Protocols.Equatable).takeIf { shape.hasTrait<EquatableConformanceTrait>() } ?: ""
Expand All @@ -121,7 +122,6 @@ class StructureGenerator(
.write("")
.call { generateInitializerForStructure(false) }
.closeBlock("}")
.write("")
}

private fun generateStructMembers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class UnionGenerator(
if (isNestedType) {
val service = model.expectShape<ServiceShape>(settings.service)
writer.openBlock("extension ${service.nestedNamespaceType(symbolProvider)} {", "}") {
writer.write("")
renderUnion()
}
} else {
Expand All @@ -77,7 +78,7 @@ class UnionGenerator(
writer.writeAvailableAttribute(model, shape)
val indirectOrNot = "indirect ".takeIf { shape.hasTrait<RecursiveUnionTrait>() } ?: ""
val equatableConformance = writer.format(", \$N", SwiftTypes.Protocols.Equatable).takeIf { shape.hasTrait<EquatableConformanceTrait>() } ?: ""
writer.openBlock("public ${indirectOrNot}enum \$union.name:L: \$N$equatableConformance {", "}\n", SwiftTypes.Protocols.Sendable) {
writer.openBlock("public ${indirectOrNot}enum \$union.name:L: \$N$equatableConformance {", "}", SwiftTypes.Protocols.Sendable) {
// event streams (@streaming union) MAY have variants that target errors.
// These errors if encountered on the stream will be thrown as an exception rather
// than showing up as one of the possible events the consumer will see on the stream (AsyncThrowingStream<T>).
Expand Down
6 changes: 3 additions & 3 deletions smithy-swift-codegen/src/test/kotlin/EnumGeneratorTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EnumGeneratorTests {

val expectedGeneratedEnum = """
/// Really long multi-line Documentation for the enum
public enum MyEnum: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
public enum MyEnum: Swift.Sendable, Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
/// Documentation for BAR
case bar
case fooBazXap
Expand Down Expand Up @@ -98,7 +98,7 @@ public enum MyEnum: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable,

val expectedGeneratedEnum = """
/// Really long multi-line Documentation for the enum
public enum MyEnum: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
public enum MyEnum: Swift.Sendable, Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
/// ""${'"'} T2 instances are Burstable Performance Instances that provide a baseline level of CPU performance with the ability to burst above the baseline.""${'"'}
case t2Micro
case t2Nano
Expand Down Expand Up @@ -141,7 +141,7 @@ public enum MyEnum: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable,
var expectedGeneratedEnum = """
extension ExampleClientTypes {
public enum Suit: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
public enum Suit: Swift.Sendable, Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
case club
case diamond
case heart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IntEnumGeneratorTests {
.getFileString("Sources/example/models/Abcs.swift").get()
Assertions.assertNotNull(enumShape)
var expectedGeneratedEnum = """
public enum Abcs: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
public enum Abcs: Swift.Sendable, Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
case a
case b
case c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class PaginatorGeneratorTest {
// Equatable conformance must have been generated for struct nested inside a pagination token.
val contents = getFileContents(context.manifest, "Sources/Test/models/NestedInputTokenValue.swift")
val expected = """
public struct NestedInputTokenValue : Swift.Equatable {
public struct NestedInputTokenValue: Swift.Sendable, Swift.Equatable {
""".trimIndent()
contents.shouldContainOnlyOnce(expected)
}
Expand All @@ -158,7 +158,7 @@ class PaginatorGeneratorTest {
// Equatable conformance must have been generated for struct nested under pagination token.
val contents = getFileContents(context.manifest, "Sources/Test/models/DoublyNestedInputTokenValue.swift")
val expected = """
public struct DoublyNestedInputTokenValue : Swift.Equatable {
public struct DoublyNestedInputTokenValue: Swift.Sendable, Swift.Equatable {
""".trimIndent()
contents.shouldContainOnlyOnce(expected)
}
Expand All @@ -169,8 +169,8 @@ class PaginatorGeneratorTest {
// Equatable conformance must have been generated for union nested under pagination token.
val contents = getFileContents(context.manifest, "Sources/Test/models/InputPaginationUnion.swift")
val expected = """
public enum InputPaginationUnion : Swift.Equatable {
""".trimIndent()
public enum InputPaginationUnion: Swift.Sendable, Swift.Equatable {
"""
contents.shouldContainOnlyOnce(expected)
}

Expand Down
120 changes: 57 additions & 63 deletions smithy-swift-codegen/src/test/kotlin/RecursiveShapeBoxerTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,85 +48,79 @@ internal class RecursiveShapeBoxerTests {
val recursiveShapesInput = manifest
.getFileString("Sources/example/models/RecursiveShapesInput.swift").get()
Assertions.assertNotNull(recursiveShapesInput)
val expected =
"""
public struct RecursiveShapesInput {
public var nested: ExampleClientTypes.RecursiveShapesInputOutputNested1?
public init(
nested: ExampleClientTypes.RecursiveShapesInputOutputNested1? = nil
)
{
self.nested = nested
}
}
""".trimIndent()
val expected = """
public struct RecursiveShapesInput: Swift.Sendable {
public var nested: ExampleClientTypes.RecursiveShapesInputOutputNested1?
public init(
nested: ExampleClientTypes.RecursiveShapesInputOutputNested1? = nil
)
{
self.nested = nested
}
}
"""
recursiveShapesInput.shouldContain(expected)

val recursiveShapesOutput = manifest
.getFileString("Sources/example/models/RecursiveShapesOutput.swift").get()
Assertions.assertNotNull(recursiveShapesOutput)
val expected2 =
"""
public struct RecursiveShapesOutput {
public var nested: ExampleClientTypes.RecursiveShapesInputOutputNested1?
public init(
nested: ExampleClientTypes.RecursiveShapesInputOutputNested1? = nil
)
{
self.nested = nested
}
}
""".trimIndent()
val expected2 = """
public struct RecursiveShapesOutput: Swift.Sendable {
public var nested: ExampleClientTypes.RecursiveShapesInputOutputNested1?
public init(
nested: ExampleClientTypes.RecursiveShapesInputOutputNested1? = nil
)
{
self.nested = nested
}
}
"""
recursiveShapesOutput.shouldContain(expected2)

val recursiveShapesInputOutputNested1 = manifest
.getFileString("Sources/example/models/RecursiveShapesInputOutputNested1.swift").get()
Assertions.assertNotNull(recursiveShapesInputOutputNested1)
val expected3 =
"""
extension ExampleClientTypes {
public struct RecursiveShapesInputOutputNested1 {
public var foo: Swift.String?
@Indirect public var nested: ExampleClientTypes.RecursiveShapesInputOutputNested2?
public init(
foo: Swift.String? = nil,
nested: ExampleClientTypes.RecursiveShapesInputOutputNested2? = nil
)
{
self.foo = foo
self.nested = nested
}
}
}
""".trimIndent()
val expected3 = """
extension ExampleClientTypes {
public struct RecursiveShapesInputOutputNested1: Swift.Sendable {
public var foo: Swift.String?
@Indirect public var nested: ExampleClientTypes.RecursiveShapesInputOutputNested2?
public init(
foo: Swift.String? = nil,
nested: ExampleClientTypes.RecursiveShapesInputOutputNested2? = nil
)
{
self.foo = foo
self.nested = nested
}
}
}
"""
recursiveShapesInputOutputNested1.shouldContain(expected3)

val recursiveShapesInputOutputNested2 = manifest
.getFileString("Sources/example/models/RecursiveShapesInputOutputNested2.swift").get()
Assertions.assertNotNull(recursiveShapesInputOutputNested2)
val expected4 =
"""
extension ExampleClientTypes {
public struct RecursiveShapesInputOutputNested2 {
public var bar: Swift.String?
public var recursiveMember: ExampleClientTypes.RecursiveShapesInputOutputNested1?
public init(
bar: Swift.String? = nil,
recursiveMember: ExampleClientTypes.RecursiveShapesInputOutputNested1? = nil
)
{
self.bar = bar
self.recursiveMember = recursiveMember
}
}
val expected4 = """
public struct RecursiveShapesInputOutputNested2: Swift.Sendable {
public var bar: Swift.String?
public var recursiveMember: ExampleClientTypes.RecursiveShapesInputOutputNested1?
public init(
bar: Swift.String? = nil,
recursiveMember: ExampleClientTypes.RecursiveShapesInputOutputNested1? = nil
)
{
self.bar = bar
self.recursiveMember = recursiveMember
}
""".trimIndent()
}
}
"""
recursiveShapesInputOutputNested2.shouldContain(expected4)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ReservedWordsGeneratorTests {
val expectedContents = """
extension ExampleClientTypes {
public enum ReservedWordsEnum: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
public enum ReservedWordsEnum: Swift.Sendable, Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
case any
case `open`
case `self`
Expand Down Expand Up @@ -57,7 +57,7 @@ extension ExampleClientTypes {
val expectedContents = """
extension ExampleClientTypes {
public enum ModelType: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
public enum ModelType: Swift.Sendable, Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
case foo
case test
case sdkUnknown(Swift.String)
Expand Down Expand Up @@ -94,7 +94,7 @@ extension ExampleClientTypes {
val expectedContents = """
extension ExampleClientTypes {
public enum ModelProtocol: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
public enum ModelProtocol: Swift.Sendable, Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable, Swift.Hashable {
case bar
case foo
case sdkUnknown(Swift.String)
Expand Down
Loading

0 comments on commit 65ce5bc

Please sign in to comment.