-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_test.go
85 lines (80 loc) · 2.26 KB
/
path_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
package bond
import "testing"
func TestConvertXPathToJSPath(t *testing.T) {
tests := map[string]struct {
input string
expected string
}{
"Simple path": {
input: "/interfaces/interface",
expected: ".interfaces.interface",
},
"Path with hyphens": {
input: "/system-config/hostname",
expected: ".system-config.hostname",
},
"Path with list node": {
input: "/interfaces/interface[name=eth0]",
expected: ".interfaces.interface{.name==\"eth0\"}",
},
"Complex path": {
input: "/network-instances/network-instance[name=default]/protocols/protocol[name=BGP]/bgp",
expected: ".network-instances.network-instance{.name==\"default\"}.protocols.protocol{.name==\"BGP\"}.bgp",
},
"Empty input": {
input: "",
expected: "",
},
"Input with multiple list nodes": {
input: "/a/b[x=1]/c[y=2]/d[z=3]",
expected: ".a.b{.x==\"1\"}.c{.y==\"2\"}.d{.z==\"3\"}",
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
result := convertXPathToJSPath(tt.input)
if result != tt.expected {
t.Errorf("convertXPathToJSPath(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}
func TestConvertJSPathToXPath(t *testing.T) {
tests := map[string]struct {
input string
expected string
}{
"Simple path": {
input: ".interfaces.interface",
expected: "/interfaces/interface",
},
"Path with hyphens": {
input: ".system-config.hostname",
expected: "/system-config/hostname",
},
"Path with list node": {
input: ".interfaces.interface{.name==\"eth0\"}",
expected: "/interfaces/interface[name=eth0]",
},
"Complex path": {
input: ".network-instances.network-instance{.name==\"default\"}.protocols.protocol{.name==\"BGP\"}.bgp",
expected: "/network-instances/network-instance[name=default]/protocols/protocol[name=BGP]/bgp",
},
"Empty input": {
input: "",
expected: "",
},
"Input with multiple list nodes": {
input: ".a.b{.x==\"1\"}.c{.y==\"2\"}.d{.z==\"3\"}",
expected: "/a/b[x=1]/c[y=2]/d[z=3]",
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
result := convertJSPathToXPath(tt.input)
if result != tt.expected {
t.Errorf("convertJSPathToXPath(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}