libxml-ruby 5.0.4 → 5.0.6

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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +17 -6
  3. data/README.rdoc +1 -1
  4. data/Rakefile +98 -98
  5. data/ext/libxml/extconf.h +1 -0
  6. data/ext/libxml/extconf.rb +5 -0
  7. data/ext/libxml/libxml.c +79 -79
  8. data/ext/libxml/ruby_xml.c +556 -556
  9. data/ext/libxml/ruby_xml_attr.c +333 -333
  10. data/ext/libxml/ruby_xml_attr.h +12 -12
  11. data/ext/libxml/ruby_xml_attr_decl.h +11 -11
  12. data/ext/libxml/ruby_xml_attributes.h +17 -17
  13. data/ext/libxml/ruby_xml_cbg.c +85 -85
  14. data/ext/libxml/ruby_xml_document.c +1129 -1129
  15. data/ext/libxml/ruby_xml_dtd.c +257 -257
  16. data/ext/libxml/ruby_xml_dtd.h +9 -9
  17. data/ext/libxml/ruby_xml_encoding.c +250 -250
  18. data/ext/libxml/ruby_xml_error.c +1003 -1003
  19. data/ext/libxml/ruby_xml_error.h +14 -14
  20. data/ext/libxml/ruby_xml_html_parser.c +91 -91
  21. data/ext/libxml/ruby_xml_html_parser.h +10 -10
  22. data/ext/libxml/ruby_xml_html_parser_context.c +351 -351
  23. data/ext/libxml/ruby_xml_html_parser_context.h +10 -10
  24. data/ext/libxml/ruby_xml_html_parser_options.c +48 -48
  25. data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
  26. data/ext/libxml/ruby_xml_input_cbg.c +188 -188
  27. data/ext/libxml/ruby_xml_input_cbg.h +20 -20
  28. data/ext/libxml/ruby_xml_io.c +47 -47
  29. data/ext/libxml/ruby_xml_io.h +10 -10
  30. data/ext/libxml/ruby_xml_namespace.c +151 -151
  31. data/ext/libxml/ruby_xml_namespace.h +10 -10
  32. data/ext/libxml/ruby_xml_namespaces.c +293 -293
  33. data/ext/libxml/ruby_xml_namespaces.h +9 -9
  34. data/ext/libxml/ruby_xml_node.h +13 -13
  35. data/ext/libxml/ruby_xml_parser.c +91 -91
  36. data/ext/libxml/ruby_xml_parser.h +10 -10
  37. data/ext/libxml/ruby_xml_parser_context.c +1009 -1009
  38. data/ext/libxml/ruby_xml_parser_context.h +10 -10
  39. data/ext/libxml/ruby_xml_parser_options.c +74 -74
  40. data/ext/libxml/ruby_xml_parser_options.h +10 -10
  41. data/ext/libxml/ruby_xml_reader.h +14 -14
  42. data/ext/libxml/ruby_xml_relaxng.h +8 -8
  43. data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
  44. data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
  45. data/ext/libxml/ruby_xml_sax_parser.c +108 -108
  46. data/ext/libxml/ruby_xml_sax_parser.h +10 -10
  47. data/ext/libxml/ruby_xml_schema.h +25 -25
  48. data/ext/libxml/ruby_xml_schema_attribute.h +37 -37
  49. data/ext/libxml/ruby_xml_schema_element.h +11 -11
  50. data/ext/libxml/ruby_xml_schema_facet.c +50 -50
  51. data/ext/libxml/ruby_xml_schema_facet.h +9 -9
  52. data/ext/libxml/ruby_xml_schema_type.h +9 -9
  53. data/ext/libxml/ruby_xml_version.h +9 -9
  54. data/ext/libxml/ruby_xml_writer.c +1124 -1124
  55. data/ext/libxml/ruby_xml_writer.h +6 -6
  56. data/ext/libxml/ruby_xml_xinclude.c +20 -20
  57. data/ext/libxml/ruby_xml_xinclude.h +11 -11
  58. data/ext/libxml/ruby_xml_xpath.c +195 -195
  59. data/ext/libxml/ruby_xml_xpath.h +15 -15
  60. data/ext/libxml/ruby_xml_xpath_context.c +362 -362
  61. data/ext/libxml/ruby_xml_xpath_context.h +9 -9
  62. data/ext/libxml/ruby_xml_xpath_expression.h +10 -10
  63. data/ext/libxml/ruby_xml_xpath_object.h +17 -17
  64. data/lib/libxml/attr.rb +122 -122
  65. data/lib/libxml/attr_decl.rb +80 -80
  66. data/lib/libxml/attributes.rb +13 -13
  67. data/lib/libxml/document.rb +194 -194
  68. data/lib/libxml/error.rb +95 -95
  69. data/lib/libxml/hpricot.rb +77 -77
  70. data/lib/libxml/html_parser.rb +96 -96
  71. data/lib/libxml/namespace.rb +61 -61
  72. data/lib/libxml/namespaces.rb +37 -37
  73. data/lib/libxml/node.rb +323 -323
  74. data/lib/libxml/parser.rb +102 -102
  75. data/lib/libxml/sax_callbacks.rb +179 -179
  76. data/lib/libxml/sax_parser.rb +40 -40
  77. data/lib/libxml/tree.rb +28 -28
  78. data/lib/libxml-ruby.rb +2 -2
  79. data/lib/libxml.rb +4 -4
  80. data/lib/xml/libxml.rb +10 -10
  81. data/lib/xml.rb +13 -13
  82. data/libxml-ruby.gemspec +50 -49
  83. data/test/test_document.rb +140 -140
  84. data/test/test_document_write.rb +142 -142
  85. data/test/test_dtd.rb +126 -126
  86. data/test/test_encoding.rb +126 -126
  87. data/test/test_error.rb +197 -194
  88. data/test/test_helper.rb +21 -20
  89. data/test/test_namespace.rb +58 -58
  90. data/test/test_node.rb +235 -235
  91. data/test/test_node_write.rb +93 -93
  92. data/test/test_parser.rb +333 -333
  93. data/test/test_reader.rb +364 -364
  94. data/test/test_writer.rb +500 -468
  95. data/test/test_xml.rb +168 -168
  96. metadata +5 -5
  97. data/test/test.rb +0 -5
