libxml-ruby 3.0.0 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY +37 -0
  3. data/MANIFEST +34 -34
  4. data/README.rdoc +65 -36
  5. data/Rakefile +21 -3
  6. data/ext/libxml/extconf.rb +30 -26
  7. data/ext/libxml/ruby_libxml.h +0 -8
  8. data/ext/libxml/ruby_xml.c +40 -0
  9. data/ext/libxml/ruby_xml_document.c +1 -5
  10. data/ext/libxml/ruby_xml_dtd.c +6 -8
  11. data/ext/libxml/ruby_xml_encoding.c +1 -13
  12. data/ext/libxml/ruby_xml_encoding.h +0 -3
  13. data/ext/libxml/ruby_xml_error.c +1 -1
  14. data/ext/libxml/ruby_xml_error.h +1 -1
  15. data/ext/libxml/ruby_xml_io.c +14 -18
  16. data/ext/libxml/ruby_xml_io.h +1 -1
  17. data/ext/libxml/ruby_xml_node.c +16 -17
  18. data/ext/libxml/ruby_xml_parser_context.c +1 -1
  19. data/ext/libxml/ruby_xml_reader.c +7 -2
  20. data/ext/libxml/ruby_xml_schema.c +44 -66
  21. data/ext/libxml/ruby_xml_schema_element.c +15 -14
  22. data/ext/libxml/ruby_xml_schema_type.c +66 -93
  23. data/ext/libxml/ruby_xml_version.h +4 -4
  24. data/ext/libxml/ruby_xml_writer.c +189 -192
  25. data/lib/libxml/schema/element.rb +0 -8
  26. data/lib/libxml/schema/type.rb +0 -8
  27. data/lib/libxml/schema.rb +0 -19
  28. data/lib/libxml-ruby.rb +30 -0
  29. data/lib/libxml.rb +3 -28
  30. data/libxml-ruby.gemspec +5 -4
  31. data/setup.rb +0 -1
  32. data/test/model/cwm_1_0.xml +11336 -0
  33. data/test/{tc_attr.rb → test_attr.rb} +18 -18
  34. data/test/{tc_attr_decl.rb → test_attr_decl.rb} +8 -8
  35. data/test/{tc_attributes.rb → test_attributes.rb} +10 -10
  36. data/test/{tc_canonicalize.rb → test_canonicalize.rb} +35 -39
  37. data/test/test_deprecated_require.rb +12 -0
  38. data/test/{tc_document.rb → test_document.rb} +31 -24
  39. data/test/test_document_write.rb +146 -0
  40. data/test/{tc_dtd.rb → test_dtd.rb} +26 -25
  41. data/test/{tc_encoding.rb → test_encoding.rb} +20 -17
  42. data/test/{tc_encoding_sax.rb → test_encoding_sax.rb} +3 -3
  43. data/test/test_error.rb +178 -0
  44. data/test/test_helper.rb +4 -11
  45. data/test/{tc_html_parser.rb → test_html_parser.rb} +31 -30
  46. data/test/test_html_parser_context.rb +23 -0
  47. data/test/test_namespace.rb +60 -0
  48. data/test/{tc_namespaces.rb → test_namespaces.rb} +29 -38
  49. data/test/{tc_node.rb → test_node.rb} +37 -31
  50. data/test/{tc_node_cdata.rb → test_node_cdata.rb} +10 -10
  51. data/test/{tc_node_comment.rb → test_node_comment.rb} +6 -6
  52. data/test/{tc_node_copy.rb → test_node_copy.rb} +3 -4
  53. data/test/{tc_node_edit.rb → test_node_edit.rb} +20 -21
  54. data/test/{tc_node_pi.rb → test_node_pi.rb} +8 -10
  55. data/test/{tc_node_text.rb → test_node_text.rb} +8 -9
  56. data/test/{tc_node_write.rb → test_node_write.rb} +16 -26
  57. data/test/test_node_xlink.rb +28 -0
  58. data/test/{tc_parser.rb → test_parser.rb} +72 -75
  59. data/test/{tc_parser_context.rb → test_parser_context.rb} +38 -44
  60. data/test/{tc_properties.rb → test_properties.rb} +5 -5
  61. data/test/test_reader.rb +364 -0
  62. data/test/{tc_relaxng.rb → test_relaxng.rb} +11 -11
  63. data/test/{tc_sax_parser.rb → test_sax_parser.rb} +38 -31
  64. data/test/{tc_schema.rb → test_schema.rb} +40 -33
  65. data/test/test_suite.rb +39 -40
  66. data/test/{tc_traversal.rb → test_traversal.rb} +4 -4
  67. data/test/{tc_writer.rb → test_writer.rb} +95 -74
  68. data/test/{tc_xinclude.rb → test_xinclude.rb} +3 -3
  69. data/test/test_xml.rb +263 -0
  70. data/test/{tc_xpath.rb → test_xpath.rb} +25 -25
  71. data/test/{tc_xpath_context.rb → test_xpath_context.rb} +5 -5
  72. data/test/{tc_xpath_expression.rb → test_xpath_expression.rb} +7 -7
  73. data/test/{tc_xpointer.rb → test_xpointer.rb} +15 -15
  74. metadata +91 -102
  75. data/test/tc_deprecated_require.rb +0 -12
  76. data/test/tc_document_write.rb +0 -195
  77. data/test/tc_error.rb +0 -178
  78. data/test/tc_html_parser_context.rb +0 -23
  79. data/test/tc_namespace.rb +0 -61
  80. data/test/tc_node_xlink.rb +0 -28
  81. data/test/tc_reader.rb +0 -358
  82. data/test/tc_xml.rb +0 -225
