libxml-ruby 1.1.4 → 2.0.0

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 (146) hide show
  1. data/{CHANGES → HISTORY} +35 -0
  2. data/LICENSE +1 -0
  3. data/MANIFEST +165 -0
  4. data/{README → README.rdoc} +2 -2
  5. data/Rakefile +47 -147
  6. data/ext/libxml/libxml.c +17 -1
  7. data/ext/libxml/ruby_libxml.h +9 -1
  8. data/ext/libxml/ruby_xml_attr.c +3 -3
  9. data/ext/libxml/ruby_xml_attr_decl.c +32 -32
  10. data/ext/libxml/ruby_xml_attributes.c +1 -1
  11. data/ext/libxml/ruby_xml_cbg.c +1 -2
  12. data/ext/libxml/ruby_xml_document.c +26 -4
  13. data/ext/libxml/ruby_xml_dtd.c +3 -3
  14. data/ext/libxml/ruby_xml_encoding.c +92 -5
  15. data/ext/libxml/ruby_xml_encoding.h +4 -0
  16. data/ext/libxml/ruby_xml_namespace.c +2 -2
  17. data/ext/libxml/ruby_xml_node.c +14 -14
  18. data/ext/libxml/ruby_xml_parser_context.c +8 -8
  19. data/ext/libxml/ruby_xml_reader.c +98 -43
  20. data/ext/libxml/ruby_xml_sax2_handler.c +13 -1
  21. data/ext/libxml/ruby_xml_sax_parser.c +4 -5
  22. data/ext/libxml/ruby_xml_version.h +5 -5
  23. data/ext/libxml/ruby_xml_xpath_context.c +9 -6
  24. data/ext/libxml/ruby_xml_xpath_object.c +1 -1
  25. data/ext/vc/libxml_ruby.sln +4 -4
  26. data/lib/libxml.rb +29 -29
  27. data/lib/libxml/attr.rb +112 -110
  28. data/lib/libxml/attr_decl.rb +2 -0
  29. data/lib/libxml/attributes.rb +13 -11
  30. data/lib/libxml/document.rb +192 -190
  31. data/lib/libxml/error.rb +89 -87
  32. data/lib/libxml/hpricot.rb +77 -75
  33. data/lib/libxml/html_parser.rb +96 -94
  34. data/lib/libxml/namespace.rb +61 -59
  35. data/lib/libxml/namespaces.rb +37 -35
  36. data/lib/libxml/node.rb +398 -384
  37. data/lib/libxml/ns.rb +21 -19
  38. data/lib/libxml/parser.rb +366 -364
  39. data/lib/libxml/properties.rb +22 -20
  40. data/lib/libxml/reader.rb +2 -0
  41. data/lib/libxml/sax_callbacks.rb +179 -177
  42. data/lib/libxml/sax_parser.rb +57 -55
  43. data/lib/libxml/tree.rb +28 -26
  44. data/lib/libxml/xpath_object.rb +15 -13
  45. data/lib/xml.rb +16 -14
  46. data/lib/xml/libxml.rb +10 -8
  47. data/libxml-ruby.gemspec +50 -0
  48. data/script/benchmark/depixelate +634 -0
  49. data/script/benchmark/hamlet.xml +9055 -0
  50. data/script/benchmark/parsecount +170 -0
  51. data/script/benchmark/sock_entries.xml +507 -0
  52. data/script/benchmark/throughput +41 -0
  53. data/script/test +6 -0
  54. data/test/etc_doc_to_s.rb +21 -19
  55. data/test/ets_doc_file.rb +17 -15
  56. data/test/ets_doc_to_s.rb +23 -21
  57. data/test/ets_gpx.rb +28 -26
  58. data/test/ets_node_gc.rb +23 -21
  59. data/test/ets_tsr.rb +11 -9
  60. data/test/model/bands.iso-8859-1.xml +5 -0
  61. data/test/model/bands.utf-8.xml +5 -0
  62. data/test/rb-magic-comment.rb +33 -0
  63. data/test/tc_attr.rb +181 -170
  64. data/test/tc_attr_decl.rb +3 -1
  65. data/test/tc_attributes.rb +134 -132
  66. data/test/tc_deprecated_require.rb +13 -11
  67. data/test/tc_document.rb +119 -113
  68. data/test/tc_document_write.rb +186 -117
  69. data/test/tc_dtd.rb +125 -123
  70. data/test/tc_error.rb +3 -1
  71. data/test/tc_html_parser.rb +139 -137
  72. data/test/tc_namespace.rb +61 -58
  73. data/test/tc_namespaces.rb +176 -173
  74. data/test/tc_node.rb +257 -180
  75. data/test/tc_node_cdata.rb +51 -49
  76. data/test/tc_node_comment.rb +33 -30
  77. data/test/tc_node_copy.rb +42 -40
  78. data/test/tc_node_edit.rb +159 -157
  79. data/test/tc_node_text.rb +71 -69
  80. data/test/tc_node_write.rb +41 -16
  81. data/test/tc_node_xlink.rb +29 -26
  82. data/test/tc_parser.rb +335 -329
  83. data/test/tc_parser_context.rb +188 -185
  84. data/test/tc_properties.rb +39 -36
  85. data/test/tc_reader.rb +297 -283
  86. data/test/tc_relaxng.rb +54 -51
  87. data/test/tc_sax_parser.rb +275 -273
  88. data/test/tc_schema.rb +53 -51
  89. data/test/tc_traversal.rb +222 -220
  90. data/test/tc_xinclude.rb +21 -19
  91. data/test/tc_xml.rb +3 -1
  92. data/test/tc_xpath.rb +195 -193
  93. data/test/tc_xpath_context.rb +80 -78
  94. data/test/tc_xpath_expression.rb +38 -35
  95. data/test/tc_xpointer.rb +74 -72
  96. data/test/test_helper.rb +14 -0
  97. data/test/test_suite.rb +39 -33
  98. metadata +65 -105
  99. data/doc/css/normal.css +0 -182
  100. data/doc/img/raze-tiny.png +0 -0
  101. data/doc/img/red-cube.jpg +0 -0
  102. data/doc/img/xml-ruby.png +0 -0
  103. data/doc/index.xml +0 -43
  104. data/doc/install.xml +0 -77
  105. data/doc/layout.rhtml +0 -38
  106. data/doc/layout.xsl +0 -67
  107. data/doc/license.xml +0 -32
  108. data/doc/log/changelog.xml +0 -1324
  109. data/doc/log/changelog.xsl +0 -42
  110. data/ext/libxml/Makefile +0 -156
  111. data/ext/libxml/extconf.h +0 -5
  112. data/ext/libxml/libxml-ruby.so.a +0 -0
  113. data/ext/libxml/libxml.o +0 -0
  114. data/ext/libxml/libxml_ruby.so +0 -0
  115. data/ext/libxml/mkmf.log +0 -129
  116. data/ext/libxml/ruby_xml.o +0 -0
  117. data/ext/libxml/ruby_xml_attr.o +0 -0
  118. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  119. data/ext/libxml/ruby_xml_attributes.o +0 -0
  120. data/ext/libxml/ruby_xml_cbg.o +0 -0
  121. data/ext/libxml/ruby_xml_document.o +0 -0
  122. data/ext/libxml/ruby_xml_dtd.o +0 -0
  123. data/ext/libxml/ruby_xml_encoding.o +0 -0
  124. data/ext/libxml/ruby_xml_error.o +0 -0
  125. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  126. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  127. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  128. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  129. data/ext/libxml/ruby_xml_io.o +0 -0
  130. data/ext/libxml/ruby_xml_namespace.o +0 -0
  131. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  132. data/ext/libxml/ruby_xml_node.o +0 -0
  133. data/ext/libxml/ruby_xml_parser.o +0 -0
  134. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  135. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  136. data/ext/libxml/ruby_xml_reader.o +0 -0
  137. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  138. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  139. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  140. data/ext/libxml/ruby_xml_schema.o +0 -0
  141. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  142. data/ext/libxml/ruby_xml_xpath.o +0 -0
  143. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  144. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  145. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  146. data/ext/libxml/ruby_xml_xpointer.o +0 -0
