libxml-ruby 3.2.2-x64-mingw-ucrt
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/HISTORY +848 -0
- data/LICENSE +21 -0
- data/MANIFEST +166 -0
- data/README.rdoc +217 -0
- data/Rakefile +99 -0
- data/ext/libxml/extconf.rb +61 -0
- data/ext/libxml/libxml.c +80 -0
- data/ext/libxml/libxml_ruby.def +35 -0
- data/ext/libxml/ruby_libxml.h +67 -0
- data/ext/libxml/ruby_xml.c +933 -0
- data/ext/libxml/ruby_xml.h +10 -0
- data/ext/libxml/ruby_xml_attr.c +333 -0
- data/ext/libxml/ruby_xml_attr.h +12 -0
- data/ext/libxml/ruby_xml_attr_decl.c +153 -0
- data/ext/libxml/ruby_xml_attr_decl.h +11 -0
- data/ext/libxml/ruby_xml_attributes.c +275 -0
- data/ext/libxml/ruby_xml_attributes.h +15 -0
- data/ext/libxml/ruby_xml_cbg.c +85 -0
- data/ext/libxml/ruby_xml_document.c +1123 -0
- data/ext/libxml/ruby_xml_document.h +11 -0
- data/ext/libxml/ruby_xml_dtd.c +248 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_encoding.c +250 -0
- data/ext/libxml/ruby_xml_encoding.h +16 -0
- data/ext/libxml/ruby_xml_error.c +996 -0
- data/ext/libxml/ruby_xml_error.h +12 -0
- data/ext/libxml/ruby_xml_html_parser.c +89 -0
- data/ext/libxml/ruby_xml_html_parser.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
- data/ext/libxml/ruby_xml_input_cbg.c +191 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- data/ext/libxml/ruby_xml_io.c +47 -0
- data/ext/libxml/ruby_xml_io.h +10 -0
- data/ext/libxml/ruby_xml_namespace.c +153 -0
- data/ext/libxml/ruby_xml_namespace.h +10 -0
- data/ext/libxml/ruby_xml_namespaces.c +293 -0
- data/ext/libxml/ruby_xml_namespaces.h +9 -0
- data/ext/libxml/ruby_xml_node.c +1402 -0
- data/ext/libxml/ruby_xml_node.h +13 -0
- data/ext/libxml/ruby_xml_parser.c +91 -0
- data/ext/libxml/ruby_xml_parser.h +12 -0
- data/ext/libxml/ruby_xml_parser_context.c +999 -0
- data/ext/libxml/ruby_xml_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_parser_options.c +66 -0
- data/ext/libxml/ruby_xml_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_reader.c +1239 -0
- data/ext/libxml/ruby_xml_reader.h +17 -0
- data/ext/libxml/ruby_xml_relaxng.c +110 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
- data/ext/libxml/ruby_xml_sax_parser.c +116 -0
- data/ext/libxml/ruby_xml_sax_parser.h +10 -0
- data/ext/libxml/ruby_xml_schema.c +278 -0
- data/ext/libxml/ruby_xml_schema.h +809 -0
- data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
- data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
- data/ext/libxml/ruby_xml_schema_element.c +95 -0
- data/ext/libxml/ruby_xml_schema_element.h +14 -0
- data/ext/libxml/ruby_xml_schema_facet.c +52 -0
- data/ext/libxml/ruby_xml_schema_facet.h +13 -0
- data/ext/libxml/ruby_xml_schema_type.c +232 -0
- data/ext/libxml/ruby_xml_schema_type.h +9 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_writer.c +1133 -0
- data/ext/libxml/ruby_xml_writer.h +10 -0
- data/ext/libxml/ruby_xml_xinclude.c +16 -0
- data/ext/libxml/ruby_xml_xinclude.h +11 -0
- data/ext/libxml/ruby_xml_xpath.c +194 -0
- data/ext/libxml/ruby_xml_xpath.h +13 -0
- data/ext/libxml/ruby_xml_xpath_context.c +360 -0
- data/ext/libxml/ruby_xml_xpath_context.h +9 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
- data/ext/libxml/ruby_xml_xpath_object.c +338 -0
- data/ext/libxml/ruby_xml_xpath_object.h +17 -0
- data/ext/libxml/ruby_xml_xpointer.c +99 -0
- data/ext/libxml/ruby_xml_xpointer.h +11 -0
- data/ext/vc/libxml_ruby.sln +28 -0
- data/lib/3.1/libxml_ruby.so +0 -0
- data/lib/libxml/attr.rb +123 -0
- data/lib/libxml/attr_decl.rb +80 -0
- data/lib/libxml/attributes.rb +14 -0
- data/lib/libxml/document.rb +194 -0
- data/lib/libxml/error.rb +95 -0
- data/lib/libxml/hpricot.rb +78 -0
- data/lib/libxml/html_parser.rb +96 -0
- data/lib/libxml/namespace.rb +62 -0
- data/lib/libxml/namespaces.rb +38 -0
- data/lib/libxml/node.rb +323 -0
- data/lib/libxml/parser.rb +101 -0
- data/lib/libxml/sax_callbacks.rb +180 -0
- data/lib/libxml/sax_parser.rb +41 -0
- data/lib/libxml/schema/attribute.rb +19 -0
- data/lib/libxml/schema/element.rb +19 -0
- data/lib/libxml/schema/type.rb +21 -0
- data/lib/libxml/schema.rb +48 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml-ruby.rb +30 -0
- data/lib/libxml.rb +5 -0
- data/lib/xml/libxml.rb +10 -0
- data/lib/xml.rb +14 -0
- data/libxml-ruby.gemspec +48 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/setup.rb +1584 -0
- data/test/c14n/given/doc.dtd +1 -0
- data/test/c14n/given/example-1.xml +14 -0
- data/test/c14n/given/example-2.xml +11 -0
- data/test/c14n/given/example-3.xml +18 -0
- data/test/c14n/given/example-4.xml +9 -0
- data/test/c14n/given/example-5.xml +12 -0
- data/test/c14n/given/example-6.xml +2 -0
- data/test/c14n/given/example-7.xml +11 -0
- data/test/c14n/given/example-8.xml +11 -0
- data/test/c14n/given/example-8.xpath +10 -0
- data/test/c14n/given/world.txt +1 -0
- data/test/c14n/result/1-1-without-comments/example-1 +4 -0
- data/test/c14n/result/1-1-without-comments/example-2 +11 -0
- data/test/c14n/result/1-1-without-comments/example-3 +14 -0
- data/test/c14n/result/1-1-without-comments/example-4 +9 -0
- data/test/c14n/result/1-1-without-comments/example-5 +3 -0
- data/test/c14n/result/1-1-without-comments/example-6 +1 -0
- data/test/c14n/result/1-1-without-comments/example-7 +1 -0
- data/test/c14n/result/1-1-without-comments/example-8 +1 -0
- data/test/c14n/result/with-comments/example-1 +6 -0
- data/test/c14n/result/with-comments/example-2 +11 -0
- data/test/c14n/result/with-comments/example-3 +14 -0
- data/test/c14n/result/with-comments/example-4 +9 -0
- data/test/c14n/result/with-comments/example-5 +4 -0
- data/test/c14n/result/with-comments/example-6 +1 -0
- data/test/c14n/result/with-comments/example-7 +1 -0
- data/test/c14n/result/without-comments/example-1 +4 -0
- data/test/c14n/result/without-comments/example-2 +11 -0
- data/test/c14n/result/without-comments/example-3 +14 -0
- data/test/c14n/result/without-comments/example-4 +9 -0
- data/test/c14n/result/without-comments/example-5 +3 -0
- data/test/c14n/result/without-comments/example-6 +1 -0
- data/test/c14n/result/without-comments/example-7 +1 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +154 -0
- data/test/model/cwm_1_0.xml +11336 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/ruby-lang.html +238 -0
- data/test/model/rubynet.xml +79 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +40 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/test_attr.rb +181 -0
- data/test/test_attr_decl.rb +132 -0
- data/test/test_attributes.rb +136 -0
- data/test/test_canonicalize.rb +120 -0
- data/test/test_deprecated_require.rb +12 -0
- data/test/test_document.rb +132 -0
- data/test/test_document_write.rb +146 -0
- data/test/test_dtd.rb +129 -0
- data/test/test_encoding.rb +129 -0
- data/test/test_encoding_sax.rb +115 -0
- data/test/test_error.rb +178 -0
- data/test/test_helper.rb +9 -0
- data/test/test_html_parser.rb +162 -0
- data/test/test_html_parser_context.rb +23 -0
- data/test/test_namespace.rb +60 -0
- data/test/test_namespaces.rb +200 -0
- data/test/test_node.rb +237 -0
- data/test/test_node_cdata.rb +50 -0
- data/test/test_node_comment.rb +32 -0
- data/test/test_node_copy.rb +40 -0
- data/test/test_node_edit.rb +158 -0
- data/test/test_node_pi.rb +37 -0
- data/test/test_node_text.rb +69 -0
- data/test/test_node_write.rb +97 -0
- data/test/test_node_xlink.rb +28 -0
- data/test/test_parser.rb +324 -0
- data/test/test_parser_context.rb +198 -0
- data/test/test_properties.rb +38 -0
- data/test/test_reader.rb +364 -0
- data/test/test_relaxng.rb +53 -0
- data/test/test_sax_parser.rb +326 -0
- data/test/test_schema.rb +168 -0
- data/test/test_suite.rb +48 -0
- data/test/test_traversal.rb +152 -0
- data/test/test_writer.rb +468 -0
- data/test/test_xinclude.rb +20 -0
- data/test/test_xml.rb +263 -0
- data/test/test_xpath.rb +244 -0
- data/test/test_xpath_context.rb +88 -0
- data/test/test_xpath_expression.rb +37 -0
- data/test/test_xpointer.rb +72 -0
- metadata +325 -0
| @@ -0,0 +1,326 @@ | |
| 1 | 
            +
            # encoding: UTF-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative './test_helper'
         | 