@@ -1,46 +1,46 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require './test_helper'
3
+ require_relative './test_helper'
4
4
 
5
5
  class CDataCommentTest < Minitest::Test
6
6
  def setup
7
- xp = XML::Parser.string('<root></root>')
7
+ xp = LibXML::XML::Parser.string('<root></root>')
8
8
  @doc = xp.parse
9
- assert_instance_of(XML::Document, @doc)
9
+ assert_instance_of(LibXML::XML::Document, @doc)
10
10
  @root = @doc.root
11
11
  end
12
12
 
13
13
  def test_node_type
14
- cnode = XML::Node.new_cdata('test cdata')
15
- assert_equal(XML::Node::CDATA_SECTION_NODE, cnode.node_type)
14
+ cnode = LibXML::XML::Node.new_cdata('test cdata')
15
+ assert_equal(LibXML::XML::Node::CDATA_SECTION_NODE, cnode.node_type)
16
16
  end
17
17
 
18
18
  def test_add_cdata
19
- @root << XML::Node.new_cdata('mycdata')
19
+ @root << LibXML::XML::Node.new_cdata('mycdata')
20
20
  assert_equal '<root><![CDATA[mycdata]]></root>',
21
21
  @root.to_s.gsub(/\n\s*/,'')
22
22
  end
23
23
 
24
24
  def test_add_cdata_2
25
- @root << XML::Node.new_cdata('mycdata')
25
+ @root << LibXML::XML::Node.new_cdata('mycdata')
26
26
  assert_equal 'cdata',
27
27
  @root.child.node_type_name
28
28
  end
29
29
 
30
30
  def test_add_cdata_3
31
- @root << el = XML::Node.new_cdata('mycdata')
31
+ @root << el = LibXML::XML::Node.new_cdata('mycdata')
32
32
  el << "_this_is_added"
33
33
  assert_equal '<root><![CDATA[mycdata_this_is_added]]></root>',
34
34
  @root.to_s.gsub(/\n\s*/,'')
35
35
  end
36
36
 
37
37
  def test_attributes
38
- cnode = XML::Node.new_cdata('test cdata')
38
+ cnode = LibXML::XML::Node.new_cdata('test cdata')
39
39
  assert_equal(0, cnode.attributes.length)
40
40
  end
41
41
 
42
42
  def test_set_cdata_attribute
43
- cnode = XML::Node.new_cdata('test cdata')
43
+ cnode = LibXML::XML::Node.new_cdata('test cdata')
44
44
 
45
45
  # Can't create attributes on non-element nodes
46
46
  assert_raises(ArgumentError) do
@@ -1,30 +1,30 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require './test_helper'
3
+ require_relative './test_helper'
4
4
 
5
5
 
6
6
  class NodeCommentTest < Minitest::Test
