forked from sbstjn/allot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameter_test.go
96 lines (79 loc) · 1.94 KB
/
parameter_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 allot
import (
"regexp"
"testing"
)
func TestExpression(t *testing.T) {
var data = []struct {
data string
expression string
}{
{"string", "([^\\s]+)"},
{"integer", "([0-9]+)"},
{"unknown", ""},
}
for _, set := range data {
exp, err := regexp.Compile(set.expression)
if err != nil {
t.Errorf("TextExpression regexp does not compile: %s", set.expression)
}
test := Expression(set.data)
if test == nil && set.expression != "" {
t.Errorf("Expression for data \"%s\" is not valid", set.data)
}
if test != nil && test.String() != exp.String() {
t.Errorf("Expression() not matching test data! got \"%s\", expected \"%s\"", test.String(), exp.String())
}
}
}
func TestParameterExpression(t *testing.T) {
var data = []struct {
name string
data string
expression string
}{
{"lorem", "string", "([^\\s]+)"},
{"ipsum", "integer", "([0-9]+)"},
}
for _, set := range data {
param := NewParameterWithType(set.name, set.data)
exp := regexp.MustCompile(set.expression)
pExp := param.Expression()
if pExp.String() != exp.String() {
t.Errorf("Expression() not matching test data! got \"%s\", expected \"%s\"", pExp.String(), exp.String())
}
}
}
func TestParse(t *testing.T) {
var data = []struct {
text string
name string
data string
}{
{"<lorem>", "lorem", "string"},
{"<ipsum:integer>", "ipsum", "integer"},
}
var param Parameter
for _, set := range data {
param = Parse(set.text)
if param.Name() != set.name {
t.Errorf("param.Name() should be \"%s\", but is \"%s\"", set.name, param.Name())
}
}
}
func TestParameter(t *testing.T) {
var data = []struct {
name string
data string
}{
{"lorem", "string"},
{"ipsum", "integer"},
}
var param Parameter
for _, set := range data {
param = NewParameterWithType(set.name, set.data)
if param.Name() != set.name {
t.Errorf("param.Name() should be \"%s\", but is \"%s\"", set.name, param.Name())
}
}
}