| 4 | 
            +
            require 'stringio'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class DocTypeCallback
         | 
| 7 | 
            +
              include LibXML::XML::SaxParser::Callbacks
         | 
| 8 | 
            +
              def on_start_element(element, attributes)
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            class TestCaseCallbacks
         | 
| 13 | 
            +
              include LibXML::XML::SaxParser::Callbacks
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              attr_accessor :result
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def initialize
         | 
| 18 | 
            +
                @result = Array.new
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def on_cdata_block(cdata)
         | 
| 22 | 
            +
                @result << "cdata: #{cdata}"
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def on_characters(chars)
         | 
| 26 | 
            +
                @result << "characters: #{chars}"
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def on_comment(text)
         | 
| 30 | 
            +
                @result << "comment: #{text}"
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def on_end_document
         | 
| 34 | 
            +
                @result << "end_document"
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              def on_end_element(name)
         | 
| 38 | 
            +
                @result << "end_element: #{name}"
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              def on_end_element_ns(name, prefix, uri)
         | 
| 42 | 
            +
                @result << "end_element_ns #{name}, prefix: #{prefix}, uri: #{uri}"
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              # Called for parser errors.
         | 
| 46 | 
            +
              def on_error(error)
         | 
| 47 | 
            +
                @result << "error: #{error}"
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              def on_processing_instruction(target, data)
         | 
| 51 | 
            +
                @result << "pi: #{target} #{data}"
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              def on_start_document
         | 
| 55 | 
            +
                @result << "startdoc"
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
              def on_start_element(name, attributes)
         | 
| 59 | 
            +
                attributes ||= Hash.new
         | 
| 60 | 
            +
                @result << "start_element: #{name}, attr: #{attributes.inspect}"
         | 
