libxml-ruby 2.0.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/HISTORY +516 -0
  2. data/LICENSE +23 -0
  3. data/MANIFEST +165 -0
  4. data/README.rdoc +161 -0
  5. data/Rakefile +82 -0
  6. data/ext/libxml/extconf.rb +122 -0
  7. data/ext/libxml/libxml.c +93 -0
  8. data/ext/libxml/ruby_libxml.h +101 -0
  9. data/ext/libxml/ruby_xml.c +893 -0
  10. data/ext/libxml/ruby_xml.h +10 -0
  11. data/ext/libxml/ruby_xml_attr.c +352 -0
  12. data/ext/libxml/ruby_xml_attr.h +14 -0
  13. data/ext/libxml/ruby_xml_attr_decl.c +171 -0
  14. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  15. data/ext/libxml/ruby_xml_attributes.c +277 -0
  16. data/ext/libxml/ruby_xml_attributes.h +17 -0
  17. data/ext/libxml/ruby_xml_cbg.c +85 -0
  18. data/ext/libxml/ruby_xml_document.c +958 -0
  19. data/ext/libxml/ruby_xml_document.h +17 -0
  20. data/ext/libxml/ruby_xml_dtd.c +257 -0
  21. data/ext/libxml/ruby_xml_dtd.h +9 -0
  22. data/ext/libxml/ruby_xml_encoding.c +221 -0
  23. data/ext/libxml/ruby_xml_encoding.h +16 -0
  24. data/ext/libxml/ruby_xml_error.c +1004 -0
  25. data/ext/libxml/ruby_xml_error.h +14 -0
  26. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  27. data/ext/libxml/ruby_xml_html_parser.h +12 -0
  28. data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
  29. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  30. data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
  31. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  32. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  33. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  34. data/ext/libxml/ruby_xml_io.c +30 -0
  35. data/ext/libxml/ruby_xml_io.h +9 -0
  36. data/ext/libxml/ruby_xml_namespace.c +170 -0
  37. data/ext/libxml/ruby_xml_namespace.h +12 -0
  38. data/ext/libxml/ruby_xml_namespaces.c +295 -0
  39. data/ext/libxml/ruby_xml_namespaces.h +11 -0
  40. data/ext/libxml/ruby_xml_node.c +1386 -0
  41. data/ext/libxml/ruby_xml_node.h +13 -0
  42. data/ext/libxml/ruby_xml_parser.c +94 -0
  43. data/ext/libxml/ruby_xml_parser.h +14 -0
  44. data/ext/libxml/ruby_xml_parser_context.c +982 -0
  45. data/ext/libxml/ruby_xml_parser_context.h +12 -0
  46. data/ext/libxml/ruby_xml_parser_options.c +68 -0
  47. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  48. data/ext/libxml/ruby_xml_reader.c +1057 -0
  49. data/ext/libxml/ruby_xml_reader.h +14 -0
  50. data/ext/libxml/ruby_xml_relaxng.c +111 -0
  51. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  52. data/ext/libxml/ruby_xml_sax2_handler.c +334 -0
  53. data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
  54. data/ext/libxml/ruby_xml_sax_parser.c +136 -0
  55. data/ext/libxml/ruby_xml_sax_parser.h +12 -0
  56. data/ext/libxml/ruby_xml_schema.c +159 -0
  57. data/ext/libxml/ruby_xml_schema.h +11 -0
  58. data/ext/libxml/ruby_xml_version.h +9 -0
  59. data/ext/libxml/ruby_xml_xinclude.c +18 -0
  60. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  61. data/ext/libxml/ruby_xml_xpath.c +107 -0
  62. data/ext/libxml/ruby_xml_xpath.h +12 -0
  63. data/ext/libxml/ruby_xml_xpath_context.c +390 -0
  64. data/ext/libxml/ruby_xml_xpath_context.h +11 -0
  65. data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
  66. data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
  67. data/ext/libxml/ruby_xml_xpath_object.c +336 -0
  68. data/ext/libxml/ruby_xml_xpath_object.h +19 -0
  69. data/ext/libxml/ruby_xml_xpointer.c +101 -0
  70. data/ext/libxml/ruby_xml_xpointer.h +13 -0
  71. data/ext/mingw/Rakefile +34 -0
  72. data/ext/mingw/build.rake +41 -0
  73. data/ext/vc/libxml_ruby.sln +26 -0
  74. data/lib/1.8/libxml_ruby.so +0 -0
  75. data/lib/1.9/libxml_ruby.so +0 -0
  76. data/lib/libxml.rb +30 -0
  77. data/lib/libxml/attr.rb +113 -0
  78. data/lib/libxml/attr_decl.rb +80 -0
  79. data/lib/libxml/attributes.rb +14 -0
  80. data/lib/libxml/document.rb +192 -0
  81. data/lib/libxml/error.rb +90 -0
  82. data/lib/libxml/hpricot.rb +78 -0
  83. data/lib/libxml/html_parser.rb +96 -0
  84. data/lib/libxml/namespace.rb +62 -0
  85. data/lib/libxml/namespaces.rb +38 -0
  86. data/lib/libxml/node.rb +399 -0
  87. data/lib/libxml/ns.rb +22 -0
  88. data/lib/libxml/parser.rb +367 -0
  89. data/lib/libxml/properties.rb +23 -0
  90. data/lib/libxml/reader.rb +29 -0
  91. data/lib/libxml/sax_callbacks.rb +180 -0
  92. data/lib/libxml/sax_parser.rb +58 -0
  93. data/lib/libxml/tree.rb +29 -0
  94. data/lib/libxml/xpath_object.rb +16 -0
  95. data/lib/xml.rb +16 -0
  96. data/lib/xml/libxml.rb +10 -0
  97. data/libxml-ruby.gemspec +50 -0
  98. data/script/benchmark/depixelate +634 -0
  99. data/script/benchmark/hamlet.xml +9055 -0
  100. data/script/benchmark/parsecount +170 -0
  101. data/script/benchmark/sock_entries.xml +507 -0
  102. data/script/benchmark/throughput +41 -0
  103. data/script/test +6 -0
  104. data/setup.rb +1585 -0
  105. data/test/etc_doc_to_s.rb +21 -0
  106. data/test/ets_doc_file.rb +17 -0
  107. data/test/ets_doc_to_s.rb +23 -0
  108. data/test/ets_gpx.rb +28 -0
  109. data/test/ets_node_gc.rb +23 -0
  110. data/test/ets_test.xml +2 -0
  111. data/test/ets_tsr.rb +11 -0
  112. data/test/model/atom.xml +13 -0
  113. data/test/model/bands.iso-8859-1.xml +5 -0
  114. data/test/model/bands.utf-8.xml +5 -0
  115. data/test/model/bands.xml +5 -0
  116. data/test/model/books.xml +146 -0
  117. data/test/model/merge_bug_data.xml +58 -0
  118. data/test/model/ruby-lang.html +238 -0
  119. data/test/model/rubynet.xml +79 -0
  120. data/test/model/rubynet_project +1 -0
  121. data/test/model/shiporder.rnc +28 -0
  122. data/test/model/shiporder.rng +86 -0
  123. data/test/model/shiporder.xml +23 -0
  124. data/test/model/shiporder.xsd +31 -0
  125. data/test/model/soap.xml +27 -0
  126. data/test/model/xinclude.xml +5 -0
  127. data/test/rb-magic-comment.rb +33 -0
  128. data/test/tc_attr.rb +181 -0
  129. data/test/tc_attr_decl.rb +133 -0
  130. data/test/tc_attributes.rb +135 -0
  131. data/test/tc_deprecated_require.rb +13 -0
  132. data/test/tc_document.rb +119 -0
  133. data/test/tc_document_write.rb +187 -0
  134. data/test/tc_dtd.rb +125 -0
  135. data/test/tc_error.rb +138 -0
  136. data/test/tc_html_parser.rb +140 -0
  137. data/test/tc_namespace.rb +62 -0
  138. data/test/tc_namespaces.rb +177 -0
  139. data/test/tc_node.rb +258 -0
  140. data/test/tc_node_cdata.rb +51 -0
  141. data/test/tc_node_comment.rb +33 -0
  142. data/test/tc_node_copy.rb +42 -0
  143. data/test/tc_node_edit.rb +160 -0
  144. data/test/tc_node_text.rb +71 -0
  145. data/test/tc_node_write.rb +108 -0
  146. data/test/tc_node_xlink.rb +29 -0
  147. data/test/tc_parser.rb +336 -0
  148. data/test/tc_parser_context.rb +189 -0
  149. data/test/tc_properties.rb +39 -0
  150. data/test/tc_reader.rb +298 -0
  151. data/test/tc_relaxng.rb +54 -0
  152. data/test/tc_sax_parser.rb +276 -0
  153. data/test/tc_schema.rb +53 -0
  154. data/test/tc_traversal.rb +222 -0
  155. data/test/tc_xinclude.rb +21 -0
  156. data/test/tc_xml.rb +226 -0
  157. data/test/tc_xpath.rb +195 -0
  158. data/test/tc_xpath_context.rb +80 -0
  159. data/test/tc_xpath_expression.rb +38 -0
  160. data/test/tc_xpointer.rb +74 -0
  161. data/test/test_helper.rb +14 -0
  162. data/test/test_suite.rb +39 -0
  163. metadata +254 -0
