Skip to content

Commit a9b7640

Browse files
committed
Consolidate test helpers
1 parent c592301 commit a9b7640

50 files changed

Lines changed: 1208 additions & 1332 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Add `NewEnvelopeXY` constructor for building an `Envelope` from variadic x/y
6+
coordinate pairs, following the existing `New*XY` constructor pattern.
7+
58
## v0.58.0
69

710
2026-02-15

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# CLAUDE.md
2+
3+
Update CHANGELOG.md whenever making a change visible to users of this module.

geom/accessor_test.go

Lines changed: 95 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -4,170 +4,175 @@ import (
44
"testing"
55

66
"github.com/peterstace/simplefeatures/geom"
7+
"github.com/peterstace/simplefeatures/internal/test"
78
)
89

910
func TestPointAccessorNonEmpty(t *testing.T) {
10-
xy, ok := geomFromWKT(t, "POINT(1 2)").MustAsPoint().XY()
11-
expectBoolEq(t, ok, true)
12-
expectXYEq(t, xy, geom.XY{1, 2})
11+
xy, ok := test.FromWKT(t, "POINT(1 2)").MustAsPoint().XY()
12+
test.Eq(t, ok, true)
13+
test.Eq(t, xy, geom.XY{1, 2})
1314
}
1415

1516
func TestPointAccessorEmpty(t *testing.T) {
16-
_, ok := geomFromWKT(t, "POINT EMPTY").MustAsPoint().XY()
17-
expectBoolEq(t, ok, false)
17+
_, ok := test.FromWKT(t, "POINT EMPTY").MustAsPoint().XY()
18+
test.Eq(t, ok, false)
19+
}
20+
21+
func xyCoords(x, y float64) geom.Coordinates {
22+
return geom.Coordinates{XY: geom.XY{x, y}, Type: geom.DimXY}
1823
}
1924

2025
func TestLineStringAccessor(t *testing.T) {
21-
ls := geomFromWKT(t, "LINESTRING(1 2,3 4,5 6)").MustAsLineString()
26+
ls := test.FromWKT(t, "LINESTRING(1 2,3 4,5 6)").MustAsLineString()
2227
seq := ls.Coordinates()
2328
pt12 := xyCoords(1, 2)
2429
pt34 := xyCoords(3, 4)
2530
pt56 := xyCoords(5, 6)
2631

2732
t.Run("start", func(t *testing.T) {
2833
want := geom.NewPoint(pt12)
29-
expectGeomEq(t, ls.StartPoint().AsGeometry(), want.AsGeometry())
34+
test.ExactEquals(t, ls.StartPoint().AsGeometry(), want.AsGeometry())
3035
})
3136
t.Run("end", func(t *testing.T) {
3237
want := geom.NewPoint(pt56)
33-
expectGeomEq(t, ls.EndPoint().AsGeometry(), want.AsGeometry())
38+
test.ExactEquals(t, ls.EndPoint().AsGeometry(), want.AsGeometry())
3439
})
3540
t.Run("num points", func(t *testing.T) {
36-
expectIntEq(t, seq.Length(), 3)
41+
test.Eq(t, seq.Length(), 3)
3742
})
3843
t.Run("point n", func(t *testing.T) {
39-
expectPanics(t, func() { seq.Get(-1) })
40-
expectCoordsEq(t, seq.Get(0), pt12)
41-
expectCoordsEq(t, seq.Get(1), pt34)
42-
expectCoordsEq(t, seq.Get(2), pt56)
43-
expectPanics(t, func() { seq.Get(3) })
44+
test.Panics(t, func() { seq.Get(-1) })
45+
test.Eq(t, seq.Get(0), pt12)
46+
test.Eq(t, seq.Get(1), pt34)
47+
test.Eq(t, seq.Get(2), pt56)
48+
test.Panics(t, func() { seq.Get(3) })
4449
})
4550
}
4651