7
7
  def setup
8
- xp = XML::Parser.string('<root></root>')
8
+ xp = LibXML::XML::Parser.string('<root></root>')
9
9
  @doc = xp.parse
10
- assert_instance_of(XML::Document, @doc)
10
+ assert_instance_of(LibXML::XML::Document, @doc)
11
11
  @root = @doc.root
12
12
  end
13
13
 
14
14
  def test_libxml_node_add_comment_01
15
- @root << XML::Node.new_comment('mycomment')
15
+ @root << LibXML::XML::Node.new_comment('mycomment')
16
16
  assert_equal '<root><!--mycomment--></root>',
17
17
  @root.to_s.gsub(/\n\s*/,'')
18
18
  end
19
19
 
20
20
  def test_libxml_node_add_comment_02
21
- @root << XML::Node.new_comment('mycomment')
21
+ @root << LibXML::XML::Node.new_comment('mycomment')
22
22
  assert_equal 'comment',
23
23
  @root.child.node_type_name
24
24
  end
25
25
 
26
26
  def test_libxml_node_add_comment_03
27
- @root << el = XML::Node.new_comment('mycomment')
27
+ @root << el = LibXML::XML::Node.new_comment('mycomment')
28
28
  el << "_this_is_added"
29
29
  assert_equal '<root><!--mycomment_this_is_added--></root>',
30
30
  @root.to_s.gsub(/\n\s*/,'')
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require './test_helper'
3
+ require_relative './test_helper'
4
4
 
5
5
  # see mailing list archive
6
6
  # [libxml-devel] Segmentation fault when add the cloned/copied node
@@ -15,7 +15,7 @@ class TestNodeCopy < Minitest::Test
15
15
  </body></html>
16
16
  STR
17
17
 
18
- doc = XML::Parser.string(str).parse
18
+ doc = LibXML::XML::Parser.string(str).parse
19
19
 
20
20
  xpath = "//div"
21
21
  @div1 = doc.find(xpath).to_a[0]
@@ -37,5 +37,4 @@ class TestNodeCopy < Minitest::Test
37
37
  end
38
38
  assert @div1.to_s =~ /foo/
39
39
  end
40
-
41
- end # TC_XML_Node_Copy
40
+ end
@@ -1,10 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require './test_helper'
3
+ require_relative './test_helper'
4
4
 
5
5
  class TestNodeEdit < Minitest::Test
6
6
  def setup
7
- xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
7
+ xp = LibXML::XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
8
8
  @doc = xp.parse
9
9
  end
10
10
 
@@ -25,37 +25,37 @@ class TestNodeEdit < Minitest::Test
25
25
  end
26
26
 
27
27
  def test_add_next_01
28
- first_node.next = XML::Node.new('num', 'one-and-a-half')
28
+ first_node.next = LibXML::XML::Node.new('num', 'one-and-a-half')
29
29
  assert_equal('<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
30
30
  @doc.root.to_s.gsub(/\n\s*/,''))
31
31
  end
32
32
 
33
33
  def test_add_next_02
34
- second_node.next = XML::Node.new('num', 'two-and-a-half')
34
+ second_node.next = LibXML::XML::Node.new('num', 'two-and-a-half')
35
35
  assert_equal('<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
36
36
  @doc.root.to_s.gsub(/\n\s*/,''))
37
37
  end
38
38
 
39
39
  def test_add_next_03
40
- third_node.next = XML::Node.new('num', 'four')
40
+ third_node.next = LibXML::XML::Node.new('num', 'four')
41
41
  assert_equal '<test><num>one</num><num>two</num><num>three</num><num>four</num></test>',
42
42
  @doc.root.to_s.gsub(/\n\s*/,'')
43
43
  end
44
44
 
45
45
  def test_add_prev_01
46
- first_node.prev = XML::Node.new('num', 'half')
46
+ first_node.prev = LibXML::XML::Node.new('num', 'half')
47
47
  assert_equal '<test><num>half</num><num>one</num><num>two</num><num>three</num></test>',
48
48
  @doc.root.to_s.gsub(/\n\s*/,'')
49
49
  end
50
50
 
51
51
  def test_add_prev_02
