Skip to content

Commit

Permalink
more tests for writer builder
Browse files Browse the repository at this point in the history
  • Loading branch information
goshacodes committed Aug 28, 2024
1 parent dca38a2 commit eb7fdfd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ trait JsonReaderDerivation:

inline def derived[A](inline config: ReaderBuilder[A])(using mirror: Mirror.ProductOf[A]): JsonReader[A] =
Derivation.deriveJsonReaderForProduct[A](config)


@deprecated("Use ReaderBuilder instead")
inline def derived[A](inline config: ReaderDerivationConfig)(using mirror: Mirror.ProductOf[A]): JsonReader[A] =
Derivation.deriveJsonReaderForProductLegacy[A](config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import tethys.writers.tokens.SimpleTokenWriter
class SemiautoWriterDerivationTest extends AnyFlatSpec with Matchers {

behavior of "semiauto derivation"
it should "generate proper writer from WriterDescription" in {
it should "generate proper writer from WriterBuilder" in {
def freeVariable: String = "e"
implicit val dWriter: JsonWriter[D] = jsonWriter[D](WriterBuilder[D].fieldStyle(FieldStyle.UpperCase))

Expand All @@ -37,6 +37,27 @@ class SemiautoWriterDerivationTest extends AnyFlatSpec with Matchers {
)
}

it should "generate proper writer from WriterDerivationConfig" in {
def freeVariable: String = "e"

implicit val dWriter: JsonWriter[D] = jsonWriter[D](
WriterDerivationConfig.withFieldStyle(tethys.derivation.builder.FieldStyle.uppercase)
)

implicit val testWriter: JsonWriter[JsonTreeTestData] = jsonWriter {
WriterDerivationConfig.withFieldStyle(FieldStyle.UpperCase)
}
JsonTreeTestData(5, b = false, C(D(1))).asTokenList shouldBe obj(
"A" -> 5,
"B" -> false,
"C" -> obj(
"d" -> obj(
"A" -> 1
)
)
)
}

it should "derive writer for update partial" in {
implicit val partialWriter: JsonWriter[D] = jsonWriter {
WriterBuilder[D]
Expand Down

0 comments on commit eb7fdfd

Please sign in to comment.