-
Notifications
You must be signed in to change notification settings - Fork 1
/
golconda_test.go
64 lines (51 loc) · 1.58 KB
/
golconda_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
package golconda
import (
"testing"
)
func TestAndEmptyCondition(t *testing.T) {
expected := "(TRUE)"
c := NewAnd()
emptyCondition, _ := c.Build()
if emptyCondition != expected {
t.Errorf("Expected %s, got %s", expected, emptyCondition)
}
}
func TestOrEmptyCondition(t *testing.T) {
expected := "(FALSE)"
c := NewOr()
emptyCondition, _ := c.Build()
if emptyCondition != expected {
t.Errorf("Expected %s, got %s", expected, emptyCondition)
}
}
func TestAppend(t *testing.T) {
expected := "(somecondition)"
c := NewAnd()
operator := Operator{}
operator.Expression = "somecondition"
operator.Vals = append(operator.Vals, 1)
c.Append(func(paramPlaceholder operatorParamBuilder) Operator { return operator })
conditionString, values := c.Build()
if conditionString != expected {
t.Errorf("Expected %s, got %s", expected, conditionString)
}
if values[0] != 1 {
t.Errorf("values: Expected %d, got %d", operator.Vals[0], values[0])
}
}
func TestAppendCondition(t *testing.T) {
expected := "(somecondition AND (anothercondition OR other))"
c := NewAnd()
operator := Operator{}
operator.Expression = "somecondition"
sub := NewOr()
operatorSub := Operator{}
operatorSub.Expression = "anothercondition OR other"
operatorSub.Vals = append(operatorSub.Vals, 1)
sub.Append(func(paramPlaceholder operatorParamBuilder) Operator { return operatorSub })
c.Append(func(paramPlaceholder operatorParamBuilder) Operator { return operator }, sub.AsOperator())
conditionString, _ := c.Build()
if conditionString != expected {
t.Errorf("Expected %s, got %s", expected, conditionString)
}
}