-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: scala 3 default value from fields (#626)
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
zio-schema-json/shared/src/test/scala-3/zio/schema/codec/DefaultValueSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package zio.schema.codec | ||
|
||
import zio.Console._ | ||
import zio._ | ||
import zio.json.{ DeriveJsonEncoder, JsonEncoder } | ||
import zio.schema._ | ||
import zio.test.Assertion._ | ||
import zio.test.TestAspect._ | ||
import zio.test.* | ||
|
||
object DefaultValueSpec extends ZIOSpecDefault { | ||
|
||
def spec: Spec[TestEnvironment, Any] = | ||
suite("Custom Spec")( | ||
customSuite, | ||
) @@ timeout(90.seconds) | ||
|
||
private val customSuite = suite("custom")( | ||
suite("default value schema")( | ||
test("default value at last field") { | ||
val result = JsonCodec.jsonDecoder(Schema[WithDefaultValue]).decodeJson("""{"orderId": 1}""") | ||
assertTrue(result.isRight) | ||
} | ||
) | ||
) | ||
|
||
case class WithDefaultValue(orderId:Int, description: String = "desc") | ||
|
||
object WithDefaultValue { | ||
implicit lazy val schema: Schema[WithDefaultValue] = DeriveSchema.gen[WithDefaultValue] | ||
} | ||
|
||
} |