...

Source file src/github.com/doug-martin/goqu/v9/exp/bitwise_test.go

Documentation: github.com/doug-martin/goqu/v9/exp

     1  package exp_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/doug-martin/goqu/v9/exp"
     7  	"github.com/stretchr/testify/suite"
     8  )
     9  
    10  type bitwiseExpressionSuite struct {
    11  	suite.Suite
    12  }
    13  
    14  func TestBitwiseExpressionSuite(t *testing.T) {
    15  	suite.Run(t, &bitwiseExpressionSuite{})
    16  }
    17  
    18  func (bes *bitwiseExpressionSuite) TestClone() {
    19  	be := exp.NewBitwiseExpression(exp.BitwiseAndOp, exp.NewIdentifierExpression("", "", "col"), 1)
    20  	bes.Equal(be, be.Clone())
    21  }
    22  
    23  func (bes *bitwiseExpressionSuite) TestExpression() {
    24  	be := exp.NewBitwiseExpression(exp.BitwiseAndOp, exp.NewIdentifierExpression("", "", "col"), 1)
    25  	bes.Equal(be, be.Expression())
    26  }
    27  
    28  func (bes *bitwiseExpressionSuite) TestAs() {
    29  	be := exp.NewBitwiseExpression(exp.BitwiseInversionOp, exp.NewIdentifierExpression("", "", "col"), 1)
    30  	bes.Equal(exp.NewAliasExpression(be, "a"), be.As("a"))
    31  }
    32  
    33  func (bes *bitwiseExpressionSuite) TestAsc() {
    34  	be := exp.NewBitwiseExpression(exp.BitwiseAndOp, exp.NewIdentifierExpression("", "", "col"), 1)
    35  	bes.Equal(exp.NewOrderedExpression(be, exp.AscDir, exp.NoNullsSortType), be.Asc())
    36  }
    37  
    38  func (bes *bitwiseExpressionSuite) TestDesc() {
    39  	be := exp.NewBitwiseExpression(exp.BitwiseOrOp, exp.NewIdentifierExpression("", "", "col"), 1)
    40  	bes.Equal(exp.NewOrderedExpression(be, exp.DescSortDir, exp.NoNullsSortType), be.Desc())
    41  }
    42  
    43  func (bes *bitwiseExpressionSuite) TestAllOthers() {
    44  	be := exp.NewBitwiseExpression(exp.BitwiseRightShiftOp, exp.NewIdentifierExpression("", "", "col"), 1)
    45  	rv := exp.NewRangeVal(1, 2)
    46  	pattern := "bitwiseExp like%"
    47  	inVals := []interface{}{1, 2}
    48  	testCases := []struct {
    49  		Ex       exp.Expression
    50  		Expected exp.Expression
    51  	}{
    52  		{Ex: be.Eq(1), Expected: exp.NewBooleanExpression(exp.EqOp, be, 1)},
    53  		{Ex: be.Neq(1), Expected: exp.NewBooleanExpression(exp.NeqOp, be, 1)},
    54  		{Ex: be.Gt(1), Expected: exp.NewBooleanExpression(exp.GtOp, be, 1)},
    55  		{Ex: be.Gte(1), Expected: exp.NewBooleanExpression(exp.GteOp, be, 1)},
    56  		{Ex: be.Lt(1), Expected: exp.NewBooleanExpression(exp.LtOp, be, 1)},
    57  		{Ex: be.Lte(1), Expected: exp.NewBooleanExpression(exp.LteOp, be, 1)},
    58  		{Ex: be.Between(rv), Expected: exp.NewRangeExpression(exp.BetweenOp, be, rv)},
    59  		{Ex: be.NotBetween(rv), Expected: exp.NewRangeExpression(exp.NotBetweenOp, be, rv)},
    60  		{Ex: be.Like(pattern), Expected: exp.NewBooleanExpression(exp.LikeOp, be, pattern)},
    61  		{Ex: be.NotLike(pattern), Expected: exp.NewBooleanExpression(exp.NotLikeOp, be, pattern)},
    62  		{Ex: be.ILike(pattern), Expected: exp.NewBooleanExpression(exp.ILikeOp, be, pattern)},
    63  		{Ex: be.NotILike(pattern), Expected: exp.NewBooleanExpression(exp.NotILikeOp, be, pattern)},
    64  		{Ex: be.RegexpLike(pattern), Expected: exp.NewBooleanExpression(exp.RegexpLikeOp, be, pattern)},
    65  		{Ex: be.RegexpNotLike(pattern), Expected: exp.NewBooleanExpression(exp.RegexpNotLikeOp, be, pattern)},
    66  		{Ex: be.RegexpILike(pattern), Expected: exp.NewBooleanExpression(exp.RegexpILikeOp, be, pattern)},
    67  		{Ex: be.RegexpNotILike(pattern), Expected: exp.NewBooleanExpression(exp.RegexpNotILikeOp, be, pattern)},
    68  		{Ex: be.In(inVals), Expected: exp.NewBooleanExpression(exp.InOp, be, inVals)},
    69  		{Ex: be.NotIn(inVals), Expected: exp.NewBooleanExpression(exp.NotInOp, be, inVals)},
    70  		{Ex: be.Is(true), Expected: exp.NewBooleanExpression(exp.IsOp, be, true)},
    71  		{Ex: be.IsNot(true), Expected: exp.NewBooleanExpression(exp.IsNotOp, be, true)},
    72  		{Ex: be.IsNull(), Expected: exp.NewBooleanExpression(exp.IsOp, be, nil)},
    73  		{Ex: be.IsNotNull(), Expected: exp.NewBooleanExpression(exp.IsNotOp, be, nil)},
    74  		{Ex: be.IsTrue(), Expected: exp.NewBooleanExpression(exp.IsOp, be, true)},
    75  		{Ex: be.IsNotTrue(), Expected: exp.NewBooleanExpression(exp.IsNotOp, be, true)},
    76  		{Ex: be.IsFalse(), Expected: exp.NewBooleanExpression(exp.IsOp, be, false)},
    77  		{Ex: be.IsNotFalse(), Expected: exp.NewBooleanExpression(exp.IsNotOp, be, false)},
    78  		{Ex: be.Distinct(), Expected: exp.NewSQLFunctionExpression("DISTINCT", be)},
    79  	}
    80  
    81  	for _, tc := range testCases {
    82  		bes.Equal(tc.Expected, tc.Ex)
    83  	}
    84  }
    85  

View as plain text