libxml-ruby-r19mingw 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
data/test/tc_dtd.rb ADDED
@@ -0,0 +1,123 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TestDtd < Test::Unit::TestCase
5
+ def setup
6
+ xp = XML::Parser.string(<<-EOS)
7
+ <root>
8
+ <head a="ee" id="1">Colorado</head>
9
+ <descr>Lots of nice mountains</descr>
10
+ </root>
11
+ EOS
12
+ @doc = xp.parse
13
+ end
14
+
15
+ def teardown
16
+ @doc = nil
17
+ end
18
+
19
+ def dtd
20
+ XML::Dtd.new(<<-EOS)
21
+ <!ELEMENT root (head, descr)>
22
+ <!ELEMENT head (#PCDATA)>
23
+ <!ATTLIST head
24
+ id NMTOKEN #REQUIRED
25
+ a CDATA #IMPLIED
26
+ >
27
+ <!ELEMENT descr (#PCDATA)>
28
+ EOS
29
+ end
30
+
31
+ def test_internal_subset
32
+ xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, nil, true
33
+ assert xhtml_dtd.name.nil?
34
+ assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
35
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
36
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
37
+
38
+ xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1", nil, true
39
+ assert_equal "xhtml1", xhtml_dtd.name
40
+ assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
41
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
42
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
43
+ end
44
+
45
+ def test_external_subset
46
+ xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil
47
+ assert xhtml_dtd.name.nil?
48
+ assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
49
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
50
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
51
+
52
+ xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1"
53
+ assert_equal "xhtml1", xhtml_dtd.name
54
+ assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
55
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
56
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
57
+ end
58
+
59
+ def test_valid
60
+ assert(@doc.validate(dtd))
61
+ end
62
+
63
+ def test_invalid
64
+ new_node = XML::Node.new('invalid', 'this will mess up validation')
65
+ @doc.root.child_add(new_node)
66
+
67
+ messages = Hash.new
68
+ error = assert_raise(XML::Error) do
69
+ @doc.validate(dtd)
70
+ end
71
+
72
+ # Check the error worked
73
+ assert_not_nil(error)
74
+ assert_kind_of(XML::Error, error)
75
+ assert_equal("Error: No declaration for element invalid.", error.message)
76
+ assert_equal(XML::Error::VALID, error.domain)
77
+ assert_equal(XML::Error::DTD_UNKNOWN_ELEM, error.code)
78
+ assert_equal(XML::Error::ERROR, error.level)
79
+ assert_nil(error.file)
80
+ assert_nil(error.line)
81
+ assert_equal('invalid', error.str1)
82
+ assert_equal('invalid', error.str2)
83
+ assert_nil(error.str3)
84
+ assert_equal(0, error.int1)
85
+ assert_equal(0, error.int2)
86
+ assert_not_nil(error.node)
87
+ assert_equal('invalid', error.node.name)
88
+ end
89
+
90
+ def test_external_dtd
91
+ xml = <<-EOS
92
+ <!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []>
93
+ <test>
94
+ <title>T1</title>
95
+ </test>
96
+ EOS
97
+
98
+ errors = Array.new
99
+ XML::Error.set_handler do |error|
100
+ errors << error
101
+ end
102
+
103
+ XML.default_load_external_dtd = false
104
+ doc = XML::Parser.string(xml).parse
105
+ assert_equal(0, errors.length)
106
+
107
+ errors.clear
108
+ XML.default_load_external_dtd = true
109
+ doc = XML::Parser.string(xml).parse
110
+ assert_equal(1, errors.length)
111
+ assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
112
+ errors[0].to_s)
113
+
114
+ errors = Array.new
115
+ doc = XML::Parser.string(xml, :options => XML::Parser::Options::DTDLOAD).parse
116
+ assert_equal(1, errors.length)
117
+ assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
118
+ errors[0].to_s)
119
+ ensure
120
+ XML.default_load_external_dtd = false
121
+ XML::Error.reset_handler
122
+ end
123
+ end
data/test/tc_error.rb ADDED
@@ -0,0 +1,136 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+ require 'stringio'
4
+
5
+ class TestError < Test::Unit::TestCase
6
+ def test_invalid_handler
7
+ assert_raises(RuntimeError) do
8
+ XML::Error.set_handler
9
+ end
10
+ end
11
+
12
+ def test_handler
13
+ exception = nil
14
+ XML::Error.set_handler do |error|
15
+ exception = error
16
+ end
17
+
18
+ # Raise the error
19
+ XML::Reader.new('<foo').read
20
+
21
+ # Check the handler worked
22
+ assert_not_nil(exception)
23
+ assert_kind_of(XML::Error, exception)
24
+ assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", exception.message)
25
+ assert_equal(XML::Error::XML_FROM_PARSER, exception.domain)
26
+ assert_equal(XML::Error::XML_ERR_GT_REQUIRED, exception.code)
27
+ assert_equal(XML::Error::XML_ERR_FATAL, exception.level)
28
+ assert_nil(exception.file)
29
+ assert_equal(1, exception.line)
30
+ assert_equal('foo', exception.str1)
31
+ assert_nil(exception.str2)
32
+ assert_nil(exception.str3)
33
+ assert_equal(0, exception.int1)
34
+ assert_equal(5, exception.int2)
35
+ assert_nil(exception.node)
36
+ end
37
+
38
+ def test_reset_handler
39
+ exception = nil
40
+ XML::Error.set_handler do |error|
41
+ exception = error
42
+ end
43
+
44
+ XML::Error.reset_handler
45
+ reader = XML::Reader.new('<foo')
46
+ assert_nil(exception)
47
+ end
48
+
49
+ def test_verbose_handler
50
+ XML::Error.set_handler(&XML::Error::VERBOSE_HANDLER)
51
+ output = StringIO.new
52
+ original_stderr = Object::STDERR
53
+
54
+ Object.const_set(:STDERR, output)
55
+ begin
56
+ assert_raise(XML::Error) do
57
+ XML::Parser.string('<foo><bar/></foz>').parse
58
+ end
59
+ ensure
60
+ Object.const_set(:STDERR, original_stderr)
61
+ end
62
+ assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.\n", output.string)
63
+ end
64
+
65
+ def test_no_hanlder
66
+ XML::Error.reset_handler
67
+ output = StringIO.new
68
+ original_stderr = Object::STDERR
69
+
70
+ Object.const_set(:STDERR, output)
71
+ begin
72
+ assert_raise(XML::Error) do
73
+ XML::Parser.string('<foo><bar/></foz>').parse
74
+ end
75
+ ensure
76
+ Object.const_set(:STDERR, original_stderr)
77
+ end
78
+ assert_equal('', output.string)
79
+ end
80
+
81
+ def test_parse_error
82
+ exception = assert_raise(XML::Error) do
83
+ XML::Parser.string('<foo><bar/></foz>').parse
84
+ end
85
+
86
+ assert_instance_of(XML::Error, exception)
87
+ assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message)
88
+ assert_equal(XML::Error::XML_FROM_PARSER, exception.domain)
89
+ assert_equal(XML::Error::XML_ERR_TAG_NAME_MISMATCH, exception.code)
90
+ assert_equal(XML::Error::XML_ERR_FATAL, exception.level)
91
+ assert_nil(exception.file)
92
+ assert_equal(1, exception.line)
93
+ end
94
+
95
+ def test_xpath_error
96
+ doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
97
+
98
+ exception = assert_raise(XML::Error) do
99
+ elements = doc.find('/foo[bar=test')
100
+ end
101
+
102
+ assert_instance_of(XML::Error, exception)
103
+ assert_equal("Error: Invalid predicate at :0.", exception.message)
104
+ assert_equal(XML::Error::XML_FROM_XPATH, exception.domain)
105
+ assert_equal(XML::Error::XML_XPATH_INVALID_PREDICATE_ERROR, exception.code)
106
+ assert_equal(XML::Error::XML_ERR_ERROR, exception.level)
107
+ assert_nil(exception.file)
108
+ assert_nil(nil)
109
+ end
110
+
111
+ def test_double_parse
112
+ XML::Parser.register_error_handler(lambda {|msg| nil })
113
+ parser = XML::Parser.string("<test>something</test>")
114
+ doc = parser.parse
115
+
116
+ error = assert_raise(RuntimeError) do
117
+ # Try parsing a second time
118
+ parser.parse
119
+ end
120
+
121
+ assert_equal("You cannot parse a data source twice", error.to_s)
122
+ end
123
+
124
+ def test_libxml_parser_empty_string
125
+ xp = XML::Parser.new
126
+
127
+ assert_raise(TypeError) do
128
+ xp.string = nil
129
+ end
130
+
131
+ xp.string = ''
132
+ assert_raise(XML::Error) do
133
+ xp.parse
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,138 @@
1
+ require 'xml'
2
+ require 'stringio'
3
+ require 'test/unit'
4
+
5
+ class HTMLParserTest < Test::Unit::TestCase
6
+ def html_file
7
+ File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html'))
8
+ end
9
+
10
+ # ----- Sources ------
11
+ def test_file
12
+ xp = XML::HTMLParser.file(html_file)
13
+ assert_instance_of(XML::HTMLParser, xp)
14
+ doc = xp.parse
15
+ assert_not_nil(doc)
16
+ end
17
+
18
+ def test_noexistent_file
19
+ error = assert_raise(XML::Error) do
20
+ XML::HTMLParser.file('i_dont_exist.xml')
21
+ end
22
+
23
+ assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
24
+ end
25
+
26
+ def test_nil_file
27
+ error = assert_raise(TypeError) do
28
+ XML::HTMLParser.file(nil)
29
+ end
30
+
31
+ assert_equal("can't convert nil into String", error.to_s)
32
+ end
33
+
34
+ def test_io
35
+ File.open(html_file) do |io|
36
+ xp = XML::HTMLParser.io(io)
37
+ assert_instance_of(XML::HTMLParser, xp)
38
+
39
+ doc = xp.parse
40
+ assert_instance_of(XML::Document, doc)
41
+ end
42
+ end
43
+
44
+ def test_io_gc
45
+ # Test that the reader keeps a reference
46
+ # to the io object
47
+ file = File.open(html_file)
48
+ parser = XML::HTMLParser.io(file)
49
+ file = nil
50
+ GC.start
51
+ assert(parser.parse)
52
+ end
53
+
54
+ def test_nil_io
55
+ error = assert_raise(TypeError) do
56
+ XML::HTMLParser.io(nil)
57
+ end
58
+
59
+ assert_equal("Must pass in an IO object", error.to_s)
60
+ end
61
+
62
+ def test_string_io
63
+ data = File.read(html_file)
64
+ io = StringIO.new(data)
65
+ xp = XML::HTMLParser.io(io)
66
+ assert_instance_of(XML::HTMLParser, xp)
67
+
68
+ doc = xp.parse
69
+ assert_instance_of(XML::Document, doc)
70
+ end
71
+
72
+ def test_string
73
+ str = '<html><body><p>hi</p></body></html>'
74
+ xp = XML::HTMLParser.string(str)
75
+
76
+ assert_instance_of(XML::HTMLParser, xp)
77
+ assert_instance_of(XML::HTMLParser, xp)
78
+
79
+ doc = xp.parse
80
+ assert_instance_of(XML::Document, doc)
81
+ end
82
+
83
+ def test_nil_string
84
+ error = assert_raise(TypeError) do
85
+ XML::HTMLParser.string(nil)
86
+ end
87
+
88
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
89
+ end
90
+
91
+ def test_parse
92
+ html = <<-EOS
93
+ <html>
94
+ <head>
95
+ <meta name=keywords content=nasty>
96
+ </head>
97
+ <body>Hello<br>World</html>
98
+ EOS
99
+
100
+ parser = XML::HTMLParser.string(html)
101
+ doc = parser.parse
102
+ assert_instance_of XML::Document, doc
103
+
104
+ root = doc.root
105
+ assert_instance_of XML::Node, root
106
+ assert_equal 'html', root.name
107
+
108
+ head = root.child
109
+ assert_instance_of XML::Node, head
110
+ assert_equal 'head', head.name
111
+
112
+ meta = head.child
113
+ assert_instance_of XML::Node, meta
114
+ assert_equal 'meta', meta.name
115
+ assert_equal 'keywords', meta[:name]
116
+ assert_equal 'nasty', meta[:content]
117
+
118
+ body = head.next
119
+ assert_instance_of XML::Node, body
120
+ assert_equal 'body', body.name
121
+
122
+ hello = body.child
123
+ # It appears that some versions of libxml2 add a layer of <p>
124
+ # cant figure our why or how, so this skips it if there
125
+ hello = hello.child if hello.name == "p"
126
+
127
+ assert_instance_of XML::Node, hello
128
+ assert_equal 'Hello', hello.content
129
+
130
+ br = hello.next
131
+ assert_instance_of XML::Node, br
132
+ assert_equal 'br', br.name
133
+
134
+ world = br.next
135
+ assert_instance_of XML::Node, world
136
+ assert_equal 'World', world.content
137
+ end
138
+ end
@@ -0,0 +1,59 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TestNS < Test::Unit::TestCase
5
+ def setup
6
+ file = File.join(File.dirname(__FILE__), 'model/soap.xml')
7
+ @doc = XML::Document.file(file)
8
+ end
9
+
10
+ def teardown
11
+ @doc = nil
12
+ end
13
+
14
+ def test_create_ns
15
+ node = XML::Node.new('foo')
16
+ ns = XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com')
17
+ assert_equal(ns.prefix, 'my_namepace')
18
+ assert_equal(ns.href, 'http://www.mynamespace.com')
19
+ end
20
+
21
+ def test_create_default_ns
22
+ node = XML::Node.new('foo')
23
+ ns = XML::Namespace.new(node, nil, 'http://www.mynamespace.com')
24
+ assert_equal(ns.prefix, nil)
25
+ assert_equal(ns.href, 'http://www.mynamespace.com')
26
+ end
27
+
28
+ def test_create_unbound_ns
29
+ error = assert_raise(TypeError) do
30
+ XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
31
+ end
32
+ assert_equal('wrong argument type nil (expected Data)', error.to_s)
33
+ end
34
+
35
+ def test_duplicate_ns
36
+ node = XML::Node.new('foo')
37
+ XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
38
+ assert_raises(XML::Error) do
39
+ XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
40
+ end
41
+ end
42
+
43
+ def test_eql
44
+ node = XML::Node.new('Envelope')
45
+ ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
46
+
47
+ assert(node.namespaces.namespace.eql?(node.namespaces.namespace))
48
+ end
49
+
50
+ def test_equal
51
+ node1 = XML::Node.new('Envelope')
52
+ ns1 = XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
53
+
54
+ node2 = XML::Node.new('Envelope')
55
+ ns2 = XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
56
+
57
+ assert(ns1 == ns2)
58
+ end
59
+ end