libxml-ruby-3.1.0/ 0000755 0000041 0000041 00000000000 13312105254 014005 5 ustar www-data www-data libxml-ruby-3.1.0/test/ 0000755 0000041 0000041 00000000000 13312105254 014764 5 ustar www-data www-data libxml-ruby-3.1.0/test/test_node_edit.rb 0000644 0000041 0000041 00000011014 13312105254 020277 0 ustar www-data www-data # encoding: UTF-8
require File.expand_path('../test_helper', __FILE__)
class TestNodeEdit < Minitest::Test
def setup
xp = XML::Parser.string('onetwothree')
@doc = xp.parse
end
def teardown
@doc = nil
end
def first_node
@doc.root.child
end
def second_node
first_node.next
end
def third_node
second_node.next
end
def test_add_next_01
first_node.next = XML::Node.new('num', 'one-and-a-half')
assert_equal('oneone-and-a-halftwothree',
@doc.root.to_s.gsub(/\n\s*/,''))
end
def test_add_next_02
second_node.next = XML::Node.new('num', 'two-and-a-half')
assert_equal('onetwotwo-and-a-halfthree',
@doc.root.to_s.gsub(/\n\s*/,''))
end
def test_add_next_03
third_node.next = XML::Node.new('num', 'four')
assert_equal 'onetwothreefour',
@doc.root.to_s.gsub(/\n\s*/,'')
end
def test_add_prev_01
first_node.prev = XML::Node.new('num', 'half')
assert_equal 'halfonetwothree',
@doc.root.to_s.gsub(/\n\s*/,'')
end
def test_add_prev_02
second_node.prev = XML::Node.new('num', 'one-and-a-half')
assert_equal 'oneone-and-a-halftwothree',
@doc.root.to_s.gsub(/\n\s*/,'')
end
def test_add_prev_03
third_node.prev = XML::Node.new('num', 'two-and-a-half')
assert_equal 'onetwotwo-and-a-halfthree',
@doc.root.to_s.gsub(/\n\s*/,'')
end
def test_remove_node
first_node.remove!
assert_equal('twothree',
@doc.root.to_s.gsub(/\n\s*/,''))
end
def test_remove_node_gc
xp = XML::Parser.string('onetwothree')
doc = xp.parse
doc.root.child.remove!
GC.start
refute_nil(doc)
end
def test_remove_node_iteration
nodes = Array.new
@doc.root.each_element do |node|
if node.name == 'num'
nodes << node
node.remove!
end
end
assert_equal(3, nodes.length)
end
def test_reuse_removed_node
# Remove the node
node = @doc.root.first.remove!
refute_nil(node)
# Add it to the end of the document
@doc.root.last.next = node
assert_equal('twothreeone',
@doc.root.to_s.gsub(/\n\s*/,''))
end
def test_append_existing_node
doc = XML::Parser.string('abfirstsecondcd').parse
node1 = doc.find_first('//two')
doc.root << node1
assert_equal('abfirstcdsecond',
doc.root.to_s)
end
def test_wrong_doc
doc1 = XML::Parser.string('').parse
doc2 = XML::Parser.string('').parse
node = doc1.root.child
error = assert_raises(XML::Error) do
doc2.root << node
end
GC.start
assert_equal(' Nodes belong to different documents. You must first import the node by calling XML::Document.import.',
error.to_s)
end
# This test is to verify that an earlier reported bug has been fixed
def test_merge
documents = []
# Read in 500 documents
500.times do
documents << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
end
master_doc = documents.shift
documents.each do |child_doc|
master_body = master_doc.find("//body").first
child_body = child_doc.find("//body").first
child_element = child_body.detect do |node|
node.element?
end
master_body << child_element.copy(true)
end
end
def test_append_chain
node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
assert_equal('bars contents',
node.to_s)
end
def test_set_base
@doc.root.base_uri = 'http://www.rubynet.org/'
assert_equal("\n one\n two\n three\n",
@doc.root.to_s)
end
end
libxml-ruby-3.1.0/test/test_node_xlink.rb 0000644 0000041 0000041 00000001411 13312105254 020477 0 ustar www-data www-data # encoding: UTF-8
# $Id$
require File.expand_path('../test_helper', __FILE__)
class TC_XML_Node_XLink < Minitest::Test
def setup()
xp = XML::Parser.string('one')
doc = xp.parse
assert_instance_of(XML::Document, doc)
@root = doc.root
assert_instance_of(XML::Node, @root)
end
def teardown()
@root = nil
end
def test_xml_node_xlink()
for elem in @root.find('fixnum')
assert_instance_of(XML::Node, elem)
assert_instance_of(TrueClass, elem.xlink?)
assert_equal("simple", elem.xlink_type_name)
assert_equal(XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type)
end
end
end
libxml-ruby-3.1.0/test/test_namespaces.rb 0000644 0000041 0000041 00000016407 13312105254 020477 0 ustar www-data www-data # encoding: UTF-8
require File.expand_path('../test_helper', __FILE__)
class TestNamespaces < Minitest::Test
def setup
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
@doc = XML::Document.file(file)
end
def teardown
@doc = nil
end
def test_namespace_node
node = @doc.root
ns = node.namespaces.namespace
assert_equal('soap', ns.prefix)
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href)
end
def test_namespace_attr
node = @doc.root
attr = node.attributes.get_attribute('encodingStyle')
assert_equal('soap', attr.ns.prefix)
assert_equal('soap', attr.namespaces.namespace.prefix)
end
def test_set_namespace_node
node = XML::Node.new('Envelope')
assert_equal('', node.to_s)
ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
assert_equal("", node.to_s)
assert_nil(node.namespaces.namespace)
# Now put the node in the soap namespace
node.namespaces.namespace = ns
refute_nil(node.namespaces.namespace)
assert_equal("", node.to_s)
end
def test_set_namespace_attribute
# Create node
node = XML::Node.new('Envelope')
assert_equal('', node.to_s)
# Create attribute
attr = XML::Attr.new(node, "encodingStyle", "http://www.w3.org/2001/12/soap-encoding")
assert_equal('',
node.to_s)
# Create namespace attribute
ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
assert_equal('',
node.to_s)
assert_nil(node.namespaces.namespace)
# Now put the node in the soap namespace
node.namespaces.namespace = ns
refute_nil(node.namespaces.namespace)
assert_equal('',
node.to_s)
# Now put the attribute in the soap namespace
attr.namespaces.namespace = ns
refute_nil(node.namespaces.namespace)
assert_equal('',
node.to_s)
end
def test_define_namespace
node = XML::Node.new('Envelope')
assert_equal('', node.to_s)
XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
assert_equal("", node.to_s)
assert_nil(node.namespaces.namespace)
end
def test_define_default_namespace
node = XML::Node.new('Envelope')
assert_equal('', node.to_s)
XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/')
assert_equal("", node.to_s)
# This seems wrong, but appears to be the way libxml works
assert_nil(node.namespaces.namespace)
end
def test_namespaces
node = @doc.find_first('//ns1:IdAndName',
:ns1 => 'http://domain.somewhere.com')
namespaces = node.namespaces.sort
assert_equal(5, namespaces.length)
namespace = namespaces[0]
assert_instance_of(XML::Namespace, namespace)
assert_nil(namespace.prefix)
assert_equal('http://services.somewhere.com', namespace.href)
namespace = namespaces[1]
assert_instance_of(XML::Namespace, namespace)
assert_equal('ns1', namespace.prefix)
assert_equal('http://domain.somewhere.com', namespace.href)
namespace = namespaces[2]
assert_instance_of(XML::Namespace, namespace)
assert_equal('soap', namespace.prefix)
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
namespace = namespaces[3]
assert_instance_of(XML::Namespace, namespace)
assert_equal('xsd', namespace.prefix)
assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
namespace = namespaces[4]
assert_instance_of(XML::Namespace, namespace)
assert_equal('xsi', namespace.prefix)
assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
end
def test_namespace_definitions
ns_defs = @doc.root.namespaces.definitions
assert_equal(3, ns_defs.size)
namespace = ns_defs[0]
assert_instance_of(XML::Namespace, namespace)
assert_equal('soap', namespace.prefix)
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
namespace = ns_defs[1]
assert_instance_of(XML::Namespace, namespace)
assert_equal('xsd', namespace.prefix)
assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
namespace = ns_defs[2]
assert_instance_of(XML::Namespace, namespace)
assert_equal('xsi', namespace.prefix)
assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
node = @doc.root.find_first('//ns:getManufacturerNamesResponse',
:ns => 'http://services.somewhere.com')
ns_defs = node.namespaces.definitions
assert_equal(1, ns_defs.size)
namespace = ns_defs[0]
assert_instance_of(XML::Namespace, namespace)
assert_nil(namespace.prefix)
assert_equal('http://services.somewhere.com', namespace.href)
end
def test_find_by_prefix
namespace = @doc.root.namespaces.find_by_prefix('soap')
assert_instance_of(XML::Namespace, namespace)
assert_equal('soap', namespace.prefix)
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
end
def test_find_default_ns
namespace = @doc.root.namespaces.find_by_prefix(nil)
assert_nil(namespace)
node = @doc.find_first('//ns1:getManufacturerNamesResponse',
:ns1 => 'http://services.somewhere.com')
namespace = node.namespaces.find_by_prefix(nil)
assert_instance_of(XML::Namespace, namespace)
assert_nil(namespace.prefix)
assert_equal('http://services.somewhere.com', namespace.href)
end
def test_find_ns_by_href
node = @doc.find_first('//ns1:getManufacturerNamesResponse',
:ns1 => 'http://services.somewhere.com')
namespace = node.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
assert_instance_of(XML::Namespace, namespace)
assert_equal('soap', namespace.prefix)
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
end
def test_default_namespace
doc = XML::Document.string('')
ns = doc.root.namespaces.default
assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
end
def test_default_prefix
doc = XML::Document.string('')
doc.root.namespaces.default_prefix = 'soap'
node = doc.root.find_first('/soap:Envelope')
refute_nil(node)
end
end
libxml-ruby-3.1.0/test/test_sax_parser.rb 0000644 0000041 0000041 00000025427 13312105254 020531 0 ustar www-data www-data # encoding: UTF-8
require File.expand_path('../test_helper', __FILE__)
require 'stringio'
class DocTypeCallback
include XML::SaxParser::Callbacks
def on_start_element(element, attributes)
end
end
class TestCaseCallbacks
include XML::SaxParser::Callbacks
attr_accessor :result
def initialize
@result = Array.new
end
def on_cdata_block(cdata)
@result << "cdata: #{cdata}"
end
def on_characters(chars)
@result << "characters: #{chars}"
end
def on_comment(text)
@result << "comment: #{text}"
end
def on_end_document
@result << "end_document"
end
def on_end_element(name)
@result << "end_element: #{name}"
end
def on_end_element_ns(name, prefix, uri)
@result << "end_element_ns #{name}, prefix: #{prefix}, uri: #{uri}"
end
# Called for parser errors.
def on_error(error)
@result << "error: #{error}"
end
def on_processing_instruction(target, data)
@result << "pi: #{target} #{data}"
end
def on_start_document
@result << "startdoc"
end
def on_start_element(name, attributes)
attributes ||= Hash.new
@result << "start_element: #{name}, attr: #{attributes.inspect}"
end
def on_start_element_ns(name, attributes, prefix, uri, namespaces)
attributes ||= Hash.new
namespaces ||= Hash.new
@result << "start_element_ns: #{name}, attr: #{attributes.inspect}, prefix: #{prefix}, uri: #{uri}, ns: #{namespaces.inspect}"
end
end
class TestSaxParser < Minitest::Test
def saxtest_file
File.join(File.dirname(__FILE__), 'model/atom.xml')
end
def verify(parser)
result = parser.callbacks.result
i = -1
assert_equal("startdoc", result[i+=1])
assert_equal("pi: xml-stylesheet type=\"text/xsl\" href=\"my_stylesheet.xsl\"", result[i+=1])
assert_equal("start_element: feed, attr: {}", result[i+=1])
assert_equal("start_element_ns: feed, attr: {}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {nil=>\"http://www.w3.org/2005/Atom\"}", result[i+=1])
assert_equal("characters: \n ", result[i+=1])
assert_equal("comment: Not a valid atom entry ", result[i+=1])
assert_equal("characters: \n ", result[i+=1])
assert_equal("start_element: entry, attr: {}", result[i+=1])
assert_equal("start_element_ns: entry, attr: {}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
assert_equal("characters: \n ", result[i+=1])
assert_equal("start_element: title, attr: {\"type\"=>\"html\"}", result[i+=1])
assert_equal("start_element_ns: title, attr: {\"type\"=>\"html\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
assert_equal("cdata: <>", result[i+=1])
assert_equal("end_element: title", result[i+=1])
assert_equal("end_element_ns title, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
assert_equal("characters: \n ", result[i+=1])
assert_equal("start_element: content, attr: {\"type\"=>\"xhtml\"}", result[i+=1])
assert_equal("start_element_ns: content, attr: {\"type\"=>\"xhtml\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
assert_equal("characters: \n ", result[i+=1])
assert_equal("start_element: xhtml:div, attr: {}", result[i+=1])
assert_equal("start_element_ns: div, attr: {}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {\"xhtml\"=>\"http://www.w3.org/1999/xhtml\"}", result[i+=1])
assert_equal("characters: \n ", result[i+=1])
assert_equal("start_element: xhtml:p, attr: {}", result[i+=1])
assert_equal("start_element_ns: p, attr: {}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {}", result[i+=1])
assert_equal("characters: hi there", result[i+=1])
assert_equal("end_element: xhtml:p", result[i+=1])
assert_equal("end_element_ns p, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
assert_equal("characters: \n ", result[i+=1])
assert_equal("end_element: xhtml:div", result[i+=1])
assert_equal("end_element_ns div, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
assert_equal("characters: \n ", result[i+=1])
assert_equal("end_element: content", result[i+=1])
assert_equal("end_element_ns content, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
assert_equal("characters: \n ", result[i+=1])
assert_equal("end_element: entry", result[i+=1])
assert_equal("end_element_ns entry, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
assert_equal("characters: \n", result[i+=1])
assert_equal("end_element: feed", result[i+=1])
assert_equal("end_element_ns feed, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
assert_equal("end_document", result[i+=1])
end
def test_file
parser = XML::SaxParser.file(saxtest_file)
parser.callbacks = TestCaseCallbacks.new
parser.parse
verify(parser)
end
def test_file_no_callbacks
parser = XML::SaxParser.file(saxtest_file)
assert_equal true, parser.parse
end
def test_noexistent_file
error = assert_raises(XML::Error) do
XML::SaxParser.file('i_dont_exist.xml')
end
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
end
def test_nil_file
error = assert_raises(TypeError) do
XML::SaxParser.file(nil)
end
assert_match(/nil into String/, error.to_s)
end
def test_io
File.open(saxtest_file) do |file|
parser = XML::SaxParser.io(file)
parser.callbacks = TestCaseCallbacks.new
parser.parse
verify(parser)
end
end
def test_nil_io
error = assert_raises(TypeError) do
XML::HTMLParser.io(nil)
end
assert_equal("Must pass in an IO object", error.to_s)
end
def test_string_no_callbacks
xml = File.read(saxtest_file)
parser = XML::SaxParser.string(xml)
assert_equal true, parser.parse
end
def test_string
xml = File.read(saxtest_file)
parser = XML::SaxParser.string(xml)
parser.callbacks = TestCaseCallbacks.new
parser.parse
verify(parser)
end
def test_string_io
xml = File.read(saxtest_file)
io = StringIO.new(xml)
parser = XML::SaxParser.io(io)
parser.callbacks = TestCaseCallbacks.new
parser.parse
verify(parser)
end
def test_nil_string
error = assert_raises(TypeError) do
XML::SaxParser.string(nil)
end
assert_equal("wrong argument type nil (expected String)", error.to_s)
end
def test_doctype
xml = <<-EOS
a1
EOS
parser = XML::SaxParser.string(xml)
parser.callbacks = DocTypeCallback.new
doc = parser.parse
refute_nil(doc)
end
def test_parse_warning
# Two xml PIs is a warning
xml = <<-EOS
EOS
parser = XML::SaxParser.string(xml)
parser.callbacks = TestCaseCallbacks.new
parser.parse
# Check callbacks
result = parser.callbacks.result
i = -1
assert_equal("startdoc", result[i+=1])
assert_equal("error: Warning: xmlParsePITarget: invalid name prefix 'xml' at :2.", result[i+=1])
assert_equal("pi: xml-invalid ", result[i+=1])
assert_equal("start_element: Test, attr: {}", result[i+=1])
assert_equal("start_element_ns: Test, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
assert_equal("end_element: Test", result[i+=1])
assert_equal("end_element_ns Test, prefix: , uri: ", result[i+=1])
assert_equal("end_document", result[i+=1])
end
def test_parse_error
xml = <<-EOS
EOS
parser = XML::SaxParser.string(xml)
parser.callbacks = TestCaseCallbacks.new
error = assert_raises(XML::Error) do
parser.parse
end
# Check callbacks
result = parser.callbacks.result
i = -1
assert_equal("startdoc", result[i+=1])
assert_equal("start_element: Results, attr: {}", result[i+=1])
assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
assert_equal("characters: \n", result[i+=1])
assert_equal("error: Fatal error: Premature end of data in tag Results line 1 at :2.", result[i+=1])
assert_equal("end_document", result[i+=1])
refute_nil(error)
assert_kind_of(XML::Error, error)
assert_equal("Fatal error: Premature end of data in tag Results line 1 at :2.", error.message)
assert_equal(XML::Error::PARSER, error.domain)
assert_equal(XML::Error::TAG_NOT_FINISHED, error.code)
assert_equal(XML::Error::FATAL, error.level)
assert_nil(error.file)
assert_equal(2, error.line)
assert_equal('Results', error.str1)
assert_nil(error.str2)
assert_nil(error.str3)
assert_equal(1, error.int1)
assert_equal(1, error.int2)
assert_nil(error.node)
end
def test_parse_seg_fail
xml = <<-EOS
AQUALIA THERMAL Lichte cr├иme - Versterkende & kalmerende 24 u hydraterende verzorging
Huid wordt continu gehydrateerd, intens versterkt en gekalmeerd.
Hypoallergeen. Geschikt voor de gevoelige huid.
01.EFFECTIVITEIT
Intensief gehydrateerd, de huid voelt gekalmeerd. Ze voelt de hele dag soepel en fluweelzacht aan, zonder een trekkerig gevoel. De huid is elastischer, soepeler en stralender. Doeltreffendheid getest onder dermatologisch toezicht.
02.GEBRUIK
's Morgens en/ of 's avonds aanbrengen.
03.ACTIEVE INGREDIENTEN
Technologische innovatie: 24 u continue cellulaire vochtnevel. Voor de 1ste keer worden Thermaal Bronwater van Vichy, rijk aan zeldzame mineralen en Actief HyaluronineтДв verwerkt in microcapsules, die deze vervolgens verspreiden in de cellen.
04.TEXTUUR
De lichte cr├иme is verfrissend en trekt makkelijk in. Niet vet en niet kleverig. Zonder 'maskereffect'.