libxml-ruby 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +8 -0
  3. data/ext/libxml/extconf.h +3 -0
  4. data/ext/libxml/extconf.rb +30 -26
  5. data/ext/libxml/ruby_libxml.h +0 -8
  6. data/ext/libxml/ruby_xml.c +40 -0
  7. data/ext/libxml/ruby_xml_document.c +1 -1
  8. data/ext/libxml/ruby_xml_dtd.c +6 -8
  9. data/ext/libxml/ruby_xml_node.c +1 -1
  10. data/ext/libxml/ruby_xml_parser_context.c +1 -1
  11. data/ext/libxml/ruby_xml_version.h +3 -3
  12. data/lib/libxml-ruby.rb +30 -0
  13. data/lib/libxml.rb +3 -28
  14. data/libxml-ruby.gemspec +2 -2
  15. data/test/test_attr.rb +18 -18
  16. data/test/test_attr_decl.rb +8 -8
  17. data/test/test_attributes.rb +10 -10
  18. data/test/test_canonicalize.rb +16 -24
  19. data/test/test_deprecated_require.rb +3 -3
  20. data/test/test_document.rb +118 -112
  21. data/test/test_document_write.rb +39 -88
  22. data/test/test_dtd.rb +23 -23
  23. data/test/test_encoding.rb +15 -15
  24. data/test/test_encoding_sax.rb +3 -3
  25. data/test/test_error.rb +51 -51
  26. data/test/test_helper.rb +2 -9
  27. data/test/test_html_parser.rb +30 -30
  28. data/test/test_html_parser_context.rb +6 -6
  29. data/test/test_namespace.rb +16 -16
  30. data/test/test_namespaces.rb +25 -25
  31. data/test/test_node.rb +36 -30
  32. data/test/test_node_cdata.rb +10 -10
  33. data/test/test_node_comment.rb +6 -6
  34. data/test/test_node_copy.rb +2 -2
  35. data/test/test_node_edit.rb +16 -16
  36. data/test/test_node_pi.rb +7 -7
  37. data/test/test_node_text.rb +6 -6
  38. data/test/test_node_write.rb +16 -26
  39. data/test/test_node_xlink.rb +6 -6
  40. data/test/test_parser.rb +68 -72
  41. data/test/test_parser_context.rb +28 -28
  42. data/test/test_properties.rb +5 -5
  43. data/test/test_reader.rb +80 -85
  44. data/test/test_relaxng.rb +11 -11
  45. data/test/test_sax_parser.rb +28 -28
  46. data/test/test_schema.rb +24 -24
  47. data/test/test_suite.rb +3 -4
  48. data/test/test_traversal.rb +4 -4
  49. data/test/test_writer.rb +50 -52
  50. data/test/test_xinclude.rb +3 -3
  51. data/test/test_xml.rb +114 -102
  52. data/test/test_xpath.rb +22 -22
  53. data/test/test_xpath_context.rb +5 -5
  54. data/test/test_xpath_expression.rb +6 -6
  55. data/test/test_xpointer.rb +15 -15
  56. metadata +6 -5
@@ -1,10 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.expand_path('../test_helper', __FILE__)
3
+ require_relative './test_helper'
4
4
 
5
5
  class AttributesTest < Minitest::Test
6
6
  def setup
7
- xp = XML::Parser.string(<<-EOS)
7
+ xp = LibXML::XML::Parser.string(<<-EOS)
8
8
  <CityModel name="value"
9
9
  xmlns="http://www.opengis.net/examples"
10
10
  xmlns:city="http://www.opengis.net/examples"
@@ -33,14 +33,14 @@ class AttributesTest < Minitest::Test
33
33
 
34
34
  def test_attributes
35
35
  attributes = city_member.attributes
36
- assert_instance_of(XML::Attributes, attributes)
36
+ assert_instance_of(LibXML::XML::Attributes, attributes)
37
37
  assert_equal(5, attributes.length)
38
38
  end
39
39
 
40
40
  def test_each
41
41
  attributes = city_member.attributes
42
42
  length = attributes.inject(0) do |result, attr|
43
- assert_instance_of(XML::Attr, attr)
43
+ assert_instance_of(LibXML::XML::Attr, attr)
44
44
  result + 1
45
45
  end
46
46
  assert_equal(5, length)
@@ -50,25 +50,25 @@ class AttributesTest < Minitest::Test
50
50
  attributes = city_member.attributes