4752
func TestLineStringEmptyAccessor(t *testing.T) {
48-
ls := geomFromWKT(t, "LINESTRING EMPTY").MustAsLineString()
53+
ls := test.FromWKT(t, "LINESTRING EMPTY").MustAsLineString()
4954
seq := ls.Coordinates()
50-
emptyPoint := geomFromWKT(t, "POINT EMPTY")
55+
emptyPoint := test.FromWKT(t, "POINT EMPTY")
5156

5257
t.Run("start", func(t *testing.T) {
53-
expectGeomEq(t, ls.StartPoint().AsGeometry(), emptyPoint)
58+
test.ExactEquals(t, ls.StartPoint().AsGeometry(), emptyPoint)
5459
})
5560
t.Run("end", func(t *testing.T) {
56-
expectGeomEq(t, ls.EndPoint().AsGeometry(), emptyPoint)
61+
test.ExactEquals(t, ls.EndPoint().AsGeometry(), emptyPoint)
5762
})
5863
t.Run("num points", func(t *testing.T) {
59-
expectIntEq(t, seq.Length(), 0)
64+
test.Eq(t, seq.Length(), 0)
6065
})
6166
t.Run("point n", func(t *testing.T) {
62-
expectPanics(t, func() { seq.Get(-1) })
63-
expectPanics(t, func() { seq.Get(0) })
64-
expectPanics(t, func() { seq.Get(1) })
67+
test.Panics(t, func() { seq.Get(-1) })
68+
test.Panics(t, func() { seq.Get(0) })
69+
test.Panics(t, func() { seq.Get(1) })
6570
})
6671
}
6772

6873
func TestLineStringAccessorWithDuplicates(t *testing.T) {
69-
ls := geomFromWKT(t, "LINESTRING(1 2,3 4,3 4,5 6)").MustAsLineString()
74+
ls := test.FromWKT(t, "LINESTRING(1 2,3 4,3 4,5 6)").MustAsLineString()
7075
seq := ls.Coordinates()
7176
pt12 := xyCoords(1, 2)
7277
pt34 := xyCoords(3, 4)
7378
pt56 := xyCoords(5, 6)
7479

7580
t.Run("num points", func(t *testing.T) {
76-
expectIntEq(t, seq.Length(), 4)
81+
test.Eq(t, seq.Length(), 4)
7782
})
7883
t.Run("point n", func(t *testing.T) {
79-
expectPanics(t, func() { seq.Get(-1) })
80-
expectCoordsEq(t, seq.Get(0), pt12)
81-
expectCoordsEq(t, seq.Get(1), pt34)
82-
expectCoordsEq(t, seq.Get(2), pt34)
83-
expectCoordsEq(t, seq.Get(3), pt56)
84-
expectPanics(t, func() { seq.Get(4) })
84+
test.Panics(t, func() { seq.Get(-1) })
85+
test.Eq(t, seq.Get(0), pt12)
86+
test.Eq(t, seq.Get(1), pt34)
87+
test.Eq(t, seq.Get(2), pt34)
88+
test.Eq(t, seq.Get(3), pt56)
89+
test.Panics(t, func() { seq.Get(4) })
8590
})
8691
}
8792

8893
func TestLineStringAccessorWithMoreDuplicates(t *testing.T) {
89-
ls := geomFromWKT(t, "LINESTRING(1 2,1 2,3 4,3 4,3 4,5 6,5 6)").MustAsLineString()
94+
ls := test.FromWKT(t, "LINESTRING(1 2,1 2,3 4,3 4,3 4,5 6,5 6)").MustAsLineString()
9095
seq := ls.Coordinates()
9196
pt12 := xyCoords(1, 2)
9297
pt34 := xyCoords(3, 4)
9398
pt56 := xyCoords(5, 6)
9499

95100
t.Run("num points", func(t *testing.T) {
96-
expectIntEq(t, seq.Length(), 7)
101+
test.Eq(t, seq.Length(), 7)
97102
})
98103
t.Run("point n", func(t *testing.T) {
99-
expectPanics(t, func() { seq.Get(-1) })
100-
expectCoordsEq(t, seq.Get(0), pt12)
101-
expectCoordsEq(t, seq.Get(1), pt12)
102-
expectCoordsEq(t, seq.Get(2), pt34)
103-
expectCoordsEq(t, seq.Get(3), pt34)
104-
expectCoordsEq(t, seq.Get(4), pt34)
105-
expectCoordsEq(t, seq.Get(5), pt56)
106-
expectCoordsEq(t, seq.Get(6), pt56)
107-
expectPanics(t, func() { seq.Get(7) })
104+
test.Panics(t, func() { seq.Get(-1) })
105+
test.Eq(t, seq.Get(0), pt12)
106+
test.Eq(t, seq.Get(1), pt12)
107+
test.Eq(t, seq.Get(2), pt34)
108+
test.Eq(t, seq.Get(3), pt34)
109+
test.Eq(t, seq.Get(4), pt34)
110+
test.Eq(t, seq.Get(5), pt56)
111+
test.Eq(t, seq.Get(6), pt56)
112+
test.Panics(t, func() { seq.Get(7) })
108113
})
109114
}
110115

