require "libxml" require 'test/unit' class TC_XML_Document_Write3 < Test::Unit::TestCase def setup() @doc = XML::Document.new('1.0') assert_instance_of(XML::Document, @doc) @doc.root = XML::Node.new('rubynet') end def teardown() @doc = nil end def test_ruby_xml_document_write_child() xml = "\n\n \n\n" @doc.root.child = XML::Node.new('pkg') assert_equal(xml, @doc.to_s) end def test_ruby_xml_document_write_content_append() xml = "\n" xml << "\n" xml << " \n" xml << " \n" xml << " libxml\n" xml << " \n" xml << " \n" xml << "\n" pkg = @doc.root.child = XML::Node.new('pkg') meta = pkg.child = XML::Node.new('meta') assert_equal meta, meta << (pkgname = XML::Node.new('pkgname')) pkgname << 'libxml' assert_equal(xml, @doc.to_s) end def test_ruby_xml_document_write_node_search_href() prefix = 'xlink' uri = 'http://www.rubynet.org' xml = "\n" xml << "\n" xml << " \n" xml << "\n" @doc = XML::Parser.string(xml).parse assert_equal(xml, @doc.to_s) ns = @doc.root.search_href(uri) assert_instance_of(XML::NS, ns) assert_equal(uri, ns.href) assert_equal(prefix, ns.prefix) end def test_ruby_xml_document_write_sibling() xml = "\n\n \n \n\n" child = @doc.root.child = XML::Node.new('pkg') assert_instance_of(XML::Node, child) child.sibling = XML::Node.new('pkg2') assert_equal(xml, @doc.to_s) end def test_ruby_xml_document_write_set_doc_property() xml = "\n" xml << "\n" xml << " \n" xml << "\n" @doc['xmlns:xlink'] = "http://www.w3.org/1999/xlink" pkg = @doc.root.child = XML::Node.new('pkg') assert_equal(xml, @doc.to_s) end def test_ruby_xml_document_write_set_node_base() xml = "\n" xml << "\n" xml << " \n" xml << "\n" pkg = @doc.root.child = XML::Node.new('pkg') pkg.base = 'http://www.rubynet.org/' assert_equal(xml, @doc.to_s) end def test_ruby_xml_document_write_set_node_property() xml = "\n" xml << "\n" xml << " \n" xml << " \n" xml << " libxml\n" xml << " \n" xml << " \n" xml << "\n" @doc.root['xmlns:xlink'] = "http://www.w3.org/1999/xlink" pkg = @doc.root.child = XML::Node.new('pkg') pkg['version'] = '1.0' meta = pkg.child = XML::Node.new('meta') pkgname = meta.child = XML::Node.new('pkgname', 'libxml') assert_equal(xml, @doc.to_s) end end