github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/function/spatial/point_test.go (about) 1 // Copyright 2020-2021 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 TestPoint(t *testing.T) { 28 t.Run("create valid point with integers", func(t *testing.T) { 29 require := require.New(t) 30 f := NewPoint(expression.NewLiteral(1, types.Int64), 31 expression.NewLiteral(2, types.Int64), 32 ) 33 34 v, err := f.Eval(sql.NewEmptyContext(), nil) 35 require.NoError(err) 36 require.Equal(types.Point{X: 1, Y: 2}, v) 37 }) 38 39 t.Run("create valid point with floats", func(t *testing.T) { 40 require := require.New(t) 41 f := NewPoint(expression.NewLiteral(123.456, types.Float64), 42 expression.NewLiteral(789.000, types.Float64), 43 ) 44 45 v, err := f.Eval(sql.NewEmptyContext(), nil) 46 require.NoError(err) 47 require.Equal(types.Point{X: 123.456, Y: 789}, v) 48 }) 49 50 t.Run("create valid point with null x", func(t *testing.T) { 51 require := require.New(t) 52 f := NewPoint(expression.NewLiteral(nil, types.Null), 53 expression.NewLiteral(2, types.Int32), 54 ) 55 56 v, err := f.Eval(sql.NewEmptyContext(), nil) 57 require.NoError(err) 58 require.Equal(nil, v) 59 }) 60 61 t.Run("create valid point with null y", func(t *testing.T) { 62 require := require.New(t) 63 f := NewPoint(expression.NewLiteral(1, types.Int32), 64 expression.NewLiteral(nil, types.Null), 65 ) 66 67 v, err := f.Eval(sql.NewEmptyContext(), nil) 68 require.NoError(err) 69 require.Equal(nil, v) 70 }) 71 72 t.Run("create valid point with nulls", func(t *testing.T) { 73 require := require.New(t) 74 f := NewPoint(expression.NewLiteral(nil, types.Null), 75 expression.NewLiteral(nil, types.Null), 76 ) 77 78 v, err := f.Eval(sql.NewEmptyContext(), nil) 79 require.NoError(err) 80 require.Equal(nil, v) 81 }) 82 }