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
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'hpricot'
5
+ require 'xml'
6
+ require 'rexml/document'
7
+
8
+ ITERATIONS = 3
9
+ NESTED_ITERATIONS = 5
10
+
11
+ def bm(name, filename, &block)
12
+ text = File.open(filename).read
13
+ length = text.length / 1024.0 / 1024.0
14
+ puts "#{filename}: #{name} (#{(length * 1024).round} kb)"
15
+ for j in 0 .. NESTED_ITERATIONS
16
+ s = Time.now.to_f
17
+ for i in 0 .. ITERATIONS
18
+ block.call(text)
19
+ end
20
+ timer = Time.now.to_f - s
21
+ puts "\t#{length * ITERATIONS / timer} MB/s"
22
+ end
23
+ end
24
+
25
+ def bm_suite(filenames)
26
+ filenames.each do |filename|
27
+ bm("LIBXML THROUGHPUT:", filename) do |text|
28
+ XML::Document.file(filename)
29
+ end
30
+
31
+ bm("HPRICOT THROUGHPUT:", filename) do |text|
32
+ Hpricot.XML(text)
33
+ end
34
+
35
+ bm("REXML THROUGHPUT:", filename) do |text|
36
+ REXML::Document.new(text)
37
+ end
38
+ end
39
+ end
40
+
41
+ bm_suite("hamlet.xml")
data/script/test ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ %w{test lib ext/libxml}.each{ |path| $LOAD_PATH.unshift(path) }
4
+
5
+ load './test/test_suite.rb'
6
+
data/test/etc_doc_to_s.rb CHANGED
@@ -1,19 +1,21 @@
1
- require 'xml'
2
-
3
- 1.times do |count|
4
-
5
- xml_doc = XML::Document.new()
6
- xml_doc.encoding = "UTF-8"
7
- xml_doc.root = XML::Node.new("Request")
8
-
9
- 1000.times do |index|
10
- xml_doc.root << node = XML::Node.new("row")
11
- node["user_id"] = index.to_s
12
- node << "600445"
13
- end
14
-
15
- xml_str = xml_doc.to_s
16
- print "\r#{count}"
17
- $stdout.flush
18
- end
19
- puts "\n"
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ 1.times do |count|
6
+
7
+ xml_doc = XML::Document.new()
8
+ xml_doc.encoding = "UTF-8"
9
+ xml_doc.root = XML::Node.new("Request")
10
+
11
+ 1000.times do |index|
12
+ xml_doc.root << node = XML::Node.new("row")
13
+ node["user_id"] = index.to_s
14
+ node << "600445"
15
+ end
16
+
17
+ xml_str = xml_doc.to_s
18
+ print "\r#{count}"
19
+ $stdout.flush
20
+ end
21
+ puts "\n"
data/test/ets_doc_file.rb CHANGED
@@ -1,15 +1,17 @@
1
- require 'xml'
2
-
3
- # This is related to bug 8337, complaint is on amd64/fbsd
4
- # unknown if it happens on other amd64/os combos
5
-
6
- Process.setrlimit(Process::RLIMIT_NOFILE,10005)
7
-
8
- (1..10000).each{|time|
9
- XML::Document.file(File.join(File.dirname(__FILE__),'ets_test.xml'))
10
- if time % 100 == 0
11
- print "\r#{time}"
12
- $stdout.flush
13
- end
14
- }
15
- puts "\n"
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ # This is related to bug 8337, complaint is on amd64/fbsd
6
+ # unknown if it happens on other amd64/os combos
7
+
8
+ Process.setrlimit(Process::RLIMIT_NOFILE,10005)
9
+
10
+ (1..10000).each{|time|
11
+ XML::Document.file(File.join(File.dirname(__FILE__),'ets_test.xml'))
12
+ if time % 100 == 0
13
+ print "\r#{time}"
14
+ $stdout.flush
15
+ end
16
+ }
17
+ puts "\n"
data/test/ets_doc_to_s.rb CHANGED
@@ -1,21 +1,23 @@
1
- require 'xml'
2
-
3
- 100.times do |count|
4
-
5
- xml_doc = XML::Document.new()
6
- xml_doc.encoding = "UTF-8"
7
- xml_doc.root = XML::Node.new("Request")
8
-
9
- 1000.times do |index|
10
-
11
- xml_doc.root << node = XML::Node.new("row")
12
- node["user_id"] = index.to_s
13
- node << "600445"
14
-
15
- end
16
-
17
- xml_str = xml_doc.to_s
18
- print "\r#{count}"
19
- $stdout.flush
20
- end
21
- puts "\n"
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ 100.times do |count|
6
+
7
+ xml_doc = XML::Document.new()
8
+ xml_doc.encoding = "UTF-8"
9
+ xml_doc.root = XML::Node.new("Request")
10
+
11
+ 1000.times do |index|
12
+
13
+ xml_doc.root << node = XML::Node.new("row")
14
+ node["user_id"] = index.to_s
15
+ node << "600445"
16
+
17
+ end
18
+
19
+ xml_str = xml_doc.to_s
20
+ print "\r#{count}"
21
+ $stdout.flush
22
+ end
23
+ puts "\n"
data/test/ets_gpx.rb CHANGED
@@ -1,26 +1,28 @@
1
- require 'libxml'
2
-
3
- 100.times do
4
- doc = XML::Document.new
5
- doc.encoding = 'UTF-8'
6
-
7
- root = XML::Node.new 'gpx'
8
- root['version'] = '1.0'
9
- root['creator'] = 'OpenStreetMap.org'
10
- root['xmlns'] = "http://www.topografix.com/GPX/1/0/"
11
-
12
- doc.root = root
13
-
14
- track = XML::Node.new 'trk'
15
- doc.root << track
16
-
17
- trkseg = XML::Node.new 'trkseg'
18
- track << trkseg
19
-
20
- 1.upto(1000) do |n|
21
- trkpt = XML::Node.new 'trkpt'
22
- trkpt['lat'] = n.to_s
23
- trkpt['lon'] = n.to_s
24
- trkseg << trkpt
25
- end
26
- end
1
+ # encoding: UTF-8
2
+
3
+ require 'libxml'
4
+
5
+ 100.times do
6
+ doc = XML::Document.new
7
+ doc.encoding = 'UTF-8'
8
+
9
+ root = XML::Node.new 'gpx'
10
+ root['version'] = '1.0'
11
+ root['creator'] = 'OpenStreetMap.org'
12
+ root['xmlns'] = "http://www.topografix.com/GPX/1/0/"
13
+
14
+ doc.root = root
15
+
16
+ track = XML::Node.new 'trk'
17
+ doc.root << track
18
+
19
+ trkseg = XML::Node.new 'trkseg'
20
+ track << trkseg
21
+
22
+ 1.upto(1000) do |n|
23
+ trkpt = XML::Node.new 'trkpt'
24
+ trkpt['lat'] = n.to_s
25
+ trkpt['lon'] = n.to_s
26
+ trkseg << trkpt
27
+ end
28
+ end
data/test/ets_node_gc.rb CHANGED
@@ -1,21 +1,23 @@
1
- require 'xml'
2
-
3
- # test of bug 13310, clears MEM2
4
-
5
- include GC
6
-
7
- inner = XML::Node.new('inner')
8
- save = nil
9
- 1.times do
10
- outer = XML::Node.new('outer')
11
- outer.child = inner
12
- 1.times do
13
- doc = XML::Document.new
14
- doc.root = outer
15
- # Uncomment the following line and it won't crash
16
- save = doc
17
- end
18
- garbage_collect
19
- end
20
- garbage_collect
21
- puts inner
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ # test of bug 13310, clears MEM2
6
+
7
+ include GC
8
+
9
+ inner = XML::Node.new('inner')
10
+ save = nil
11
+ 1.times do
12
+ outer = XML::Node.new('outer')
13
+ outer.child = inner
14
+ 1.times do
15
+ doc = XML::Document.new
16
+ doc.root = outer
17
+ # Uncomment the following line and it won't crash
18
+ save = doc
19
+ end
20
+ garbage_collect
21
+ end
22
+ garbage_collect
23
+ puts inner
data/test/ets_tsr.rb CHANGED
@@ -1,9 +1,11 @@
1
- require 'xml'
2
-
3
- 10_000.times {|n|
4
- j=XML::Node.new2(nil,"happy#{n}")
5
- 10.times {|r|
6
- j1=XML::Node.new("happy#{r}","farts")
7
- j.child=j1
8
- }
9
- }
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ 10_000.times {|n|
6
+ j=XML::Node.new2(nil,"happy#{n}")
7
+ 10.times {|r|
8
+ j1=XML::Node.new("happy#{r}","farts")
9
+ j.child=j1
10
+ }
11
+ }
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <bands genre="metal">
3
+ <m�tley_cr�e country="us">M�tley Cr�e is an American heavy metal band formed in Los Angeles, California in 1981.</m�tley_cr�e>
4
+ <iron_maiden country="uk">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>
5
+ </bands>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <bands genre="metal">
3
+ <mötley_crüe country="us">Mötley Crüe is an American heavy metal band formed in Los Angeles, California in 1981.</mötley_crüe>
4
+ <iron_maiden country="uk">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>
5
+ </bands>
@@ -0,0 +1,33 @@
1
+ #!/usr/local/ruby/bin/ruby
2
+ # encoding: UTF-8
3
+
4
+ ARGV.reject! { |path| !File.file?(path) }
5
+ (puts DATA.read.gsub("$0", File.basename($0)); exit 1) if ARGV.empty?
6
+
7
+ ARGV.each do |path|
8
+ ls = IO.readlines(path)
9
+ ix = ls[0] !~ /^#!/ ? 0 : 1
10
+ next if ls[ix] =~ /#.*?coding\s*[:=]\s*\S/
11
+ ls.insert ix, "# encoding: UTF-8\n", ("\n" unless ls[ix] =~ /^#?\s*\n/)
12
+ open(path, 'w') { |f| f.write ls.join }
13
+ end
14
+
15
+ __END__
16
+ Add the unicode magic comment to ruby files.
17
+
18
+ * Files are modified in-place.
19
+ * If a file already contains a magic comment, it's skipped.
20
+ * Comment is added below the shebang if it exists, otherwise as the first line.
21
+
22
+ Usage:
23
+ $0 file-1 [file-2 ... file-n]
24
+
25
+ Examples:
26
+ # Add comment to standalone ruby files:
27
+ $0 foo.rb bar.rb
28
+
29
+ # Add comment to an entire ruby library or app:
30
+ find . -name '*.rb' -type f -print0 | xargs -0 $0
31
+
32
+ # Add comment to app files in a rails application:
33
+ find app config lib -name '*.rb' -type f -print0 | xargs -0 $0
data/test/tc_attr.rb CHANGED
@@ -1,170 +1,181 @@
1
- require 'xml'
2
- require 'test/unit'
3
-
4
- class AttrNodeTest < 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
- <type>City</type>
15
- <cityMember name="Cambridge"
16
- xlink:type="simple"
17
- xlink:title="Trinity Lane"
18
- xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
19
- gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
20
- </CityModel>
21
- EOS
22
-
23
- @doc = xp.parse
24
- end
25
-
26
- def teardown()
27
- @doc = nil
28
- end
29
-
30
- def city_member
31
- @doc.find('/city:CityModel/city:cityMember').first
32
- end
33
-
34
- def test_types
35
- attribute = city_member.attributes.get_attribute('name')
36
- assert_instance_of(XML::Attr, attribute)
37
- assert_equal('attribute', attribute.node_type_name)
38
- end
39
-
40
- def test_name
41
- attribute = city_member.attributes.get_attribute('name')
42
- assert_equal('name', attribute.name)
43
-
44
- attribute = city_member.attributes.get_attribute('href')
45
- assert_equal('href', attribute.name)
46
- assert_equal('xlink', attribute.ns.prefix)
47
- assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
48
-
49
- attribute = city_member.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
50
- assert_equal('href', attribute.name)
51
- assert_equal('xlink', attribute.ns.prefix)
52
- assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
53
- end
54
-
55
- def test_value
56
- attribute = city_member.attributes.get_attribute('name')
57
- assert_equal('Cambridge', attribute.value)
58
-
59
- attribute = city_member.attributes.get_attribute('href')
60
- assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
61
- end
62
-
63
- def test_set_value
64
- attribute = city_member.attributes.get_attribute('name')
65
- attribute.value = 'London'
66
- assert_equal('London', attribute.value)
67
-
68
- attribute = city_member.attributes.get_attribute('href')
69
- attribute.value = 'http://i.have.changed'
70
- assert_equal('http://i.have.changed', attribute.value)
71
- end
72
-
73
- def test_set_nil
74
- attribute = city_member.attributes.get_attribute('name')
75
- assert_raise(TypeError) do
76
- attribute.value = nil
77
- end
78
- end
79
-
80
- def test_create
81
- attributes = city_member.attributes
82
- assert_equal(5, attributes.length)
83
-
84
- attr = XML::Attr.new(city_member, 'size', '50,000')
85
- assert_instance_of(XML::Attr, attr)
86
-
87
- attributes = city_member.attributes
88
- assert_equal(6, attributes.length)
89
-
90
- assert_equal(attributes['size'], '50,000')
91
- end
92
-
93
- def test_create_on_node
94
- attributes = city_member.attributes
95
- assert_equal(5, attributes.length)
96
-
97
- attributes['country'] = 'England'
98
-
99
- attributes = city_member.attributes
100
- assert_equal(6, attributes.length)
101
-
102
- assert_equal(attributes['country'], 'England')
103
- end
104
-
105
- def test_create_ns
106
- assert_equal(5, city_member.attributes.length)
107
-
108
- ns = XML::NS.new(city_member, 'my_namepace', 'http://www.mynamespace.com')
109
- attr = XML::Attr.new(city_member, 'rating', 'rocks', ns)
110
- assert_instance_of(XML::Attr, attr)
111
- assert_equal('rating', attr.name)
112
- assert_equal('rocks', attr.value)
113
-
114
- attributes = city_member.attributes
115
- assert_equal(6, attributes.length)
116
-
117
- assert_equal('rocks', city_member['rating'])
118
- end
119
-
120
- def test_remove
121
- attributes = city_member.attributes
122
- assert_equal(5, attributes.length)
123
-
124
- attribute = attributes.get_attribute('name')
125
- assert_not_nil(attribute.parent)
126
- assert(attribute.parent?)
127
-
128
- attribute.remove!
129
- assert_equal(4, attributes.length)
130
- assert_nil(attribute.parent)
131
- assert(!attribute.parent?)
132
- end
133
-
134
- def test_first
135
- attribute = city_member.attributes.first
136
- assert_instance_of(XML::Attr, attribute)
137
- assert_equal('name', attribute.name)
138
- assert_equal('Cambridge', attribute.value)
139
-
140
- attribute = attribute.next
141
- assert_instance_of(XML::Attr, attribute)
142
- assert_equal('type', attribute.name)
143
- assert_equal('simple', attribute.value)
144
-
145
- attribute = attribute.next
146
- assert_instance_of(XML::Attr, attribute)
147
- assert_equal('title', attribute.name)
148
- assert_equal('Trinity Lane', attribute.value)
149
-
150
- attribute = attribute.next
151
- assert_instance_of(XML::Attr, attribute)
152
- assert_equal('href', attribute.name)
153
- assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
154
-
155
- attribute = attribute.next
156
- assert_instance_of(XML::Attr, attribute)
157
- assert_equal('remoteSchema', attribute.name)
158
- assert_equal("city.xsd#xpointer(//complexType[@name='RoadType'])", attribute.value)
159
-
160
- attribute = attribute.next
161
- assert_nil(attribute)
162
- end
163
-
164
- def test_no_attributes
165
- element = @doc.find('/city:CityModel/city:type').first
166
-
167
- assert_not_nil(element.attributes)
168
- assert_equal(0, element.attributes.length)
169
- end
170
- end
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class AttrNodeTest < 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
+ <type>City</type>
17
+ <cityMember name="Cambridge"
18
+ xlink:type="simple"
19
+ xlink:title="Trinity Lane"
20
+ xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
21
+ gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
22
+ </CityModel>
23
+ EOS
24
+
25
+ @doc = xp.parse
26
+ end
27
+
28
+ def teardown
29
+ @doc = nil
30
+ end
31
+
32
+ def city_member
33
+ @doc.find('/city:CityModel/city:cityMember').first
34
+ end
35
+
36
+ def test_doc
37
+ assert_not_nil(@doc)
38
+ assert_equal(XML::Encoding::NONE, @doc.encoding)
39
+ end
40
+
41
+ def test_types
42
+ attribute = city_member.attributes.get_attribute('name')
43
+ assert_instance_of(XML::Attr, attribute)
44
+ assert_equal('attribute', attribute.node_type_name)
45
+ end
46
+
47
+ def test_name
48
+ attribute = city_member.attributes.get_attribute('name')
49
+ assert_equal('name', attribute.name)
50
+ assert_equal(Encoding::ASCII_8BIT, attribute.name.encoding) if defined?(Encoding)
51
+
52
+ attribute = city_member.attributes.get_attribute('href')
53
+ assert_equal('href', attribute.name)
54
+ assert_equal('xlink', attribute.ns.prefix)
55
+ assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
56
+
57
+ attribute = city_member.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
58
+ assert_equal('href', attribute.name)
59
+ assert_equal('xlink', attribute.ns.prefix)
60
+ assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
61
+ end
62
+
63
+ def test_value
64
+ attribute = city_member.attributes.get_attribute('name')
65
+ assert_equal('Cambridge', attribute.value)
66
+ assert_equal(Encoding::ASCII_8BIT, attribute.value.encoding) if defined?(Encoding)
67
+
68
+ attribute = city_member.attributes.get_attribute('href')
69
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
70
+ end
71
+
72
+ def test_set_value
73
+ attribute = city_member.attributes.get_attribute('name')
74
+ attribute.value = 'London'
75
+ assert_equal('London', attribute.value)
76
+ assert_equal(Encoding::ASCII_8BIT, attribute.value.encoding) if defined?(Encoding)
77
+
78
+ attribute = city_member.attributes.get_attribute('href')
79
+ attribute.value = 'http://i.have.changed'
80
+ assert_equal('http://i.have.changed', attribute.value)
81
+ assert_equal(Encoding::ASCII_8BIT, attribute.value.encoding) if defined?(Encoding)
82
+ end
83
+
84
+ def test_set_nil
85
+ attribute = city_member.attributes.get_attribute('name')
86
+ assert_raise(TypeError) do
87
+ attribute.value = nil
88
+ end
89
+ end
90
+
91
+ def test_create
92
+ attributes = city_member.attributes
93
+ assert_equal(5, attributes.length)
94
+
95
+ attr = XML::Attr.new(city_member, 'size', '50,000')
96
+ assert_instance_of(XML::Attr, attr)
97
+
98
+ attributes = city_member.attributes
99
+ assert_equal(6, attributes.length)
100
+
101
+ assert_equal(attributes['size'], '50,000')
102
+ end
103
+
104
+ def test_create_on_node
105
+ attributes = city_member.attributes
106
+ assert_equal(5, attributes.length)
107
+
108
+ attributes['country'] = 'England'
109
+
110
+ attributes = city_member.attributes
111
+ assert_equal(6, attributes.length)
112
+
113
+ assert_equal(attributes['country'], 'England')
114
+ end
115
+
116
+ def test_create_ns
117
+ assert_equal(5, city_member.attributes.length)
118
+
119
+ ns = XML::Namespace.new(city_member, 'my_namepace', 'http://www.mynamespace.com')
120
+ attr = XML::Attr.new(city_member, 'rating', 'rocks', ns)
121
+ assert_instance_of(XML::Attr, attr)
122
+ assert_equal('rating', attr.name)
123
+ assert_equal('rocks', attr.value)
124
+
125
+ attributes = city_member.attributes
126
+ assert_equal(6, attributes.length)
127
+
128
+ assert_equal('rocks', city_member['rating'])
129
+ end
130
+
131
+ def test_remove
132
+ attributes = city_member.attributes
133
+ assert_equal(5, attributes.length)
134
+
135
+ attribute = attributes.get_attribute('name')
136
+ assert_not_nil(attribute.parent)
137
+ assert(attribute.parent?)
138
+
139
+ attribute.remove!
140
+ assert_equal(4, attributes.length)
141
+ assert_nil(attribute.parent)
142
+ assert(!attribute.parent?)
143
+ end
144
+
145
+ def test_first
146
+ attribute = city_member.attributes.first
147
+ assert_instance_of(XML::Attr, attribute)
148
+ assert_equal('name', attribute.name)
149
+ assert_equal('Cambridge', attribute.value)
150
+
151
+ attribute = attribute.next
152
+ assert_instance_of(XML::Attr, attribute)
153
+ assert_equal('type', attribute.name)
154
+ assert_equal('simple', attribute.value)
155
+
156
+ attribute = attribute.next
157
+ assert_instance_of(XML::Attr, attribute)
158
+ assert_equal('title', attribute.name)
159
+ assert_equal('Trinity Lane', attribute.value)
160
+
161
+ attribute = attribute.next
162
+ assert_instance_of(XML::Attr, attribute)
163
+ assert_equal('href', attribute.name)
164
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
165
+
166
+ attribute = attribute.next
167
+ assert_instance_of(XML::Attr, attribute)
168
+ assert_equal('remoteSchema', attribute.name)
169
+ assert_equal("city.xsd#xpointer(//complexType[@name='RoadType'])", attribute.value)
170
+
171
+ attribute = attribute.next
172
+ assert_nil(attribute)
173
+ end
174
+
175
+ def test_no_attributes
176
+ element = @doc.find('/city:CityModel/city:type').first
177
+
178
+ assert_not_nil(element.attributes)
179
+ assert_equal(0, element.attributes.length)
180
+ end
181
+ end