data/test/tc_error.rb CHANGED
@@ -1,4 +1,6 @@
1
- require 'xml'
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
2
4
  require 'test/unit'
3
5
  require 'stringio'
4
6
 
@@ -1,138 +1,140 @@
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
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'stringio'
5
+ require 'test/unit'
6
+
7
+ class HTMLParserTest < Test::Unit::TestCase
8
+ def html_file
9
+ File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html'))
10
+ end
11
+
12
+ # ----- Sources ------
13
+ def test_file
14
+ xp = XML::HTMLParser.file(html_file)
15
+ assert_instance_of(XML::HTMLParser, xp)
16
+ doc = xp.parse
17
+ assert_not_nil(doc)
18
+ end
19
+
20
+ def test_noexistent_file
21
+ error = assert_raise(XML::Error) do
22
+ XML::HTMLParser.file('i_dont_exist.xml')
23
+ end
24
+
25
+ assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
26
+ end
27
+
28
+ def test_nil_file
29
+ error = assert_raise(TypeError) do
30
+ XML::HTMLParser.file(nil)
31
+ end
32
+
33
+ assert_equal("can't convert nil into String", error.to_s)
34
+ end
35
+
36
+ def test_io
37
+ File.open(html_file) do |io|
38
+ xp = XML::HTMLParser.io(io)
39
+ assert_instance_of(XML::HTMLParser, xp)
40
+
41
+ doc = xp.parse
42
+ assert_instance_of(XML::Document, doc)
43
+ end
44
+ end
45
+
46
+ def test_io_gc
47
+ # Test that the reader keeps a reference
48
+ # to the io object
49
+ file = File.open(html_file)
50
+ parser = XML::HTMLParser.io(file)
51
+ file = nil
52
+ GC.start
53
+ assert(parser.parse)
54
+ end
55
+
56
+ def test_nil_io
57
+ error = assert_raise(TypeError) do
58
+ XML::HTMLParser.io(nil)
59
+ end
60
+
61
+ assert_equal("Must pass in an IO object", error.to_s)
62
+ end
63
+
64
+ def test_string_io
65
+ data = File.read(html_file)
66
+ io = StringIO.new(data)
67
+ xp = XML::HTMLParser.io(io)
68
+ assert_instance_of(XML::HTMLParser, xp)
69
+
70
+ doc = xp.parse
71
+ assert_instance_of(XML::Document, doc)
72
+ end
73
+
74
+ def test_string
75
+ str = '<html><body><p>hi</p></body></html>'
76
+ xp = XML::HTMLParser.string(str)
77
+
78
+ assert_instance_of(XML::HTMLParser, xp)
79
+ assert_instance_of(XML::HTMLParser, xp)
80
+
81
+ doc = xp.parse
82
+ assert_instance_of(XML::Document, doc)
83
+ end
84
+
85
+ def test_nil_string
86
+ error = assert_raise(TypeError) do
87
+ XML::HTMLParser.string(nil)
88
+ end
89
+
90
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
91
+ end
92
+
93
+ def test_parse
94
+ html = <<-EOS
95
+ <html>
96
+ <head>
97
+ <meta name=keywords content=nasty>
98
+ </head>
99
+ <body>Hello<br>World</html>
100
+ EOS
101
+
102
+ parser = XML::HTMLParser.string(html)
103
+ doc = parser.parse
104
+ assert_instance_of XML::Document, doc
105
+
106
+ root = doc.root
107
+ assert_instance_of XML::Node, root
108
+ assert_equal 'html', root.name
109
+
110
+ head = root.child
111
+ assert_instance_of XML::Node, head
112
+ assert_equal 'head', head.name
113
+
114
+ meta = head.child
115
+ assert_instance_of XML::Node, meta
116
+ assert_equal 'meta', meta.name
117
+ assert_equal 'keywords', meta[:name]
118
+ assert_equal 'nasty', meta[:content]
119
+
120
+ body = head.next
121
+ assert_instance_of XML::Node, body
122
+ assert_equal 'body', body.name
123
+
124
+ hello = body.child
125
+ # It appears that some versions of libxml2 add a layer of <p>
126
+ # cant figure our why or how, so this skips it if there
127
+ hello = hello.child if hello.name == "p"
128
+
129
+ assert_instance_of XML::Node, hello
130
+ assert_equal 'Hello', hello.content
131
+
132
+ br = hello.next
133
+ assert_instance_of XML::Node, br
134
+ assert_equal 'br', br.name
135
+
136
+ world = br.next
137
+ assert_instance_of XML::Node, world
138
+ assert_equal 'World', world.content
139
+ end
138
140
  end
