Skip to content

Commit

Permalink
Switch to github.com/alecthomas/assert/v2 for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Oct 30, 2023
1 parent 0fdefcc commit e843850
Show file tree
Hide file tree
Showing 27 changed files with 216 additions and 211 deletions.
6 changes: 3 additions & 3 deletions bigxy/big_cga_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"testing"

"github.com/stretchr/testify/require"
"github.com/alecthomas/assert/v2"

"github.com/twpayne/go-geom"
"github.com/twpayne/go-geom/bigxy"
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestOrientationIndex(t *testing.T) {
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
orientationIndex := bigxy.OrientationIndex(testData.vectorOrigin, testData.vectorEnd, testData.point)
require.Equal(t, testData.result, orientationIndex)
assert.Equal(t, testData.result, orientationIndex)
})
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestIntersection(t *testing.T) {
} {
t.Run(tc.desc, func(t *testing.T) {
calculatedIntersection := bigxy.Intersection(tc.line1Start, tc.line1End, tc.line2Start, tc.line2End)
require.Equal(t, tc.result, calculatedIntersection)
assert.Equal(t, tc.result, calculatedIntersection)
})
}
}
2 changes: 1 addition & 1 deletion bounds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strconv"
"testing"

"github.com/stretchr/testify/assert"
"github.com/alecthomas/assert/v2"
)

