|
| 1 | +package exp |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/suite" |
| 7 | +) |
| 8 | + |
| 9 | +type castExpressionSuite struct { |
| 10 | + suite.Suite |
| 11 | + ce CastExpression |
| 12 | +} |
| 13 | + |
| 14 | +func TestCastExpressionSuite(t *testing.T) { |
| 15 | + suite.Run(t, &castExpressionSuite{ |
| 16 | + ce: NewCastExpression(NewIdentifierExpression("", "", "a"), "TEXT"), |
| 17 | + }) |
| 18 | +} |
| 19 | + |
| 20 | +func (ces *castExpressionSuite) TestClone() { |
| 21 | + ces.Equal(ces.ce, ces.ce.Clone()) |
| 22 | +} |
| 23 | + |
| 24 | +func (ces *castExpressionSuite) TestExpression() { |
| 25 | + ces.Equal(ces.ce, ces.ce.Expression()) |
| 26 | +} |
| 27 | + |
| 28 | +func (ces *castExpressionSuite) TestCasted() { |
| 29 | + ces.Equal(NewIdentifierExpression("", "", "a"), ces.ce.Casted()) |
| 30 | +} |
| 31 | +func (ces *castExpressionSuite) TestType() { |
| 32 | + ces.Equal(NewLiteralExpression("TEXT"), ces.ce.Type()) |
| 33 | +} |
| 34 | + |
| 35 | +func (ces *castExpressionSuite) TestAllOthers() { |
| 36 | + ce := ces.ce |
| 37 | + rv := NewRangeVal(1, 2) |
| 38 | + pattern := "cast like%" |
| 39 | + inVals := []interface{}{1, 2} |
| 40 | + testCases := []struct { |
| 41 | + Ex Expression |
| 42 | + Expected Expression |
| 43 | + }{ |
| 44 | + {Ex: ce.As("a"), Expected: aliased(ce, "a")}, |
| 45 | + {Ex: ce.Eq(1), Expected: NewBooleanExpression(EqOp, ce, 1)}, |
| 46 | + {Ex: ce.Neq(1), Expected: NewBooleanExpression(NeqOp, ce, 1)}, |
| 47 | + {Ex: ce.Gt(1), Expected: NewBooleanExpression(GtOp, ce, 1)}, |
| 48 | + {Ex: ce.Gte(1), Expected: NewBooleanExpression(GteOp, ce, 1)}, |
| 49 | + {Ex: ce.Lt(1), Expected: NewBooleanExpression(LtOp, ce, 1)}, |
| 50 | + {Ex: ce.Lte(1), Expected: NewBooleanExpression(LteOp, ce, 1)}, |
| 51 | + {Ex: ce.Asc(), Expected: asc(ce)}, |
| 52 | + {Ex: ce.Desc(), Expected: desc(ce)}, |
| 53 | + {Ex: ce.Between(rv), Expected: between(ce, rv)}, |
| 54 | + {Ex: ce.NotBetween(rv), Expected: notBetween(ce, rv)}, |
| 55 | + {Ex: ce.Like(pattern), Expected: NewBooleanExpression(LikeOp, ce, pattern)}, |
| 56 | + {Ex: ce.NotLike(pattern), Expected: NewBooleanExpression(NotLikeOp, ce, pattern)}, |
| 57 | + {Ex: ce.ILike(pattern), Expected: NewBooleanExpression(ILikeOp, ce, pattern)}, |
| 58 | + {Ex: ce.NotILike(pattern), Expected: NewBooleanExpression(NotILikeOp, ce, pattern)}, |
| 59 | + {Ex: ce.RegexpLike(pattern), Expected: NewBooleanExpression(RegexpLikeOp, ce, pattern)}, |
| 60 | + {Ex: ce.RegexpNotLike(pattern), Expected: NewBooleanExpression(RegexpNotLikeOp, ce, pattern)}, |
| 61 | + {Ex: ce.RegexpILike(pattern), Expected: NewBooleanExpression(RegexpILikeOp, ce, pattern)}, |
| 62 | + {Ex: ce.RegexpNotILike(pattern), Expected: NewBooleanExpression(RegexpNotILikeOp, ce, pattern)}, |
| 63 | + {Ex: ce.In(inVals), Expected: NewBooleanExpression(InOp, ce, inVals)}, |
| 64 | + {Ex: ce.NotIn(inVals), Expected: NewBooleanExpression(NotInOp, ce, inVals)}, |
| 65 | + {Ex: ce.Is(true), Expected: NewBooleanExpression(IsOp, ce, true)}, |
| 66 | + {Ex: ce.IsNot(true), Expected: NewBooleanExpression(IsNotOp, ce, true)}, |
| 67 | + {Ex: ce.IsNull(), Expected: NewBooleanExpression(IsOp, ce, nil)}, |
| 68 | + {Ex: ce.IsNotNull(), Expected: NewBooleanExpression(IsNotOp, ce, nil)}, |
| 69 | + {Ex: ce.IsTrue(), Expected: NewBooleanExpression(IsOp, ce, true)}, |
| 70 | + {Ex: ce.IsNotTrue(), Expected: NewBooleanExpression(IsNotOp, ce, true)}, |
| 71 | + {Ex: ce.IsFalse(), Expected: NewBooleanExpression(IsOp, ce, false)}, |
| 72 | + {Ex: ce.IsNotFalse(), Expected: NewBooleanExpression(IsNotOp, ce, false)}, |
| 73 | + {Ex: ce.Distinct(), Expected: NewSQLFunctionExpression("DISTINCT", ce)}, |
| 74 | + } |
| 75 | + |
| 76 | + for _, tc := range testCases { |
| 77 | + ces.Equal(tc.Expected, tc.Ex) |
| 78 | + } |
| 79 | +} |
0 commit comments