data/test/tc_namespace.rb CHANGED
@@ -1,59 +1,62 @@
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
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ require 'test/unit'
6
+
7
+ class TestNS < Test::Unit::TestCase
8
+ def setup
9
+ file = File.join(File.dirname(__FILE__), 'model/soap.xml')
10
+ @doc = XML::Document.file(file)
11
+ end
12
+
13
+ def teardown
14
+ @doc = nil
15
+ end
16
+
17
+ def test_create_ns
18
+ node = XML::Node.new('foo')
19
+ ns = XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com')
20
+ assert_equal(ns.prefix, 'my_namepace')
21
+ assert_equal(ns.href, 'http://www.mynamespace.com')
22
+ end
23
+
24
+ def test_create_default_ns
25
+ node = XML::Node.new('foo')
26
+ ns = XML::Namespace.new(node, nil, 'http://www.mynamespace.com')
27
+ assert_equal(ns.prefix, nil)
28
+ assert_equal(ns.href, 'http://www.mynamespace.com')
29
+ end
30
+
31
+ def test_create_unbound_ns
32
+ error = assert_raise(TypeError) do
33
+ XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
34
+ end
35
+ assert_equal('wrong argument type nil (expected Data)', error.to_s)
36
+ end
37
+
38
+ def test_duplicate_ns
39
+ node = XML::Node.new('foo')
40
+ XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
41
+ assert_raises(XML::Error) do
42
+ XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
43
+ end
44
+ end
45
+
46
+ def test_eql
47
+ node = XML::Node.new('Envelope')
48
+ ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
49
+
50
+ assert(node.namespaces.namespace.eql?(node.namespaces.namespace))
51
+ end
52
+
53
+ def test_equal
54
+ node1 = XML::Node.new('Envelope')
55
+ ns1 = XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
56
+
57
+ node2 = XML::Node.new('Envelope')
58
+ ns2 = XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
59
+
60
+ assert(ns1 == ns2)
61
+ end
59
62
  end
