libxml-ruby-r19mingw 1.1.4

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