111116
func TestPolygonAccessor(t *testing.T) {
112-
poly := geomFromWKT(t, "POLYGON((0 0,5 0,5 3,0 3,0 0),(1 1,2 1,2 2,1 2,1 1),(3 1,4 1,4 2,3 2,3 1))").MustAsPolygon()
113-
outer := geomFromWKT(t, "LINESTRING(0 0,5 0,5 3,0 3,0 0)")
114-
inner0 := geomFromWKT(t, "LINESTRING(1 1,2 1,2 2,1 2,1 1)")
115-
inner1 := geomFromWKT(t, "LINESTRING(3 1,4 1,4 2,3 2,3 1)")
116-
117-
expectGeomEq(t, poly.ExteriorRing().AsGeometry(), outer)
118-
expectIntEq(t, poly.NumInteriorRings(), 2)
119-
expectPanics(t, func() { poly.InteriorRingN(-1) })
120-
expectGeomEq(t, poly.InteriorRingN(0).AsGeometry(), inner0)
121-
expectGeomEq(t, poly.InteriorRingN(1).AsGeometry(), inner1)
122-
expectPanics(t, func() { poly.InteriorRingN(2) })
117+
poly := test.FromWKT(t, "POLYGON((0 0,5 0,5 3,0 3,0 0),(1 1,2 1,2 2,1 2,1 1),(3 1,4 1,4 2,3 2,3 1))").MustAsPolygon()
118+
outer := test.FromWKT(t, "LINESTRING(0 0,5 0,5 3,0 3,0 0)")
119+
inner0 := test.FromWKT(t, "LINESTRING(1 1,2 1,2 2,1 2,1 1)")
120+
inner1 := test.FromWKT(t, "LINESTRING(3 1,4 1,4 2,3 2,3 1)")
121+
122+
test.ExactEquals(t, poly.ExteriorRing().AsGeometry(), outer)
123+
test.Eq(t, poly.NumInteriorRings(), 2)
124+
test.Panics(t, func() { poly.InteriorRingN(-1) })
125+
test.ExactEquals(t, poly.InteriorRingN(0).AsGeometry(), inner0)
126+
test.ExactEquals(t, poly.InteriorRingN(1).AsGeometry(), inner1)
127+
test.Panics(t, func() { poly.InteriorRingN(2) })
123128
}
124129

125130
func TestMultiPointAccessor(t *testing.T) {
126-
mp := geomFromWKT(t, "MULTIPOINT((4 5),(2 3),(8 7))").MustAsMultiPoint()
127-
pt0 := geomFromWKT(t, "POINT(4 5)")
128-
pt1 := geomFromWKT(t, "POINT(2 3)")
129-
pt2 := geomFromWKT(t, "POINT(8 7)")
130-
131-
expectIntEq(t, mp.NumPoints(), 3)
132-
expectPanics(t, func() { mp.PointN(-1) })
133-
expectGeomEq(t, mp.PointN(0).AsGeometry(), pt0)
134-
expectGeomEq(t, mp.PointN(1).AsGeometry(), pt1)
135-
expectGeomEq(t, mp.PointN(2).AsGeometry(), pt2)
136-
expectPanics(t, func() { mp.PointN(3) })
131+
mp := test.FromWKT(t, "MULTIPOINT((4 5),(2 3),(8 7))").MustAsMultiPoint()
132+
pt0 := test.FromWKT(t, "POINT(4 5)")
133+
pt1 := test.FromWKT(t, "POINT(2 3)")
134+
pt2 := test.FromWKT(t, "POINT(8 7)")
135+
136+
test.Eq(t, mp.NumPoints(), 3)
137+
test.Panics(t, func() { mp.PointN(-1) })
138+
test.ExactEquals(t, mp.PointN(0).AsGeometry(), pt0)
139+
test.ExactEquals(t, mp.PointN(1).AsGeometry(), pt1)
140+
test.ExactEquals(t, mp.PointN(2).AsGeometry(), pt2)
141+
test.Panics(t, func() { mp.PointN(3) })
137142
}
138143