data/lib/libxml/tree.rb CHANGED
@@ -1,29 +1,29 @@
1
- # encoding: UTF-8
2
-
3
- module LibXML
4
- module XML
5
- class Tree # :nodoc:
6
- ELEMENT_NODE = Node::ELEMENT_NODE
7
- ATTRIBUTE_NODE = Node::ATTRIBUTE_NODE
8
- TEXT_NODE = Node::TEXT_NODE
9
- CDATA_SECTION_NODE = Node::CDATA_SECTION_NODE
10
- ENTITY_REF_NODE = Node::ENTITY_REF_NODE
11
- ENTITY_NODE = Node::ENTITY_NODE
12
- PI_NODE = Node::PI_NODE
13
- COMMENT_NODE = Node::COMMENT_NODE
14
- DOCUMENT_NODE = Node::DOCUMENT_NODE
15
- DOCUMENT_TYPE_NODE = Node::DOCUMENT_TYPE_NODE
16
- DOCUMENT_FRAG_NODE = Node::DOCUMENT_FRAG_NODE
17
- NOTATION_NODE = Node::NOTATION_NODE
18
- HTML_DOCUMENT_NODE = Node::HTML_DOCUMENT_NODE
19
- DTD_NODE = Node::DTD_NODE
20
- ELEMENT_DECL = Node::ELEMENT_DECL
21
- ATTRIBUTE_DECL = Node::ATTRIBUTE_DECL
22
- ENTITY_DECL = Node::ENTITY_DECL
23
- NAMESPACE_DECL = Node::NAMESPACE_DECL
24
- XINCLUDE_START = Node::XINCLUDE_START
25
- XINCLUDE_END = Node::XINCLUDE_END
26
- DOCB_DOCUMENT_NODE = Node::DOCB_DOCUMENT_NODE
27
- end
28
- end
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Tree # :nodoc:
6
+ ELEMENT_NODE = Node::ELEMENT_NODE
7
+ ATTRIBUTE_NODE = Node::ATTRIBUTE_NODE
8
+ TEXT_NODE = Node::TEXT_NODE
9
+ CDATA_SECTION_NODE = Node::CDATA_SECTION_NODE
10
+ ENTITY_REF_NODE = Node::ENTITY_REF_NODE
11
+ ENTITY_NODE = Node::ENTITY_NODE
12
+ PI_NODE = Node::PI_NODE
13
+ COMMENT_NODE = Node::COMMENT_NODE
14
+ DOCUMENT_NODE = Node::DOCUMENT_NODE
15
+ DOCUMENT_TYPE_NODE = Node::DOCUMENT_TYPE_NODE
16
+ DOCUMENT_FRAG_NODE = Node::DOCUMENT_FRAG_NODE
17
+ NOTATION_NODE = Node::NOTATION_NODE
18
+ HTML_DOCUMENT_NODE = Node::HTML_DOCUMENT_NODE
19
+ DTD_NODE = Node::DTD_NODE
20
+ ELEMENT_DECL = Node::ELEMENT_DECL
21
+ ATTRIBUTE_DECL = Node::ATTRIBUTE_DECL
22
+ ENTITY_DECL = Node::ENTITY_DECL
23
+ NAMESPACE_DECL = Node::NAMESPACE_DECL
24
+ XINCLUDE_START = Node::XINCLUDE_START
25
+ XINCLUDE_END = Node::XINCLUDE_END
26
+ DOCB_DOCUMENT_NODE = Node::DOCB_DOCUMENT_NODE
27
+ end
28
+ end
29
29
  end