52
- second_node.prev = XML::Node.new('num', 'one-and-a-half')
52
+ second_node.prev = LibXML::XML::Node.new('num', 'one-and-a-half')
53
53
  assert_equal '<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
54
54
  @doc.root.to_s.gsub(/\n\s*/,'')
55
55
  end
56
56
 
57
57
  def test_add_prev_03
58
- third_node.prev = XML::Node.new('num', 'two-and-a-half')
58
+ third_node.prev = LibXML::XML::Node.new('num', 'two-and-a-half')
59
59
  assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
60
60
  @doc.root.to_s.gsub(/\n\s*/,'')
61
61
  end
@@ -67,10 +67,9 @@ class TestNodeEdit < Minitest::Test
67
67
  end
68
68
 
69
69
  def test_remove_node_gc
70
- xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
70
+ xp = LibXML::XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
71
71
  doc = xp.parse
72
- node = doc.root.child.remove!
73
- node = nil
72
+ doc.root.child.remove!
74
73
  GC.start
75
74
  refute_nil(doc)
76
75
  end
@@ -99,7 +98,7 @@ class TestNodeEdit < Minitest::Test
99
98
  end
100
99
 
101
100
  def test_append_existing_node
102
- doc = XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
101
+ doc = LibXML::XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
103
102
  node1 = doc.find_first('//two')
104
103
 
105
104
  doc.root << node1
@@ -108,17 +107,17 @@ class TestNodeEdit < Minitest::Test
108
107
  end
109
108
 
110
109
  def test_wrong_doc
111
- doc1 = XML::Parser.string('<nums><one></one></nums>').parse
112
- doc2 = XML::Parser.string('<nums><two></two></nums>').parse
110
+ doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
111
+ doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
113
112
 
114
113
  node = doc1.root.child
115
114
 
116
- error = assert_raises(XML::Error) do
115
+ error = assert_raises(LibXML::XML::Error) do
117
116
  doc2.root << node
118
117
  end
119
118
 
120
119
  GC.start
121
- assert_equal(' Nodes belong to different documents. You must first import the node by calling XML::Document.import.',
120
+ assert_equal(' Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.',
122
121
  error.to_s)
123
122
  end
124
123
 
@@ -128,11 +127,12 @@ class TestNodeEdit < Minitest::Test
128
127
 
129
128
  # Read in 500 documents
130
129
  500.times do
131
- documents << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
130
+ documents << LibXML::XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
132
131
  end
133
132
 
134
133
  master_doc = documents.shift
135
- documents.inject(master_doc) do |master_doc, child_doc|
134
+
135
+ documents.each do |child_doc|
136
136
  master_body = master_doc.find("//body").first
137
137
  child_body = child_doc.find("//body").first
138
138
 
@@ -141,12 +141,11 @@ class TestNodeEdit < Minitest::Test
141
141
  end
142
142
 
143
143
  master_body << child_element.copy(true)
144
- master_doc
145
144
  end
146
145
  end
147
146
 
148
147
  def test_append_chain
149
- node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
148
+ node = LibXML::XML::Node.new('foo') << LibXML::XML::Node.new('bar') << "bars contents"
150
149
  assert_equal('<foo><bar/>bars contents</foo>',
151
150
  node.to_s)
152
151
  end
@@ -156,4 +155,4 @@ class TestNodeEdit < Minitest::Test
156
155
  assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
157
156
  @doc.root.to_s)
158
157
  end
159
- end
158
+ end
@@ -1,39 +1,37 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require './test_helper'
3
+ require_relative './test_helper'
4
4
 
5
-
6
- class NodeCommentTest < Minitest::Test
5
+ class NodePiTest < Minitest::Test
7
6
  def setup
8
- xp = XML::Parser.string('<root></root>')
7
+ xp = LibXML::XML::Parser.string('<root></root>')
9
8
  @doc = xp.parse
10
- assert_instance_of(XML::Document, @doc)
9
+ assert_instance_of(LibXML::XML::Document, @doc)
11
10
  @root = @doc.root
12
11
  end
13
12
 
14
13
  def test_libxml_node_add_pi_01
15
- @root << XML::Node.new_pi('mypi')
14
+ @root << LibXML::XML::Node.new_pi('mypi')
16
15
  assert_equal '<root><?mypi?></root>',
