-
Notifications
You must be signed in to change notification settings - Fork 1
/
is_between_test.go
70 lines (50 loc) · 1.63 KB
/
is_between_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
package golconda
import (
"testing"
)
func TestIsBetween(t *testing.T) {
expected := "date BETWEEN ? AND ?"
from := "2021-10-01"
to := "2022-10-31"
operator := IsBetween("date", from, to)(func() string { return "?" })
if operator.Expression != expected {
t.Errorf("Expected %s, got %s", expected, operator.Expression)
}
if len(operator.Vals) != 2 {
t.Errorf("Expected len of operator.Vals 2, got %d", len(operator.Vals))
}
if operator.Vals[0] != from {
t.Errorf("Expected len of operator.Vals[0] %s, got %s", from, operator.Vals[0])
}
if operator.Vals[1] != to {
t.Errorf("Expected len of operator.Vals[1] %s, got %s", to, operator.Vals[1])
}
}
func TestIsBetweenWithoutFrom(t *testing.T) {
expected := "date <= ?"
to := "2022-10-31"
operator := IsBetween("date", nil, to)(func() string { return "?" })
if operator.Expression != expected {
t.Errorf("Expected %s, got %s", expected, operator.Expression)
}
if len(operator.Vals) != 1 {
t.Errorf("Expected len of operator.Vals 1, got %d", len(operator.Vals))
}
if operator.Vals[0] != to {
t.Errorf("Expected len of operator.Vals[0] %s, got %s", to, operator.Vals[0])
}
}
func TestIsBetweenWithoutTo(t *testing.T) {
expected := "date >= ?"
from := "2021-10-01"
operator := IsBetween("date", from, nil)(func() string { return "?" })
if operator.Expression != expected {
t.Errorf("Expected %s, got %s", expected, operator.Expression)
}
if len(operator.Vals) != 1 {
t.Errorf("Expected len of operator.Vals 1, got %d", len(operator.Vals))
}
if operator.Vals[0] != from {
t.Errorf("Expected len of operator.Vals[0] %s, got %s", from, operator.Vals[0])
}
}