Skip to content

Commit

Permalink
Add more tests for scalaImports renderer
Browse files Browse the repository at this point in the history
This also fix union renderer issue
  • Loading branch information
lenguyenthanh committed May 30, 2024
1 parent 5873cc5 commit 91b4542
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,6 @@ private[internals] class Renderer(compilationUnit: CompilationUnit) { self =>
lines(
documentationAnnotation(alt.hints),
deprecationAnnotation(alt.hints),
renderScalaImports(alt.hints),
constructor
)
}
Expand Down Expand Up @@ -1100,6 +1099,7 @@ private[internals] class Renderer(compilationUnit: CompilationUnit) { self =>
lines(
documentationAnnotation(hints),
deprecationAnnotation(hints),
renderScalaImports(hints),
block(
line"sealed trait ${NameDef(name.name)} extends ${mixinExtendsStatement}scala.Product with scala.Serializable"
).withSameLineValue(line" self =>")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,10 @@ final class RendererSpec extends munit.ScalaCheckSuite {
}

test(
"generated code of a structure that is applied @scalaImports should contain imports"
"generated code of a shape that is applied @scalaImports should contain imports"
) {
val smithy =

val structure =
"""
|$version: "2.0"
|
Expand All @@ -511,12 +512,69 @@ final class RendererSpec extends munit.ScalaCheckSuite {
|}
|""".stripMargin

val contents = generateScalaCode(smithy).values
val service =
"""
|$version: "2.0"
|
|namespace smithy4s
|
|use smithy4s.meta#scalaImports
|
|apply smithy4s#MyService @scalaImports(
| ["smithy4s.providers._"]
|)
|
|
|service MyService {
| version: "1.0.0"
|}
|""".stripMargin

val union =
"""
|$version: "2.0"
|
|namespace smithy4s
|
|use smithy4s.meta#scalaImports
|
|apply smithy4s#MyUnion @scalaImports(
| ["smithy4s.providers._"]
|)
|
|union MyUnion {
| int: Integer,
| str: String
|}
|""".stripMargin

val myEnum =
"""
|$version: "2.0"
|
|namespace smithy4s
|
|use smithy4s.meta#scalaImports
|
|apply smithy4s#MyEnum @scalaImports(
| ["smithy4s.providers._"]
|)
|
|enum MyEnum {
| Right = "right"
| Left = "left"
|}
|""".stripMargin

List(structure, service, union, myEnum).foreach { smithy =>
val contents = generateScalaCode(smithy).values

assert(
contents.exists(_.contains("import smithy4s.providers._")),
"generated code should contain imports"
)
}

assert(
contents.exists(_.contains("import smithy4s.providers._")),
"generated code should contain imports"
)
}

property("enumeration order is preserved") {
Expand Down

0 comments on commit 91b4542

Please sign in to comment.