Skip to content

Commit 66af2f2

Browse files
committed
Address review feedback: Fix style issue: It requires formatting and passing CI checks.
The `constructEnumCase` should be moved to outer sc; Fix logic error: You made non-needed changes by replacing `toArray` in other plac
1 parent 5e9bd3f commit 66af2f2

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,82 @@
11
package zio.schema.codec
22

3+
// ---------------------------------------------------------------------------
4+
// GeoJSON-inspired ADT used by the hierarchical-enum tests below.
5+
// Leaf classes exist at BOTH level-1 (Feature, FeatureCollection) and
6+
// level-2 (Point, MultiPoint, …, GeometryCollection under Geometry).
7+
// Coordinates use proper data types — not bare case-objects — so the ADT
8+
// exercises non-trivial multi-level sealed-trait JSON round-trips.
9+
// ---------------------------------------------------------------------------
10+
private object GeoJsonTestData {
11+
12+
sealed trait GeoJSON
13+
object GeoJSON {
14+
15+
/** Intermediate sealed trait — leaves of this are at hierarchy level 2. */
16+
sealed trait Geometry extends GeoJSON
17+
object Geometry {
18+
final case class Point(coordinates: (Double, Double)) extends Geometry
19+
final case class MultiPoint(coordinates: List[(Double, Double)]) extends Geometry
20+
final case class LineString(coordinates: List[(Double, Double)]) extends Geometry
21+
final case class MultiLineString(coordinates: List[List[(Double, Double)]]) extends Geometry
22+
final case class Polygon(coordinates: List[List[(Double, Double)]]) extends Geometry
23+
final case class MultiPolygon(coordinates: List[List[List[(Double, Double)]]]) extends Geometry
24+
final case class GeometryCollection(geometries: List[Geometry]) extends Geometry
25+
26+
implicit lazy val schema: Schema[Geometry] = DeriveSchema.gen[Geometry]
27+
}
28+
29+
/** Direct leaves of GeoJSON — hierarchy level 1. */
30+
final case class Feature(
31+
geometry: Option[Geometry],
32+
properties: Option[Map[String, String]],
33+
bbox: Option[(Double, Double, Double, Double)]
34+
) extends GeoJSON
35+
36+
final case class FeatureCollection(
37+
features: List[Feature],
38+
bbox: Option[(Double, Double, Double, Double)]
39+
) extends GeoJSON
40+
41+
implicit lazy val schema: Schema[GeoJSON] = DeriveSchema.gen[GeoJSON]
42+
}
43+
44+
import GeoJSON._
45+
import GeoJSON.Geometry._
46+
47+
val allCases: List[GeoJSON] = List(
48+
// level-2 leaves (geometry subtypes — exercises hierarchical enum decoding)
49+
Point((102.0, 0.5)),
50+
MultiPoint(List((0.0, 0.0), (1.0, 1.0))),
51+
LineString(List((102.0, 0.0), (103.0, 1.0), (104.0, 0.0))),
52+
MultiLineString(List(List((0.0, 0.0), (1.0, 1.0)), List((2.0, 2.0), (3.0, 3.0)))),
53+
Polygon(List(List((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)))),
54+
MultiPolygon(
55+
List(List(List((102.0, 2.0), (103.0, 2.0), (103.0, 3.0), (102.0, 3.0), (102.0, 2.0))))
56+
),
57+
GeometryCollection(List(Point((100.0, 0.0)), LineString(List((101.0, 0.0), (102.0, 1.0))))),
58+
// level-1 leaves that wrap level-2 geometry
59+
Feature(Some(Point((102.0, 0.5))), Some(Map("prop0" -> "value0")), None),
60+
Feature(
61+
Some(LineString(List((102.0, 0.0), (103.0, 1.0)))),
62+
Some(Map("prop0" -> "value0", "prop1" -> "0.0")),
63+
Some((100.0, 0.0, 105.0, 1.0))
64+
),
65+
Feature(None, None, None),
66+
FeatureCollection(
67+
List(
68+
Feature(
69+
Some(MultiPolygon(List(List(List((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)))))),
70+
None,
71+
None
72+
)
73+
),
74+
None
75+
),
76+
FeatureCollection(List.empty, Some((-180.0, -90.0, 180.0, 90.0)))
77+
)
78+
}
79+
380
import java.time.{ ZoneId, ZoneOffset }
481

582
import scala.collection.immutable.ListMap

0 commit comments

Comments
 (0)