51
51
 
52
52
  attr = attributes.get_attribute('name')
53
- assert_instance_of(XML::Attr, attr)
53
+ assert_instance_of(LibXML::XML::Attr, attr)
54
54
 
55
55
  attr = attributes.get_attribute('does_not_exist')
56
56
  assert_nil(attr)
57
57
 
58
58
  attr = attributes.get_attribute('name')
59
- assert_instance_of(XML::Attr, attr)
59
+ assert_instance_of(LibXML::XML::Attr, attr)
60
60
 
61
61
  attr = attributes.get_attribute('href')
62
- assert_instance_of(XML::Attr, attr)
63
- assert_instance_of(XML::Namespace, attr.ns)
62
+ assert_instance_of(LibXML::XML::Attr, attr)
63
+ assert_instance_of(LibXML::XML::Namespace, attr.ns)
64
64
  assert_equal('xlink', attr.ns.prefix)
65
65
  assert_equal('http://www.w3.org/1999/xlink', attr.ns.href)
66
66
 
67
67
  attr = attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
68
- assert_instance_of(XML::Attr, attr)
68
+ assert_instance_of(LibXML::XML::Attr, attr)
69
69
 
70
70
  attr = attributes.get_attribute_ns('http://www.opengis.net/gml', 'remoteSchema')
71
- assert_instance_of(XML::Attr, attr)
71
+ assert_instance_of(LibXML::XML::Attr, attr)
72
72
 
73
73
  attr = attributes.get_attribute_ns('http://i.dont.exist', 'nor do i')
74
74
  assert_nil(attr)
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
- require File.expand_path('../test_helper', __FILE__)
2
+ require_relative './test_helper'
3
3
 
4
4
  class TestCanonicalize < Minitest::Test
5
5
  def path(file)
@@ -9,7 +9,7 @@ class TestCanonicalize < Minitest::Test
9
9
  # (www.w3.org) 3.1 PIs, Comments, and Outside of Document Element
10
10
  # http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
11
11
  def test_canonicalize_with_w3c_c14n_3_1
12
- given_doc = XML::Document.file(self.path('c14n/given/example-1.xml'))
12
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-1.xml'))
13
13
 
14
14
  # With Comments
15
15
  expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-1'))
@@ -22,7 +22,7 @@ class TestCanonicalize < Minitest::Test
22
22
 
23
23
  # Without Comments (XML_C14N_1_1)
24
24
  expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-1'))
25
- mode = XML::Document::XML_C14N_1_1
25
+ mode = LibXML::XML::Document::XML_C14N_1_1
26
26
  assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
27
27
  end#test_canonicalize_with_w3c_c14n_3_1
28
28
 
@@ -30,12 +30,12 @@ class TestCanonicalize < Minitest::Test
30
30
  # (www.w3.org) 3.2 Whitespace in Document Content
31
31
  # http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
32
32
  def test_canonicalize_with_w3c_c14n_3_2
33
- given_doc = XML::Document.file(self.path('c14n/given/example-2.xml'))
33
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-2.xml'))
34
34
  expected = IO.read(self.path('c14n/result/without-comments/example-2'))
35
35
  assert_equal(expected, given_doc.canonicalize)
36
36
 
37
37
  expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-2'))
38
- mode = XML::Document::XML_C14N_1_1
38
+ mode = LibXML::XML::Document::XML_C14N_1_1
39
39
  assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
40
40
  end
41
41
 
@@ -45,24 +45,24 @@ class TestCanonicalize < Minitest::Test
45
45
  # - Embedded DTD not parsed out of XML, therefore default attributes are
46
46
  # not applied to canonicalization.
47
47
  def test_canonicalize_with_w3c_c14n_3_3
48
- given_doc = XML::Document.file(self.path('c14n/given/example-3.xml'))
48
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-3.xml'))
49
49
  expected = IO.read(self.path('c14n/result/without-comments/example-3'))
50
50
  assert_equal(expected, given_doc.canonicalize)
51
51
 
52
52
  expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-3'))
53
- mode = XML::Document::XML_C14N_1_1
53
+ mode = LibXML::XML::Document::XML_C14N_1_1
54
54
  assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
55
55
  end
56
56
 
57
57
  # (www.w3.org) 3.4 Character Modifications and Character References
58
58
  # http://www.w3.org/TR/xml-c14n#Example-Chars
