Skip to content

Commit 4cb42eb

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 e0bea9e commit 4cb42eb

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,81 @@
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[codec] object GeoJsonTestData {
11+
12+
sealed trait GeoJSON
13+
object GeoJSON {
14+
/** Intermediate sealed trait — leaves of this are at hierarchy level 2. */
15+
sealed trait Geometry extends GeoJSON
16+
object Geometry {
17+
final case class Point(coordinates: (Double, Double)) extends Geometry
18+
final case class MultiPoint(coordinates: List[(Double, Double)]) extends Geometry
19+
final case class LineString(coordinates: List[(Double, Double)]) extends Geometry
20+
final case class MultiLineString(coordinates: List[List[(Double, Double)]]) extends Geometry
21+
final case class Polygon(coordinates: List[List[(Double, Double)]]) extends Geometry
22+
final case class MultiPolygon(coordinates: List[List[List[(Double, Double)]]]) extends Geometry
23+
final case class GeometryCollection(geometries: List[Geometry]) extends Geometry
24+
25+
implicit lazy val schema: Schema[Geometry] = DeriveSchema.gen[Geometry]
26+
}
27+
28+
/** Direct leaves of GeoJSON — hierarchy level 1. */
29+
final case class Feature(
30+
geometry: Option[Geometry],
31+
properties: Map[String, String],
32+
bbox: Option[(Double, Double, Double, Double)]
33+
) extends GeoJSON
34+
35+
final case class FeatureCollection(
36+
features: List[Feature],
37+
bbox: Option[(Double, Double, Double, Double)]
38+
) extends GeoJSON
39+
40+
implicit lazy val schema: Schema[GeoJSON] = DeriveSchema.gen[GeoJSON]
41+
}
42+
43+
import GeoJSON._
44+
import GeoJSON.Geometry._
45+
46+
val allCases: List[GeoJSON] = List(
47+
// level-2 leaves (geometry subtypes — exercises hierarchical enum decoding)
48+
Point((102.0, 0.5)),
49+
MultiPoint(List((0.0, 0.0), (1.0, 1.0))),
50+
LineString(List((102.0, 0.0), (103.0, 1.0), (104.0, 0.0))),
51+
MultiLineString(List(List((0.0, 0.0), (1.0, 1.0)), List((2.0, 2.0), (3.0, 3.0)))),
52+
Polygon(List(List((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)))),
53+
MultiPolygon(
54+
List(List(List((102.0, 2.0), (103.0, 2.0), (103.0, 3.0), (102.0, 3.0), (102.0, 2.0))))
55+
),
56+
GeometryCollection(List(Point((100.0, 0.0)), LineString(List((101.0, 0.0), (102.0, 1.0))))),
57+
// level-1 leaves that wrap level-2 geometry
58+
Feature(Some(Point((102.0, 0.5))), Map("prop0" -> "value0"), None),
59+
Feature(
60+
Some(LineString(List((102.0, 0.0), (103.0, 1.0)))),
61+
Map("prop0" -> "value0", "prop1" -> "0.0"),
62+
Some((100.0, 0.0, 105.0, 1.0))
63+
),
64+
Feature(None, Map.empty, None),
65+
FeatureCollection(
66+
List(
67+
Feature(
68+
Some(MultiPolygon(List(List(List((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)))))),
69+
Map.empty,
70+
None
71+
)
72+
),
73+
None
74+
),
75+
FeatureCollection(List.empty, Some((-180.0, -90.0, 180.0, 90.0)))
76+
)
77+
}
78+
379
import java.time.{ ZoneId, ZoneOffset }
480

581
import scala.collection.immutable.ListMap

0 commit comments

Comments
 (0)