func TestBoundsExtend(t *testing.T) {
Expand Down
74 changes: 37 additions & 37 deletions encoding/ewkb/ewkb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
"github.com/alecthomas/assert/v2"

"github.com/twpayne/go-geom"
"github.com/twpayne/go-geom/internal/geomtest"
Expand All @@ -16,29 +16,29 @@ func test(t *testing.T, g geom.T, xdr, ndr []byte) {
t.Run("xdr", func(t *testing.T) {
t.Run("unmarshal", func(t *testing.T) {
got, err := Unmarshal(xdr)
require.NoError(t, err)
require.Equal(t, g, got)
assert.NoError(t, err)
assert.Equal(t, g, got)
})

t.Run("marshal", func(t *testing.T) {
got, err := Marshal(g, XDR)
require.NoError(t, err)
require.Equal(t, xdr, got)
assert.NoError(t, err)
assert.Equal(t, xdr, got)
})
})
}
if ndr != nil {
t.Run("ndr", func(t *testing.T) {
t.Run("unmarshal", func(t *testing.T) {
got, err := Unmarshal(ndr)
require.NoError(t, err)
require.Equal(t, g, got)
assert.NoError(t, err)
assert.Equal(t, g, got)
})

t.Run("marshal", func(t *testing.T) {
got, err := Marshal(g, NDR)
require.NoError(t, err)
require.Equal(t, ndr, got)
assert.NoError(t, err)
assert.Equal(t, ndr, got)
})
})
}
Expand All @@ -48,98 +48,98 @@ func test(t *testing.T, g geom.T, xdr, ndr []byte) {
var p Point
if xdr != nil {
t.Run("xdr", func(t *testing.T) {
require.NoError(t, p.Scan(xdr))
require.Equal(t, Point{g}, p)
assert.NoError(t, p.Scan(xdr))
assert.Equal(t, Point{g}, p)
})
}
if ndr != nil {
t.Run("ndr", func(t *testing.T) {
require.NoError(t, p.Scan(ndr))
require.Equal(t, Point{g}, p)
assert.NoError(t, p.Scan(ndr))
assert.Equal(t, Point{g}, p)
})
}
case *geom.LineString:
var ls LineString
if xdr != nil {
t.Run("xdr", func(t *testing.T) {
require.NoError(t, ls.Scan(xdr))
require.Equal(t, LineString{g}, ls)
assert.NoError(t, ls.Scan(xdr))
assert.Equal(t, LineString{g}, ls)
})
}
if ndr != nil {
t.Run("ndr", func(t *testing.T) {
require.NoError(t, ls.Scan(ndr))
require.Equal(t, LineString{g}, ls)
assert.NoError(t, ls.Scan(ndr))
assert.Equal(t, LineString{g}, ls)
})
}
case *geom.Polygon:
var p Polygon
if xdr != nil {
t.Run("xdr", func(t *testing.T) {
require.NoError(t, p.Scan(xdr))
require.Equal(t, Polygon{g}, p)
assert.NoError(t, p.Scan(xdr))
assert.Equal(t, Polygon{g}, p)
})
}
if ndr != nil {
t.Run("ndr", func(t *testing.T) {
require.NoError(t, p.Scan(ndr))
require.Equal(t, Polygon{g}, p)
assert.NoError(t, p.Scan(ndr))
assert.Equal(t, Polygon{g}, p)
})
}
case *geom.MultiPoint:
var mp MultiPoint
if xdr != nil {
t.Run("xdr", func(t *testing.T) {
require.NoError(t, mp.Scan(xdr))
require.Equal(t, MultiPoint{g}, mp)
assert.NoError(t, mp.Scan(xdr))
assert.Equal(t, MultiPoint{g}, mp)
})
}
if ndr != nil {
t.Run("ndr", func(t *testing.T) {
require.NoError(t, mp.Scan(ndr))
require.Equal(t, MultiPoint{g}, mp)
assert.NoError(t, mp.Scan(ndr))
assert.Equal(t, MultiPoint{g}, mp)
})
}
case *geom.MultiLineString:
var mls MultiLineString
if xdr != nil {
t.Run("xdr", func(t *testing.T) {
require.NoError(t, mls.Scan(xdr))
require.Equal(t, MultiLineString{g}, mls)
assert.NoError(t, mls.Scan(xdr))
assert.Equal(t, MultiLineString{g}, mls)
})
}
if ndr != nil {
t.Run("ndr", func(t *testing.T) {
require.NoError(t, mls.Scan(ndr))
require.Equal(t, MultiLineString{g}, mls)
assert.NoError(t, mls.Scan(ndr))
assert.Equal(t, MultiLineString{g}, mls)
})
}
case *geom.MultiPolygon:
var mp MultiPolygon
if xdr != nil {
t.Run("xdr", func(t *testing.T) {
require.NoError(t, mp.Scan(xdr))
require.Equal(t, MultiPolygon{g}, mp)
assert.NoError(t, mp.Scan(xdr))
assert.Equal(t, MultiPolygon{g}, mp)
})
}
if ndr != nil {
t.Run("ndr", func(t *testing.T) {
require.NoError(t, mp.Scan(ndr))
require.Equal(t, MultiPolygon{g}, mp)
assert.NoError(t, mp.Scan(ndr))
assert.Equal(t, MultiPolygon{g}, mp)
})
}
case *geom.GeometryCollection:
var gc GeometryCollection
if xdr != nil {
t.Run("xdr", func(t *testing.T) {
require.NoError(t, gc.Scan(xdr))
require.Equal(t, GeometryCollection{g}, gc)
assert.NoError(t, gc.Scan(xdr))
assert.Equal(t, GeometryCollection{g}, gc)
})
}
if ndr != nil {
t.Run("ndr", func(t *testing.T) {
require.NoError(t, gc.Scan(ndr))
require.Equal(t, GeometryCollection{g}, gc)
assert.NoError(t, gc.Scan(ndr))
assert.Equal(t, GeometryCollection{g}, gc)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions encoding/ewkb/postgis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"database/sql"
"testing"

"github.com/alecthomas/assert/v2"
_ "github.com/lib/pq"
"github.com/stretchr/testify/require"

"github.com/twpayne/go-geom"
"github.com/twpayne/go-geom/encoding/ewkb"
Expand Down Expand Up @@ -48,5 +48,5 @@ func TestPostGIS(t *testing.T) {
if err := db.QueryRow("SELECT ST_AsEWKB(geom) FROM testgeoms WHERE ST_Within(geom, $1);", queryP).Scan(&p); err != nil {
t.Fatalf("db.QueryRow(...).Scan(...) == %v, want <nil>", err)
}
require.Equal(t, [][]geom.Coord{{{5, 3}, {5, 0}, {7, 0}, {7, 3}, {5, 3}}}, p.Coords())
assert.Equal(t, [][]geom.Coord{{{5, 3}, {5, 0}, {7, 0}, {7, 3}, {5, 3}}}, p.Coords())
}
12 changes: 6 additions & 6 deletions encoding/ewkb/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"
"testing"

"github.com/stretchr/testify/require"
"github.com/alecthomas/assert/v2"

"github.com/twpayne/go-geom"
"github.com/twpayne/go-geom/internal/geomtest"
Expand Down Expand Up @@ -45,12 +45,12 @@ func TestPointScanAndValue(t *testing.T) {
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
var gotPoint Point
require.NoError(t, gotPoint.Scan(tc.value))
require.Equal(t, tc.point, gotPoint)
require.Equal(t, tc.valid, gotPoint.Valid())
assert.NoError(t, gotPoint.Scan(tc.value))
assert.Equal(t, tc.point, gotPoint)
assert.Equal(t, tc.valid, gotPoint.Valid())
gotValue, gotErr := tc.point.Value()
require.NoError(t, gotErr)
require.Equal(t, tc.value, gotValue)
assert.NoError(t, gotErr)
assert.Equal(t, tc.value, gotValue)
})
}
}
Loading

0 comments on commit e843850

Please sign in to comment.