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

Function TestSetAttr

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

Source from the content-addressed store, hash-verified

174}
175
176func TestSetAttr(t *testing.T) {
177 for _, test := range []struct {
178 name string
179 n *Node
180 key string
181 val string
182 expected string
183 ok bool
184 }{
185 {
186 name: "node has no existing attr",
187 n: &Node{Type: AttributeNode},
188 key: "ns:k1",
189 val: "v1",
190 expected: `< ns:k1="v1"></>`,
191 ok: true,
192 },
193 {
194 name: "node has an existing attr, overwriting",
195 n: &Node{Type: AttributeNode, Attr: []Attr{{Name: xml.Name{Space: "ns", Local: "k1"}, Value: "v1"}}},
196 key: "ns:k1",
197 val: "v2",
198 expected: `< ns:k1="v2"></>`,
199 ok: true,
200 },
201 {
202 name: "node has no existing attr, no ns",
203 n: &Node{Type: AttributeNode},
204 key: "k1",
205 val: "v1",
206 expected: `< k1="v1"></>`,
207 ok: true,
208 },
209 {
210 name: "node has an existing attr, no ns, overwriting",
211 n: &Node{Type: AttributeNode, Attr: []Attr{{Name: xml.Name{Local: "k1"}, Value: "v1"}}},
212 key: "k1",
213 val: "v2",
214 expected: `< k1="v2"></>`,
215 ok: true,
216 },
217 } {
218
219 t.Run(test.name, func(t *testing.T) {
220 ok := test.n.SetAttr(test.key, test.val)
221 testTrue(t, ok == test.ok)
222 testValue(t, test.n.OutputXML(true), test.expected)
223 })
224 }
225}
226
227func TestRemoveAttr(t *testing.T) {
228 for _, test := range []struct {

Callers

nothing calls this directly

Calls 4

testTrueFunction · 0.85
testValueFunction · 0.85
SetAttrMethod · 0.80
OutputXMLMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…