xml object test
This commit is contained in:
1 parent
a5766c41ce
commit
b59a0797c9
2 files changed
+38
-3
No files matched your search
@@ -69,20 +69,21 @@ class XmlObject
|
|||||||
|
|
||||||
for i = 0 to node.children.count() - 1
|
for i = 0 to node.children.count() - 1
|
||||||
child = node.children[i]
|
child = node.children[i]
|
||||||
|
childIsString = IsString(child)
|
||||||
if i = 0
|
if i = 0
|
||||||
if not IsString(child)
|
if not childIsString
|
||||||
xmlString += `\n`
|
xmlString += `\n`
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if IsString(child)
|
if childIsString
|
||||||
xmlString += m.XmlEscape(child)
|
xmlString += m.XmlEscape(child)
|
||||||
else
|
else
|
||||||
xmlString += m.NodeToXmlString(child, indentLevel + 1)
|
xmlString += m.NodeToXmlString(child, indentLevel + 1)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if i = node.children.count() - 1
|
if i = node.children.count() - 1
|
||||||
if not IsString(child)
|
if not childIsString
|
||||||
xmlString += `${indentString}`
|
xmlString += `${indentString}`
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
namespace Tests
|
||||||
|
|
||||||
|
@suite
|
||||||
|
class XmlObjectTests extends Rooibos.BaseTestSuite
|
||||||
|
|
||||||
|
@describe("XmlObject")
|
||||||
|
|
||||||
|
@it("creates valid XML")
|
||||||
|
function _()
|
||||||
|
xml = new XmlObject()
|
||||||
|
if xml.Node("Person", { "name": `John "Joker" Doe`, "age": 30 })
|
||||||
|
xml.EmptyNode("Address", { "street": "123 Main St", "city": "Anytown", "state": "NY" })
|
||||||
|
if xml.Node("Metadata")
|
||||||
|
xml.TextNode("Data", "Some data")
|
||||||
|
xml.End()
|
||||||
|
end if
|
||||||
|
xml.End()
|
||||||
|
end if
|
||||||
|
|
||||||
|
expected = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Person age="30" name="John "Joker" Doe">
|
||||||
|
<Address city="Anytown" state="NY" street="123 Main St" />
|
||||||
|
<Metadata>
|
||||||
|
<Data>Some data</Data>
|
||||||
|
</Metadata>
|
||||||
|
</Person>
|
||||||
|
`
|
||||||
|
|
||||||
|
m.assertEqual(xml.ToXmlString(), expected)
|
||||||
|
end function
|
||||||
|
|
||||||
|
end class
|
||||||
|
|
||||||
|
end namespace
|
||||||
Reference in new issue
Block a user