forked from src-d/gitbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregation_test.go
96 lines (72 loc) · 1.98 KB
/
aggregation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package expression
import (
"testing"
"github.com/gitql/gitql/sql"
"github.com/stretchr/testify/require"
)
func TestCount_Name(t *testing.T) {
assert := require.New(t)
c := NewCount(NewLiteral("foo", sql.String))
assert.Equal("count(literal_string)", c.Name())
}
func TestCount_Eval_1(t *testing.T) {
assert := require.New(t)
c := NewCount(NewLiteral(1, sql.Integer))
b := c.NewBuffer()
assert.Equal(int32(0), c.Eval(b))
c.Update(b, nil)
c.Update(b, sql.NewRow("foo"))
c.Update(b, sql.NewRow(1))
c.Update(b, sql.NewRow(1, 2, 3))
assert.Equal(int32(4), c.Eval(b))
b2 := c.NewBuffer()
c.Update(b2, nil)
c.Update(b2, sql.NewRow("foo"))
c.Merge(b, b2)
assert.Equal(int32(6), c.Eval(b))
}
func TestCount_Eval_Star(t *testing.T) {
assert := require.New(t)
c := NewCount(NewStar())
b := c.NewBuffer()
assert.Equal(int32(0), c.Eval(b))
c.Update(b, nil)
c.Update(b, sql.NewRow("foo"))
c.Update(b, sql.NewRow(1))
c.Update(b, sql.NewRow(1, 2, 3))
assert.Equal(int32(4), c.Eval(b))
b2 := c.NewBuffer()
c.Update(b2, sql.NewRow())
c.Update(b2, sql.NewRow("foo"))
c.Merge(b, b2)
assert.Equal(int32(6), c.Eval(b))
}
func TestCount_Eval_String(t *testing.T) {
assert := require.New(t)
c := NewCount(NewGetField(0, sql.String, ""))
b := c.NewBuffer()
assert.Equal(int32(0), c.Eval(b))
c.Update(b, sql.NewRow("foo"))
assert.Equal(int32(1), c.Eval(b))
c.Update(b, sql.NewRow(nil))
assert.Equal(int32(1), c.Eval(b))
}
func TestFirst_Name(t *testing.T) {
assert := require.New(t)
c := NewFirst(NewGetField(0, sql.Integer, "field"))
assert.Equal("first(field)", c.Name())
}
func TestFirst_Eval(t *testing.T) {
assert := require.New(t)
c := NewFirst(NewGetField(0, sql.Integer, "field"))
b := c.NewBuffer()
assert.Nil(c.Eval(b))
c.Update(b, sql.NewRow(int32(1)))
assert.Equal(int32(1), c.Eval(b))
c.Update(b, sql.NewRow(int32(2)))
assert.Equal(int32(1), c.Eval(b))
b2 := c.NewBuffer()
c.Update(b2, sql.NewRow(int32(2)))
c.Merge(b, b2)
assert.Equal(int32(1), c.Eval(b))
}