github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/function/spatial/geometry_collection_test.go (about)

     1  // Copyright 2020-2022 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package spatial
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  
    22  	"github.com/dolthub/go-mysql-server/sql"
    23  	"github.com/dolthub/go-mysql-server/sql/expression"
    24  	"github.com/dolthub/go-mysql-server/sql/types"
    25  )
    26  
    27  func TestGeomColl(t *testing.T) {
    28  	t.Run("create valid empty geometrycollection", func(t *testing.T) {
    29  		require := require.New(t)
    30  		f, err := NewGeomColl()
    31  		require.NoError(err)
    32  
    33  		v, err := f.Eval(sql.NewEmptyContext(), nil)
    34  		require.NoError(err)
    35  		require.Equal(types.GeomColl{Geoms: []types.GeometryValue{}}, v)
    36  	})
    37  
    38  	t.Run("create valid geometrycollection with every geometry", func(t *testing.T) {
    39  		require := require.New(t)
    40  		point := types.Point{X: 1, Y: 2}
    41  		line := types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}
    42  		poly := types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 1}, {X: 1, Y: 0}, {X: 0, Y: 0}}}}}
    43  		mpoint := types.MultiPoint{Points: []types.Point{point, point}}
    44  		mline := types.MultiLineString{Lines: []types.LineString{line, line}}
    45  		mpoly := types.MultiPolygon{Polygons: []types.Polygon{poly, poly}}
    46  		gColl := types.GeomColl{}
    47  
    48  		f, err := NewGeomColl(
    49  			expression.NewLiteral(point, types.PointType{}),
    50  			expression.NewLiteral(line, types.LineStringType{}),
    51  			expression.NewLiteral(poly, types.PolygonType{}),
    52  			expression.NewLiteral(mpoint, types.MultiPointType{}),
    53  			expression.NewLiteral(mline, types.MultiLineStringType{}),
    54  			expression.NewLiteral(mpoly, types.MultiPolygonType{}),
    55  			expression.NewLiteral(gColl, types.GeomCollType{}),
    56  		)
    57  		require.NoError(err)
    58  
    59  		v, err := f.Eval(sql.NewEmptyContext(), nil)
    60  		require.NoError(err)
    61  		require.Equal(types.GeomColl{Geoms: []types.GeometryValue{
    62  			point,
    63  			line,
    64  			poly,
    65  			mpoint,
    66  			mline,
    67  			mpoly,
    68  			gColl,
    69  		}}, v)
    70  	})
    71  }
    72  
    73  func TestNewGeomColl(t *testing.T) {
    74  	require := require.New(t)
    75  	_, err := NewGeomColl(expression.NewLiteral(nil, types.GeometryType{}))
    76  	require.NoError(err)
    77  }