139144
func TestMultiLineStringAccessors(t *testing.T) {
140-
mls := geomFromWKT(t, "MULTILINESTRING((1 2,3 4,5 6),(7 8,9 10,11 12))").MustAsMultiLineString()
141-
ls0 := geomFromWKT(t, "LINESTRING(1 2,3 4,5 6)")
142-
ls1 := geomFromWKT(t, "LINESTRING(7 8,9 10,11 12)")
143-
144-
expectIntEq(t, mls.NumLineStrings(), 2)
145-
expectPanics(t, func() { mls.LineStringN(-1) })
146-
expectGeomEq(t, mls.LineStringN(0).AsGeometry(), ls0)
147-
expectGeomEq(t, mls.LineStringN(1).AsGeometry(), ls1)
148-
expectPanics(t, func() { mls.LineStringN(2) })
145+
mls := test.FromWKT(t, "MULTILINESTRING((1 2,3 4,5 6),(7 8,9 10,11 12))").MustAsMultiLineString()
146+
ls0 := test.FromWKT(t, "LINESTRING(1 2,3 4,5 6)")
147+
ls1 := test.FromWKT(t, "LINESTRING(7 8,9 10,11 12)")
148+
149+
test.Eq(t, mls.NumLineStrings(), 2)
150+
test.Panics(t, func() { mls.LineStringN(-1) })
151+
test.ExactEquals(t, mls.LineStringN(0).AsGeometry(), ls0)
152+
test.ExactEquals(t, mls.LineStringN(1).AsGeometry(), ls1)
153+
test.Panics(t, func() { mls.LineStringN(2) })
149154
}
150155

151156
func TestMultiPolygonAccessors(t *testing.T) {
152-
polys := geomFromWKT(t, "MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((2 0,2 1,3 0,2 0)))").MustAsMultiPolygon()
153-
poly0 := geomFromWKT(t, "POLYGON((0 0,0 1,1 0,0 0))")
154-
poly1 := geomFromWKT(t, "POLYGON((2 0,2 1,3 0,2 0))")
155-
156-
expectIntEq(t, polys.NumPolygons(), 2)
157-
expectPanics(t, func() { polys.PolygonN(-1) })
158-
expectGeomEq(t, polys.PolygonN(0).AsGeometry(), poly0)
159-
expectGeomEq(t, polys.PolygonN(1).AsGeometry(), poly1)
160-
expectPanics(t, func() { polys.PolygonN(2) })
157+
polys := test.FromWKT(t, "MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((2 0,2 1,3 0,2 0)))").MustAsMultiPolygon()
158+
poly0 := test.FromWKT(t, "POLYGON((0 0,0 1,1 0,0 0))")
159+
poly1 := test.FromWKT(t, "POLYGON((2 0,2 1,3 0,2 0))")
160+
161+
test.Eq(t, polys.NumPolygons(), 2)
162+
test.Panics(t, func() { polys.PolygonN(-1) })
163+
test.ExactEquals(t, polys.PolygonN(0).AsGeometry(), poly0)
164+
test.ExactEquals(t, polys.PolygonN(1).AsGeometry(), poly1)
165+
test.Panics(t, func() { polys.PolygonN(2) })
161166
}
162167

