Feature/xmltree additions (#20988)

* [change] add/insert/delete family of xmltree expanded with several variations. Added replace methods family

* [change] Lifted child limitations on insert methods (consulted with @araq)

* [tests] add/insert/replace/delete of xmltree XmlNodes tests added
This commit is contained in:
Michael Voronin 2022-12-22 10:32:12 +03:00 • committed by GitHub
commit 7931bdac95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 552 additions and 3 deletions

51
tests/xml/ttree_add.nim Normal file
View file

@ -0,0 +1,51 @@
discard """
output: '''
<body>
<div>Some text in body</div>
<div>Some more text in body </div>
</body>
<xml>
<head>
<div>Some text</div>
<div>Some more text </div>
</head>
<body>
<div>Some text in body</div>
<div>Some more text in body </div>
</body>
</xml>
'''
"""
# Test xmltree add/insert/delete/replace operations
import xmlparser
import xmltree
var baseDocHead = """
<xml>
<head>
<div>Some text</div>
<div>Some more text </div>
</head>
</xml>
"""
var baseDocHeadTree = parseXml(baseDocHead)
var baseDocBody = """
<body>
<div>Some text in body</div>
<div>Some more text in body </div>
</body>
"""
var baseDocBodyTree = parseXml(baseDocBody)
proc test_add() =
var testDoc = baseDocHeadTree
var newBody = newElement("body")
for item in baseDocBodyTree.items():
newBody.add(item)
echo $newBody
testDoc.add(newBody)
echo $testDoc
test_add()