-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Greg Zoller
committed
Mar 28, 2024
1 parent
b140b52
commit db8a60d
Showing
15 changed files
with
854 additions
and
516 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
486 changes: 345 additions & 141 deletions
486
src/main/scala/co.blocke.scalajack/json/JsonCodecMaker.scala
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
59 changes: 59 additions & 0 deletions
59
src/test/scala/co.blocke.scalajack/json/collections/TupleSpec.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,59 @@ | ||
package co.blocke.scalajack | ||
package json | ||
package collections | ||
|
||
import ScalaJack.* | ||
import co.blocke.scala_reflection.* | ||
import org.scalatest.funspec.AnyFunSpec | ||
import org.scalatest.matchers.should.Matchers.* | ||
import org.scalatest.* | ||
import TestUtil.* | ||
|
||
import java.util.UUID | ||
|
||
class TupleSpec() extends AnyFunSpec with JsonMatchers: | ||
|
||
describe(colorString("-------------------------------\n: Tuple Tests :\n-------------------------------", Console.YELLOW)) { | ||
describe(colorString("+++ Positive Tests +++")) { | ||
it("Tuple is null must work") { | ||
val inst = TupleHolder[Int, String, Boolean](null) | ||
val sj = sjCodecOf[TupleHolder[Int, String, Boolean]] | ||
val js = sj.toJson(inst) | ||
js should matchJson("""{"a":null}""") | ||
sj.fromJson(js) shouldEqual inst | ||
} | ||
it("Tuple of simple types must work") { | ||
val inst = TupleHolder[Int, String, Boolean]((15, "wow", true)) | ||
val sj = sjCodecOf[TupleHolder[Int, String, Boolean]] | ||
val js = sj.toJson(inst) | ||
js should matchJson("""{"a":[15,"wow",true]}""") | ||
sj.fromJson(js) shouldEqual inst | ||
} | ||
// it("Tuple of collecitons (including another tuple) must work") { | ||
// val inst = TupleHolder[Seq[Int], Map[String, Long], (Double, Char, Boolean)]((List(1, 2), Map("a" -> 3L, "b" -> 4L), (1.23d, 'X', true))) | ||
// val js = sjCodecOf[TupleHolder[Seq[Int], Map[String, Long], (Double, Char, Boolean)]].toJson(inst) | ||
// js should matchJson("""{"a":[[1,2],{"a":3,"b":4},[1.23,"X",true]]}""") | ||
// } | ||
} | ||
|
||
describe(colorString("--- Negative Tests ---")) { | ||
it("Wrong number of elements in a tuple") { | ||
val js = """{"a":[15,"wow",true,12.34]}""" | ||
val msg = | ||
"""Expected ']' here at position [19] | ||
|{"a":[15,"wow",true,12.34]} | ||
|-------------------^""".stripMargin | ||
val ex = intercept[JsonParseError](sjCodecOf[TupleHolder[Int, String, Boolean]].fromJson(js)) | ||
ex.show shouldEqual msg | ||
} | ||
it("Wrong type of elements in tuple") { | ||
val js = """{"a":[15,true,true]}""" | ||
val msg = | ||
"""Expected a String value but got 't' at position [9] | ||
|{"a":[15,true,true]} | ||
|---------^""".stripMargin | ||
val ex = intercept[JsonParseError](sjCodecOf[TupleHolder[Int, String, Boolean]].fromJson(js)) | ||
ex.show shouldEqual msg | ||
} | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
src/test/scala/co.blocke.scalajack/json/collections/TupleSpec.scalax
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
src/test/scala/co.blocke.scalajack/json/misc/EnumSpec.scalax
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,54 @@ | ||
TBD | ||
|
||
Test: | ||
|
||
* Enumeration | ||
* Enum | ||
* Java Enumeration | ||
* Sealed trait w/case object | ||
* Sealed trait w/case classes | ||
|
||
* Try permutations of Map having keys of each of the above types, including ordinal (int) values where available | ||
|
||
|
||
Partial: | ||
|
||
|
||
it("Enum as Map key and value must work") { | ||
val inst = MapHolder[Color, Color](Map(Color.Red -> Color.Blue, Color.Green -> Color.Red)) | ||
val js = sj[MapHolder[Color, Color]].toJson(inst) | ||
js should matchJson("""{"a":{"Red":"Blue","Green":"Red"}}""") | ||
} | ||
it("Enum as Map key and value must work (using id)") { | ||
val inst = MapHolder[Color, Color](Map(Color.Red -> Color.Blue, Color.Green -> Color.Red)) | ||
val js = sj[MapHolder[Color, Color]](JsonConfig.withEnumsAsIds(Some(Nil))).toJson(inst) | ||
js should matchJson("""{"a":{"0":2,"1":0}}""") | ||
} | ||
it("Enumeration as Map key and value must work") { | ||
import Permissions.* | ||
val inst = MapHolder[Permissions, Permissions](Map(Permissions.READ -> Permissions.WRITE, Permissions.EXEC -> Permissions.NONE)) | ||
val js = sj[MapHolder[Permissions, Permissions]].toJson(inst) | ||
js should matchJson("""{"a":{"READ":"WRITE","EXEC":"NONE"}}""") | ||
} | ||
it("Enumeration as Map key and value must work (using id)") { | ||
import Permissions.* | ||
val inst = MapHolder[Permissions, Permissions](Map(Permissions.READ -> Permissions.WRITE, Permissions.EXEC -> Permissions.NONE)) | ||
val js = sj[MapHolder[Permissions, Permissions]](JsonConfig.withEnumsAsIds(Some(Nil))).toJson(inst) | ||
js should matchJson("""{"a":{"0":1,"2":3}}""") | ||
} | ||
it("Java Enumeration as Map key and value must work") { | ||
val inst = MapHolder[CarEnum, CarEnum](Map(CarEnum.VW -> CarEnum.PORSCHE, CarEnum.PORSCHE -> CarEnum.TOYOTA)) | ||
val js = sj[MapHolder[CarEnum, CarEnum]].toJson(inst) | ||
js should matchJson("""{"a":{"VW":"PORSCHE","PORSCHE":"TOYOTA"}}""") | ||
} | ||
it("Java Enumeration as Map key and value must work (using id)") { | ||
val inst = MapHolder[CarEnum, CarEnum](Map(CarEnum.VW -> CarEnum.PORSCHE, CarEnum.PORSCHE -> CarEnum.TOYOTA)) | ||
val js = sj[MapHolder[CarEnum, CarEnum]](JsonConfig.withEnumsAsIds(Some(Nil))).toJson(inst) | ||
js should matchJson("""{"a":{"1":2,"2":0}}""") | ||
} | ||
it("Enum/Enumeration mix of enum as value must work") { | ||
import Permissions.* | ||
val inst = MapHolder[Color, Permissions](Map(Color.Red -> Permissions.WRITE, Color.Blue -> Permissions.NONE)) | ||
val js = sj[MapHolder[Color, Permissions]](JsonConfig.withEnumsAsIds(Some(List("co.blocke.scalajack.json.collections.Color")))).toJson(inst) | ||
js should matchJson("""{"a":{"0":"WRITE","2":"NONE"}}""") | ||
} |
Oops, something went wrong.