17
16
  @root.to_s.gsub(/\n\s*/,'')
18
17
  end
19
18
 
20
19
  def test_libxml_node_add_pi_02
21
- @root << XML::Node.new_pi('mypi')
20
+ @root << LibXML::XML::Node.new_pi('mypi')
22
21
  assert_equal 'pi',
23
22
  @root.child.node_type_name
24
23
  end
25
24
 
26
25
  def test_libxml_node_add_pi_03
27
- @root << el = XML::Node.new_pi('mypi')
26
+ @root << el = LibXML::XML::Node.new_pi('mypi')
28
27
  el << "_this_is_added"
29
28
  assert_equal '<root><?mypi _this_is_added?></root>',
30
29
  @root.to_s.gsub(/\n\s*/,'')
31
30
  end
32
31
 
33
32
  def test_libxml_node_add_pi_04
34
- @root << XML::Node.new_pi('mypi','mycontent')
33
+ @root << LibXML::XML::Node.new_pi('mypi','mycontent')
35
34
  assert_equal '<root><?mypi mycontent?></root>',
36
35
  @root.to_s.gsub(/\n\s*/,'')
37
36
  end
38
-
39
37
  end
@@ -1,17 +1,17 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require './test_helper'
3
+ require_relative './test_helper'
4
4
 
5
5
  class TestTextNode < Minitest::Test
6
6
  def test_content
7
- node = XML::Node.new_text('testdata')
8
- assert_instance_of(XML::Node, node)
7
+ node = LibXML::XML::Node.new_text('testdata')
8
+ assert_instance_of(LibXML::XML::Node, node)
9
9
  assert_equal('testdata', node.content)
10
10
  end
11
11
 
12
12
  def test_invalid_content
13
13
  error = assert_raises(TypeError) do
14
- node = XML::Node.new_text(nil)
14
+ LibXML::XML::Node.new_text(nil)
15
15
  end
16
16
  assert_equal('wrong argument type nil (expected String)', error.to_s)
17
17
  end
@@ -23,11 +23,11 @@ class TestTextNode < Minitest::Test
23
23
  # in CDATA nodes. Or if you are sanitizing existing HTML documents and want
24
24
  # to preserve the content of any of the text nodes.
25
25
  #
26
- def test_output_escaping
26
+ def test_output_escaping
27
27
  textnoenc = 'if (a < b || c > d) return "e";'
28
28
  text = "if (a &lt; b || c &gt; d) return \"e\";"
29
29
 
30
- node = XML::Node.new_text(textnoenc)
30
+ node = LibXML::XML::Node.new_text(textnoenc)
31
31
  assert node.output_escaping?
32
32
  assert_equal text, node.to_s
33
33
 
@@ -45,8 +45,8 @@ class TestTextNode < Minitest::Test
45
45
  end
46
46
 
47
47
  # Just a sanity check for output escaping.
48
- def test_output_escaping_sanity
49
- node = XML::Node.new_text('testdata')
48
+ def test_output_escaping_sanity
49
+ node = LibXML::XML::Node.new_text('testdata')
50
50
  assert_equal 'text', node.name
51
51
  assert node.output_escaping?
52
52
 
@@ -66,5 +66,4 @@ class TestTextNode < Minitest::Test
66
66
  assert_equal 'text', node.name
67
67
  assert node.output_escaping?
68
68
  end
69
-
70
69
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require './test_helper'
3
+ require_relative './test_helper'
4
4
 
5
5
  class TestNodeWrite < Minitest::Test
6
6
  def setup
@@ -8,24 +8,24 @@ class TestNodeWrite < Minitest::Test
8
8
  end
9
9
 
10
10
  def teardown
11
- XML.default_keep_blanks = true
11
+ LibXML::XML.default_keep_blanks = true
12
12
  @doc = nil
13
13
  end
14
14
 
15
15
  def load_encoding(name)
16
- @encoding = Encoding.find(name) if defined?(Encoding)
16
+ @encoding = Encoding.find(name)
17
17
  @file_name = "model/bands.#{name.downcase}.xml"
18
18
 
19
19
  # Strip spaces to make testing easier
20
- XML.default_keep_blanks = false
20
+ LibXML::XML.default_keep_blanks = false
21
21
  file = File.join(File.dirname(__FILE__), @file_name)
