...

Source file src/github.com/doug-martin/goqu/v9/exp/literal_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 literalExpressionSuite struct {
    11  	suite.Suite
    12  	le exp.LiteralExpression
    13  }
    14  
    15  func TestLiteralExpressionSuite(t *testing.T) {
    16  	suite.Run(t, &literalExpressionSuite{
    17  		le: exp.NewLiteralExpression("? + ?", 1, 2),
    18  	})
    19  }
    20  
    21  func (les *literalExpressionSuite) TestClone() {
    22  	les.Equal(les.le, les.le.Clone())
    23  }
    24  
    25  func (les *literalExpressionSuite) TestExpression() {
    26  	les.Equal(les.le, les.le.Expression())
    27  }
    28  
    29  func (les *literalExpressionSuite) TestLiteral() {
    30  	les.Equal("? + ?", les.le.Literal())
    31  }
    32  
    33  func (les *literalExpressionSuite) TestArgs() {
    34  	les.Equal([]interface{}{1, 2}, les.le.Args())
    35  }
    36  
    37  func (les *literalExpressionSuite) TestAllOthers() {
    38  	le := les.le
    39  	rv := exp.NewRangeVal(1, 2)
    40  	pattern := "literal like%"
    41  	inVals := []interface{}{1, 2}
    42  	bitwiseVals := 2
    43  	testCases := []struct {
    44  		Ex       exp.Expression
    45  		Expected exp.Expression
    46  	}{
    47  		{Ex: le.As("a"), Expected: exp.NewAliasExpression(le, "a")},
    48  		{Ex: le.Eq(1), Expected: exp.NewBooleanExpression(exp.EqOp, le, 1)},
    49  		{Ex: le.Neq(1), Expected: exp.NewBooleanExpression(exp.NeqOp, le, 1)},
    50  		{Ex: le.Gt(1), Expected: exp.NewBooleanExpression(exp.GtOp, le, 1)},
    51  		{Ex: le.Gte(1), Expected: exp.NewBooleanExpression(exp.GteOp, le, 1)},
    52  		{Ex: le.Lt(1), Expected: exp.NewBooleanExpression(exp.LtOp, le, 1)},
    53  		{Ex: le.Lte(1), Expected: exp.NewBooleanExpression(exp.LteOp, le, 1)},
    54  		{Ex: le.Asc(), Expected: exp.NewOrderedExpression(le, exp.AscDir, exp.NoNullsSortType)},
    55  		{Ex: le.Desc(), Expected: exp.NewOrderedExpression(le, exp.DescSortDir, exp.NoNullsSortType)},
    56  		{Ex: le.Between(rv), Expected: exp.NewRangeExpression(exp.BetweenOp, le, rv)},
    57  		{Ex: le.NotBetween(rv), Expected: exp.NewRangeExpression(exp.NotBetweenOp, le, rv)},
    58  		{Ex: le.Like(pattern), Expected: exp.NewBooleanExpression(exp.LikeOp, le, pattern)},
    59  		{Ex: le.NotLike(pattern), Expected: exp.NewBooleanExpression(exp.NotLikeOp, le, pattern)},
    60  		{Ex: le.ILike(pattern), Expected: exp.NewBooleanExpression(exp.ILikeOp, le, pattern)},
    61  		{Ex: le.NotILike(pattern), Expected: exp.NewBooleanExpression(exp.NotILikeOp, le, pattern)},
    62  		{Ex: le.RegexpLike(pattern), Expected: exp.NewBooleanExpression(exp.RegexpLikeOp, le, pattern)},
    63  		{Ex: le.RegexpNotLike(pattern), Expected: exp.NewBooleanExpression(exp.RegexpNotLikeOp, le, pattern)},
    64  		{Ex: le.RegexpILike(pattern), Expected: exp.NewBooleanExpression(exp.RegexpILikeOp, le, pattern)},
    65  		{Ex: le.RegexpNotILike(pattern), Expected: exp.NewBooleanExpression(exp.RegexpNotILikeOp, le, pattern)},
    66  		{Ex: le.In(inVals), Expected: exp.NewBooleanExpression(exp.InOp, le, inVals)},
    67  		{Ex: le.NotIn(inVals), Expected: exp.NewBooleanExpression(exp.NotInOp, le, inVals)},
    68  		{Ex: le.Is(true), Expected: exp.NewBooleanExpression(exp.IsOp, le, true)},
    69  		{Ex: le.IsNot(true), Expected: exp.NewBooleanExpression(exp.IsNotOp, le, true)},
    70  		{Ex: le.IsNull(), Expected: exp.NewBooleanExpression(exp.IsOp, le, nil)},
    71  		{Ex: le.IsNotNull(), Expected: exp.NewBooleanExpression(exp.IsNotOp, le, nil)},
    72  		{Ex: le.IsTrue(), Expected: exp.NewBooleanExpression(exp.IsOp, le, true)},
    73  		{Ex: le.IsNotTrue(), Expected: exp.NewBooleanExpression(exp.IsNotOp, le, true)},
    74  		{Ex: le.IsFalse(), Expected: exp.NewBooleanExpression(exp.IsOp, le, false)},
    75  		{Ex: le.IsNotFalse(), Expected: exp.NewBooleanExpression(exp.IsNotOp, le, false)},
    76  		{Ex: le.BitwiseInversion(), Expected: exp.NewBitwiseExpression(exp.BitwiseInversionOp, nil, le)},
    77  		{Ex: le.BitwiseOr(bitwiseVals), Expected: exp.NewBitwiseExpression(exp.BitwiseOrOp, le, bitwiseVals)},
    78  		{Ex: le.BitwiseAnd(bitwiseVals), Expected: exp.NewBitwiseExpression(exp.BitwiseAndOp, le, bitwiseVals)},
    79  		{Ex: le.BitwiseXor(bitwiseVals), Expected: exp.NewBitwiseExpression(exp.BitwiseXorOp, le, bitwiseVals)},
    80  		{Ex: le.BitwiseLeftShift(bitwiseVals), Expected: exp.NewBitwiseExpression(exp.BitwiseLeftShiftOp, le, bitwiseVals)},
    81  		{Ex: le.BitwiseRightShift(bitwiseVals), Expected: exp.NewBitwiseExpression(exp.BitwiseRightShiftOp, le, bitwiseVals)},
    82  	}
    83  
    84  	for _, tc := range testCases {
    85  		les.Equal(tc.Expected, tc.Ex)
    86  	}
    87  }
    88  

View as plain text