MCPcopy Create free account
hub / github.com/antchfx/xmlquery / TestAddAttr

Function TestAddAttr

node_test.go:134–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestAddAttr(t *testing.T) {
135 for _, test := range []struct {
136 name string
137 n *Node
138 key string
139 val string
140 expected string
141 ok bool
142 }{
143 {
144 name: "node has no existing attr",
145 n: &Node{Type: AttributeNode},
146 key: "ns:k1",
147 val: "v1",
148 expected: `< ns:k1="v1"></>`,
149 ok: true,
150 },
151 {
152 name: "node has existing attrs",
153 n: &Node{Type: AttributeNode, Attr: []Attr{{Name: xml.Name{Local: "k1"}, Value: "v1"}}},
154 key: "k2",
155 val: "v2",
156 expected: `< k1="v1" k2="v2"></>`,
157 ok: true,
158 },
159 {
160 name: "node already has existing attr",
161 n: &Node{Type: AttributeNode, Attr: []Attr{{Name: xml.Name{Local: "k1"}, Value: "v1"}}},
162 key: "k1",
163 val: "v1",
164 expected: `< k1="v1"></>`,
165 ok: false,
166 },
167 } {
168 t.Run(test.name, func(t *testing.T) {
169 ok := AddAttr(test.n, test.key, test.val)
170 testTrue(t, ok == test.ok)
171 testValue(t, test.n.OutputXML(true), test.expected)
172 })
173 }
174}
175
176func TestSetAttr(t *testing.T) {
177 for _, test := range []struct {

Callers

nothing calls this directly

Calls 4

AddAttrFunction · 0.85
testTrueFunction · 0.85
testValueFunction · 0.85
OutputXMLMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…