Beispiel #1
0
func TestDocumentCreateElement(t *testing.T) {
	d, _ := dom.ParseString(`<foo></foo>`)
	ne := d.CreateElement("child")
	if ne.NodeName() != "child" {
		t.Errorf("document.CreateNode('child') did not create a <child> Element")
	}
}
Beispiel #2
0
func TestDocumentElementTagName(t *testing.T) {
	d, _ := dom.ParseString("<foo></foo>")
	root := d.DocumentElement().(dom.Element)
	if root.TagName() != "foo" {
		t.Errorf("Element.tagName not set correctly")
	}
}
Beispiel #3
0
func TestNodeDocumentChildNodeIsRoot(t *testing.T) {
	d, _ := dom.ParseString(`<foo></foo>`)
	root := d.DocumentElement().(dom.Node)
	if d.ChildNodes().Item(0) != root {
		t.Errorf("document.ChildNodes().Item(0) is not the documentElement")
	}
}
Beispiel #4
0
// Element.nodeType should be 1
func TestElementNodeType(t *testing.T) {
	d, _ := dom.ParseString("<foo></foo>")
	root := d.DocumentElement()
	if root.NodeType() != 1 {
		t.Errorf("Element.nodeType not equal to 1")
	}
}
Beispiel #5
0
func TestElementNodeValue(t *testing.T) {
	d, _ := dom.ParseString("<foo></foo>")
	root := d.DocumentElement()
	if root.NodeValue() != "" {
		t.Errorf("Element.nodeValue not empty")
	}
}
Beispiel #6
0
func TestElementGetAttribute(t *testing.T) {
	d, _ := dom.ParseString("<foo bar='baz'></foo>")
	root := d.DocumentElement()
	if root.GetAttribute("bar") != "baz" {
		t.Errorf("Element.getAttribute() did not return the attribute value")
	}
}
Beispiel #7
0
func TestAttributesNamedNodeMapSetNamedItem(t *testing.T) {
	d, _ := dom.ParseString(`<parent attr1="val1" attr2="val2"></parent>`)
	r := d.DocumentElement()
	attrs := r.Attributes()

	attr2 := d.CreateAttribute("attr2")
	attr2Returned := attrs.SetNamedItem(attr2)
	if attr2Returned == nil {
		t.Errorf("NamedNodeMap.setNamedItem(attr2) returned nil")
	}
	if attr2Returned == attr2 {
		t.Errorf("NamedNodeMap.setNamedItem(attr2) returned attr2")
	}
	if r.GetAttribute("attr2") != "" {
		t.Errorf("attr2 was not empty")
	}

	attr3 := d.CreateAttribute("attr3")
	attr3Returned := attrs.SetNamedItem(attr3)
	if attr3Returned != nil {
		t.Errorf("NamedNodeMap.setNamedItem(attr3) did not return nil")
	}
	if r.GetAttribute("attr3") != "" {
		t.Errorf("attr3 was not empty")
	}
	if r.Attributes().Length() != 3 {
		t.Errorf("Did not have 3 attributes")
	}
}
Beispiel #8
0
// Document.documentElement should return an object implementing Element
func TestDocumentElementIsAnElement(t *testing.T) {
	d, _ := dom.ParseString("<foo></foo>")
	n, ok := (d.DocumentElement()).(dom.Element)
	if !ok || n.NodeType() != 1 {
		t.Errorf("Document.documentElement did not return an Element")
	}
}
Beispiel #9
0
func TestElementRemoveAttribute(t *testing.T) {
	d, _ := dom.ParseString(`<parent attr="val"/>`)
	r := d.DocumentElement()
	r.RemoveAttribute("attr")
	if r.GetAttribute("attr") != "" {
		t.Errorf("Element.RemoveAttribute() did not remove the attribute, GetAttribute() returns '%s'", r.GetAttribute("attr"))
	}
}
Beispiel #10
0
func TestCharacterDataGetData(t *testing.T) {
	d, _ := dom.ParseString(`<parent>foo</parent>`)
	r := d.DocumentElement()
	cdata := r.ChildNodes().Item(0).(dom.Text)
	if cdata.GetData() != "foo" {
		t.Errorf("CharacterData.data not correct")
	}
}
Beispiel #11
0
func TestTextNodeName(t *testing.T) {
	d, _ := dom.ParseString(`<parent>mom</parent>`)
	r := d.DocumentElement()
	txt := r.ChildNodes().Item(0)
	if txt.NodeName() != "#text" {
		t.Errorf("Did not get #text for nodeName of a text node")
	}
}
Beispiel #12
0
func TestAttrGetValue(t *testing.T) {
	d, _ := dom.ParseString(`<parent attr1="val1"/>`)
	r := d.DocumentElement()

	if r.Attributes().Item(0).(dom.Attr).GetValue() != "val1" {
		t.Errorf("Attr.GetValue() did not return the proper value")
	}
}
Beispiel #13
0
func TestAttrNodeName(t *testing.T) {
	d, _ := dom.ParseString(`<parent attr1="val"/>`)
	r := d.DocumentElement()

	if r.Attributes().Item(0).NodeName() != "attr1" {
		t.Errorf("Element.attributes().item(0).NodeName() did not return the proper value")
	}
}
Beispiel #14
0
func TestCharacterDataLength(t *testing.T) {
	d, _ := dom.ParseString(`<parent>foo</parent>`)
	r := d.DocumentElement()
	cdata := r.ChildNodes().Item(0).(dom.Text)
	if cdata.Length() != 3 {
		t.Errorf("CharacterData.length not correct")
	}
}
Beispiel #15
0
func TestTextNodeType(t *testing.T) {
	d, _ := dom.ParseString(`<parent>mom</parent>`)
	r := d.DocumentElement()
	txt := r.ChildNodes().Item(0)
	if txt.NodeType() != 3 {
		t.Errorf("Did not get the correct node type for a text node")
	}
}
Beispiel #16
0
func TestElementSetAttributeNodeAlreadyOwned(t *testing.T) {
	d1, _ := dom.ParseString(`<foo attr1="val1"/>`)
	d2, _ := dom.ParseString(`<foo/>`)

	r1 := d1.DocumentElement()
	r2 := d2.DocumentElement()

	attr1 := r1.GetAttributeNode("attr1")

	r2.SetAttributeNode(attr1)

	if r1.Attributes().Length() != 1 {
		t.Errorf("Root 1 lost an attribute")
	}
	if r2.Attributes().Length() != 0 {
		t.Errorf("Root 2 gained an attribute")
	}
}
Beispiel #17
0
func TestAttrOwnerElement(t *testing.T) {
	d, _ := dom.ParseString(`<parent attr1="val1"/>`)
	r := d.DocumentElement()
	a := r.GetAttributeNode("attr1")

	if a.OwnerElement() != r {
		t.Errorf("a.OwnerElement() not set to the owner element")
	}
}
Beispiel #18
0
func TestAppendChildParent(t *testing.T) {
	d, _ := dom.ParseString(`<parent></parent>`)
	root := d.DocumentElement()
	ne := d.CreateElement("child")
	root.AppendChild(ne)
	if ne.ParentNode() != root.(dom.Node) {
		t.Errorf("Node.appendChild() did not set the parent node")
	}
}
Beispiel #19
0
func TestNodeListLength(t *testing.T) {
	d, _ := dom.ParseString(`<foo><bar></bar><baz></baz></foo>`)
	root := d.DocumentElement()
	children := root.ChildNodes()
	l := int(children.Length())
	if l != 2 {
		t.Errorf("NodeList.length did not return the correct number of children (" + strconv.Itoa(l) + " instead of 2)")
	}
}
Beispiel #20
0
func TestNodeListItemForNull(t *testing.T) {
	d, _ := dom.ParseString(`<foo><bar></bar><baz></baz></foo>`)
	root := d.DocumentElement()
	children := root.ChildNodes()
	if children.Item(2) != nil ||
		children.Item(100000) != nil {
		t.Errorf("NodeList.item(i) did not return nil")
	}
}
Beispiel #21
0
func TestNodeListItem(t *testing.T) {
	d, _ := dom.ParseString(`<foo><bar></bar><baz></baz></foo>`)
	root := d.DocumentElement()
	children := root.ChildNodes()
	if children.Item(1).NodeName() != "baz" ||
		children.Item(0).NodeName() != "bar" {
		t.Errorf("NodeList.item(i) did not return the correct child")
	}
}
Beispiel #22
0
func TestTextNodeValue(t *testing.T) {
	d, _ := dom.ParseString(`<parent>mom</parent>`)
	r := d.DocumentElement()
	txt := r.ChildNodes().Item(0)
	nval := txt.NodeValue()
	if nval != "mom" {
		t.Errorf("Did not get the correct node value for a text node (got %#v)", nval)
	}
}
Beispiel #23
0
func TestNodeParentNodeOnRoot(t *testing.T) {
	d, _ := dom.ParseString(`<foo></foo>`)

	root := d.DocumentElement().(dom.Node)

	if root.ParentNode() != d.(dom.Node) {
		t.Errorf("documentElement.ParentNode() did not return the document")
	}
}
Beispiel #24
0
func TestElementSetAttributeNode(t *testing.T) {
	d, _ := dom.ParseString(`<foo/>`)
	root := d.DocumentElement()
	newAttr := d.CreateAttribute("attr1")

	root.SetAttributeNode(newAttr)
	if root.Attributes().Length() != 1 {
		t.Errorf("Element.attributes.length not 1")
	}
}
Beispiel #25
0
func TestAttrSetValue(t *testing.T) {
	d, _ := dom.ParseString(`<parent attr1="val1"/>`)
	r := d.DocumentElement()
	a := r.Attributes().Item(0).(dom.Attr)
	a.SetValue("foo")

	if a.GetValue() != "foo" {
		t.Errorf("Attr.SetValue() did not work")
	}
}
Beispiel #26
0
func TestAttributesOnElement(t *testing.T) {
	d, _ := dom.ParseString(`<parent attr1="val" attr2="val"><child></child></parent>`)
	r := d.DocumentElement()
	c := r.ChildNodes().Item(0)

	if r.Attributes() == nil || r.Attributes().Length() != 2 ||
		c.Attributes() == nil || c.Attributes().Length() != 0 {
		t.Errorf("Element.attributes().length did not return the proper value")
	}
}
Beispiel #27
0
func TestToXml(t *testing.T) {
	d1, _ := dom.ParseString(`<parent attr="val">mom<foo/></parent>`)
	s := dom.ToXml(d1)
	d2, _ := dom.ParseString(s)
	r2 := d2.DocumentElement()

	if r2.NodeName() != "parent" {
		t.Errorf("r2 nodeName != parent")
	}
	if r2.GetAttribute("attr") != "val" {
		t.Errorf("r2 attribute value != val")
	}
	if r2.ChildNodes().Length() != 2 {
		t.Errorf("r2.childNodes.length != 2")
	}
	if r2.ChildNodes().Item(0).NodeValue() != "mom" {
		t.Errorf("First text node value != 'mom', it was '%s' instead", r2.ChildNodes().Item(0).NodeValue())
	}
}
Beispiel #28
0
func TestNodeLastChild(t *testing.T) {
	d, _ := dom.ParseString(`<parent><child0/><child1/><child2/></parent>`)
	r := d.DocumentElement()
	children := r.ChildNodes()
	child2 := children.Item(2)
	if child2.LastChild() != nil {
		t.Errorf("Node.lastChild did not return null on an empty node")
	} else if r.LastChild() != child2 {
		t.Errorf("Node.lastChild did not return the last child")
	}
}
Beispiel #29
0
func TestAppendChild(t *testing.T) {
	d, _ := dom.ParseString(`<parent></parent>`)
	root := d.DocumentElement()
	ne := d.CreateElement("child").(dom.Node)
	appended := root.AppendChild(ne)
	if appended != ne ||
		root.ChildNodes().Length() != 1 ||
		root.ChildNodes().Item(0) != ne {
		t.Errorf("Node.appendChild() did not add the new element")
	}
}
Beispiel #30
0
func TestAttributesNamedNodeMapLive(t *testing.T) {
	d, _ := dom.ParseString(`<parent attr1="val1" attr2="val2"></parent>`)
	r := d.DocumentElement()
	attrs := r.Attributes()
	n2 := attrs.Length()
	r.SetAttribute("attr3", "val3")
	n3 := attrs.Length()
	if n2 != 2 || n3 != 3 {
		t.Errorf("NamedNodeMap via Node.Attributes() was not live")
	}
}