| 61 | 
            +
              end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              def on_start_element_ns(name, attributes, prefix, uri, namespaces)
         | 
| 64 | 
            +
                attributes ||= Hash.new
         | 
| 65 | 
            +
                namespaces ||= Hash.new
         | 
| 66 | 
            +
                @result << "start_element_ns: #{name}, attr: #{attributes.inspect}, prefix: #{prefix}, uri: #{uri}, ns: #{namespaces.inspect}"
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
            end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            class TestSaxParser < Minitest::Test
         | 
| 71 | 
            +
              def saxtest_file
         | 
| 72 | 
            +
                File.join(File.dirname(__FILE__), 'model/atom.xml')
         | 
| 73 | 
            +
              end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
              def verify(parser)
         | 
| 76 | 
            +
                result = parser.callbacks.result
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                i = -1
         | 
| 79 | 
            +
                assert_equal("startdoc", result[i+=1])
         | 
| 80 | 
            +
                assert_equal("pi: xml-stylesheet type=\"text/xsl\" href=\"my_stylesheet.xsl\"", result[i+=1])
         | 
| 81 | 
            +
                assert_equal("start_element: feed, attr: {}", result[i+=1])
         | 
| 82 | 
            +
                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])
         | 
| 83 | 
            +
                assert_equal("characters: \n  ", result[i+=1])
         | 
| 84 | 
            +
                assert_equal("comment:  Not a valid atom entry ", result[i+=1])
         | 
| 85 | 
            +
                assert_equal("characters: \n  ", result[i+=1])
         | 
| 86 | 
            +
                assert_equal("start_element: entry, attr: {}", result[i+=1])
         | 
