-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_test.go
More file actions
80 lines (62 loc) · 2.03 KB
/
node_test.go
File metadata and controls
80 lines (62 loc) · 2.03 KB
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
package routing
import (
"regexp"
"testing"
)
func TestNode_RegexpToString_Works(t *testing.T) {
node1 := node{t: nodeTypeStatic}
if node1.regexpToString() != "" {
t.Errorf("node Type static returns invalid string")
}
node2 := node{t: nodeTypeDynamic, regexp: nil}
if node2.regexpToString() != "" {
t.Errorf("node without reg expression returns invalid string")
}
node3 := node{t: nodeTypeDynamic, regexp: regexp.MustCompile("[0-9]+")}
if node3.regexpToString() != "[0-9]+" {
t.Errorf("node with regular expression returns invalid string")
}
}
func TestNode_IsCatchAll_Works(t *testing.T) {
node1 := node{t: nodeTypeStatic}
if node1.isCatchAll() {
t.Errorf("node Type static is catch all")
}
node2 := node{t: nodeTypeDynamic, regexp: nil}
if node2.isCatchAll() {
t.Errorf("node without reg expression is catch all")
}
node3 := node{t: nodeTypeDynamic, regexp: regexp.MustCompile("[0-9]+")}
if node3.isCatchAll() {
t.Errorf("node with no catch all regexp is catch all")
}
node4 := node{t: nodeTypeDynamic, regexp: regexp.MustCompile(catchAllExpression)}
if !node4.isCatchAll() {
t.Errorf("node with valid catch all expression is not catch all")
}
}
func TestNode_RegexpEquals_Works(t *testing.T) {
node1 := node{t: nodeTypeDynamic, regexp: regexp.MustCompile("[a-z]+")}
node2 := node{t: nodeTypeDynamic, regexp: regexp.MustCompile("[0-9]+")}
node3 := node{t: nodeTypeDynamic, regexp: regexp.MustCompile("[0-9]+")}
if node1.regexpEquals(&node2) {
t.Errorf("node1 is equal to node 2")
}
if !node2.regexpEquals(&node3) {
t.Errorf("node2 is not equal to node 3")
}
}
func TestNode_HasParameters_Works(t *testing.T) {
node1 := node{t: nodeTypeStatic}
node2 := node{t: nodeTypeDynamic, parent: &node1, regexp: regexp.MustCompile("[0-9]+")}
node3 := node{t: nodeTypeStatic, parent: &node2}
if node1.hasParameters() != false {
t.Errorf("node1 has parameters")
}
if node2.hasParameters() != true {
t.Errorf("node2 has no parameters")
}
if node3.hasParameters() != true {
t.Errorf("node3 has no parameters")
}
}