59
59
  def test_canonicalize_with_w3c_c14n_3_4
60
- given_doc = XML::Document.file(self.path('c14n/given/example-4.xml'))
60
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-4.xml'))
61
61
  expected = IO.read(self.path('c14n/result/without-comments/example-4'))
62
62
  assert_equal(expected, given_doc.canonicalize)
63
63
 
64
64
  expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-4'))
65
- mode = XML::Document::XML_C14N_1_1
65
+ mode = LibXML::XML::Document::XML_C14N_1_1
66
66
  assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
67
67
  end
68
68
 
@@ -71,7 +71,7 @@ class TestCanonicalize < Minitest::Test
71
71
  # (2012-02-20) Failing likely due to a logic error
72
72
  # - libxml2(c14n.c:1788) XML_ENTITY_REF_NODE is invalid node for parsing.
73
73
  def test_canonicalize_with_w3c_c14n_3_5
74
- #given_doc = XML::Document.file(self.path('c14n/given/example-5.xml'))
74
+ #given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-5.xml'))
75
75
 
76
76
  # With Comments
77
77
  #expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-5'))
@@ -84,7 +84,7 @@ class TestCanonicalize < Minitest::Test
84
84
  # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
85
85
  #assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
86
86
  #expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-5'))
87
- #mode = XML::Document::XML_C14N_1_1
87
+ #mode = LibXML::XML::Document::XML_C14N_1_1
88
88
 
89
89
  # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
90
90
  #assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
@@ -93,20 +93,12 @@ class TestCanonicalize < Minitest::Test
93
93
  # (www.w3.org) 3.6 UTF-8 Encoding
94
94
  # http://www.w3.org/TR/xml-c14n#Example-UTF8
95
95
  def test_canonicalize_with_w3c_c14n_3_6
96
- given_doc = XML::Document.file(self.path('c14n/given/example-6.xml'))
97
- if defined?(Encoding)
98
- expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8)
99
- else
100
- expected = IO.read(self.path('c14n/result/without-comments/example-6'))
101
- end
96
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-6.xml'))
97
+ expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8)
102
98
  assert_equal(expected, given_doc.canonicalize)
103
99
 
104
- if defined?(Encoding)
105
- expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8)
106
- else
107
- expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'))
108
- end
109
- mode = XML::Document::XML_C14N_1_1
100
+ expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8)
101
+ mode = LibXML::XML::Document::XML_C14N_1_1
110
102
  assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
111
103
  end
112
104
 
@@ -114,7 +106,7 @@ class TestCanonicalize < Minitest::Test
114
106
  # http://www.w3.org/TR/xml-c14n#Example-DocSubsets
115
107
  def test_canonicalize_with_w3c_c14n_3_7
116
108
  # Non Canonicalized Document
117
- # given_doc = XML::Document.file(self.path('c14n/given/example-7.xml'))
109
+ # given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-7.xml'))
118
110
  #expected = IO.read(self.path('c14n/result/without-comments/example-7'))
119
111
 
120
112
  # e1_node = given_doc.find_first('ietf:e1', 'ietf:http://www.ietf.org')
@@ -4,9 +4,9 @@ require 'xml/libxml'
4
4
 
5
5
  class TestDeprecatedRequire < Minitest::Test
6
6
  def test_basic
7
- xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
8
- assert_instance_of(XML::Parser, xp)
7
+ xp = LibXML::XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
8
+ assert_instance_of(LibXML::XML::Parser, xp)
9
9
  @doc = xp.parse
10
- assert_instance_of(XML::Document, @doc)
10
+ assert_instance_of(LibXML::XML::Document, @doc)
11
11
  end
12
12
  end
@@ -1,125 +1,131 @@
1
1
  # encoding: UTF-8
2
- require File.expand_path('../test_helper', __FILE__)
2
+ require_relative './test_helper'
3
3
 
4
4
  class TestDocument < Minitest::Test
5
5
  def setup
6
- xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
7
- assert_instance_of(XML::Parser, xp)
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
8
  @doc = xp.parse
9
- assert_instance_of(XML::Document, @doc)
9
+ assert_instance_of(LibXML::XML::Document, @doc)
10
10
  end
11
11
 
12
12
  def teardown
13
13
  @doc = nil
14
14
  end
15
15
 
