github.com/dolthub/go-mysql-server@v0.18.0/sql/range_column_expr_test.go (about) 1 // Copyright 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 sql_test 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 22 "github.com/dolthub/go-mysql-server/sql" 23 "github.com/dolthub/go-mysql-server/sql/types" 24 ) 25 26 func TestTryIntersect(t *testing.T) { 27 res, ok, err := sql.LessThanRangeColumnExpr(6, types.Int8).TryIntersect(sql.GreaterThanRangeColumnExpr(-1, types.Int8)) 28 assert.NoError(t, err) 29 assert.True(t, ok) 30 assert.Equal(t, sql.RangeType_OpenOpen, res.Type()) 31 32 res, ok, err = sql.NotNullRangeColumnExpr(types.Int8).TryIntersect(sql.AllRangeColumnExpr(types.Int8)) 33 assert.NoError(t, err) 34 assert.True(t, ok) 35 assert.Equal(t, sql.RangeType_GreaterThan, res.Type()) 36 assert.False(t, sql.RangeCutIsBinding(res.LowerBound)) 37 38 _, ok, err = sql.NotNullRangeColumnExpr(types.Int8).TryIntersect(sql.NullRangeColumnExpr(types.Int8)) 39 assert.NoError(t, err) 40 assert.False(t, ok) 41 _, ok, err = sql.NullRangeColumnExpr(types.Int8).TryIntersect(sql.NotNullRangeColumnExpr(types.Int8)) 42 assert.NoError(t, err) 43 assert.False(t, ok) 44 } 45 46 func TestTryUnion(t *testing.T) { 47 res, ok, err := sql.NotNullRangeColumnExpr(types.Int8).TryUnion(sql.NullRangeColumnExpr(types.Int8)) 48 assert.NoError(t, err) 49 assert.True(t, ok) 50 assert.Equal(t, sql.RangeType_All, res.Type()) 51 res, ok, err = sql.NullRangeColumnExpr(types.Int8).TryUnion(sql.NotNullRangeColumnExpr(types.Int8)) 52 assert.NoError(t, err) 53 assert.True(t, ok) 54 assert.Equal(t, sql.RangeType_All, res.Type()) 55 }