| 87 | 
            +
                assert_equal("start_element_ns: entry, attr: {}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
         | 
| 88 | 
            +
                assert_equal("characters: \n    ", result[i+=1])
         | 
| 89 | 
            +
                assert_equal("start_element: title, attr: {\"type\"=>\"html\"}", result[i+=1])
         | 
| 90 | 
            +
                assert_equal("start_element_ns: title, attr: {\"type\"=>\"html\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
         | 
| 91 | 
            +
                assert_equal("cdata: <<strong>>", result[i+=1])
         | 
| 92 | 
            +
                assert_equal("end_element: title", result[i+=1])
         | 
| 93 | 
            +
                assert_equal("end_element_ns title, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
         | 
| 94 | 
            +
                assert_equal("characters: \n    ", result[i+=1])
         | 
| 95 | 
            +
                assert_equal("start_element: content, attr: {\"type\"=>\"xhtml\"}", result[i+=1])
         | 
| 96 | 
            +
                assert_equal("start_element_ns: content, attr: {\"type\"=>\"xhtml\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
         | 
| 97 | 
            +
                assert_equal("characters: \n      ", result[i+=1])
         | 
| 98 | 
            +
                assert_equal("start_element: xhtml:div, attr: {}", result[i+=1])
         | 
| 99 | 
            +
                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])
         | 
| 100 | 
            +
                assert_equal("characters: \n        ", result[i+=1])
         | 
| 101 | 
            +
                assert_equal("start_element: xhtml:p, attr: {}", result[i+=1])
         | 
| 102 | 
            +
                assert_equal("start_element_ns: p, attr: {}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {}", result[i+=1])
         | 
| 103 | 
            +
                assert_equal("characters: hi there", result[i+=1])
         | 
| 104 | 
            +
                assert_equal("end_element: xhtml:p", result[i+=1])
         | 
| 105 | 
            +
                assert_equal("end_element_ns p, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
         | 
| 106 | 
            +
                assert_equal("characters: \n      ", result[i+=1])
         | 
| 107 | 
            +
                assert_equal("end_element: xhtml:div", result[i+=1])
         | 
| 108 | 
            +
                assert_equal("end_element_ns div, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
         | 
| 109 | 
            +
                assert_equal("characters: \n    ", result[i+=1])
         | 
| 110 | 
            +
                assert_equal("end_element: content", result[i+=1])
         | 
| 111 | 
            +
                assert_equal("end_element_ns content, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
         | 
| 112 | 
            +
                assert_equal("characters: \n  ", result[i+=1])
         | 
| 113 | 
            +
                assert_equal("end_element: entry", result[i+=1])
         | 
| 114 | 
            +
                assert_equal("end_element_ns entry, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
         | 
| 115 | 
            +
                assert_equal("characters: \n", result[i+=1])
         | 
| 116 | 
            +
                assert_equal("end_element: feed", result[i+=1])
         | 
| 117 | 
            +
                assert_equal("end_element_ns feed, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
         | 
| 118 | 
            +
                assert_equal("end_document", result[i+=1])
         | 
| 119 | 
            +
              end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
              def test_file
         | 
| 122 | 
            +
                parser = LibXML::XML::SaxParser.file(saxtest_file)
         | 
| 123 | 
            +
                parser.callbacks = TestCaseCallbacks.new
         | 
| 124 | 
            +
                parser.parse
         | 
| 125 | 
            +
                verify(parser)
         | 
| 126 | 
            +
              end
         | 
| 127 | 
            +
             | 
| 128 | 
            +
              def test_file_no_callbacks
         | 
| 129 | 
            +
                parser = LibXML::XML::SaxParser.file(saxtest_file)
         | 
| 130 | 
            +
                assert_equal true, parser.parse
         | 
| 131 | 
            +
              end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
              def test_noexistent_file
         | 
| 134 | 
            +
                error = assert_raises(LibXML::XML::Error) do
         | 
| 135 | 
            +
                  LibXML::XML::SaxParser.file('i_dont_exist.xml')
         | 
| 136 | 
            +
                end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
         | 
| 139 | 
            +
              end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
              def test_nil_file
         | 
| 142 | 
            +
                error = assert_raises(TypeError) do
         | 
| 143 | 
            +
                  LibXML::XML::SaxParser.file(nil)
         | 
| 144 | 
            +
                end
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                assert_match(/nil into String/, error.to_s)
         | 
| 147 | 
            +
              end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
              def test_io
         | 
| 150 | 
            +
                File.open(saxtest_file) do |file|
         | 
| 151 | 
            +
                  parser = LibXML::XML::SaxParser.io(file)
         | 
| 152 | 
            +
                  parser.callbacks = TestCaseCallbacks.new
         | 
| 153 | 
            +
                  parser.parse
         | 
| 154 | 
            +
                  verify(parser)
         | 
| 155 | 
            +
                end
         | 
| 156 | 
            +
              end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
              def test_nil_io
         | 
| 159 | 
            +
                error = assert_raises(TypeError) do
         | 
| 160 | 
            +
                  LibXML::XML::HTMLParser.io(nil)
         | 
| 161 | 
            +
                end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                assert_equal("Must pass in an IO object", error.to_s)
         | 
| 164 | 
            +
              end
         | 
| 165 | 
            +
             | 
| 166 | 
            +
              def test_string_no_callbacks
         | 
| 167 | 
            +
                xml = File.read(saxtest_file)
         | 
| 168 | 
            +
                parser = LibXML::XML::SaxParser.string(xml)
         | 
| 169 | 
            +
                assert_equal true, parser.parse
         | 
| 170 | 
            +
              end
         | 
| 171 | 
            +
             | 
| 172 | 
            +
              def test_string
         | 
| 173 | 
            +
                xml = File.read(saxtest_file)
         | 
| 174 | 
            +
                parser = LibXML::XML::SaxParser.string(xml)
         | 
| 175 | 
            +
                parser.callbacks = TestCaseCallbacks.new
         | 
| 176 | 
            +
                parser.parse
         | 
| 177 | 
            +
                verify(parser)
         | 
| 178 | 
            +
              end
         | 
| 179 | 
            +
             | 
| 180 | 
            +
              def test_string_io
         | 
| 181 | 
            +
                xml = File.read(saxtest_file)
         | 
| 182 | 
            +
                io = StringIO.new(xml)
         | 
| 183 | 
            +
                parser = LibXML::XML::SaxParser.io(io)
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                parser.callbacks = TestCaseCallbacks.new
         | 
| 186 | 
            +
                parser.parse
         | 
| 187 | 
            +
                verify(parser)
         | 
| 188 | 
            +
              end
         | 
| 189 | 
            +
             | 
| 190 | 
            +
              def test_nil_string
         | 
| 191 | 
            +
                error = assert_raises(TypeError) do
         | 
| 192 | 
            +
                  LibXML::XML::SaxParser.string(nil)
         | 
| 193 | 
            +
                end
         | 
| 194 | 
            +
             | 
| 195 | 
            +
                assert_equal("wrong argument type nil (expected String)", error.to_s)
         | 
| 196 | 
            +
              end
         | 
| 197 | 
            +
             | 
| 198 | 
            +
              def test_doctype
         | 
| 199 | 
            +
                xml = <<-EOS
         | 
| 200 | 
            +
            <?xml version="1.0" encoding="UTF-8"?>
         | 
| 201 | 
            +
            <!DOCTYPE Results SYSTEM "results.dtd">
         | 
| 202 | 
            +
            <Results>
         | 
| 203 | 
            +
            <a>a1</a>
         | 
| 204 | 
            +
            </Results>
         | 
| 205 | 
            +
            EOS
         | 
| 206 | 
            +
                parser = LibXML::XML::SaxParser.string(xml)
         | 
| 207 | 
            +
                parser.callbacks = DocTypeCallback.new
         | 
| 208 | 
            +
                doc = parser.parse
         | 
| 209 | 
            +
                refute_nil(doc)
         | 
| 210 | 
            +
              end
         | 
| 211 | 
            +
             | 
| 212 | 
            +
              def test_parse_warning
         | 
| 213 | 
            +
                # Two xml PIs is a warning
         | 
| 214 | 
            +
                xml = <<-EOS
         | 
| 215 | 
            +
            <?xml version="1.0" encoding="utf-8"?>
         | 
| 216 | 
            +
            <?xml-invalid?>
         | 
| 217 | 
            +
            <Test/>
         | 
| 218 | 
            +
            EOS
         | 
| 219 | 
            +
             | 
| 220 | 
            +
                parser = LibXML::XML::SaxParser.string(xml)
         | 
| 221 | 
            +
                parser.callbacks = TestCaseCallbacks.new
         | 
| 222 | 
            +
             | 
| 223 | 
            +
                parser.parse
         | 
| 224 | 
            +
             | 
| 225 | 
            +
                # Check callbacks
         | 
| 226 | 
            +
                result = parser.callbacks.result
         | 
| 227 | 
            +
                i = -1
         | 
| 228 | 
            +
                assert_equal("startdoc", result[i+=1])
         | 
| 229 | 
            +
                assert_equal("error: Warning: xmlParsePITarget: invalid name prefix 'xml' at :2.", result[i+=1])
         | 
| 230 | 
            +
                assert_equal("pi: xml-invalid ", result[i+=1])
         | 
| 231 | 
            +
                assert_equal("start_element: Test, attr: {}", result[i+=1])
         | 
| 232 | 
            +
                assert_equal("start_element_ns: Test, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
         | 
| 233 | 
            +
                assert_equal("end_element: Test", result[i+=1])
         | 
| 234 | 
            +
                assert_equal("end_element_ns Test, prefix: , uri: ", result[i+=1])
         | 
| 235 | 
            +
                assert_equal("end_document", result[i+=1])
         | 
| 236 | 
            +
              end
         | 
| 237 | 
            +
             | 
| 238 | 
            +
              def test_parse_error
         | 
| 239 | 
            +
                xml = <<-EOS
         | 
| 240 | 
            +
                  <Results>
         | 
| 241 | 
            +
                EOS
         | 
| 242 | 
            +
                parser = LibXML::XML::SaxParser.string(xml)
         | 
| 243 | 
            +
                parser.callbacks = TestCaseCallbacks.new
         | 
| 244 | 
            +
             | 
| 245 | 
            +
                error = assert_raises(LibXML::XML::Error) do
         | 
| 246 | 
            +
                  parser.parse
         | 
| 247 | 
            +
                end
         | 
| 248 | 
            +
             | 
| 249 | 
            +
                # Check callbacks
         | 
| 250 | 
            +
                result = parser.callbacks.result
         | 
| 251 | 
            +
             | 
| 252 | 
            +
                i = -1
         | 
| 253 | 
            +
             | 
| 254 | 
            +
                base_err_msg = "Fatal error: (Premature end of data in tag Results line 1|EndTag: '<\\/' not found) at :2\\."
         | 
| 255 | 
            +
                re_err_msg1 = /\A(error: )#{base_err_msg}\z/
         | 
| 256 | 
            +
                re_err_msg2 = /\A#{base_err_msg}\z/
         | 
| 257 | 
            +
             | 
| 258 | 
            +
                assert_equal("startdoc", result[i+=1])
         | 
| 259 | 
            +
                assert_equal("start_element: Results, attr: {}", result[i+=1])
         | 
| 260 | 
            +
                assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
         | 
| 261 | 
            +
                assert_equal("characters: \n", result[i+=1])
         | 
| 262 | 
            +
                assert_match(re_err_msg1, result[i+=1])
         | 
| 263 | 
            +
                assert_equal("end_document", result[i+=1])
         | 
| 264 | 
            +
             | 
| 265 | 
            +
                refute_nil(error)
         | 
| 266 | 
            +
                assert_kind_of(LibXML::XML::Error, error)
         | 
| 267 | 
            +
                assert_match(re_err_msg2, error.message)
         | 
| 268 | 
            +
                assert_equal(LibXML::XML::Error::PARSER, error.domain)
         | 
| 269 | 
            +
             | 
| 270 | 
            +
                assert([LibXML::XML::Error::TAG_NOT_FINISHED, LibXML::XML::Error::LTSLASH_REQUIRED].include?(error.code))
         | 
| 271 | 
            +
                assert_equal(LibXML::XML::Error::FATAL, error.level)
         | 
| 272 | 
            +
                assert_nil(error.file)
         | 
| 273 | 
            +
                assert_equal(2, error.line)
         | 
| 274 | 
            +
                # Sometimes this is nil and sometimes its not depending on OS and libxlm version
         | 
| 275 | 
            +
                # assert_nil(error.str1)
         | 
| 276 | 
            +
                assert_nil(error.str2)
         | 
| 277 | 
            +
                assert_nil(error.str3)
         | 
| 278 | 
            +
                assert([0, 1].include?(error.int1))
         | 
| 279 | 
            +
                assert_equal(1, error.int2)
         | 
| 280 | 
            +
                assert_nil(error.node)
         | 
| 281 | 
            +
              end
         | 
| 282 | 
            +
             | 
| 283 | 
            +
              def test_parse_seg_fail
         | 
| 284 | 
            +
                xml = <<-EOS
         | 
| 285 | 
            +
                  <?xml version="1.0" encoding="ISO-8859-1" ?>
         | 
| 286 | 
            +
                  <Products>
         | 
| 287 | 
            +
                    <Product>
         | 
| 288 | 
            +
                      <ProductDescription>
         | 
| 289 | 
            +
                        AQUALIA THERMAL Lichte cr├иme - Versterkende & kalmerende 24 u hydraterende verzorging<br />
         | 
| 290 | 
            +
                        Huid wordt continu gehydrateerd, intens versterkt en gekalmeerd.<br />
         | 
| 291 | 
            +
                        Hypoallergeen. Geschikt voor de gevoelige huid.<br />
         | 
| 292 | 
            +
                        <br />
         | 
| 293 | 
            +
                        01.EFFECTIVITEIT<br />
         | 
| 294 | 
            +
                        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. <br />
         | 
| 295 | 
            +
                        <br />
         | 
| 296 | 
            +
                        02.GEBRUIK<br />
         | 
| 297 | 
            +
                        's Morgens en/ of 's avonds aanbrengen. <br />
         | 
| 298 | 
            +
                        <br />
         | 
| 299 | 
            +
                        03.ACTIEVE INGREDIENTEN<br />
         | 
| 300 | 
            +
                        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. <br />
         | 
| 301 | 
            +
                        <br />
         | 
| 302 | 
            +
                        04.TEXTUUR<br />
         | 
| 303 | 
            +
                        De lichte cr├иme is verfrissend en trekt makkelijk in. Niet vet en niet kleverig. Zonder 'maskereffect'. <br />
         | 
| 304 | 
            +
                        <br />
         | 
| 305 | 
            +
                        05.GEUR<br />
         | 
| 306 | 
            +
                        Geparfumeerd <br />
         | 
| 307 | 
            +
                        <br />
         | 
| 308 | 
            +
                        06.INHOUD<br />
         | 
| 309 | 
            +
                        40 ml tube <br />
         | 
| 310 | 
            +
                      </ProductDescription>
         | 
| 311 | 
            +
                    </Product>
         | 
| 312 | 
            +
                  </Products>
         | 
| 313 | 
            +
                EOS
         | 
| 314 | 
            +
             | 
| 315 | 
            +
                parser = LibXML::XML::SaxParser.string(xml)
         | 
| 316 | 
            +
                parser.callbacks = TestCaseCallbacks.new
         | 
| 317 | 
            +
             | 
| 318 | 
            +
                error = assert_raises(LibXML::XML::Error) do
         | 
| 319 | 
            +
                  parser.parse
         | 
| 320 | 
            +
                end
         | 
| 321 | 
            +
                assert_equal("Fatal error: xmlParseEntityRef: no name at :5.", error.to_s)
         | 
| 322 | 
            +
             | 
| 323 | 
            +
                # Check callbacks
         | 
| 324 | 
            +
                parser.callbacks.result
         | 
| 325 | 
            +
              end
         | 
| 326 | 
            +
            end
         | 
    
        data/test/test_schema.rb
    ADDED
    
    | @@ -0,0 +1,168 @@ | |
| 1 | 
            +
            # encoding: UTF-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative './test_helper'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            class TestSchema < Minitest::Test
         | 
| 6 | 
            +
              def setup
         | 
| 7 | 
            +
                file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
         | 
| 8 | 
            +
                @doc = LibXML::XML::Document.file(file)
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              def teardown
         | 
| 12 | 
            +
                @doc = nil
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def schema
         | 
| 16 | 
            +
                document = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd'))
         | 
| 17 | 
            +
                LibXML::XML::Schema.document(document)
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def check_error(error)
         | 
| 21 | 
            +
                refute_nil(error)
         | 
| 22 | 
            +
                assert(error.message.match(/Error: Element 'invalid': This element is not expected. Expected is \( item \)/))
         | 
| 23 | 
            +
                assert_kind_of(LibXML::XML::Error, error)
         | 
| 24 | 
            +
                assert_equal(LibXML::XML::Error::SCHEMASV, error.domain)
         | 
| 25 | 
            +
                assert_equal(LibXML::XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code)
         | 
| 26 | 
            +
                assert_equal(LibXML::XML::Error::ERROR, error.level)
         | 
| 27 | 
            +
                assert(error.file.match(/shiporder.xml/)) if error.file
         | 
| 28 | 
            +
                assert_nil(error.str1)
         | 
| 29 | 
            +
                assert_nil(error.str2)
         | 
| 30 | 
            +
                assert_nil(error.str3)
         | 
| 31 | 
            +
                assert_equal(0, error.int1)
         | 
| 32 | 
            +
                assert_equal(0, error.int2)
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              def test_load_from_doc
         | 
| 36 | 
            +
                assert_instance_of(LibXML::XML::Schema, schema)
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              def test_doc_valid
         | 
| 40 | 
            +
                assert(@doc.validate_schema(schema))
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              def test_doc_invalid
         | 
| 44 | 
            +
                new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
         | 
| 45 | 
            +
                @doc.root << new_node
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                error = assert_raises(LibXML::XML::Error) do
         | 
| 48 | 
            +
                  @doc.validate_schema(schema)
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                check_error(error)
         | 
| 52 | 
            +
                assert_nil(error.line)
         | 
| 53 | 
            +
                refute_nil(error.node)
         | 
| 54 | 
            +
                assert_equal('invalid', error.node.name)
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              def test_reader_valid
         | 
| 58 | 
            +
                reader = LibXML::XML::Reader.string(@doc.to_s)
         | 
| 59 | 
            +
                assert(reader.schema_validate(schema))
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                while reader.read
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              def test_reader_invalid
         | 
| 66 | 
            +
                # Set error handler
         | 
| 67 | 
            +
                errors = Array.new
         | 
| 68 | 
            +
                LibXML::XML::Error.set_handler do |error|
         | 
| 69 | 
            +
                  errors << error
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
         | 
| 73 | 
            +
                @doc.root << new_node
         | 
| 74 | 
            +
                reader = LibXML::XML::Reader.string(@doc.to_s)
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                # Set a schema
         | 
| 77 | 
            +
                assert(reader.schema_validate(schema))
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                while reader.read
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                assert_equal(1, errors.length)
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                error = errors.first
         | 
| 85 | 
            +
                check_error(error)
         | 
| 86 | 
            +
                assert_equal(21, error.line)
         | 
| 87 | 
            +
              ensure
         | 
| 88 | 
            +
                LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
         | 
| 89 | 
            +
              end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
             | 
| 92 | 
            +
              # Schema meta-data tests
         | 
| 93 | 
            +
              def test_elements
         | 
| 94 | 
            +
                assert_instance_of(Hash, schema.elements)
         | 
| 95 | 
            +
                assert_equal(1, schema.elements.length)
         | 
| 96 | 
            +
                assert_instance_of(LibXML::XML::Schema::Element, schema.elements['shiporder'])
         | 
| 97 | 
            +
              end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
              def test_types
         | 
| 100 | 
            +
                assert_instance_of(Hash, schema.types)
         | 
| 101 | 
            +
                assert_equal(1, schema.types.length)
         | 
| 102 | 
            +
                assert_instance_of(LibXML::XML::Schema::Type, schema.types['shiporder'])
         | 
| 103 | 
            +
              end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
              def test_imported_types
         | 
| 106 | 
            +
                assert_instance_of(Hash, schema.imported_types)
         | 
| 107 | 
            +
                assert_equal(1, schema.imported_types.length)
         | 
| 108 | 
            +
                assert_instance_of(LibXML::XML::Schema::Type, schema.types['shiporder'])
         | 
| 109 | 
            +
              end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
              def test_namespaces
         | 
| 112 | 
            +
                assert_instance_of(Array, schema.namespaces)
         | 
| 113 | 
            +
                assert_equal(1, schema.namespaces.length)
         | 
| 114 | 
            +
              end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
              def test_schema_type
         | 
| 117 | 
            +
                type = schema.types['shiporder']
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                assert_equal('shiporder', type.name)
         | 
| 120 | 
            +
                assert_nil(type.namespace)
         | 
| 121 | 
            +
                assert_equal("Shiporder type documentation", type.annotation)
         | 
| 122 | 
            +
                assert_instance_of(LibXML::XML::Node, type.node)
         | 
| 123 | 
            +
                assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_COMPLEX, type.kind)
         | 
| 124 | 
            +
                assert_instance_of(LibXML::XML::Schema::Type, type.base)
         | 
| 125 | 
            +
                assert_equal("anyType", type.base.name)
         | 
| 126 | 
            +
                assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_BASIC, type.base.kind)
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                assert_instance_of(Hash, type.elements)
         | 
| 129 | 
            +
                assert_equal(3, type.elements.length)
         | 
| 130 | 
            +
              end
         | 
| 131 | 
            +
             | 
| 132 | 
            +
              def test_schema_element
         | 
| 133 | 
            +
                element = schema.types['shiporder'].elements['orderperson']
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                assert_equal('orderperson', element.name)
         | 
| 136 | 
            +
                assert_nil(element.namespace)
         | 
| 137 | 
            +
                assert_equal("orderperson element documentation", element.annotation)
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                element = schema.types['shiporder'].elements['item']
         | 
| 140 | 
            +
                assert_equal('item', element.name)
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                element = schema.types['shiporder'].elements['item'].type.elements['note']
         | 
| 143 | 
            +
                assert_equal('note', element.name)
         | 
| 144 | 
            +
                assert_equal('string', element.type.name)
         | 
| 145 | 
            +
              end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
              def test_schema_attributes
         | 
| 148 | 
            +
                type = schema.types['shiporder']
         | 
| 149 | 
            +
             | 
| 150 | 
            +
                assert_instance_of(Array, type.attributes)
         | 
| 151 | 
            +
                assert_equal(2, type.attributes.length)
         | 
| 152 | 
            +
                assert_instance_of(LibXML::XML::Schema::Attribute, type.attributes.first)
         | 
| 153 | 
            +
              end
         | 
| 154 | 
            +
             | 
| 155 | 
            +
              def test_schema_attribute
         | 
| 156 | 
            +
                attribute = schema.types['shiporder'].attributes.first
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                assert_equal("orderid", attribute.name)
         | 
| 159 | 
            +
                assert_nil(attribute.namespace)
         | 
| 160 | 
            +
                assert_equal(1, attribute.occurs)
         | 
| 161 | 
            +
                assert_equal('string', attribute.type.name)
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                attribute = schema.types['shiporder'].attributes[1]
         | 
| 164 | 
            +
                assert_equal(2, attribute.occurs)
         | 
| 165 | 
            +
                assert_equal('1', attribute.default)
         | 
| 166 | 
            +
                assert_equal('integer', attribute.type.name)
         | 
| 167 | 
            +
              end
         | 
| 168 | 
            +
            end
         | 
    
        data/test/test_suite.rb
    ADDED
    
    | @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            # encoding: UTF-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # Change to current directory so relative
         | 
| 4 | 
            +
            # requires work.
         | 
| 5 | 
            +
            dir = File.dirname(__FILE__)
         | 
| 6 | 
            +
            Dir.chdir(dir)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            require './test_attr'
         | 
| 9 | 
            +
            require './test_attr_decl'
         | 
| 10 | 
            +
            require './test_attributes'
         | 
| 11 | 
            +
            require './test_canonicalize'
         | 
| 12 | 
            +
            require './test_document'
         | 
| 13 | 
            +
            require './test_document_write'
         | 
| 14 | 
            +
            require './test_dtd'
         | 
| 15 | 
            +
            require './test_error'
         | 
| 16 | 
            +
            require './test_html_parser'
         | 
| 17 | 
            +
            require './test_html_parser_context'
         | 
| 18 | 
            +
            require './test_namespace'
         | 
| 19 | 
            +
            require './test_namespaces'
         | 
| 20 | 
            +
            require './test_node'
         | 
| 21 | 
            +
            require './test_node_cdata'
         | 
| 22 | 
            +
            require './test_node_comment'
         | 
| 23 | 
            +
            require './test_node_copy'
         | 
| 24 | 
            +
            require './test_node_edit'
         | 
| 25 | 
            +
            require './test_node_pi'
         | 
| 26 | 
            +
            require './test_node_text'
         | 
| 27 | 
            +
            require './test_node_write'
         | 
| 28 | 
            +
            require './test_node_xlink'
         | 
| 29 | 
            +
            require './test_parser'
         | 
| 30 | 
            +
            require './test_parser_context'
         | 
| 31 | 
            +
            require './test_reader'
         | 
| 32 | 
            +
            require './test_relaxng'
         | 
| 33 | 
            +
            require './test_sax_parser'
         | 
| 34 | 
            +
            require './test_schema'
         | 
| 35 | 
            +
            require './test_traversal'
         | 
| 36 | 
            +
            require './test_writer'
         | 
| 37 | 
            +
            require './test_xinclude'
         | 
| 38 | 
            +
            require './test_xpath'
         | 
| 39 | 
            +
            require './test_xpath_context'
         | 
| 40 | 
            +
            require './test_xpath_expression'
         | 
| 41 | 
            +
            require './test_xpointer'
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            require './test_encoding'
         | 
| 44 | 
            +
            require './test_encoding_sax'
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            # Compatibility
         | 
| 47 | 
            +
            require './test_properties'
         | 
| 48 | 
            +
            require './test_deprecated_require'
         | 
| @@ -0,0 +1,152 @@ | |
| 1 | 
            +
            # encoding: UTF-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative './test_helper'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            class TestTranversal < Minitest::Test
         | 
| 6 | 
            +
              ROOT_NODES_LENGTH = 27
         | 
| 7 | 
            +
              ROOT_ELEMENTS_LENGTH = 13
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              def setup
         | 
| 10 | 
            +
                filename = File.join(File.dirname(__FILE__), 'model/books.xml')
         | 
| 11 | 
            +
                @doc = LibXML::XML::Document.file(filename)
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              def teardown
         | 
| 15 | 
            +
                @doc = nil
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
              
         | 
| 18 | 
            +
              def test_children
         | 
| 19 | 
            +
                # Includes text nodes and such
         | 
| 20 | 
            +
                assert_equal(ROOT_NODES_LENGTH, @doc.root.children.length)
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
              
         | 
| 23 | 
            +
              def test_children_iteration
         | 
| 24 | 
            +
                # Includes text nodes and such
         | 
| 25 | 
            +
                nodes = @doc.root.children.inject([]) do |arr, node|
         | 
| 26 | 
            +
                  arr << node
         | 
| 27 | 
            +
                  arr
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
                
         | 
| 30 | 
            +
                assert_equal(ROOT_NODES_LENGTH, nodes.length)
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def test_no_children
         | 
| 34 | 
            +
                # Get a node with no children
         | 
| 35 | 
            +
                node = @doc.find_first('/catalog/book[@id="bk113"]/price')
         | 
| 36 | 
            +
                assert_equal(0, node.children.length)
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              def test_no_children_inner_xml
         | 
| 40 | 
            +
                # Get a node with no children
         | 
| 41 | 
            +
                node = @doc.find_first('/catalog/book[@id="bk113"]/price')
         | 
| 42 | 
            +
                assert_nil(node.inner_xml)
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
              def test_each
         | 
| 45 | 
            +
                # Includes text nodes and such
         | 
| 46 | 
            +
                nodes = @doc.root.inject([]) do |arr, node|
         | 
| 47 | 
            +
                  arr << node
         | 
| 48 | 
            +
                  arr
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
                
         | 
| 51 | 
            +
                assert_equal(ROOT_NODES_LENGTH, nodes.length)
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
              
         | 
| 54 | 
            +
              def test_each_element
         | 
| 55 | 
            +
                # Includes text nodes and such
         | 
| 56 | 
            +
                nodes = []
         | 
| 57 | 
            +
                @doc.root.each_element do |node|
         | 
| 58 | 
            +
                  nodes << node
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
                
         | 
| 61 | 
            +
                assert_equal(ROOT_ELEMENTS_LENGTH, nodes.length)
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
              
         | 
| 64 | 
            +
              def test_next
         | 
| 65 | 
            +
                nodes = []
         | 
| 66 | 
            +
                
         | 
| 67 | 
            +
                node = @doc.root.first
         | 
| 68 | 
            +
                
         | 
| 69 | 
            +
                while node
         | 
| 70 | 
            +
                  nodes << node
         | 
| 71 | 
            +
                  node = node.next
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
                assert_equal(ROOT_NODES_LENGTH, nodes.length)
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              def test_next?
         | 
| 77 | 
            +
                first_node = @doc.root.first
         | 
| 78 | 
            +
                assert(first_node.next?)
         | 
| 79 | 
            +
                
         | 
| 80 | 
            +
                last_node = @doc.root.last
         | 
| 81 | 
            +
                assert(!last_node.next?)
         | 
| 82 | 
            +
              end
         | 
| 83 | 
            +
                
         | 
| 84 | 
            +
              def test_prev
         | 
| 85 | 
            +
                nodes = []
         | 
| 86 | 
            +
                
         | 
| 87 | 
            +
                node = @doc.root.last
         | 
| 88 | 
            +
                
         | 
| 89 | 
            +
                while node
         | 
| 90 | 
            +
                  nodes << node
         | 
| 91 | 
            +
                  node = node.prev
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
                assert_equal(ROOT_NODES_LENGTH, nodes.length)
         | 
| 94 | 
            +
              end
         | 
| 95 | 
            +
              
         | 
| 96 | 
            +
              def test_prev?
         | 
| 97 | 
            +
                first_node = @doc.root.first
         | 
| 98 | 
            +
                assert(!first_node.prev?)
         | 
| 99 | 
            +
                
         | 
| 100 | 
            +
                last_node = @doc.root.last
         | 
| 101 | 
            +
                assert(last_node.prev?)
         | 
| 102 | 
            +
              end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
              def test_parent?
         | 
| 105 | 
            +
                assert(!@doc.parent?)
         | 
| 106 | 
            +
                assert(@doc.root.parent?)
         | 
| 107 | 
            +
              end
         | 
| 108 | 
            +
               
         | 
| 109 | 
            +
              def test_child?
         | 
| 110 | 
            +
                assert(@doc.child?)
         | 
| 111 | 
            +
                assert(!@doc.root.first.child?)
         | 
| 112 | 
            +
              end
         | 
| 113 | 
            +
              
         | 
| 114 | 
            +
              def test_next_prev_equivalence
         | 
| 115 | 
            +
                next_nodes = []
         | 
| 116 | 
            +
                last_nodes = []
         | 
| 117 | 
            +
                
         | 
| 118 | 
            +
                node = @doc.root.first
         | 
| 119 | 
            +
                while node
         | 
| 120 | 
            +
                  next_nodes << node
         | 
| 121 | 
            +
                  node = node.next
         | 
| 122 | 
            +
                end
         | 
| 123 | 
            +
              
         | 
| 124 | 
            +
                node = @doc.root.last
         | 
| 125 | 
            +
                while node
         | 
| 126 | 
            +
                  last_nodes << node
         | 
| 127 | 
            +
                  node = node.prev
         | 
| 128 | 
            +
                end
         | 
| 129 | 
            +
                
         | 
| 130 | 
            +
                assert_equal(next_nodes, last_nodes.reverse)
         | 
| 131 | 
            +
              end
         | 
| 132 | 
            +
              
         | 
| 133 | 
            +
              def test_next_children_equivalence
         | 
| 134 | 
            +
                next_nodes = []
         | 
| 135 | 
            +
                
         | 
| 136 | 
            +
                node = @doc.root.first
         | 
| 137 | 
            +
                while node
         | 
| 138 | 
            +
                  next_nodes << node
         | 
| 139 | 
            +
                  node = node.next
         | 
| 140 | 
            +
                end
         | 
| 141 | 
            +
              
         | 
| 142 | 
            +
                assert_equal(@doc.root.children, next_nodes)
         | 
| 143 | 
            +
              end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
              def test_doc_class
         | 
| 146 | 
            +
                assert_instance_of(LibXML::XML::Document, @doc)
         | 
| 147 | 
            +
              end
         | 
| 148 | 
            +
              
         | 
| 149 | 
            +
              def test_root_class
         | 
| 150 | 
            +
                assert_instance_of(LibXML::XML::Node, @doc.root)
         | 
| 151 | 
            +
              end
         | 
| 152 | 
            +
            end
         |