22
- @doc = XML::Document.file(file)
22
+ @doc = LibXML::XML::Document.file(file)
23
23
  end
24
24
 
25
25
  def test_to_s_default
26
26
  # Default to_s has indentation
27
27
  node = @doc.root
28
- assert_equal(Encoding::UTF_8, node.to_s.encoding) if defined?(Encoding)
28
+ assert_equal(Encoding::UTF_8, node.to_s.encoding)
29
29
  assert_equal("<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>",
30
30
  node.to_s)
31
31
  end
@@ -33,11 +33,11 @@ class TestNodeWrite < Minitest::Test
33
33
  def test_to_s_no_global_indentation
34
34
  # No indentation due to global setting
35
35
  node = @doc.root
36
- XML.indent_tree_output = false
36
+ LibXML::XML.indent_tree_output = false
37
37
  assert_equal("<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>",
38
38
  node.to_s)
39
39
  ensure
40
- XML.indent_tree_output = true
40
+ LibXML::XML.indent_tree_output = true
41
41
  end
42
42
 
43
43
  def test_to_s_no_indentation
@@ -61,23 +61,18 @@ class TestNodeWrite < Minitest::Test
61
61
  # UTF8:
62
62
  # ö - c3 b6 in hex, \303\266 in octal
63
63
  # ü - c3 bc in hex, \303\274 in octal
64
- value = node.to_s(:encoding => XML::Encoding::UTF_8)
65
- assert_equal(Encoding::UTF_8, node.to_s.encoding) if defined?(Encoding)
64
+ value = node.to_s(:encoding => LibXML::XML::Encoding::UTF_8)
65
+ assert_equal(Encoding::UTF_8, node.to_s.encoding)
66
66
  assert_equal("<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>",
67
67
  value)
68
68
 
69
69
  # ISO_8859_1:
70
70
  # ö - f6 in hex, \366 in octal
71
71
  # ü - fc in hex, \374 in octal
72
- value = node.to_s(:encoding => XML::Encoding::ISO_8859_1)
73
- if defined?(Encoding)
74
- assert_equal(Encoding::ISO8859_1, value.encoding)
75
- assert_equal("<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>".force_encoding(Encoding::ISO8859_1),
76
- value)
77
- else
78
- assert_equal("<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>",
72
+ value = node.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1)
73
+ assert_equal(Encoding::ISO8859_1, value.encoding)
74
+ assert_equal("<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>".force_encoding(Encoding::ISO8859_1),
79
75
  value)
80
- end
81
76
 
82
77
  # Invalid encoding
83
78
  error = assert_raises(ArgumentError) do
@@ -90,14 +85,9 @@ class TestNodeWrite < Minitest::Test
90
85
  # Default to_s has indentation
91
86
  node = @doc.root
92
87
 
93
- if defined?(Encoding)
94
- assert_equal(Encoding::UTF_8, node.inner_xml.encoding)
95
- assert_equal("<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>",
96
- node.inner_xml)
97
- else
98
- assert_equal("<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>",
99
- node.inner_xml)
100
- end
88
+ assert_equal(Encoding::UTF_8, node.inner_xml.encoding)
89
+ assert_equal("<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>",
90
+ node.inner_xml)
101
91
  end
102
92
 
103
93
  # --- Debug ---
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+
3
+ # $Id$
4
+ require_relative './test_helper'
5
+
6
+
7
+ class TC_XML_Node_XLink < Minitest::Test
8
+ def setup()
9
+ xp = LibXML::XML::Parser.string('<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>')
10
+ doc = xp.parse
11
+ assert_instance_of(LibXML::XML::Document, doc)
12
+ @root = doc.root
13
+ assert_instance_of(LibXML::XML::Node, @root)
14
+ end
15
+
16
+ def teardown()
17
+ @root = nil
18
+ end
19
+
20
+ def test_xml_node_xlink()
21
+ for elem in @root.find('fixnum')
22
+ assert_instance_of(LibXML::XML::Node, elem)
23
+ assert_instance_of(TrueClass, elem.xlink?)
24
+ assert_equal("simple", elem.xlink_type_name)
25
+ assert_equal(LibXML::XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type)
26
+ end
27
+ end
28
+ end