@@ -250,7 +250,7 @@ func TestRemoveFromTree(t *testing.T) {
250250 testTrue (t , n != nil )
251251 RemoveFromTree (n )
252252 verifyNodePointers (t , doc )
253- testValue (t , doc .OutputXML ( false ),
253+ testValue (t , doc .OutputXMLWithOptions ( WithoutPreserveSpace () ),
254254 `<?procinst?><!--comment--><aaa><bbb></bbb><ddd></ddd><ggg></ggg></aaa>` )
255255 })
256256
@@ -260,7 +260,7 @@ func TestRemoveFromTree(t *testing.T) {
260260 testTrue (t , n != nil )
261261 RemoveFromTree (n )
262262 verifyNodePointers (t , doc )
263- testValue (t , doc .OutputXML ( false ),
263+ testValue (t , doc .OutputXMLWithOptions ( WithoutPreserveSpace () ),
264264 `<?procinst?><!--comment--><aaa><ddd><eee><fff></fff></eee></ddd><ggg></ggg></aaa>` )
265265 })
266266
@@ -270,7 +270,7 @@ func TestRemoveFromTree(t *testing.T) {
270270 testTrue (t , n != nil )
271271 RemoveFromTree (n )
272272 verifyNodePointers (t , doc )
273- testValue (t , doc .OutputXML ( false ),
273+ testValue (t , doc .OutputXMLWithOptions ( WithoutPreserveSpace () ),
274274 `<?procinst?><!--comment--><aaa><bbb></bbb><ggg></ggg></aaa>` )
275275 })
276276
@@ -280,7 +280,7 @@ func TestRemoveFromTree(t *testing.T) {
280280 testTrue (t , n != nil )
281281 RemoveFromTree (n )
282282 verifyNodePointers (t , doc )
283- testValue (t , doc .OutputXML ( false ),
283+ testValue (t , doc .OutputXMLWithOptions ( WithoutPreserveSpace () ),
284284 `<?procinst?><!--comment--><aaa><bbb></bbb><ddd><eee><fff></fff></eee></ddd></aaa>` )
285285 })
286286
@@ -290,7 +290,7 @@ func TestRemoveFromTree(t *testing.T) {
290290 testValue (t , procInst .Type , DeclarationNode )
291291 RemoveFromTree (procInst )
292292 verifyNodePointers (t , doc )
293- testValue (t , doc .OutputXML ( false ),
293+ testValue (t , doc .OutputXMLWithOptions ( WithoutPreserveSpace () ),
294294 `<!--comment--><aaa><bbb></bbb><ddd><eee><fff></fff></eee></ddd><ggg></ggg></aaa>` )
295295 })
296296
@@ -300,19 +300,44 @@ func TestRemoveFromTree(t *testing.T) {
300300 testValue (t , commentNode .Type , CommentNode )
301301 RemoveFromTree (commentNode )
302302 verifyNodePointers (t , doc )
303- testValue (t , doc .OutputXML ( false ),
303+ testValue (t , doc .OutputXMLWithOptions ( WithoutPreserveSpace () ),
304304 `<?procinst?><aaa><bbb></bbb><ddd><eee><fff></fff></eee></ddd><ggg></ggg></aaa>` )
305305 })
306306
307307 t .Run ("remove call on root does nothing" , func (t * testing.T ) {
308308 doc := parseXML ()
309309 RemoveFromTree (doc )
310310 verifyNodePointers (t , doc )
311- testValue (t , doc .OutputXML ( false ),
311+ testValue (t , doc .OutputXMLWithOptions ( WithoutPreserveSpace () ),
312312 `<?procinst?><!--comment--><aaa><bbb></bbb><ddd><eee><fff></fff></eee></ddd><ggg></ggg></aaa>` )
313313 })
314314}
315315
316+ func TestAddImmediateSibling (t * testing.T ) {
317+ s := `<?xml version="1.0" encoding="UTF-8"?>
318+ <AAA>
319+ <BBB id="1"/>
320+ <CCC id="2">
321+ <DDD/>
322+ </CCC>
323+ <CCC id="3">
324+ <DDD/>
325+ </CCC>
326+ </AAA>`
327+ root , err := Parse (strings .NewReader (s ))
328+ if err != nil {
329+ t .Error (err )
330+ }
331+
332+ aaa := findNode (root , "AAA" )
333+ n := aaa .SelectElement ("BBB" )
334+ if n == nil {
335+ t .Fatalf ("n is nil" )
336+ }
337+ AddImmediateSibling (n , & Node {Type : ElementNode , Data : "r" })
338+ testValue (t , root .OutputXMLWithOptions (WithoutPreserveSpace ()), `<?xml version="1.0" encoding="UTF-8"?><AAA><BBB id="1"></BBB><r></r><CCC id="2"><DDD></DDD></CCC><CCC id="3"><DDD></DDD></CCC></AAA>` )
339+ }
340+
316341func TestSelectElement (t * testing.T ) {
317342 s := `<?xml version="1.0" encoding="UTF-8"?>
318343 <AAA>
@@ -497,7 +522,6 @@ func TestWriteWithNamespacePrefix(t *testing.T) {
497522 }
498523}
499524
500-
501525func TestQueryWithPrefix (t * testing.T ) {
502526 s := `<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body test="1"><ns2:Fault xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="http://www.w3.org/2003/05/soap-envelope"><faultcode>ns2:Client</faultcode><faultstring>This is a client fault</faultstring></ns2:Fault></S:Body></S:Envelope>`
503527 doc , _ := Parse (strings .NewReader (s ))
@@ -582,7 +606,7 @@ func TestOutputXMLWithSpaceDirect(t *testing.T) {
582606 t .Errorf (`expected "%s", obtained "%s"` , expected , g )
583607 }
584608
585- output := html .UnescapeString (doc .OutputXML ( true ))
609+ output := html .UnescapeString (doc .OutputXMLWithOptions ( WithOutputSelf (), WithoutPreserveSpace () ))
586610 if strings .Contains (output , "\n " ) {
587611 t .Errorf ("the outputted xml contains newlines" )
588612 }
@@ -606,7 +630,7 @@ func TestOutputXMLWithSpaceOverwrittenToPreserve(t *testing.T) {
606630 t .Errorf (`expected "%s", obtained "%s"` , expected , g )
607631 }
608632
609- output := html .UnescapeString (doc .OutputXML ( true ))
633+ output := html .UnescapeString (doc .OutputXMLWithOptions ( WithOutputSelf (), WithoutPreserveSpace () ))
610634 if strings .Contains (output , "\n " ) {
611635 t .Errorf ("the outputted xml contains newlines" )
612636 }
@@ -680,8 +704,8 @@ func TestOutputXMLWithPreserveSpaceOption(t *testing.T) {
680704 </student>
681705 </class_list>`
682706 doc , _ := Parse (strings .NewReader (s ))
683- resultWithSpace := doc .OutputXMLWithOptions (WithPreserveSpace () )
684- resultWithoutSpace := doc .OutputXMLWithOptions ()
707+ resultWithSpace := doc .OutputXMLWithOptions ()
708+ resultWithoutSpace := doc .OutputXMLWithOptions (WithoutPreserveSpace () )
685709 if ! strings .Contains (resultWithSpace , "> Robert <" ) {
686710 t .Errorf ("output was not expected. expected %v but got %v" , " Robert " , resultWithSpace )
687711 }
0 commit comments