data/lib/libxml-ruby.rb CHANGED
@@ -3,9 +3,9 @@
3
3
  # Load the C-based binding.
4
4
  begin
5
5
  RUBY_VERSION =~ /(\d+.\d+)/
6
- require "#{$1}/libxml_ruby"
6
+ require_relative "#{$1}/libxml_ruby"
7
7
  rescue LoadError
8
- require "libxml_ruby"
8
+ require_relative "libxml_ruby"
9
9
  end
10
10
 
11
11
  # Load Ruby supporting code.
data/lib/libxml.rb CHANGED
@@ -1,5 +1,5 @@
1
- # encoding: UTF-8
2
- #
3
- # This include is deprecated, use libxml-ruby instead!
4
-
1
+ # encoding: UTF-8
2
+ #
3
+ # This include is deprecated, use libxml-ruby instead!
4
+
5
5
  require 'libxml-ruby'
data/lib/xml/libxml.rb CHANGED
@@ -1,10 +1,10 @@
1
- # encoding: UTF-8
2
-
3
- # This is here for backward compatibility.
4
- #
5
- # TODO: DEPRECATE!
6
-
7
- require 'libxml.rb'
8
-
9
- include LibXML
10
-
1
+ # encoding: UTF-8
2
+
3
+ # This is here for backward compatibility.
4
+ #
5
+ # TODO: DEPRECATE!
6
+
7
+ require 'libxml.rb'
8
+
9
+ include LibXML
10
+
data/lib/xml.rb CHANGED
@@ -1,14 +1,14 @@
1
- # encoding: UTF-8
2
-
3
- # This file loads libxml and adds the LibXML namespace
4
- # to the toplevel for conveneience. The end result
5
- # is to have XML:: universally exposed.
6
- #
7
- # It is recommend that you only load this file for libs
8
- # that do not have their own namespace, eg. administrative
9
- # scripts, personal programs, etc. For other applications
10
- # require 'libxml' instead and include LibXML into your
11
- # app/libs namespace.
12
-
13
- require 'libxml'
1
+ # encoding: UTF-8
2
+
3
+ # This file loads libxml and adds the LibXML namespace
4
+ # to the toplevel for conveneience. The end result
5
+ # is to have XML:: universally exposed.
6
+ #
7
+ # It is recommend that you only load this file for libs
8
+ # that do not have their own namespace, eg. administrative
9
+ # scripts, personal programs, etc. For other applications
10
+ # require 'libxml' instead and include LibXML into your
11
+ # app/libs namespace.
12
+
13
+ require 'libxml'
14
14
  include LibXML