@@ -0,0 +1,133 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class AttrDeclTest < Test::Unit::TestCase
7
+ def setup
8
+ xp = XML::Parser.string(<<-EOS)
9
+ <!DOCTYPE test [
10
+ <!ELEMENT root (property*)>
11
+ <!ELEMENT property EMPTY>
12
+ <!ATTLIST property name NMTOKEN #REQUIRED>
13
+ <!ATTLIST property access (r | w | rw) "rw">
14
+ ]>
15
+ <root>
16
+ <property name="readonly" access="r" />
17
+ <property name="readwrite" />
18
+ </root>
19
+ EOS
20
+ @doc = xp.parse
21
+ end
22
+
23
+ def teardown
24
+ @doc = nil
25
+ end
26
+
27
+ def test_attributes
28
+ # Get a element with an access attribute
29
+ elem = @doc.find_first('/root/property[@name="readonly"]')
30
+ assert_equal(2, elem.attributes.length)
31
+ assert_not_nil(elem['access'])
32
+
33
+ # Get a element node without a access attribute
34
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
35
+ assert_equal(1, elem.attributes.length)
36
+ assert_nil(elem['access'])
37
+ end
38
+
39
+ def test_attr
40
+ # Get a property node without a access attribute
41
+ elem = @doc.find_first('/root/property[@name="readonly"]')
42
+
43
+ # Get the attr_decl
44
+ attr = elem.attributes.get_attribute('access')
45
+ assert_not_nil(attr)
46
+ assert_equal(XML::Node::ATTRIBUTE_NODE, attr.node_type)
47
+ assert_equal('attribute', attr.node_type_name)
48
+
49
+ # Get its value
50
+ assert_equal('r', attr.value)
51
+ end
52
+
53
+ def test_attr_decl
54
+ # Get a property node without a access attribute
55
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
56
+
57
+ # Get the attr_decl
58
+ attr_decl = elem.attributes.get_attribute('access')
59
+ assert_not_nil(attr_decl)
60
+ assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
61
+ assert_equal('attribute declaration', attr_decl.node_type_name)
62
+
63
+ # Get its value
64
+ assert_equal('rw', attr_decl.value)
65
+ end
66
+
67
+ def test_type
68
+ # Get a property node without a access attribute
69
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
70
+ attr_decl = elem.attributes.get_attribute('access')
71
+
72
+ assert_not_nil(attr_decl)
73
+ assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
74
+ assert_equal('attribute declaration', attr_decl.node_type_name)
75
+ end
76
+
77
+ def test_name
78
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
79
+ attr_decl = elem.attributes.get_attribute('access')
80
+
81
+ assert_equal('access', attr_decl.name)
82
+ end
83
+
84
+ def test_value
85
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
86
+ attr_decl = elem.attributes.get_attribute('access')
87
+
88
+ assert_equal('rw', attr_decl.value)
89
+ end
90
+
91
+ def test_to_s
92
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
93
+ attr_decl = elem.attributes.get_attribute('access')
94
+
95
+ assert_equal('access = rw', attr_decl.to_s)
96
+ end
97
+
98
+ def test_prev
99
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
100
+ attr_decl = elem.attributes.get_attribute('access')
101
+
102
+ first_decl = attr_decl.prev
103
+ assert_equal(XML::Node::ATTRIBUTE_DECL, first_decl.node_type)
104
+ assert_equal('name', first_decl.name)
105
+ assert_nil(first_decl.value)
106
+
107
+ elem_decl = first_decl.prev
108
+ assert_equal(XML::Node::ELEMENT_DECL, elem_decl.node_type)
109
+ end
110
+
111
+ def test_next
112
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
113
+ attr_decl = elem.attributes.get_attribute('access')
114
+
115
+ next_decl = attr_decl.next
116
+ assert_nil(next_decl)
117
+ end
118
+
119
+ def test_doc
120
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
121
+ attr_decl = elem.attributes.get_attribute('access')
122
+
123
+ assert_same(@doc, attr_decl.doc)
124
+ end
125
+
126
+ def test_parent
127
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
128
+ attr_decl = elem.attributes.get_attribute('access')
129
+
130
+ parent = attr_decl.parent
131
+ assert_instance_of(XML::Dtd, parent)
132
+ end
133
+ end
@@ -0,0 +1,135 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class AttributesTest < Test::Unit::TestCase
7
+ def setup
8
+ xp = XML::Parser.string(<<-EOS)
9
+ <CityModel
10
+ xmlns="http://www.opengis.net/examples"
11
+ xmlns:city="http://www.opengis.net/examples"
12
+ xmlns:gml="http://www.opengis.net/gml"
13
+ xmlns:xlink="http://www.w3.org/1999/xlink"
14
+ xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
15
+ xsi:schemaLocation="http://www.opengis.net/examples city.xsd">
16
+ <cityMember name="Cambridge"
17
+ xlink:type="simple"
18
+ xlink:title="Trinity Lane"
19
+ xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
20
+ gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
21
+ </CityModel>
22
+ EOS
23
+
24
+ @doc = xp.parse
25
+ end
26
+
27
+ def teardown
28
+ @doc = nil
29
+ end
30
+
31
+ def city_member
32
+ @doc.find('/city:CityModel/city:cityMember').first
33
+ end
34
+
35
+ def test_attributes
36
+ attributes = city_member.attributes
37
+ assert_instance_of(XML::Attributes, attributes)
38
+ assert_equal(5, attributes.length)
39
+ end
40
+
41
+ def test_each
42
+ attributes = city_member.attributes
43
+ length = attributes.inject(0) do |result, attr|
44
+ assert_instance_of(XML::Attr, attr)
45
+ result + 1
46
+ end
47
+ assert_equal(5, length)
48
+ end
49
+
50
+ def test_get_attribute
51
+ attributes = city_member.attributes
52
+
53
+ attr = attributes.get_attribute('name')
54
+ assert_instance_of(XML::Attr, attr)
55
+
56
+ attr = attributes.get_attribute('does_not_exist')
57
+ assert_nil(attr)
58
+
59
+ attr = attributes.get_attribute('name')
60
+ assert_instance_of(XML::Attr, attr)
61
+
62
+ attr = attributes.get_attribute('href')
63
+ assert_instance_of(XML::Attr, attr)
64
+ assert_instance_of(XML::Namespace, attr.ns)
65
+ assert_equal('xlink', attr.ns.prefix)
66
+ assert_equal('http://www.w3.org/1999/xlink', attr.ns.href)
67
+
68
+ attr = attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
69
+ assert_instance_of(XML::Attr, attr)
70
+
71
+ attr = attributes.get_attribute_ns('http://www.opengis.net/gml', 'remoteSchema')
72
+ assert_instance_of(XML::Attr, attr)
73
+
74
+ attr = attributes.get_attribute_ns('http://i.dont.exist', 'nor do i')
75
+ assert_nil(attr)
76
+ end
77
+
78
+ def test_property
79
+ attr = city_member.property('name')
80
+ assert_instance_of(String, attr)
81
+ assert_equal('Cambridge', attr)
82
+ end
83
+
84
+ def test_get_values
85
+ assert_equal('Cambridge', city_member[:name])
86
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', city_member[:href])
87
+
88
+ attributes = city_member.attributes
89
+ assert_equal('Cambridge', attributes[:name])
90
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attributes[:href])
91
+ end
92
+
93
+ def test_set_values
94
+ city_member[:name] = 'London'
95
+ assert_equal('London', city_member[:name])
96
+
97
+ city_member[:href] = 'foo'
98
+ assert_equal('foo', city_member[:href])
99
+
100
+ attributes = city_member.attributes
101
+
102
+ attributes[:name] = 'London'
103
+ assert_equal('London', attributes[:name])
104
+
105
+ attributes[:href] = 'foo'
106
+ assert_equal('foo', attributes[:href])
107
+ end
108
+
109
+ def test_str_sym()
110
+ attributes = city_member.attributes
111
+ assert_equal('Cambridge', attributes[:name])
112
+ assert_equal('Cambridge', attributes['name'])
113
+ end
114
+
115
+ def test_remove_first
116
+ attributes = @doc.find_first('/city:CityModel/city:cityMember').attributes
117
+ assert_equal(5, attributes.length)
118
+ attr = attributes.first
119
+ attr.remove!
120
+ assert_equal(4, attributes.length)
121
+ end
122
+
123
+ def test_remove_all
124
+ node = @doc.find_first('/city:CityModel/city:cityMember')
125
+ assert_equal(5, node.attributes.length)
126
+
127
+ attrs = Array.new
128
+ node.attributes.each do |attr|
129
+ attrs << attr
130
+ attr.remove!
131
+ end
132
+ assert_equal(5, attrs.length)
133
+ assert_equal(0, node.attributes.length)
134
+ end
135
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'xml/libxml'
4
+ require 'test/unit'
5
+
6
+ class TestDeprecatedRequire < Test::Unit::TestCase
7
+ def test_basic
8
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
9
+ assert_instance_of(XML::Parser, xp)
10
+ @doc = xp.parse
11
+ assert_instance_of(XML::Document, @doc)
12
+ end
13
+ end
@@ -0,0 +1,119 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ require 'test/unit'
6
+
7
+
8
+ class TestDocument < Test::Unit::TestCase
9
+ def setup
10
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
11
+ assert_instance_of(XML::Parser, xp)
12
+ @doc = xp.parse
13
+ assert_instance_of(XML::Document, @doc)
14
+ end
15
+
16
+ def teardown
17
+ @doc = nil
18
+ end
19
+
20
+ def test_klass
21
+ assert_instance_of(XML::Document, @doc)
22
+ end
23
+
24
+ def test_context
25
+ context = @doc.context
26
+ assert_instance_of(XML::XPath::Context, context)
27
+ end
28
+
29
+ def test_find
30
+ set = @doc.find('/ruby_array/fixnum')
31
+ assert_instance_of(XML::XPath::Object, set)
32
+ assert_raise(NoMethodError) {
33
+ xpt = set.xpath
34
+ }
35
+ end
36
+
37
+ def test_compression
38
+ if XML.enabled_zlib?
39
+ 0.upto(9) do |i|
40
+ assert_equal(i, @doc.compression = i)
41
+ assert_equal(i, @doc.compression)
42
+ end
43
+
44
+ 9.downto(0) do |i|
45
+ assert_equal(i, @doc.compression = i)
46
+ assert_equal(i, @doc.compression)
47
+ end
48
+
49
+ 10.upto(20) do |i|
50
+ # assert_equal(9, @doc.compression = i)
51
+ assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
52
+ assert_equal(9, @doc.compression)
53
+ end
54
+
55
+ -1.downto(-10) do |i|
56
+ # assert_equal(0, @doc.compression = i)
57
+ assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
58
+ assert_equal(0, @doc.compression)
59
+ end
60
+ end
61
+ end
62
+
63
+ def test_version
64
+ assert_equal('1.0', @doc.version)
65
+
66
+ doc = XML::Document.new('6.9')
67
+ assert_equal('6.9', doc.version)
68
+ end
69
+
70
+ def test_write_root
71
+ @doc.root = XML::Node.new('rubynet')
72
+ assert_instance_of(XML::Node, @doc.root)
73
+ assert_instance_of(XML::Document, @doc.root.doc)
74
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
75
+ @doc.to_s(:indent => false))
76
+ end
77
+
78
+ def test_encoding
79
+ doc = XML::Document.new
80
+ assert_equal(XML::Encoding::NONE, doc.encoding)
81
+ assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) if defined?(Encoding)
82
+
83
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
84
+ doc = XML::Document.file(file)
85
+ assert_equal(XML::Encoding::UTF_8, doc.encoding)
86
+ assert_equal(Encoding::UTF_8, doc.rb_encoding) if defined?(Encoding)
87
+
88
+ doc.encoding = XML::Encoding::ISO_8859_1
89
+ assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
90
+ assert_equal(Encoding::ISO8859_1, doc.rb_encoding) if defined?(Encoding)
91
+ end
92
+
93
+ def test_doc_node_type
94
+ assert_equal(XML::Node::DOCUMENT_NODE, XML::Document.new.node_type)
95
+ end
96
+
97
+ def test_doc_node_type_name
98
+ assert_equal('document_xml', XML::Document.new.node_type_name)
99
+ end
100
+
101
+ def test_xhtml
102
+ doc = XML::Document.new
103
+ assert(!doc.xhtml?)
104
+ XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
105
+ assert(doc.xhtml?)
106
+ end
107
+
108
+ def test_import_node
109
+ doc1 = XML::Parser.string('<nums><one></one></nums>').parse
110
+ doc2 = XML::Parser.string('<nums><two></two></nums>').parse
111
+
112
+ node = doc1.root.child
113
+
114
+ doc2.root << doc2.import(node)
115
+
116
+ assert_equal("<nums>\n <two/>\n <one/>\n</nums>",
117
+ doc2.root.to_s)
118
+ end
119
+ end
@@ -0,0 +1,187 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'tmpdir'
5
+ require 'test/unit'
6
+
7
+ class TestDocumentWrite < Test::Unit::TestCase
8
+ def setup
9
+ load_encoding("utf-8")
10
+ end
11
+
12
+ def teardown
13
+ XML.default_keep_blanks = true
14
+ @doc = nil
15
+ end
16
+
17
+ def load_encoding(name)
18
+ @encoding = Encoding.find(name) if defined?(Encoding)
19
+ @file_name = "model/bands.#{name.downcase}.xml"
20
+
21
+ # Strip spaces to make testing easier
22
+ XML.default_keep_blanks = false
23
+ file = File.join(File.dirname(__FILE__), @file_name)
24
+ @doc = XML::Document.file(file)
25
+ end
26
+
27
+ # --- to_s tests ---
28
+ def test_to_s_default
29
+ # Default to_s has indentation
30
+ if defined?(Encoding)
31
+ 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",
32
+ @doc.to_s)
33
+ else
34
+ 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",
35
+ @doc.to_s)
36
+ end
37
+ end
38
+
39
+ def test_to_s_no_global_indentation
40
+ # No indentation due to global setting
41
+ XML.indent_tree_output = false
42
+ value = @doc.to_s
43
+
44
+ if defined?(Encoding)
45
+ assert_equal(Encoding::UTF_8, value.encoding)
46
+ 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",
47
+ value)
48
+ else
49
+ 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",
50
+ value)
51
+ end
52
+ ensure
53
+ XML.indent_tree_output = true
54
+ end
55
+
56
+ def test_to_s_no_indentation
57
+ # No indentation due to local setting
58
+ value = @doc.to_s(:indent => false)
59
+ if defined?(Encoding)
60
+ assert_equal(Encoding::UTF_8, value.encoding)
61
+ 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",
62
+ value)
63
+ else
64
+ 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",
65
+ value)
66
+ end
67
+ end
68
+
69
+ def test_to_s_encoding
70
+ # Test encodings
71
+
72
+ # UTF8:
73
+ # ö - c3 b6 in hex, \303\266 in octal
74
+ # ü - c3 bc in hex, \303\274 in octal
75
+ value = @doc.to_s(:encoding => XML::Encoding::UTF_8)
76
+ if defined?(Encoding)
77
+ assert_equal(Encoding::UTF_8, value.encoding)
78
+ 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",
79
+ value)
80
+ else
81
+ 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",
82
+ value)
83
+ end
84
+
85
+ # ISO_8859_1:
86
+ # ö - f6 in hex, \366 in octal
87
+ # ü - fc in hex, \374 in octal
88
+ value = @doc.to_s(:encoding => XML::Encoding::ISO_8859_1)
89
+ if defined?(Encoding)
90
+ assert_equal(Encoding::ISO8859_1, value.encoding)
91
+ 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),
92
+ @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
93
+ else
94
+ 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",
95
+ @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
96
+ end
97
+
98
+ # Invalid encoding
99
+ error = assert_raise(ArgumentError) do
100
+ @doc.to_s(:encoding => -9999)
101
+ end
102
+ assert_equal('Unknown encoding value: -9999', error.to_s)
103
+ end
104
+
105
+ # --- save tests -----
106
+ def test_save_utf8
107
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8.xml")
108
+
109
+ bytes = @doc.save(temp_filename)
110
+ assert_equal(305, bytes)
111
+
112
+ if defined?(Encoding)
113
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
114
+ assert_equal(Encoding::UTF_8, contents.encoding)
115
+ 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",
116
+ contents)
117
+ else
118
+ contents = File.read(temp_filename)
119
+ 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",
120
+ contents)
121
+ end
122
+ ensure
123
+ File.delete(temp_filename)
124
+ end
125
+
126
+ def test_save_utf8_no_indents
127
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8_no_indents.xml")
128
+
129
+ bytes = @doc.save(temp_filename, :indent => false)
130
+ assert_equal(298, bytes)
131
+
132
+ if defined?(Encoding)
133
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
134
+ 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",
135
+ contents)
136
+ else
137
+ contents = File.read(temp_filename)
138
+ 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",
139
+ contents)
140
+ end
141
+ ensure
142
+ File.delete(temp_filename)
143
+ end
144
+
145
+ def test_save_iso_8859_1
146
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml")
147
+ bytes = @doc.save(temp_filename, :encoding => XML::Encoding::ISO_8859_1)
148
+ assert_equal(304, bytes)
149
+
150
+ if defined?(Encoding)
151
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
152
+ assert_equal(Encoding::ISO8859_1, contents.encoding)
153
+ 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),
154
+ contents)
155
+ else
156
+ contents = File.read(temp_filename)
157
+ 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",
158
+ contents)
159
+ end
160
+ ensure
161
+ File.delete(temp_filename)
162
+ end
163
+
164
+ def test_save_iso_8859_1_no_indent
165
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml")
166
+ bytes = @doc.save(temp_filename, :indent => false, :encoding => XML::Encoding::ISO_8859_1)
167
+ assert_equal(297, bytes)
168
+
169
+ if defined?(Encoding)
170
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
171
+ assert_equal(Encoding::ISO8859_1, contents.encoding)
172
+ 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),
173
+ contents)
174
+ else
175
+ contents = File.read(temp_filename)
176
+ 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",
177
+ contents)
178
+ end
179
+ ensure
180
+ File.delete(temp_filename)
181
+ end
182
+
183
+ # --- Debug ---
184
+ def test_debug
185
+ assert(@doc.debug)
186
+ end
187
+ end