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 windowExpressionTest struct {
11 suite.Suite
12 }
13
14 func TestWindowExpressionSuite(t *testing.T) {
15 suite.Run(t, new(windowExpressionTest))
16 }
17
18 func (wet *windowExpressionTest) TestClone() {
19 w := exp.NewWindowExpression(exp.NewIdentifierExpression("", "", "w"), nil, nil, nil)
20 w2 := w.Clone()
21
22 wet.Equal(w, w2)
23 }
24
25 func (wet *windowExpressionTest) TestExpression() {
26 w := exp.NewWindowExpression(exp.NewIdentifierExpression("", "", "w"), nil, nil, nil)
27 w2 := w.Expression()
28
29 wet.Equal(w, w2)
30 }
31
32 func (wet *windowExpressionTest) TestName() {
33 name := exp.NewIdentifierExpression("", "", "w")
34 w := exp.NewWindowExpression(exp.NewIdentifierExpression("", "", "w"), nil, nil, nil)
35
36 wet.Equal(name, w.Name())
37 }
38
39 func (wet *windowExpressionTest) TestPartitionCols() {
40 cols := exp.NewColumnListExpression("a", "b")
41 w := exp.NewWindowExpression(exp.NewIdentifierExpression("", "", "w"), nil, cols, nil)
42
43 wet.Equal(cols, w.PartitionCols())
44 wet.Equal(cols, w.Clone().(exp.WindowExpression).PartitionCols())
45 }
46
47 func (wet *windowExpressionTest) TestOrderCols() {
48 cols := exp.NewColumnListExpression("a", "b")
49 w := exp.NewWindowExpression(exp.NewIdentifierExpression("", "", "w"), nil, nil, cols)
50
51 wet.Equal(cols, w.OrderCols())
52 wet.Equal(cols, w.Clone().(exp.WindowExpression).OrderCols())
53 }
54
55 func (wet *windowExpressionTest) TestPartitionBy() {
56 cols := exp.NewColumnListExpression("a", "b")
57 w := exp.NewWindowExpression(exp.NewIdentifierExpression("", "", "w"), nil, nil, nil).PartitionBy("a", "b")
58
59 wet.Equal(cols, w.PartitionCols())
60 }
61
62 func (wet *windowExpressionTest) TestOrderBy() {
63 cols := exp.NewColumnListExpression("a", "b")
64 w := exp.NewWindowExpression(exp.NewIdentifierExpression("", "", "w"), nil, nil, nil).OrderBy("a", "b")
65
66 wet.Equal(cols, w.OrderCols())
67 }
68
69 func (wet *windowExpressionTest) TestParent() {
70 parent := exp.NewIdentifierExpression("", "", "w1")
71 w := exp.NewWindowExpression(exp.NewIdentifierExpression("", "", "w"), parent, nil, nil)
72
73 wet.Equal(parent, w.Parent())
74 }
75
76 func (wet *windowExpressionTest) TestInherit() {
77 parent := exp.NewIdentifierExpression("", "", "w1")
78 w := exp.NewWindowExpression(exp.NewIdentifierExpression("", "", "w"), parent, nil, nil)
79
80 wet.Equal(parent, w.Parent())
81
82 w = w.Inherit("w2")
83 wet.Equal(exp.NewIdentifierExpression("", "", "w2"), w.Parent())
84 }
85
View as plain text