16
- def test_klass
17
- assert_instance_of(XML::Document, @doc)
18
- end
19
-
20
- def test_context
21
- context = @doc.context
22
- assert_instance_of(XML::XPath::Context, context)
23
- end
24
-
25
- def test_find
26
- set = @doc.find('/ruby_array/fixnum')
27
- assert_instance_of(XML::XPath::Object, set)
28
- assert_raises(NoMethodError) {
29
- set.xpath
30
- }
31
- end
32
-
33
- def test_compression
34
- if 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 = XML::Document.new('6.9')
63
- assert_equal('6.9', doc.version)
64
- end
65
-
66
- def test_write_root
67
- @doc.root = XML::Node.new('rubynet')
68
- assert_instance_of(XML::Node, @doc.root)
69
- assert_instance_of(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(XML::Node::DOCUMENT_NODE, XML::Document.new.node_type)
76
- end
77
-
78
- def test_doc_node_type_name
79
- assert_equal('document_xml', XML::Document.new.node_type_name)
80
- end
81
-
82
- def test_xhtml
83
- doc = XML::Document.new
84
- assert(!doc.xhtml?)
85
- 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(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 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 = XML::Parser.string('<nums><one></one></nums>').parse
109
- doc2 = XML::Parser.string('<nums><two></two></nums>').parse
110
-
111
- node = doc1.root.child
112
-
113
- error = assert_raises(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 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))
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
+ schema_document = LibXML::XML::Document.file('d:/src/libxml-ruby/test/model/atom.xml', options: LibXML::XML::Parser::Options::NONET)
124
130
  end
125
131
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.expand_path('../test_helper', __FILE__)
3
+ require_relative './test_helper'
4
4
  require 'tmpdir'
5
5
 
6
6
  class TestDocumentWrite < Minitest::Test
@@ -8,56 +8,41 @@ class TestDocumentWrite < Minitest::Test
8
8
  @file_name = "model/bands.utf-8.xml"
9
9
 
10
10
  # Strip spaces to make testing easier
11
- XML.default_keep_blanks = false
11
+ LibXML::XML.default_keep_blanks = false
12
12
  file = File.join(File.dirname(__FILE__), @file_name)
13
- @doc = XML::Document.file(file)
13
+ @doc = LibXML::XML::Document.file(file)
14
14
  end
15
15
 
16
16
  def teardown
17
- XML.default_keep_blanks = true
17
+ LibXML::XML.default_keep_blanks = true
18
18
  @doc = nil
19
19
  end
20
20
 
21
21
  # --- to_s tests ---
22
22
  def test_to_s_default
23
23
  # Default to_s has indentation
24
- if defined?(Encoding)
25
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
26
- @doc.to_s)
27
- else
28
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
29
- @doc.to_s)
30
- end
24
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
25
+ @doc.to_s)
31
26
  end
32
27
 
33
28
  def test_to_s_no_global_indentation
34
29
  # No indentation due to global setting
35
- XML.indent_tree_output = false
30
+ LibXML::XML.indent_tree_output = false
36
31
  value = @doc.to_s
37
32
 
38
- if defined?(Encoding)
39
- assert_equal(Encoding::UTF_8, value.encoding)
40
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n<m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n<iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
41
- value)
42
- else
43
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
44
- value)
45
- end
33
+ assert_equal(Encoding::UTF_8, value.encoding)
34
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n<m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n<iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
35
+ value)
46
36
  ensure
47
- XML.indent_tree_output = true
37
+ LibXML::XML.indent_tree_output = true
48
38
  end
49
39
 
50
40
  def test_to_s_no_indentation
51
41
  # No indentation due to local setting
52
42
  value = @doc.to_s(:indent => false)
53
- if defined?(Encoding)
54
- assert_equal(Encoding::UTF_8, value.encoding)
55
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\"><m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
56
- value)
57
- else
58
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
59
- value)
60
- end
43
+ assert_equal(Encoding::UTF_8, value.encoding)
44
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\"><m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
45
+ value)
61
46
  end
62
47
 
63
48
  def test_to_s_encoding
@@ -66,28 +51,18 @@ class TestDocumentWrite < Minitest::Test
66
51
  # UTF8:
67
52
  # ö - c3 b6 in hex, \303\266 in octal
68
53
  # ü - c3 bc in hex, \303\274 in octal