data/libxml-ruby.gemspec CHANGED
@@ -1,49 +1,50 @@
1
- # encoding: utf-8
2
- require 'date'
3
-
4
- # Determine the current version of the software
5
- version = File.read('ext/libxml/ruby_xml_version.h').match(/\s*RUBY_LIBXML_VERSION\s*['"](\d.+)['"]/)[1]
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = 'libxml-ruby'
9
- spec.version = version
10
- spec.homepage = 'https://xml4r.github.io/libxml-ruby/'
11
- spec.summary = 'Ruby Bindings for LibXML2'
12
- spec.description = <<-EOS
13
- The Libxml-Ruby project provides Ruby language bindings for the GNOME
14
- Libxml2 XML toolkit. It is free software, released under the MIT License.
15
- Libxml-ruby's primary advantage over REXML is performance - if speed
16
- is your need, these are good libraries to consider, as demonstrated
17
- by the informal benchmark below.
18
- EOS
19
- spec.authors = ['Ross Bamform', 'Wai-Sun Chia', 'Sean Chittenden',
20
- 'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage',
21
- 'Ryan Johnson']
22
- spec.platform = Gem::Platform::RUBY
23
- spec.bindir = 'bin'
24
- spec.extensions = ['ext/libxml/extconf.rb']
25
- spec.files = Dir.glob(['HISTORY',
26
- 'LICENSE',
27
- 'libxml-ruby.gemspec',
28
- 'MANIFEST',
29
- 'Rakefile',
30
- 'README.rdoc',
31
- 'setup.rb',
32
- 'ext/libxml/*.def',
33
- 'ext/libxml/*.h',
34
- 'ext/libxml/*.c',
35
- 'ext/libxml/*.rb',
36
- 'ext/vc/*.sln',
37
- 'ext/vc/*.vcprojx',
38
- 'lib/**/*.rb',
39
- 'script/**/*',
40
- 'test/**/*'])
41
-
42
- spec.test_files = Dir.glob('test/test_*.rb')
43
- spec.required_ruby_version = '>= 2.5'
44
- spec.date = DateTime.now
45
- spec.add_development_dependency('logger')
46
- spec.add_development_dependency('rake-compiler')
47
- spec.add_development_dependency('minitest')
48
- spec.license = 'MIT'
49
- end
1
+ # encoding: utf-8
2
+ require 'date'
3
+
4
+ # Determine the current version of the software
5
+ version = File.read('ext/libxml/ruby_xml_version.h').match(/\s*RUBY_LIBXML_VERSION\s*['"](\d.+)['"]/)[1]
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'libxml-ruby'
9
+ spec.version = version
10
+ spec.homepage = 'https://xml4r.github.io/libxml-ruby/'
11
+ spec.summary = 'Ruby Bindings for LibXML2'
12
+ spec.description = <<-EOS
13
+ The Libxml-Ruby project provides Ruby language bindings for the GNOME
14
+ Libxml2 XML toolkit. It is free software, released under the MIT License.
15
+ Libxml-ruby's primary advantage over REXML is performance - if speed
16
+ is your need, these are good libraries to consider, as demonstrated
17
+ by the informal benchmark below.
18
+ EOS
19
+ spec.authors = ['Ross Bamform', 'Wai-Sun Chia', 'Sean Chittenden',
20
+ 'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage',
21
+ 'Ryan Johnson']
22
+ spec.platform = Gem::Platform::RUBY
23
+ spec.bindir = 'bin'
24
+ spec.extensions = ['ext/libxml/extconf.rb']
25
+ spec.metadata = {'documentation_uri' => 'https://xml4r.github.io/libxml-ruby/'}
26
+ spec.files = Dir.glob(['HISTORY',
27
+ 'LICENSE',
28
+ 'libxml-ruby.gemspec',
29
+ 'MANIFEST',
30
+ 'Rakefile',
31
+ 'README.rdoc',
32
+ 'setup.rb',
33
+ 'ext/libxml/*.def',
34
+ 'ext/libxml/*.h',
35
+ 'ext/libxml/*.c',
36
+ 'ext/libxml/*.rb',
37
+ 'ext/vc/*.sln',
38
+ 'ext/vc/*.vcprojx',
39
+ 'lib/**/*.rb',
40
+ 'script/**/*',
41
+ 'test/**/*'])
42
+
43
+ spec.test_files = Dir.glob('test/test_*.rb')
44
+ spec.required_ruby_version = '>= 2.5'
45
+ spec.date = DateTime.now
46
+ spec.add_development_dependency('logger')
47
+ spec.add_development_dependency('rake-compiler')
48
+ spec.add_development_dependency('minitest')
49
+ spec.license = 'MIT'
50
+ end
@@ -1,140 +1,140 @@
1
- # encoding: UTF-8
2
- require_relative './test_helper'
3
-
4
- class TestDocument < Minitest::Test
5
- def setup
6
- xp = LibXML::XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
7
- assert_instance_of(LibXML::XML::Parser, xp)
8
- @doc = xp.parse
9
- assert_instance_of(LibXML::XML::Document, @doc)
10
- end
11
-
12
- def teardown
13
- @doc = nil
14
- end
15
-
16
- def test_klass
17
- assert_instance_of(LibXML::XML::Document, @doc)
18
- end
19
-
20
- def test_context
21
- context = @doc.context
22
- assert_instance_of(LibXML::XML::XPath::Context, context)
23
- end
24
-
25
- def test_find
26
- set = @doc.find('/ruby_array/fixnum')
27
- assert_instance_of(LibXML::XML::XPath::Object, set)
28
- assert_raises(NoMethodError) {
29
- set.xpath
30
- }
31
- end
32
-
33
- def test_compression
34
- if LibXML::XML.enabled_zlib?
35
- 0.upto(9) do |i|
36
- assert_equal(i, @doc.compression = i)
37
- assert_equal(i, @doc.compression)
38
- end
39
-
40
- 9.downto(0) do |i|
41
- assert_equal(i, @doc.compression = i)
42
- assert_equal(i, @doc.compression)
43
- end
44
-
45
- 10.upto(20) do |i|
46
- # assert_equal(9, @doc.compression = i)
47
- assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
48
- assert_equal(9, @doc.compression)
49
- end
50
-
51
- -1.downto(-10) do |i|
52
- # assert_equal(0, @doc.compression = i)
53
- assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
54
- assert_equal(0, @doc.compression)
55
- end
56
- end
57
- end
58
-
59
- def test_version
60
- assert_equal('1.0', @doc.version)
61
-
62
- doc = LibXML::XML::Document.new('6.9')
63
- assert_equal('6.9', doc.version)
64
- end
65
-
66
- def test_write_root
67
- @doc.root = LibXML::XML::Node.new('rubynet')
68
- assert_instance_of(LibXML::XML::Node, @doc.root)
69
- assert_instance_of(LibXML::XML::Document, @doc.root.doc)
70
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
71
- @doc.to_s(:indent => false))
72
- end
73
-
74
- def test_doc_node_type
75
- assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type)
76
- end
77
-
78
- def test_doc_node_type_name
79
- assert_equal('document_xml', LibXML::XML::Document.new.node_type_name)
80
- end
81
-
82
- def test_xhtml
83
- doc = LibXML::XML::Document.new
84
- assert(!doc.xhtml?)
85
- LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true)
86
- assert(doc.xhtml?)
87
- end
88
-
89
- def test_document_root
90
- doc1 = LibXML::XML::Document.string("<one/>")
91
- doc2 = LibXML::XML::Document.string("<two/>")
92
-
93
- error = assert_raises(LibXML::XML::Error) do
94
- doc1.root = doc2.root
95
- end
96
- assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
97
- error.to_s)
98
-
99
- doc2.root << doc2.import(doc1.root)
100
- assert_equal('<one/>', doc1.root.to_s)
101
- assert_equal('<two><one/></two>', doc2.root.to_s(:indent => false))
102
-
103
- assert(!doc1.root.equal?(doc2.root))
104
- assert(doc1.root.doc != doc2.root.doc)
105
- end
106
-
107
- def test_import_node
108
- doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
109
- doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
110
-
111
- node = doc1.root.child
112
-
113
- error = assert_raises(LibXML::XML::Error) do
114
- doc2.root << node
115
- end
116
-
117
- assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
118
- error.to_s)
119
-
120
- doc2.root << doc2.import(node)
121
-
122
- assert_equal("<nums><two/><one/></nums>",
123
- doc2.root.to_s(:indent => false))
124
- end
125
-
126
- def test_nonet
127
- xml_string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
128
- xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET)
129
- file = File.join(File.dirname(__FILE__), 'model/atom.xml')
130
- schema_document = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NONET)
131
- end
132
-
133
- def test_io
134
- File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
135
- doc = LibXML::XML::Document.io(io)
136
- assert_instance_of(LibXML::XML::Document, doc)
137
- end
138
- end
139
-
140
- end
1
+ # encoding: UTF-8
2
+ require_relative './test_helper'
3
+
4
+ class TestDocument < Minitest::Test
5
+ def setup
6
+ xp = LibXML::XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
7
+ assert_instance_of(LibXML::XML::Parser, xp)
8
+ @doc = xp.parse
9
+ assert_instance_of(LibXML::XML::Document, @doc)
10
+ end
11
+
12
+ def teardown
13
+ @doc = nil
14
+ end
15
+
16
+ def test_klass
17
+ assert_instance_of(LibXML::XML::Document, @doc)
18
+ end
19
+
20
+ def test_context
21
+ context = @doc.context
22
+ assert_instance_of(LibXML::XML::XPath::Context, context)
23
+ end
24
+
25
+ def test_find
26
+ set = @doc.find('/ruby_array/fixnum')
27
+ assert_instance_of(LibXML::XML::XPath::Object, set)
28
+ assert_raises(NoMethodError) {
29
+ set.xpath
30
+ }
31
+ end
32
+
33
+ def test_compression
34
+ if LibXML::XML.enabled_zlib?
35
+ 0.upto(9) do |i|
36
+ assert_equal(i, @doc.compression = i)
37
+ assert_equal(i, @doc.compression)
38
+ end
39
+
40
+ 9.downto(0) do |i|
41
+ assert_equal(i, @doc.compression = i)
42
+ assert_equal(i, @doc.compression)
43
+ end
44
+
45
+ 10.upto(20) do |i|
46
+ # assert_equal(9, @doc.compression = i)
47
+ assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
48
+ assert_equal(9, @doc.compression)
49
+ end
50
+
51
+ -1.downto(-10) do |i|
52
+ # assert_equal(0, @doc.compression = i)
53
+ assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
54
+ assert_equal(0, @doc.compression)
55
+ end
56
+ end
57
+ end
58
+
59
+ def test_version
60
+ assert_equal('1.0', @doc.version)
61
+
62
+ doc = LibXML::XML::Document.new('6.9')
63
+ assert_equal('6.9', doc.version)
64
+ end
65
+
66
+ def test_write_root
67
+ @doc.root = LibXML::XML::Node.new('rubynet')
68
+ assert_instance_of(LibXML::XML::Node, @doc.root)
69
+ assert_instance_of(LibXML::XML::Document, @doc.root.doc)
70
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
71
+ @doc.to_s(:indent => false))
72
+ end
73
+
74
+ def test_doc_node_type
75
+ assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type)
76
+ end
77
+
78
+ def test_doc_node_type_name
79
+ assert_equal('document_xml', LibXML::XML::Document.new.node_type_name)
80
+ end
81
+
82
+ def test_xhtml
83
+ doc = LibXML::XML::Document.new
84
+ assert(!doc.xhtml?)
85
+ LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true)
86
+ assert(doc.xhtml?)
87
+ end
88
+
89
+ def test_document_root
90
+ doc1 = LibXML::XML::Document.string("<one/>")
91
+ doc2 = LibXML::XML::Document.string("<two/>")
92
+
93
+ error = assert_raises(LibXML::XML::Error) do
94
+ doc1.root = doc2.root
95
+ end
96
+ assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
97
+ error.to_s)
98
+
99
+ doc2.root << doc2.import(doc1.root)
100
+ assert_equal('<one/>', doc1.root.to_s)
101
+ assert_equal('<two><one/></two>', doc2.root.to_s(:indent => false))
102
+
103
+ assert(!doc1.root.equal?(doc2.root))
104
+ assert(doc1.root.doc != doc2.root.doc)
105
+ end
106
+
107
+ def test_import_node
108
+ doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
109
+ doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
110
+
111
+ node = doc1.root.child
112
+
113
+ error = assert_raises(LibXML::XML::Error) do
114
+ doc2.root << node
115
+ end
116
+
117
+ assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
118
+ error.to_s)
119
+
120
+ doc2.root << doc2.import(node)
121
+
122
+ assert_equal("<nums><two/><one/></nums>",
123
+ doc2.root.to_s(:indent => false))
124
+ end
125
+
126
+ def test_nonet
127
+ xml_string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
128
+ xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET)
129
+ file = File.join(File.dirname(__FILE__), 'model/atom.xml')
130
+ schema_document = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NONET)
131
+ end
132
+
133
+ def test_io
134
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
135
+ doc = LibXML::XML::Document.io(io)
136
+ assert_instance_of(LibXML::XML::Document, doc)
137
+ end
138
+ end
139
+
140
+ end