2
0

Add tests to Polygon

This commit is contained in:
duohedron
2020-10-06 08:43:41 +02:00
committed by Jack Christensen
parent 2dca42ee7d
commit e09987f1d6
+42
View File
@@ -20,3 +20,45 @@ func TestPolygonTranscode(t *testing.T) {
&pgtype.Polygon{Status: pgtype.Null},
})
}
func TestPolygon_Set(t *testing.T) {
tests := []struct {
name string
arg interface{}
status pgtype.Status
wantErr bool
}{
{
name: "string",
arg: "((3.14,1.678901234),(7.1,5.234),(5.0,3.234))",
status: pgtype.Present,
wantErr: false,
}, {
name: "[]float64",
arg: []float64{1, 2, 3.45, 6.78, 1.23, 4.567, 8.9, 1.0},
status: pgtype.Present,
wantErr: false,
}, {
name: "[]Vec2",
arg: []pgtype.Vec2{{1, 2}, {2.3, 4.5}, {6.78, 9.123}},
status: pgtype.Present,
wantErr: false,
}, {
name: "null",
arg: nil,
status: pgtype.Null,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dst := &pgtype.Polygon{}
if err := dst.Set(tt.arg); (err != nil) != tt.wantErr {
t.Errorf("Set() error = %v, wantErr %v", err, tt.wantErr)
}
if dst.Status != tt.status {
t.Errorf("Expected status: %v; got: %v", tt.status, dst.Status)
}
})
}
}