69
- value = @doc.to_s(:encoding => XML::Encoding::UTF_8)
70
- if defined?(Encoding)
71
- assert_equal(Encoding::UTF_8, value.encoding)
72
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
73
- value)
74
- else
75
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
76
- value)
77
- end
54
+ value = @doc.to_s(:encoding => LibXML::XML::Encoding::UTF_8)
55
+ assert_equal(Encoding::UTF_8, value.encoding)
56
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
57
+ value)
78
58
 
79
59
  # ISO_8859_1:
80
60
  # ö - f6 in hex, \366 in octal
81
61
  # ü - fc in hex, \374 in octal
82
- value = @doc.to_s(:encoding => XML::Encoding::ISO_8859_1)
83
- if defined?(Encoding)
84
- assert_equal(Encoding::ISO8859_1, value.encoding)
85
- assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n".force_encoding(Encoding::ISO8859_1),
86
- @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
87
- else
88
- assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">M\366tley Cr\374e is an American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
89
- @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
90
- end
62
+ value = @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1)
63
+ assert_equal(Encoding::ISO8859_1, value.encoding)
64
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n".force_encoding(Encoding::ISO8859_1),
65
+ @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1))
91
66
 
92
67
  # Invalid encoding
93
68
  error = assert_raises(ArgumentError) do
@@ -103,16 +78,10 @@ class TestDocumentWrite < Minitest::Test
103
78
  bytes = @doc.save(temp_filename)
104
79
  assert_equal(305, bytes)
105
80
 
106
- if defined?(Encoding)
107
- contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
108
- assert_equal(Encoding::UTF_8, contents.encoding)
109
- assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
110
- contents)
111
- else
112
- contents = File.read(temp_filename)
113
- assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
114
- contents)
115
- end
81
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
82
+ assert_equal(Encoding::UTF_8, contents.encoding)
83
+ assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
84
+ contents)
116
85
  ensure
117
86
  File.delete(temp_filename)
118
87
  end
@@ -123,53 +92,35 @@ class TestDocumentWrite < Minitest::Test
123
92
  bytes = @doc.save(temp_filename, :indent => false)
124
93
  assert_equal(298, bytes)
125
94
 
126
- if defined?(Encoding)
127
- contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
128
- assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\"><m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
129
- contents)
130
- else
131
- contents = File.read(temp_filename)
132
- assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
133
- contents)
134
- end
95
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
96
+ assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\"><m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
97
+ contents)
135
98
  ensure
136
99
  File.delete(temp_filename)
137
100
  end
138
101
 
139
102
  def test_save_iso_8859_1
140
103
  temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml")
141
- bytes = @doc.save(temp_filename, :encoding => XML::Encoding::ISO_8859_1)
104
+ bytes = @doc.save(temp_filename, :encoding => LibXML::XML::Encoding::ISO_8859_1)
142
105
  assert_equal(304, bytes)
143
106
 
144
- if defined?(Encoding)
145
- contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
146
- assert_equal(Encoding::ISO8859_1, contents.encoding)
147
- assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n".force_encoding(Encoding::ISO8859_1),
148
- contents)
149
- else
150
- contents = File.read(temp_filename)
151
- assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
152
- contents)
153
- end
107
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
108
+ assert_equal(Encoding::ISO8859_1, contents.encoding)
109
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n".force_encoding(Encoding::ISO8859_1),
110
+ contents)
154
111
  ensure
155
112
  File.delete(temp_filename)
156
113
  end
157
114
 
158
115
  def test_save_iso_8859_1_no_indent
159
116
  temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml")
160
- bytes = @doc.save(temp_filename, :indent => false, :encoding => XML::Encoding::ISO_8859_1)
117
+ bytes = @doc.save(temp_filename, :indent => false, :encoding => LibXML::XML::Encoding::ISO_8859_1)
161
118
  assert_equal(297, bytes)
162
119
 
163
- if defined?(Encoding)
164
- contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
165
- assert_equal(Encoding::ISO8859_1, contents.encoding)
166
- assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\"><m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n".force_encoding(Encoding::ISO8859_1),
167
- contents)
168
- else
169
- contents = File.read(temp_filename)
170
- assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\"><m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
171
- contents)
172
- end
120
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
121
+ assert_equal(Encoding::ISO8859_1, contents.encoding)
122
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\"><m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n".force_encoding(Encoding::ISO8859_1),
123
+ contents)
173
124
  ensure
174
125
  File.delete(temp_filename)
175
126
  end