github.com/dolthub/go-mysql-server@v0.18.0/sql/range_cut_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 "fmt" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 23 "github.com/dolthub/go-mysql-server/sql" 24 "github.com/dolthub/go-mysql-server/sql/types" 25 ) 26 27 func TestRangeCutCompare(t *testing.T) { 28 type tc struct { 29 left, right sql.RangeCut 30 res int 31 } 32 for _, testcase := range []tc{ 33 {sql.AboveAll{}, sql.BelowNull{}, 1}, 34 {sql.AboveAll{}, sql.AboveNull{}, 1}, 35 {sql.AboveAll{}, sql.Above{1}, 1}, 36 {sql.AboveAll{}, sql.Below{1}, 1}, 37 {sql.AboveAll{}, sql.AboveAll{}, 0}, 38 39 {sql.Above{1}, sql.AboveNull{}, 1}, 40 {sql.Above{1}, sql.BelowNull{}, 1}, 41 {sql.Above{1}, sql.Above{1}, 0}, 42 {sql.Above{1}, sql.Below{1}, 1}, 43 {sql.Above{2}, sql.Above{1}, 1}, 44 45 {sql.Below{1}, sql.AboveNull{}, 1}, 46 {sql.Below{1}, sql.BelowNull{}, 1}, 47 {sql.Below{1}, sql.Below{1}, 0}, 48 {sql.Below{2}, sql.Below{1}, 1}, 49 50 {sql.AboveNull{}, sql.BelowNull{}, 1}, 51 52 {sql.BelowNull{}, sql.BelowNull{}, 0}, 53 } { 54 t.Run(fmt.Sprintf("%s/%s = %d", testcase.left.String(), testcase.right.String(), testcase.res), func(t *testing.T) { 55 res, err := testcase.left.Compare(testcase.right, types.Int8) 56 assert.NoError(t, err) 57 assert.Equal(t, testcase.res, res, "forward Compare") 58 59 res, err = testcase.right.Compare(testcase.left, types.Int8) 60 assert.NoError(t, err) 61 assert.Equal(t, -testcase.res, res, "reverse Compare") 62 }) 63 } 64 }