-
Notifications
You must be signed in to change notification settings - Fork 2
/
operator_test.go
49 lines (42 loc) · 1.11 KB
/
operator_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
package mgs
import "testing"
type operatorTest struct {
Input string
Expected SearchOperator
}
type operatorStringTest struct {
Input SearchOperator
Expected string
}
var operatorTests = []operatorTest{
{"=", EQUAL},
{"!=", NOT_EQUAL},
{">", GREATER_THAN},
{">=", GREATER_THAN_EQUAL},
{"<", LESS_THAN},
{"<=", LESS_THAN_EQUAL},
{"!", EXISTS},
}
var operatorStringTests = []operatorStringTest{
{EQUAL, "EQUAL"},
{NOT_EQUAL, "NOT_EQUAL"},
{GREATER_THAN, "GREATER_THAN"},
{GREATER_THAN_EQUAL, "GREATER_THAN_EQUAL"},
{LESS_THAN, "LESS_THAN"},
{LESS_THAN_EQUAL, "LESS_THAN_EQUAL"},
{EXISTS, "EXISTS"},
}
func TestShouldGetOperationFromString(t *testing.T) {
for _, test := range operatorTests {
if result := test.Expected.GetOperation(test.Input); result != test.Expected {
t.Errorf("Result %s not equal to expected %s", result, test.Expected)
}
}
}
func TestShouldReturnStringFromSearchOperator(t *testing.T) {
for _, test := range operatorStringTests {
if result := test.Input.String(); result != test.Expected {
t.Errorf("Result %s not equal to expected %s", result, test.Expected)
}
}
}