github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/function/spatial/multilinestring_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 TestMultiLineString(t *testing.T) { 28 t.Run("create valid multilinestring", func(t *testing.T) { 29 require := require.New(t) 30 f, err := NewMultiLineString(expression.NewLiteral(types.LineString{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 1}}}, types.LineStringType{})) 31 require.NoError(err) 32 33 v, err := f.Eval(sql.NewEmptyContext(), nil) 34 require.NoError(err) 35 require.Equal(types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 1}}}}}, v) 36 }) 37 38 t.Run("create valid multilinestring with multiple linestrings", func(t *testing.T) { 39 require := require.New(t) 40 f, err := NewMultiLineString(expression.NewLiteral(types.LineString{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 1}}}, types.LineStringType{}), 41 expression.NewLiteral(types.LineString{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}}}, types.LineStringType{}), 42 expression.NewLiteral(types.LineString{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}}}, types.LineStringType{})) 43 require.NoError(err) 44 45 v, err := f.Eval(sql.NewEmptyContext(), nil) 46 require.NoError(err) 47 require.Equal(types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 1}}}, {Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}}}, {Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}}}}}, v) 48 }) 49 } 50 51 func TestNewMultiLineString(t *testing.T) { 52 require := require.New(t) 53 _, err := NewMultiLineString(expression.NewLiteral(nil, types.LineStringType{}), 54 expression.NewLiteral(nil, types.LineStringType{}), 55 expression.NewLiteral(nil, types.LineStringType{}), 56 ) 57 require.NoError(err) 58 }