163168
func TestGeometryCollectionAccessors(t *testing.T) {
164-
geoms := geomFromWKT(t, "GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 0,0 0)),POLYGON((2 0,2 1,3 0,2 0)))").MustAsGeometryCollection()
165-
geom0 := geomFromWKT(t, "POLYGON((0 0,0 1,1 0,0 0))")
166-
geom1 := geomFromWKT(t, "POLYGON((2 0,2 1,3 0,2 0))")
167-
168-
expectIntEq(t, geoms.NumGeometries(), 2)
169-
expectPanics(t, func() { geoms.GeometryN(-1) })
170-
expectGeomEq(t, geoms.GeometryN(0), geom0)
171-
expectGeomEq(t, geoms.GeometryN(1), geom1)
172-
expectPanics(t, func() { geoms.GeometryN(2) })
169+
geoms := test.FromWKT(t, "GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 0,0 0)),POLYGON((2 0,2 1,3 0,2 0)))").MustAsGeometryCollection()
170+
geom0 := test.FromWKT(t, "POLYGON((0 0,0 1,1 0,0 0))")
171+
geom1 := test.FromWKT(t, "POLYGON((2 0,2 1,3 0,2 0))")
172+
173+
test.Eq(t, geoms.NumGeometries(), 2)
174+
test.Panics(t, func() { geoms.GeometryN(-1) })
175+
test.ExactEquals(t, geoms.GeometryN(0), geom0)
176+
test.ExactEquals(t, geoms.GeometryN(1), geom1)
177+
test.Panics(t, func() { geoms.GeometryN(2) })
173178
}

geom/alg_convex_hull_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/peterstace/simplefeatures/geom"
8+
"github.com/peterstace/simplefeatures/internal/test"
89
)
910

1011
func TestConvexHull(t *testing.T) {
@@ -199,8 +200,8 @@ func TestConvexHull(t *testing.T) {
199200
} {
200201
t.Run(strconv.Itoa(i), func(t *testing.T) {
201202
t.Logf("input: %s", tt.input)
202-
got := geomFromWKT(t, tt.input).ConvexHull()
203-
expectGeomEq(t, got, geomFromWKT(t, tt.output), geom.IgnoreOrder)
203+
got := test.FromWKT(t, tt.input).ConvexHull()
204+
test.ExactEquals(t, got, test.FromWKT(t, tt.output), geom.IgnoreOrder)
204205
})
205206
}
206207
}

geom/alg_densify_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/peterstace/simplefeatures/geom"
8+
"github.com/peterstace/simplefeatures/internal/test"
89
)
910

1011
func TestDensifyEmpty(t *testing.T) {
@@ -27,7 +28,7 @@ func TestDensifyEmpty(t *testing.T) {
2728
t.Run(ct.String(), func(t *testing.T) {
2829
input := empty.ForceCoordinatesType(ct)
2930
got := input.Densify(1.0)
30-
expectGeomEq(t, got, input)
31+
test.ExactEquals(t, got, input)
3132
})
3233
}
3334
})
@@ -67,9 +68,9 @@ func TestDensify(t *testing.T) {
6768
{"GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(0 0,1 1))", 1.0, "GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(0 0,0.5 0.5,1 1))"},
6869
} {
6970
t.Run(strconv.Itoa(i), func(t *testing.T) {
70-
input := geomFromWKT(t, tc.input)
71+
input := test.FromWKT(t, tc.input)
7172
got := input.Densify(tc.maxDist)
72-
expectGeomEqWKT(t, got, tc.want)
73+
test.ExactEqualsWKT(t, got, tc.want)
7374
})
7475
}
7576
}
@@ -87,8 +88,8 @@ func TestDensifyInvalidMaxDist(t *testing.T) {
8788
{"MULTIPOINT((0 0))", 0},
8889
} {
8990
t.Run(strconv.Itoa(i), func(t *testing.T) {
90-
input := geomFromWKT(t, tc.input)
91-
expectPanics(t, func() { input.Densify(tc.maxDist) })
91+
input := test.FromWKT(t, tc.input)
92+
test.Panics(t, func() { input.Densify(tc.maxDist) })
9293
})
9394
}
9495
}

geom/alg_distance_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/peterstace/simplefeatures/geom"
9+
"github.com/peterstace/simplefeatures/internal/test"
910
)
1011

1112
func TestDistance(t *testing.T) {
@@ -113,8 +114,8 @@ func TestDistance(t *testing.T) {
113114
desc = "rev"
114115
}
115116
t.Run(desc, func(t *testing.T) {
116-
g1 := geomFromWKT(t, tt.wkt1)
117-
g2 := geomFromWKT(t, tt.wkt2)
117+
g1 := test.FromWKT(t, tt.wkt1)
118+
g2 := test.FromWKT(t, tt.wkt2)
118119
if flip {
119120
g1, g2 = g2, g1
120121
}

0 commit comments

Comments
 (0)