coupa-libxml-ruby 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +488 -0
- data/LICENSE +22 -0
- data/README +161 -0
- data/Rakefile +188 -0
- data/doc/css/normal.css +182 -0
- data/doc/img/raze-tiny.png +0 -0
- data/doc/img/red-cube.jpg +0 -0
- data/doc/img/xml-ruby.png +0 -0
- data/doc/index.xml +43 -0
- data/doc/install.xml +77 -0
- data/doc/layout.rhtml +38 -0
- data/doc/layout.xsl +67 -0
- data/doc/license.xml +32 -0
- data/doc/log/changelog.xml +1324 -0
- data/doc/log/changelog.xsl +42 -0
- data/doc/rdoc/classes/LibXML.html +207 -0
- data/doc/rdoc/classes/LibXML/XML.html +407 -0
- data/doc/rdoc/classes/LibXML/XML/Attr.html +521 -0
- data/doc/rdoc/classes/LibXML/XML/AttrDecl.html +360 -0
- data/doc/rdoc/classes/LibXML/XML/Attributes.html +149 -0
- data/doc/rdoc/classes/LibXML/XML/Document.html +460 -0
- data/doc/rdoc/classes/LibXML/XML/Error.html +129 -0
- data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +263 -0
- data/doc/rdoc/classes/LibXML/XML/Namespace.html +248 -0
- data/doc/rdoc/classes/LibXML/XML/Namespaces.html +200 -0
- data/doc/rdoc/classes/LibXML/XML/Node.html +1351 -0
- data/doc/rdoc/classes/LibXML/XML/Parser.html +328 -0
- data/doc/rdoc/classes/LibXML/XML/Reader.html +172 -0
- data/doc/rdoc/classes/LibXML/XML/SaxParser.html +232 -0
- data/doc/rdoc/classes/LibXML/XML/SaxParser/Callbacks.html +506 -0
- data/doc/rdoc/classes/LibXML/XML/SaxParser/VerboseCallbacks.html +555 -0
- data/doc/rdoc/classes/LibXML/XML/XPath.html +111 -0
- data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +162 -0
- data/doc/rdoc/classes/cXMLDtd.html +114 -0
- data/doc/rdoc/classes/cXMLNode.html +114 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/CHANGES.html +794 -0
- data/doc/rdoc/files/LICENSE.html +131 -0
- data/doc/rdoc/files/README.html +343 -0
- data/doc/rdoc/files/ext/libxml/libxml_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_attr_decl_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_cbg_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_encoding_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_error_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_context_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_options_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_io_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_namespace_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_namespaces_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_options_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_sax2_handler_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_expression_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +101 -0
- data/doc/rdoc/files/lib/libxml/attr_decl_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/attr_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/attributes_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/document_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/error_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/hpricot_rb.html +192 -0
- data/doc/rdoc/files/lib/libxml/html_parser_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/namespace_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/namespaces_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/node_rb.html +108 -0
- data/doc/rdoc/files/lib/libxml/ns_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/parser_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/properties_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/reader_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/sax_callbacks_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/sax_parser_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/tree_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/xpath_object_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml_rb.html +133 -0
- data/doc/rdoc/files/lib/xml/libxml_rb.html +124 -0
- data/doc/rdoc/files/lib/xml_rb.html +134 -0
- data/doc/rdoc/fr_class_index.html +46 -0
- data/doc/rdoc/fr_file_index.html +84 -0
- data/doc/rdoc/fr_method_index.html +155 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/ext/libxml/Makefile +157 -0
- data/ext/libxml/build.log +4 -0
- data/ext/libxml/extconf.h +5 -0
- data/ext/libxml/extconf.rb +278 -0
- data/ext/libxml/libxml.c +77 -0
- data/ext/libxml/libxml.o +0 -0
- data/ext/libxml/libxml_ruby.bundle +0 -0
- data/ext/libxml/mkmf.log +228 -0
- data/ext/libxml/ruby_libxml.h +93 -0
- data/ext/libxml/ruby_xml.c +893 -0
- data/ext/libxml/ruby_xml.h +10 -0
- data/ext/libxml/ruby_xml.o +0 -0
- data/ext/libxml/ruby_xml_attr.c +352 -0
- data/ext/libxml/ruby_xml_attr.h +14 -0
- data/ext/libxml/ruby_xml_attr.o +0 -0
- data/ext/libxml/ruby_xml_attr_decl.c +171 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attr_decl.o +0 -0
- data/ext/libxml/ruby_xml_attributes.c +277 -0
- data/ext/libxml/ruby_xml_attributes.h +17 -0
- data/ext/libxml/ruby_xml_attributes.o +0 -0
- data/ext/libxml/ruby_xml_cbg.c +86 -0
- data/ext/libxml/ruby_xml_cbg.o +0 -0
- data/ext/libxml/ruby_xml_document.c +1006 -0
- data/ext/libxml/ruby_xml_document.c.old +936 -0
- data/ext/libxml/ruby_xml_document.h +17 -0
- data/ext/libxml/ruby_xml_document.o +0 -0
- data/ext/libxml/ruby_xml_dtd.c +257 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_dtd.o +0 -0
- data/ext/libxml/ruby_xml_encoding.c +134 -0
- data/ext/libxml/ruby_xml_encoding.h +12 -0
- data/ext/libxml/ruby_xml_encoding.o +0 -0
- data/ext/libxml/ruby_xml_error.c +1004 -0
- data/ext/libxml/ruby_xml_error.h +14 -0
- data/ext/libxml/ruby_xml_error.o +0 -0
- data/ext/libxml/ruby_xml_html_parser.c +92 -0
- data/ext/libxml/ruby_xml_html_parser.h +12 -0
- data/ext/libxml/ruby_xml_html_parser.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.o +0 -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_input_cbg.o +0 -0
- data/ext/libxml/ruby_xml_io.c +30 -0
- data/ext/libxml/ruby_xml_io.h +9 -0
- data/ext/libxml/ruby_xml_io.o +0 -0
- data/ext/libxml/ruby_xml_namespace.c +170 -0
- data/ext/libxml/ruby_xml_namespace.h +12 -0
- data/ext/libxml/ruby_xml_namespace.o +0 -0
- data/ext/libxml/ruby_xml_namespaces.c +295 -0
- data/ext/libxml/ruby_xml_namespaces.h +11 -0
- data/ext/libxml/ruby_xml_namespaces.o +0 -0
- data/ext/libxml/ruby_xml_node.c +1386 -0
- data/ext/libxml/ruby_xml_node.h +13 -0
- data/ext/libxml/ruby_xml_node.o +0 -0
- data/ext/libxml/ruby_xml_parser.c +94 -0
- data/ext/libxml/ruby_xml_parser.h +14 -0
- data/ext/libxml/ruby_xml_parser.o +0 -0
- data/ext/libxml/ruby_xml_parser_context.c +982 -0
- data/ext/libxml/ruby_xml_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_parser_options.c +68 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_reader.c +1002 -0
- data/ext/libxml/ruby_xml_reader.h +14 -0
- data/ext/libxml/ruby_xml_reader.o +0 -0
- data/ext/libxml/ruby_xml_relaxng.c +111 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_relaxng.o +0 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +322 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
- data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
- data/ext/libxml/ruby_xml_sax_parser.c +137 -0
- data/ext/libxml/ruby_xml_sax_parser.h +12 -0
- data/ext/libxml/ruby_xml_sax_parser.o +0 -0
- data/ext/libxml/ruby_xml_schema.c +159 -0
- data/ext/libxml/ruby_xml_schema.h +11 -0
- data/ext/libxml/ruby_xml_schema.o +0 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_xinclude.c +18 -0
- data/ext/libxml/ruby_xml_xinclude.h +13 -0
- data/ext/libxml/ruby_xml_xinclude.o +0 -0
- data/ext/libxml/ruby_xml_xpath.c +107 -0
- data/ext/libxml/ruby_xml_xpath.h +12 -0
- data/ext/libxml/ruby_xml_xpath.o +0 -0
- data/ext/libxml/ruby_xml_xpath_context.c +387 -0
- data/ext/libxml/ruby_xml_xpath_context.h +11 -0
- data/ext/libxml/ruby_xml_xpath_context.o +0 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
- data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
- data/ext/libxml/ruby_xml_xpath_object.c +336 -0
- data/ext/libxml/ruby_xml_xpath_object.h +19 -0
- data/ext/libxml/ruby_xml_xpath_object.o +0 -0
- data/ext/libxml/ruby_xml_xpointer.c +101 -0
- data/ext/libxml/ruby_xml_xpointer.h +13 -0
- data/ext/libxml/ruby_xml_xpointer.o +0 -0
- data/ext/mingw/Rakefile +34 -0
- data/ext/mingw/build.rake +41 -0
- data/ext/vc/libxml_ruby.sln +26 -0
- data/lib/libxml.rb +30 -0
- data/lib/libxml/attr.rb +111 -0
- data/lib/libxml/attr_decl.rb +78 -0
- data/lib/libxml/attributes.rb +12 -0
- data/lib/libxml/document.rb +190 -0
- data/lib/libxml/error.rb +88 -0
- data/lib/libxml/hpricot.rb +76 -0
- data/lib/libxml/html_parser.rb +94 -0
- data/lib/libxml/namespace.rb +60 -0
- data/lib/libxml/namespaces.rb +36 -0
- data/lib/libxml/node.rb +385 -0
- data/lib/libxml/ns.rb +20 -0
- data/lib/libxml/parser.rb +365 -0
- data/lib/libxml/properties.rb +21 -0
- data/lib/libxml/reader.rb +27 -0
- data/lib/libxml/sax_callbacks.rb +178 -0
- data/lib/libxml/sax_parser.rb +56 -0
- data/lib/libxml/tree.rb +27 -0
- data/lib/libxml/xpath_object.rb +14 -0
- data/lib/xml.rb +14 -0
- data/lib/xml/libxml.rb +8 -0
- data/setup.rb +1585 -0
- data/test/etc_doc_to_s.rb +19 -0
- data/test/ets_doc_file.rb +15 -0
- data/test/ets_doc_to_s.rb +21 -0
- data/test/ets_gpx.rb +26 -0
- data/test/ets_node_gc.rb +21 -0
- data/test/ets_test.xml +2 -0
- data/test/ets_tsr.rb +9 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +146 -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 +31 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/tc_attr.rb +170 -0
- data/test/tc_attr_decl.rb +131 -0
- data/test/tc_attributes.rb +133 -0
- data/test/tc_deprecated_require.rb +11 -0
- data/test/tc_document.rb +113 -0
- data/test/tc_document_write.rb +118 -0
- data/test/tc_dtd.rb +123 -0
- data/test/tc_error.rb +136 -0
- data/test/tc_html_parser.rb +138 -0
- data/test/tc_namespace.rb +59 -0
- data/test/tc_namespaces.rb +174 -0
- data/test/tc_node.rb +181 -0
- data/test/tc_node_cdata.rb +49 -0
- data/test/tc_node_comment.rb +30 -0
- data/test/tc_node_copy.rb +40 -0
- data/test/tc_node_edit.rb +158 -0
- data/test/tc_node_text.rb +69 -0
- data/test/tc_node_write.rb +83 -0
- data/test/tc_node_xlink.rb +26 -0
- data/test/tc_parser.rb +330 -0
- data/test/tc_parser_context.rb +186 -0
- data/test/tc_properties.rb +36 -0
- data/test/tc_reader.rb +284 -0
- data/test/tc_relaxng.rb +51 -0
- data/test/tc_sax_parser.rb +274 -0
- data/test/tc_schema.rb +51 -0
- data/test/tc_traversal.rb +220 -0
- data/test/tc_xinclude.rb +19 -0
- data/test/tc_xml.rb +224 -0
- data/test/tc_xpath.rb +193 -0
- data/test/tc_xpath_context.rb +78 -0
- data/test/tc_xpath_expression.rb +35 -0
- data/test/tc_xpointer.rb +72 -0
- data/test/test_suite.rb +33 -0
- metadata +376 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestParserContext < Test::Unit::TestCase
|
5
|
+
def test_string
|
6
|
+
# UTF8
|
7
|
+
xml = <<-EOS
|
8
|
+
<bands>
|
9
|
+
<metal>m\303\266tley_cr\303\274e</metal>
|
10
|
+
</bands>
|
11
|
+
EOS
|
12
|
+
|
13
|
+
context = XML::Parser::Context.string(xml)
|
14
|
+
assert_instance_of(XML::Parser::Context, context)
|
15
|
+
assert_equal(XML::Encoding::NONE, context.encoding)
|
16
|
+
assert_nil(context.base_uri)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_encoding
|
20
|
+
# ISO_8859_1:
|
21
|
+
xml = <<-EOS
|
22
|
+
<bands>
|
23
|
+
<metal>m\366tley_cr\374e</metal>
|
24
|
+
</bands>
|
25
|
+
EOS
|
26
|
+
|
27
|
+
context = XML::Parser::Context.string(xml)
|
28
|
+
assert_equal(XML::Encoding::NONE, context.encoding)
|
29
|
+
|
30
|
+
context.encoding = XML::Encoding::ISO_8859_1
|
31
|
+
assert_equal(XML::Encoding::ISO_8859_1, context.encoding)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_base_uri
|
35
|
+
# UTF8
|
36
|
+
xml = <<-EOS
|
37
|
+
<bands>
|
38
|
+
<metal>m\303\266tley_cr\303\274e</metal>
|
39
|
+
</bands>
|
40
|
+
EOS
|
41
|
+
|
42
|
+
context = XML::Parser::Context.string(xml)
|
43
|
+
assert_nil(context.base_uri)
|
44
|
+
|
45
|
+
context.base_uri = 'http://libxml.rubyforge.org'
|
46
|
+
assert_equal('http://libxml.rubyforge.org', context.base_uri)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_string_empty
|
50
|
+
error = assert_raise(TypeError) do
|
51
|
+
parser = XML::Parser::Context.string(nil)
|
52
|
+
end
|
53
|
+
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
54
|
+
|
55
|
+
error = assert_raise(ArgumentError) do
|
56
|
+
XML::Parser::Context.string('')
|
57
|
+
end
|
58
|
+
assert_equal("Must specify a string with one or more characters", error.to_s)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_well_formed
|
62
|
+
parser = XML::Parser.string("<abc/>")
|
63
|
+
parser.parse
|
64
|
+
assert(parser.context.well_formed?)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_not_well_formed
|
68
|
+
parser = XML::Parser.string("<abc>")
|
69
|
+
assert_raise(XML::Error) do
|
70
|
+
parser.parse
|
71
|
+
end
|
72
|
+
assert(!parser.context.well_formed?)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_version_info
|
76
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
|
77
|
+
parser = XML::Parser.file(file)
|
78
|
+
assert_nil(parser.context.version)
|
79
|
+
parser.parse
|
80
|
+
assert_equal("1.0", parser.context.version)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_depth
|
84
|
+
context = XML::Parser::Context.new
|
85
|
+
assert_instance_of(Fixnum, context.depth)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_disable_sax
|
89
|
+
context = XML::Parser::Context.new
|
90
|
+
assert(!context.disable_sax?)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_docbook
|
94
|
+
context = XML::Parser::Context.new
|
95
|
+
assert(!context.docbook?)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_html
|
99
|
+
context = XML::Parser::Context.new
|
100
|
+
assert(!context.html?)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_keep_blanks
|
104
|
+
context = XML::Parser::Context.new
|
105
|
+
if context.keep_blanks?
|
106
|
+
assert_instance_of(TrueClass, context.keep_blanks?)
|
107
|
+
else
|
108
|
+
assert_instance_of(FalseClass, context.keep_blanks?)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
if ENV['NOTWORKING']
|
113
|
+
def test_num_chars
|
114
|
+
assert_equal(17, context.num_chars)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_replace_entities
|
119
|
+
context = XML::Parser::Context.new
|
120
|
+
assert(!context.replace_entities?)
|
121
|
+
|
122
|
+
# context.options = 1
|
123
|
+
# assert(context.replace_entities?)
|
124
|
+
|
125
|
+
context.options = 0
|
126
|
+
assert(!context.replace_entities?)
|
127
|
+
|
128
|
+
context.replace_entities = true
|
129
|
+
assert(context.replace_entities?)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_space_depth
|
133
|
+
context = XML::Parser::Context.new
|
134
|
+
assert_equal(1, context.space_depth)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_subset_external
|
138
|
+
context = XML::Parser::Context.new
|
139
|
+
assert(!context.subset_external?)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_data_directory_get
|
143
|
+
context = XML::Parser::Context.new
|
144
|
+
assert_nil(context.data_directory)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_parse_error
|
148
|
+
xp = XML::Parser.string('<foo><bar/></foz>')
|
149
|
+
|
150
|
+
assert_raise(XML::Error) do
|
151
|
+
xp.parse
|
152
|
+
end
|
153
|
+
|
154
|
+
# Now check context
|
155
|
+
context = xp.context
|
156
|
+
assert_equal(nil, context.data_directory)
|
157
|
+
assert_equal(0, context.depth)
|
158
|
+
assert_equal(true, context.disable_sax?)
|
159
|
+
assert_equal(false, context.docbook?)
|
160
|
+
assert_equal(XML::Encoding::NONE, context.encoding)
|
161
|
+
assert_equal(76, context.errno)
|
162
|
+
assert_equal(false, context.html?)
|
163
|
+
assert_equal(5, context.io_max_num_streams)
|
164
|
+
assert_equal(1, context.io_num_streams)
|
165
|
+
assert_equal(true, context.keep_blanks?)
|
166
|
+
assert_equal(1, context.io_num_streams)
|
167
|
+
assert_equal(nil, context.name_node)
|
168
|
+
assert_equal(0, context.name_depth)
|
169
|
+
assert_equal(10, context.name_depth_max)
|
170
|
+
assert_equal(17, context.num_chars)
|
171
|
+
assert_equal(false, context.replace_entities?)
|
172
|
+
assert_equal(1, context.space_depth)
|
173
|
+
assert_equal(10, context.space_depth_max)
|
174
|
+
assert_equal(false, context.subset_external?)
|
175
|
+
assert_equal(nil, context.subset_external_system_id)
|
176
|
+
assert_equal(nil, context.subset_external_uri)
|
177
|
+
assert_equal(false, context.subset_internal?)
|
178
|
+
assert_equal(nil, context.subset_internal_name)
|
179
|
+
assert_equal(false, context.stats?)
|
180
|
+
assert_equal(true, context.standalone?)
|
181
|
+
assert_equal(false, context.valid)
|
182
|
+
assert_equal(false, context.validate?)
|
183
|
+
assert_equal('1.0', context.version)
|
184
|
+
assert_equal(false, context.well_formed?)
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
# Properties is deprecated - use attributes instead.
|
5
|
+
# Tests for backwards compatibility
|
6
|
+
|
7
|
+
class TestProperties < Test::Unit::TestCase
|
8
|
+
def setup()
|
9
|
+
xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
|
10
|
+
@doc = xp.parse
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown()
|
14
|
+
@doc = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_traversal
|
18
|
+
properties = @doc.root.properties
|
19
|
+
|
20
|
+
assert_instance_of(XML::Attributes, properties)
|
21
|
+
attribute = properties.first
|
22
|
+
assert_equal('uga', attribute.name)
|
23
|
+
assert_equal('booga', attribute.value)
|
24
|
+
|
25
|
+
attribute = attribute.next
|
26
|
+
assert_instance_of(XML::Attr, attribute)
|
27
|
+
assert_equal('foo', attribute.name)
|
28
|
+
assert_equal('bar', attribute.value)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_no_properties
|
32
|
+
properties = @doc.root.child.properties
|
33
|
+
assert_instance_of(XML::Attributes, properties)
|
34
|
+
assert_equal(0, properties.length)
|
35
|
+
end
|
36
|
+
end
|
data/test/tc_reader.rb
ADDED
@@ -0,0 +1,284 @@
|
|
1
|
+
require 'xml'
|
2
|
+
require 'stringio'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestReader < Test::Unit::TestCase
|
6
|
+
XML_FILE = File.join(File.dirname(__FILE__), 'model/atom.xml')
|
7
|
+
|
8
|
+
def verify_simple(reader)
|
9
|
+
node_types = []
|
10
|
+
|
11
|
+
# Read each node
|
12
|
+
26.times do
|
13
|
+
assert(reader.read)
|
14
|
+
node_types << reader.node_type
|
15
|
+
end
|
16
|
+
|
17
|
+
# There are no more nodes
|
18
|
+
assert(!reader.read)
|
19
|
+
|
20
|
+
# Check what was read
|
21
|
+
expected = [XML::Reader::TYPE_PROCESSING_INSTRUCTION,
|
22
|
+
XML::Reader::TYPE_ELEMENT,
|
23
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
24
|
+
XML::Reader::TYPE_COMMENT,
|
25
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
26
|
+
XML::Reader::TYPE_ELEMENT,
|
27
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
28
|
+
XML::Reader::TYPE_ELEMENT,
|
29
|
+
XML::Reader::TYPE_CDATA,
|
30
|
+
XML::Reader::TYPE_END_ELEMENT,
|
31
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
32
|
+
XML::Reader::TYPE_ELEMENT,
|
33
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
34
|
+
XML::Reader::TYPE_ELEMENT,
|
35
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
36
|
+
XML::Reader::TYPE_ELEMENT,
|
37
|
+
XML::Reader::TYPE_TEXT,
|
38
|
+
XML::Reader::TYPE_END_ELEMENT,
|
39
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
40
|
+
XML::Reader::TYPE_END_ELEMENT,
|
41
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
42
|
+
XML::Reader::TYPE_END_ELEMENT,
|
43
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
44
|
+
XML::Reader::TYPE_END_ELEMENT,
|
45
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
46
|
+
XML::Reader::TYPE_END_ELEMENT]
|
47
|
+
|
48
|
+
assert_equal(expected, node_types)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_document
|
52
|
+
reader = XML::Reader.document(XML::Document.file(XML_FILE))
|
53
|
+
verify_simple(reader)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_file
|
57
|
+
reader = XML::Reader.file(XML_FILE)
|
58
|
+
verify_simple(reader)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_invalid_file
|
62
|
+
assert_raise(XML::Error) do
|
63
|
+
XML::Reader.file('/does/not/exist')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_string
|
68
|
+
reader = XML::Reader.string(File.read(XML_FILE))
|
69
|
+
verify_simple(reader)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_io
|
73
|
+
File.open(XML_FILE, 'rb') do |io|
|
74
|
+
reader = XML::Reader.io(io)
|
75
|
+
verify_simple(reader)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_io_gc
|
80
|
+
# Test that the reader keeps a reference
|
81
|
+
# to the io object
|
82
|
+
file = File.open(XML_FILE, 'rb')
|
83
|
+
reader = XML::Reader.io(file)
|
84
|
+
file = nil
|
85
|
+
GC.start
|
86
|
+
assert(reader.read)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_string_io
|
90
|
+
data = File.read(XML_FILE)
|
91
|
+
string_io = StringIO.new(data)
|
92
|
+
reader = XML::Reader.io(string_io)
|
93
|
+
verify_simple(reader)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_error
|
97
|
+
reader = XML::Reader.string('<foo blah')
|
98
|
+
|
99
|
+
error = assert_raise(XML::Error) do
|
100
|
+
reader.read
|
101
|
+
end
|
102
|
+
assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", error.to_s)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_deprecated_error_handler
|
106
|
+
called = false
|
107
|
+
reader = XML::Reader.string('<foo blah')
|
108
|
+
reader.set_error_handler do |error|
|
109
|
+
called = true
|
110
|
+
end
|
111
|
+
|
112
|
+
assert_raise(XML::Error) do
|
113
|
+
reader.read
|
114
|
+
end
|
115
|
+
|
116
|
+
assert(called)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_deprecated_reset_error_handler
|
120
|
+
called = false
|
121
|
+
reader = XML::Reader.string('<foo blah')
|
122
|
+
reader.set_error_handler do |error|
|
123
|
+
called = true
|
124
|
+
end
|
125
|
+
reader.reset_error_handler
|
126
|
+
|
127
|
+
assert_raise(XML::Error) do
|
128
|
+
reader.read
|
129
|
+
end
|
130
|
+
|
131
|
+
assert(!called)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_attr
|
135
|
+
parser = XML::Reader.string("<foo x='1' y='2'/>")
|
136
|
+
assert(parser.read)
|
137
|
+
assert_equal('foo', parser.name)
|
138
|
+
assert_equal('1', parser['x'])
|
139
|
+
assert_equal('1', parser[0])
|
140
|
+
assert_equal('2', parser['y'])
|
141
|
+
assert_equal('2', parser[1])
|
142
|
+
assert_equal(nil, parser['z'])
|
143
|
+
assert_equal(nil, parser[2])
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_value
|
147
|
+
parser = XML::Reader.string("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
|
148
|
+
assert(parser.read)
|
149
|
+
assert_equal('foo', parser.name)
|
150
|
+
assert_equal(nil, parser.value)
|
151
|
+
3.times do |i|
|
152
|
+
assert(parser.read)
|
153
|
+
assert_equal(XML::Reader::TYPE_ELEMENT, parser.node_type)
|
154
|
+
assert_equal('bar', parser.name)
|
155
|
+
assert(parser.read)
|
156
|
+
assert_equal(XML::Reader::TYPE_TEXT, parser.node_type)
|
157
|
+
assert_equal((i + 1).to_s, parser.value)
|
158
|
+
assert(parser.read)
|
159
|
+
assert_equal(XML::Reader::TYPE_END_ELEMENT, parser.node_type)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_expand
|
164
|
+
reader = XML::Reader.file(XML_FILE)
|
165
|
+
reader.read
|
166
|
+
node = reader.expand
|
167
|
+
doc = node.doc
|
168
|
+
reader.close
|
169
|
+
GC.start
|
170
|
+
|
171
|
+
doc.standalone?
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_mode
|
175
|
+
reader = XML::Reader.string('<xml/>')
|
176
|
+
assert_equal(XML::Reader::MODE_INITIAL, reader.read_state)
|
177
|
+
reader.read
|
178
|
+
assert_equal(XML::Reader::MODE_EOF, reader.read_state)
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_bytes_consumed
|
182
|
+
reader = XML::Reader.file(XML_FILE)
|
183
|
+
reader.read
|
184
|
+
assert_equal(416, reader.byte_consumed)
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_node
|
188
|
+
XML.default_line_numbers = true
|
189
|
+
reader = XML::Reader.file(XML_FILE)
|
190
|
+
|
191
|
+
# first try to get a node
|
192
|
+
assert_nil(reader.node)
|
193
|
+
|
194
|
+
reader.read
|
195
|
+
assert_instance_of(XML::Node, reader.node)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_base_uri
|
199
|
+
# UTF8:
|
200
|
+
# ö - c3 b6 in hex, \303\266 in octal
|
201
|
+
# ü - c3 bc in hex, \303\274 in octal
|
202
|
+
xml = "<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
|
203
|
+
reader = XML::Reader.string(xml, :base_uri => "http://libxml.rubyforge.org")
|
204
|
+
|
205
|
+
reader.read
|
206
|
+
assert_equal(reader.base_uri, "http://libxml.rubyforge.org")
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_options
|
210
|
+
xml = <<-EOS
|
211
|
+
<!DOCTYPE foo [<!ENTITY foo 'bar'>]>
|
212
|
+
<test>
|
213
|
+
<cdata><![CDATA[something]]></cdata>
|
214
|
+
<entity>&foo;</entity>
|
215
|
+
</test>
|
216
|
+
EOS
|
217
|
+
|
218
|
+
# Parse normally
|
219
|
+
reader = XML::Reader.string(xml)
|
220
|
+
reader.read # foo
|
221
|
+
reader.read # test
|
222
|
+
reader.read # text
|
223
|
+
reader.read # cdata
|
224
|
+
reader.read # cdata-section
|
225
|
+
assert_equal(XML::Node::CDATA_SECTION_NODE, reader.node_type)
|
226
|
+
|
227
|
+
# Convert cdata section to text
|
228
|
+
reader = XML::Reader.string(xml, :options => XML::Parser::Options::NOCDATA)
|
229
|
+
reader.read # foo
|
230
|
+
reader.read # test
|
231
|
+
reader.read # text
|
232
|
+
reader.read # cdata
|
233
|
+
reader.read # cdata-section
|
234
|
+
assert_equal(XML::Node::TEXT_NODE, reader.node_type)
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_encoding
|
238
|
+
# ISO_8859_1:
|
239
|
+
# ö - f6 in hex, \366 in octal
|
240
|
+
# ü - fc in hex, \374 in octal
|
241
|
+
xml = "<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
|
242
|
+
|
243
|
+
reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
|
244
|
+
reader.read
|
245
|
+
|
246
|
+
# libxml converts all data sources to utf8 internally
|
247
|
+
assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
248
|
+
reader.read_outer_xml)
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_invalid_encoding
|
252
|
+
# ISO_8859_1:
|
253
|
+
# ö - f6 in hex, \366 in octal
|
254
|
+
# ü - fc in hex, \374 in octal
|
255
|
+
xml = "<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
|
256
|
+
|
257
|
+
reader = XML::Reader.string(xml)
|
258
|
+
error = assert_raise(XML::Error) do
|
259
|
+
node = reader.read
|
260
|
+
end
|
261
|
+
|
262
|
+
assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
|
263
|
+
error.to_s)
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_file_encoding
|
268
|
+
reader = XML::Reader.file(XML_FILE)
|
269
|
+
reader.read
|
270
|
+
assert_equal(reader.encoding, XML::Encoding::UTF_8)
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_string_encoding
|
274
|
+
# ISO_8859_1:
|
275
|
+
# ö - f6 in hex, \366 in octal
|
276
|
+
# ü - fc in hex, \374 in octal
|
277
|
+
xml = "<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
|
278
|
+
reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
|
279
|
+
reader.read
|
280
|
+
|
281
|
+
# Encoding is always null for strings, very annoying!
|
282
|
+
assert_equal(reader.encoding, XML::Encoding::NONE)
|
283
|
+
end
|
284
|
+
end
|