@@ -1,174 +1,177 @@
1
- require "xml"
2
- require 'test/unit'
3
-
4
- class TestNamespaces < 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_namespace
15
- node = @doc.root
16
- ns = node.namespaces.namespace
17
- assert_equal('soap', ns.prefix)
18
- assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href)
19
- end
20
-
21
- def test_set_namespace
22
- node = XML::Node.new('Envelope')
23
- assert_equal('<Envelope/>', node.to_s)
24
-
25
- ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
26
- assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
27
- assert_nil(node.namespaces.namespace)
28
-
29
- # Now put the node in the soap namespace
30
- node.namespaces.namespace = ns
31
- assert_not_nil(node.namespaces.namespace)
32
- assert_equal("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
33
- end
34
-
35
- def test_define_namespace
36
- node = XML::Node.new('Envelope')
37
- assert_equal('<Envelope/>', node.to_s)
38
-
39
- XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
40
- assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
41
- assert_nil(node.namespaces.namespace)
42
- end
43
-
44
- def test_define_default_namespace
45
- node = XML::Node.new('Envelope')
46
- assert_equal('<Envelope/>', node.to_s)
47
-
48
- XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/')
49
- assert_equal("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
50
- # This seems wrong, but appears to be the way libxml works
51
- assert_nil(node.namespaces.namespace)
52
- end
53
-
54
- def test_namespaces
55
- node = @doc.find_first('//ns1:IdAndName',
56
- :ns1 => 'http://domain.somewhere.com')
57
-
58
- namespaces = node.namespaces.sort
59
- assert_equal(5, namespaces.length)
60
-
61
- namespace = namespaces[0]
62
- assert_instance_of(XML::Namespace, namespace)
63
- assert_equal(nil, namespace.prefix)
64
- assert_equal('http://services.somewhere.com', namespace.href)
65
-
66
- namespace = namespaces[1]
67
- assert_instance_of(XML::Namespace, namespace)
68
- assert_equal('ns1', namespace.prefix)
69
- assert_equal('http://domain.somewhere.com', namespace.href)
70
-
71
- namespace = namespaces[2]
72
- assert_instance_of(XML::Namespace, namespace)
73
- assert_equal('soap', namespace.prefix)
74
- assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
75
-
76
- namespace = namespaces[3]
77
- assert_instance_of(XML::Namespace, namespace)
78
- assert_equal('xsd', namespace.prefix)
79
- assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
80
-
81
- namespace = namespaces[4]
82
- assert_instance_of(XML::Namespace, namespace)
83
- assert_equal('xsi', namespace.prefix)
84
- assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
85
- end
86
-
87
- def test_namespaces
88
- node = @doc.find_first('//ns1:IdAndName',
89
- :ns1 => 'http://domain.somewhere.com')
90
-
91
- namespaces = node.namespaces.each do |namespace|
92
- assert_instance_of(XML::Namespace, namespace)
93
- end
94
- end
95
-
96
- def test_namespace_definitions
97
- ns_defs = @doc.root.namespaces.definitions
98
- assert_equal(3, ns_defs.size)
99
-
100
- namespace = ns_defs[0]
101
- assert_instance_of(XML::Namespace, namespace)
102
- assert_equal('soap', namespace.prefix)
103
- assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
104
-
105
- namespace = ns_defs[1]
106
- assert_instance_of(XML::Namespace, namespace)
107
- assert_equal('xsd', namespace.prefix)
108
- assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
109
-
110
- namespace = ns_defs[2]
111
- assert_instance_of(XML::Namespace, namespace)
112
- assert_equal('xsi', namespace.prefix)
113
- assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
114
-
115
- node = @doc.root.find_first('//ns:getManufacturerNamesResponse',
116
- :ns => 'http://services.somewhere.com')
117
- ns_defs = node.namespaces.definitions
118
- assert_equal(1, ns_defs.size)
119
-
120
- namespace = ns_defs[0]
121
- assert_instance_of(XML::Namespace, namespace)
122
- assert_equal(nil, namespace.prefix)
123
- assert_equal('http://services.somewhere.com', namespace.href)
124
- end
125
-
126
- def test_find_by_prefix
127
- node = @doc.find_first('//ns1:getManufacturerNamesResponse',
128
- :ns1 => 'http://services.somewhere.com')
129
-
130
- namespace = @doc.root.namespaces.find_by_prefix('soap')
131
-
132
- assert_instance_of(XML::Namespace, namespace)
133
- assert_equal('soap', namespace.prefix)
134
- assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
135
- end
136
-
137
- def test_find_default_ns
138
- namespace = @doc.root.namespaces.find_by_prefix(nil)
139
- assert_nil(namespace)
140
-
141
- node = @doc.find_first('//ns1:getManufacturerNamesResponse',
142
- :ns1 => 'http://services.somewhere.com')
143
- namespace = node.namespaces.find_by_prefix(nil)
144
-
145
- assert_instance_of(XML::Namespace, namespace)
146
- assert_equal(nil, namespace.prefix)
147
- assert_equal('http://services.somewhere.com', namespace.href)
148
- end
149
-
150
- def test_find_ns_by_href
151
- node = @doc.find_first('//ns1:getManufacturerNamesResponse',
152
- :ns1 => 'http://services.somewhere.com')
153
-
154
- namespace = node.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
155
-
156
- assert_instance_of(XML::Namespace, namespace)
157
- assert_equal('soap', namespace.prefix)
158
- assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
159
- end
160
-
161
- def test_default_namespace
162
- doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
163
- ns = doc.root.namespaces.default
164
- assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
165
- end
166
-
167
- def test_default_prefix
168
- doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
169
- doc.root.namespaces.default_prefix = 'soap'
170
-
171
- node = doc.root.find_first('/soap:Envelope')
172
- assert_not_nil(node)
173
- end
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ require 'test/unit'
6
+
7
+ class TestNamespaces < Test::Unit::TestCase
8
+ def setup
9
+ file = File.join(File.dirname(__FILE__), 'model/soap.xml')
10
+ @doc = XML::Document.file(file)
11
+ end
12
+
13
+ def teardown
14
+ @doc = nil
15
+ end
16
+
17
+ def test_namespace
18
+ node = @doc.root
19
+ ns = node.namespaces.namespace
20
+ assert_equal('soap', ns.prefix)
21
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href)
22
+ end
23
+
24
+ def test_set_namespace
25
+ node = XML::Node.new('Envelope')
26
+ assert_equal('<Envelope/>', node.to_s)
27
+
28
+ ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
29
+ assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
30
+ assert_nil(node.namespaces.namespace)
31
+
32
+ # Now put the node in the soap namespace
33
+ node.namespaces.namespace = ns
34
+ assert_not_nil(node.namespaces.namespace)
35
+ assert_equal("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
36
+ end
37
+
38
+ def test_define_namespace
39
+ node = XML::Node.new('Envelope')
40
+ assert_equal('<Envelope/>', node.to_s)
41
+
42
+ XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
43
+ assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
44
+ assert_nil(node.namespaces.namespace)
45
+ end
46
+
47
+ def test_define_default_namespace
48
+ node = XML::Node.new('Envelope')
49
+ assert_equal('<Envelope/>', node.to_s)
50
+
51
+ XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/')
52
+ assert_equal("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
53
+ # This seems wrong, but appears to be the way libxml works
54
+ assert_nil(node.namespaces.namespace)
55
+ end
56
+
57
+ def test_namespaces
58
+ node = @doc.find_first('//ns1:IdAndName',
59
+ :ns1 => 'http://domain.somewhere.com')
60
+
61
+ namespaces = node.namespaces.sort
62
+ assert_equal(5, namespaces.length)
63
+
64
+ namespace = namespaces[0]
65
+ assert_instance_of(XML::Namespace, namespace)
66
+ assert_equal(nil, namespace.prefix)
67
+ assert_equal('http://services.somewhere.com', namespace.href)
68
+
69
+ namespace = namespaces[1]
70
+ assert_instance_of(XML::Namespace, namespace)
71
+ assert_equal('ns1', namespace.prefix)
72
+ assert_equal('http://domain.somewhere.com', namespace.href)
73
+
74
+ namespace = namespaces[2]
75
+ assert_instance_of(XML::Namespace, namespace)
76
+ assert_equal('soap', namespace.prefix)
77
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
78
+
79
+ namespace = namespaces[3]
80
+ assert_instance_of(XML::Namespace, namespace)
81
+ assert_equal('xsd', namespace.prefix)
82
+ assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
83
+
84
+ namespace = namespaces[4]
85
+ assert_instance_of(XML::Namespace, namespace)
86
+ assert_equal('xsi', namespace.prefix)
87
+ assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
88
+ end
89
+
90
+ def test_namespaces
91
+ node = @doc.find_first('//ns1:IdAndName',
92
+ :ns1 => 'http://domain.somewhere.com')
93
+
94
+ namespaces = node.namespaces.each do |namespace|
95
+ assert_instance_of(XML::Namespace, namespace)
96
+ end
97
+ end
98
+
99
+ def test_namespace_definitions
100
+ ns_defs = @doc.root.namespaces.definitions
101
+ assert_equal(3, ns_defs.size)
102
+
103
+ namespace = ns_defs[0]
104
+ assert_instance_of(XML::Namespace, namespace)
105
+ assert_equal('soap', namespace.prefix)
106
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
107
+
108
+ namespace = ns_defs[1]
109
+ assert_instance_of(XML::Namespace, namespace)
110
+ assert_equal('xsd', namespace.prefix)
111
+ assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
112
+
113
+ namespace = ns_defs[2]
114
+ assert_instance_of(XML::Namespace, namespace)
115
+ assert_equal('xsi', namespace.prefix)
116
+ assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
117
+
118
+ node = @doc.root.find_first('//ns:getManufacturerNamesResponse',
119
+ :ns => 'http://services.somewhere.com')
120
+ ns_defs = node.namespaces.definitions
121
+ assert_equal(1, ns_defs.size)
122
+
123
+ namespace = ns_defs[0]
124
+ assert_instance_of(XML::Namespace, namespace)
125
+ assert_equal(nil, namespace.prefix)
126
+ assert_equal('http://services.somewhere.com', namespace.href)
127
+ end
128
+
129
+ def test_find_by_prefix
130
+ node = @doc.find_first('//ns1:getManufacturerNamesResponse',
131
+ :ns1 => 'http://services.somewhere.com')
132
+
133
+ namespace = @doc.root.namespaces.find_by_prefix('soap')
134
+
135
+ assert_instance_of(XML::Namespace, namespace)
136
+ assert_equal('soap', namespace.prefix)
137
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
138
+ end
139
+
140
+ def test_find_default_ns
141
+ namespace = @doc.root.namespaces.find_by_prefix(nil)
142
+ assert_nil(namespace)
143
+
144
+ node = @doc.find_first('//ns1:getManufacturerNamesResponse',
145
+ :ns1 => 'http://services.somewhere.com')
146
+ namespace = node.namespaces.find_by_prefix(nil)
147
+
148
+ assert_instance_of(XML::Namespace, namespace)
149
+ assert_equal(nil, namespace.prefix)
150
+ assert_equal('http://services.somewhere.com', namespace.href)
151
+ end
152
+
153
+ def test_find_ns_by_href
154
+ node = @doc.find_first('//ns1:getManufacturerNamesResponse',
155
+ :ns1 => 'http://services.somewhere.com')
156
+
157
+ namespace = node.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
158
+
159
+ assert_instance_of(XML::Namespace, namespace)
160
+ assert_equal('soap', namespace.prefix)
161
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
162
+ end
163
+
164
+ def test_default_namespace
165
+ doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
166
+ ns = doc.root.namespaces.default
167
+ assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
168
+ end
169
+
170
+ def test_default_prefix
171
+ doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
172
+ doc.root.namespaces.default_prefix = 'soap'
173
+
174
+ node = doc.root.find_first('/soap:Envelope')
175
+ assert_not_nil(node)
176
+ end
174
177
  end