libxml-ruby 2.8.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +15 -0
  3. data/README.rdoc +7 -7
  4. data/Rakefile +80 -78
  5. data/ext/libxml/extconf.h +4 -0
  6. data/ext/libxml/extconf.rb +57 -116
  7. data/ext/libxml/libxml.c +4 -0
  8. data/ext/libxml/ruby_xml.c +977 -893
  9. data/ext/libxml/ruby_xml.h +20 -10
  10. data/ext/libxml/ruby_xml_attr.c +333 -333
  11. data/ext/libxml/ruby_xml_attr_decl.c +2 -2
  12. data/ext/libxml/ruby_xml_cbg.c +85 -85
  13. data/ext/libxml/ruby_xml_document.c +1133 -1147
  14. data/ext/libxml/ruby_xml_dtd.c +261 -268
  15. data/ext/libxml/ruby_xml_encoding.c +262 -260
  16. data/ext/libxml/ruby_xml_encoding.h +19 -19
  17. data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
  18. data/ext/libxml/ruby_xml_input_cbg.c +191 -191
  19. data/ext/libxml/ruby_xml_io.c +52 -50
  20. data/ext/libxml/ruby_xml_namespace.c +2 -2
  21. data/ext/libxml/ruby_xml_node.c +1446 -1452
  22. data/ext/libxml/ruby_xml_parser_context.c +999 -1001
  23. data/ext/libxml/ruby_xml_reader.c +1226 -1228
  24. data/ext/libxml/ruby_xml_relaxng.c +110 -111
  25. data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
  26. data/ext/libxml/ruby_xml_schema.c +300 -301
  27. data/ext/libxml/ruby_xml_version.h +3 -3
  28. data/ext/libxml/ruby_xml_writer.c +14 -15
  29. data/ext/libxml/ruby_xml_xpath.c +188 -188
  30. data/ext/libxml/ruby_xml_xpath_context.c +360 -361
  31. data/ext/libxml/ruby_xml_xpath_object.c +335 -335
  32. data/libxml-ruby.gemspec +47 -44
  33. data/test/tc_attr.rb +5 -7
  34. data/test/tc_attr_decl.rb +5 -6
  35. data/test/tc_attributes.rb +1 -2
  36. data/test/tc_canonicalize.rb +1 -2
  37. data/test/tc_deprecated_require.rb +1 -2
  38. data/test/tc_document.rb +4 -5
  39. data/test/tc_document_write.rb +2 -3
  40. data/test/tc_dtd.rb +4 -5
  41. data/test/tc_encoding.rb +126 -126
  42. data/test/tc_encoding_sax.rb +4 -3
  43. data/test/tc_error.rb +14 -15
  44. data/test/tc_html_parser.rb +15 -7
  45. data/test/tc_html_parser_context.rb +1 -2
  46. data/test/tc_namespace.rb +2 -3
  47. data/test/tc_namespaces.rb +5 -6
  48. data/test/tc_node.rb +2 -3
  49. data/test/tc_node_cdata.rb +2 -3
  50. data/test/tc_node_comment.rb +1 -2
  51. data/test/tc_node_copy.rb +1 -2
  52. data/test/tc_node_edit.rb +5 -7
  53. data/test/tc_node_pi.rb +1 -2
  54. data/test/tc_node_text.rb +2 -3
  55. data/test/tc_node_write.rb +2 -3
  56. data/test/tc_node_xlink.rb +1 -2
  57. data/test/tc_parser.rb +18 -24
  58. data/test/tc_parser_context.rb +6 -7
  59. data/test/tc_properties.rb +1 -2
  60. data/test/tc_reader.rb +9 -10
  61. data/test/tc_relaxng.rb +4 -5
  62. data/test/tc_sax_parser.rb +9 -10
  63. data/test/tc_schema.rb +4 -5
  64. data/test/tc_traversal.rb +1 -2
  65. data/test/tc_writer.rb +1 -2
  66. data/test/tc_xinclude.rb +1 -2
  67. data/test/tc_xml.rb +1 -2
  68. data/test/tc_xpath.rb +8 -9
  69. data/test/tc_xpath_context.rb +3 -4
  70. data/test/tc_xpath_expression.rb +3 -4
  71. data/test/tc_xpointer.rb +1 -3
  72. data/test/test_helper.rb +3 -1
  73. data/test/test_suite.rb +0 -1
  74. metadata +47 -11
  75. data/test/etc_doc_to_s.rb +0 -21
  76. data/test/ets_doc_file.rb +0 -17
  77. data/test/ets_doc_to_s.rb +0 -23
  78. data/test/ets_gpx.rb +0 -28
  79. data/test/ets_node_gc.rb +0 -23
  80. data/test/ets_test.xml +0 -2
  81. data/test/ets_tsr.rb +0 -11
@@ -1,44 +1,47 @@
1
- # encoding: utf-8
2
-
3
- # Determine the current version of the software
4
- version = File.read('ext/libxml/ruby_xml_version.h').match(/\s*RUBY_LIBXML_VERSION\s*['"](\d.+)['"]/)[1]
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'libxml-ruby'
8
- spec.version = version
9
- spec.homepage = 'http://xml4r.github.com/libxml-ruby'
10
- spec.summary = 'Ruby Bindings for LibXML2'
11
- spec.description = <<-EOS
12
- The Libxml-Ruby project provides Ruby language bindings for the GNOME
13
- Libxml2 XML toolkit. It is free software, released under the MIT License.
14
- Libxml-ruby's primary advantage over REXML is performance - if speed
15
- is your need, these are good libraries to consider, as demonstrated
16
- by the informal benchmark below.
17
- EOS
18
- spec.authors = ['Ross Bamform', 'Wai-Sun Chia', 'Sean Chittenden',
19
- 'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage',
20
- 'Ryan Johnson']
21
- spec.platform = Gem::Platform::RUBY
22
- spec.bindir = "bin"
23
- spec.extensions = ["ext/libxml/extconf.rb"]
24
- spec.files = Dir.glob(['HISTORY',
25
- 'LICENSE',
26
- 'libxml-ruby.gemspec',
27
- 'MANIFEST',
28
- 'Rakefile',
29
- 'README.rdoc',
30
- 'setup.rb',
31
- 'ext/libxml/*.def',
32
- 'ext/libxml/*.h',
33
- 'ext/libxml/*.c',
34
- 'ext/libxml/*.rb',
35
- 'ext/vc/*.sln',
36
- 'ext/vc/*.vcprojx',
37
- 'lib/**/*.rb',
38
- 'script/**/*',
39
- 'test/**/*'])
40
- spec.test_files = Dir.glob("test/tc_*.rb")
41
- spec.required_ruby_version = '>= 1.8.6'
42
- spec.date = DateTime.now
43
- spec.license = 'MIT'
44
- end
1
+ # encoding: utf-8
2
+
3
+ # Determine the current version of the software
4
+ version = File.read('ext/libxml/ruby_xml_version.h').match(/\s*RUBY_LIBXML_VERSION\s*['"](\d.+)['"]/)[1]
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'libxml-ruby'
8
+ spec.version = version
9
+ spec.homepage = 'http://xml4r.github.com/libxml-ruby'
10
+ spec.summary = 'Ruby Bindings for LibXML2'
11
+ spec.description = <<-EOS
12
+ The Libxml-Ruby project provides Ruby language bindings for the GNOME
13
+ Libxml2 XML toolkit. It is free software, released under the MIT License.
14
+ Libxml-ruby's primary advantage over REXML is performance - if speed
15
+ is your need, these are good libraries to consider, as demonstrated
16
+ by the informal benchmark below.
17
+ EOS
18
+ spec.authors = ['Ross Bamform', 'Wai-Sun Chia', 'Sean Chittenden',
19
+ 'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage',
20
+ 'Ryan Johnson']
21
+ spec.platform = Gem::Platform::RUBY
22
+ spec.bindir = 'bin'
23
+ spec.extensions = ['ext/libxml/extconf.rb']
24
+ spec.files = Dir.glob(['HISTORY',
25
+ 'LICENSE',
26
+ 'libxml-ruby.gemspec',
27
+ 'MANIFEST',
28
+ 'Rakefile',
29
+ 'README.rdoc',
30
+ 'setup.rb',
31
+ 'ext/libxml/*.def',
32
+ 'ext/libxml/*.h',
33
+ 'ext/libxml/*.c',
34
+ 'ext/libxml/*.rb',
35
+ 'ext/vc/*.sln',
36
+ 'ext/vc/*.vcprojx',
37
+ 'lib/**/*.rb',
38
+ 'script/**/*',
39
+ 'test/**/*'])
40
+ spec.test_files = Dir.glob('test/tc_*.rb')
41
+ spec.required_ruby_version = '>= 1.8.6'
42
+ spec.date = DateTime.now
43
+ spec.add_development_dependency('hanna_guado')
44
+ spec.add_development_dependency('rake-compiler')
45
+ spec.add_development_dependency('minitest')
46
+ spec.license = 'MIT'
47
+ end
@@ -1,9 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require './test_helper'
4
- require 'test/unit'
5
4
 
6
- class AttrNodeTest < Test::Unit::TestCase
5
+ class AttrNodeTest < Minitest::Test
7
6
  def setup
8
7
  xp = XML::Parser.string(<<-EOS)
9
8
  <CityModel
@@ -27,7 +26,6 @@ class AttrNodeTest < Test::Unit::TestCase
27
26
 
28
27
  def teardown
29
28
  @doc = nil
30
- GC.start
31
29
  end
32
30
 
33
31
  def city_member
@@ -35,7 +33,7 @@ class AttrNodeTest < Test::Unit::TestCase
35
33
  end
36
34
 
37
35
  def test_doc
38
- assert_not_nil(@doc)
36
+ refute_nil(@doc)
39
37
  assert_equal(XML::Encoding::NONE, @doc.encoding)
40
38
  end
41
39
 
@@ -84,7 +82,7 @@ class AttrNodeTest < Test::Unit::TestCase
84
82
 
85
83
  def test_set_nil
86
84
  attribute = city_member.attributes.get_attribute('name')
87
- assert_raise(TypeError) do
85
+ assert_raises(TypeError) do
88
86
  attribute.value = nil
89
87
  end
90
88
  end
@@ -134,7 +132,7 @@ class AttrNodeTest < Test::Unit::TestCase
134
132
  assert_equal(5, attributes.length)
135
133
 
136
134
  attribute = attributes.get_attribute('name')
137
- assert_not_nil(attribute.parent)
135
+ refute_nil(attribute.parent)
138
136
  assert(attribute.parent?)
139
137
 
140
138
  attribute.remove!
@@ -177,7 +175,7 @@ class AttrNodeTest < Test::Unit::TestCase
177
175
  def test_no_attributes
178
176
  element = @doc.find('/city:CityModel/city:type').first
179
177
 
180
- assert_not_nil(element.attributes)
178
+ refute_nil(element.attributes)
181
179
  assert_equal(0, element.attributes.length)
182
180
  end
183
181
  end
@@ -1,9 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require './test_helper'
4
- require 'test/unit'
5
4
 
6
- class AttrDeclTest < Test::Unit::TestCase
5
+ class AttrDeclTest < Minitest::Test
7
6
  def setup
8
7
  xp = XML::Parser.string(<<-EOS)
9
8
  <!DOCTYPE test [
@@ -28,7 +27,7 @@ class AttrDeclTest < Test::Unit::TestCase
28
27
  # Get a element with an access attribute
29
28
  elem = @doc.find_first('/root/property[@name="readonly"]')
30
29
  assert_equal(2, elem.attributes.length)
31
- assert_not_nil(elem['access'])
30
+ refute_nil(elem['access'])
32
31
 
33
32
  # Get a element node without a access attribute
34
33
  elem = @doc.find_first('/root/property[@name="readwrite"]')
@@ -42,7 +41,7 @@ class AttrDeclTest < Test::Unit::TestCase
42
41
 
43
42
  # Get the attr_decl
44
43
  attr = elem.attributes.get_attribute('access')
45
- assert_not_nil(attr)
44
+ refute_nil(attr)
46
45
  assert_equal(XML::Node::ATTRIBUTE_NODE, attr.node_type)
47
46
  assert_equal('attribute', attr.node_type_name)
48
47
 
@@ -56,7 +55,7 @@ class AttrDeclTest < Test::Unit::TestCase
56
55
 
57
56
  # Get the attr_decl
58
57
  attr_decl = elem.attributes.get_attribute('access')
59
- assert_not_nil(attr_decl)
58
+ refute_nil(attr_decl)
60
59
  assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
61
60
  assert_equal('attribute declaration', attr_decl.node_type_name)
62
61
 
@@ -69,7 +68,7 @@ class AttrDeclTest < Test::Unit::TestCase
69
68
  elem = @doc.find_first('/root/property[@name="readwrite"]')
70
69
  attr_decl = elem.attributes.get_attribute('access')
71
70
 
72
- assert_not_nil(attr_decl)
71
+ refute_nil(attr_decl)
73
72
  assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
74
73
  assert_equal('attribute declaration', attr_decl.node_type_name)
75
74
  end
@@ -1,9 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require './test_helper'
4
- require 'test/unit'
5
4
 
6
- class AttributesTest < Test::Unit::TestCase
5
+ class AttributesTest < Minitest::Test
7
6
  def setup
8
7
  xp = XML::Parser.string(<<-EOS)
9
8
  <CityModel name="value"
@@ -1,8 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require './test_helper'
3
- require 'test/unit'
4
3
 
5
- class TestCanonicalize < Test::Unit::TestCase
4
+ class TestCanonicalize < Minitest::Test
6
5
  # (www.w3.org) 3.1 PIs, Comments, and Outside of Document Element
7
6
  # http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
8
7
  def test_canonicalize_with_w3c_c14n_3_1
@@ -1,9 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'xml/libxml'
4
- require 'test/unit'
5
4
 
6
- class TestDeprecatedRequire < Test::Unit::TestCase
5
+ class TestDeprecatedRequire < Minitest::Test
7
6
  def test_basic
8
7
  xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
9
8
  assert_instance_of(XML::Parser, xp)
@@ -1,8 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require './test_helper'
3
- require 'test/unit'
4
3
 
5
- class TestDocument < Test::Unit::TestCase
4
+ class TestDocument < Minitest::Test
6
5
  def setup
7
6
  xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
8
7
  assert_instance_of(XML::Parser, xp)
@@ -26,7 +25,7 @@ class TestDocument < Test::Unit::TestCase
26
25
  def test_find
27
26
  set = @doc.find('/ruby_array/fixnum')
28
27
  assert_instance_of(XML::XPath::Object, set)
29
- assert_raise(NoMethodError) {
28
+ assert_raises(NoMethodError) {
30
29
  xpt = set.xpath
31
30
  }
32
31
  end
@@ -91,7 +90,7 @@ class TestDocument < Test::Unit::TestCase
91
90
  doc1 = LibXML::XML::Document.string("<one/>")
92
91
  doc2 = LibXML::XML::Document.string("<two/>")
93
92
 
94
- error = assert_raise(XML::Error) do
93
+ error = assert_raises(XML::Error) do
95
94
  doc1.root = doc2.root
96
95
  end
97
96
  assert_equal(" Nodes belong to different documents. You must first import the node by calling XML::Document.import.",
@@ -111,7 +110,7 @@ class TestDocument < Test::Unit::TestCase
111
110
 
112
111
  node = doc1.root.child
113
112
 
114
- error = assert_raise(XML::Error) do
113
+ error = assert_raises(XML::Error) do
115
114
  doc2.root << node
116
115
  end
117
116
 
@@ -2,9 +2,8 @@
2
2
 
3
3
  require './test_helper'
4
4
  require 'tmpdir'
5
- require 'test/unit'
6
5
 
7
- class TestDocumentWrite < Test::Unit::TestCase
6
+ class TestDocumentWrite < Minitest::Test
8
7
  def setup
9
8
  @file_name = "model/bands.utf-8.xml"
10
9
 
@@ -91,7 +90,7 @@ class TestDocumentWrite < Test::Unit::TestCase
91
90
  end
92
91
 
93
92
  # Invalid encoding
94
- error = assert_raise(ArgumentError) do
93
+ error = assert_raises(ArgumentError) do
95
94
  @doc.to_s(:encoding => -9999)
96
95
  end
97
96
  assert_equal('Unknown encoding value: -9999', error.to_s)
@@ -2,9 +2,8 @@
2
2
 
3
3
  require './test_helper'
4
4
 
5
- require 'test/unit'
6
5
 
7
- class TestDtd < Test::Unit::TestCase
6
+ class TestDtd < Minitest::Test
8
7
  def setup
9
8
  xp = XML::Parser.string(<<-EOS)
10
9
  <root>
@@ -71,12 +70,12 @@ class TestDtd < Test::Unit::TestCase
71
70
  new_node = XML::Node.new('invalid', 'this will mess up validation')
72
71
  @doc.root << new_node
73
72
 
74
- error = assert_raise(XML::Error) do
73
+ error = assert_raises(XML::Error) do
75
74
  @doc.validate(dtd)
76
75
  end
77
76
 
78
77
  # Check the error worked
79
- assert_not_nil(error)
78
+ refute_nil(error)
80
79
  assert_kind_of(XML::Error, error)
81
80
  assert_equal("Error: No declaration for element invalid.", error.message)
82
81
  assert_equal(XML::Error::VALID, error.domain)
@@ -89,7 +88,7 @@ class TestDtd < Test::Unit::TestCase
89
88
  assert_nil(error.str3)
90
89
  assert_equal(0, error.int1)
91
90
  assert_equal(0, error.int2)
92
- assert_not_nil(error.node)
91
+ refute_nil(error.node)
93
92
  assert_equal('invalid', error.node.name)
94
93
  end
95
94
 
@@ -1,126 +1,126 @@
1
- # encoding: UTF-8
2
-
3
- require './test_helper'
4
- require 'test/unit'
5
-
6
- # Code UTF8 Latin1 Hex
7
- # m 109 109 6D
8
- # ö 195 182 246 C3 B6 / F6
9
- # t 116 116 74
10
- # l 108 108 6C
11
- # e 101 101 65
12
- # y 121 121 79
13
- # _ 95 95 5F
14
- # c 99 99 63
15
- # r 114 114 72
16
- # ü 195 188 252 C3 BC / FC
17
- # e 101 101 65
18
-
19
- # See:
20
- # http://en.wikipedia.org/wiki/ISO/IEC_8859-1
21
- # http://en.wikipedia.org/wiki/List_of_Unicode_characters
22
-
23
- class TestEncoding < Test::Unit::TestCase
24
- def setup
25
- Encoding.default_internal = nil
26
- end
27
-
28
- def file_for_encoding(encoding)
29
- file_name = "model/bands.#{encoding.name.downcase}.xml"
30
- File.join(File.dirname(__FILE__), file_name)
31
- end
32
-
33
- def load_encoding(encoding)
34
- @encoding = encoding
35
- file = file_for_encoding(encoding)
36
-
37
- # Strip spaces to make testing easier
38
- XML.default_keep_blanks = false
39
- @doc = XML::Document.file(file)
40
- end
41
-
42
- def test_encoding
43
- doc = XML::Document.new
44
- assert_equal(XML::Encoding::NONE, doc.encoding)
45
- assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) if defined?(Encoding)
46
-
47
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
48
- doc = XML::Document.file(file)
49
- assert_equal(XML::Encoding::UTF_8, doc.encoding)
50
- assert_equal(Encoding::UTF_8, doc.rb_encoding) if defined?(Encoding)
51
-
52
- doc.encoding = XML::Encoding::ISO_8859_1
53
- assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
54
- assert_equal(Encoding::ISO8859_1, doc.rb_encoding) if defined?(Encoding)
55
- end
56
-
57
- def test_no_internal_encoding_iso_8859_1
58
- Encoding.default_internal = nil
59
- load_encoding(Encoding::ISO_8859_1)
60
- node = @doc.root.children.first
61
-
62
- name = node.name
63
- assert_equal(Encoding::UTF_8, name.encoding)
64
- assert_equal("m\u00F6tley_cr\u00FCe", name)
65
- assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101",
66
- name.bytes.to_a.join(" "))
67
- assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.",
68
- node.content)
69
-
70
- name = name.encode(Encoding::ISO_8859_1)
71
- assert_equal(Encoding::ISO_8859_1, name.encoding)
72
- assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name)
73
- assert_equal("109 246 116 108 101 121 95 99 114 252 101",
74
- name.bytes.to_a.join(" "))
75
- assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1),
76
- node.content.encode(Encoding::ISO_8859_1))
77
- end
78
-
79
- def test_internal_encoding_iso_8859_1
80
- Encoding.default_internal = Encoding::ISO_8859_1
81
- load_encoding(Encoding::ISO_8859_1)
82
- node = @doc.root.children.first
83
-
84
- name = node.name
85
- assert_equal(Encoding::ISO_8859_1, name.encoding)
86
- assert_equal("109 246 116 108 101 121 95 99 114 252 101",
87
- name.bytes.to_a.join(" "))
88
- assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name)
89
- assert_equal("109 246 116 108 101 121 95 99 114 252 101",
90
- name.bytes.to_a.join(" "))
91
- assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1),
92
- node.content.encode(Encoding::ISO_8859_1))
93
- end
94
-
95
- def test_no_internal_encoding_utf_8
96
- Encoding.default_internal = nil
97
- load_encoding(Encoding::UTF_8)
98
- node = @doc.root.children.first
99
-
100
- name = node.name
101
- assert_equal(@encoding, name.encoding)
102
- assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101",
103
- name.bytes.to_a.join(" "))
104
-
105
- name = name.encode(Encoding::ISO_8859_1)
106
- assert_equal(Encoding::ISO_8859_1, name.encoding)
107
- assert_equal("109 246 116 108 101 121 95 99 114 252 101",
108
- name.bytes.to_a.join(" "))
109
- end
110
-
111
- def test_internal_encoding_utf_8
112
- Encoding.default_internal = Encoding::ISO_8859_1
113
- load_encoding(Encoding::UTF_8)
114
- node = @doc.root.children.first
115
-
116
- name = node.name
117
- assert_equal(Encoding::ISO_8859_1, name.encoding)
118
- assert_equal("109 246 116 108 101 121 95 99 114 252 101",
119
- name.bytes.to_a.join(" "))
120
- end
121
-
122
- def test_encoding_conversions
123
- assert_equal("UTF-8", XML::Encoding.to_s(XML::Encoding::UTF_8))
124
- assert_equal(XML::Encoding::UTF_8, XML::Encoding.from_s("UTF-8"))
125
- end
126
- end
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ # Code UTF8 Latin1 Hex
6
+ # m 109 109 6D
7
+ # ö 195 182 246 C3 B6 / F6
8
+ # t 116 116 74
9
+ # l 108 108 6C
10
+ # e 101 101 65
11
+ # y 121 121 79
12
+ # _ 95 95 5F
13
+ # c 99 99 63
14
+ # r 114 114 72
15
+ # ü 195 188 252 C3 BC / FC
16
+ # e 101 101 65
17
+
18
+ # See:
19
+ # http://en.wikipedia.org/wiki/ISO/IEC_8859-1
20
+ # http://en.wikipedia.org/wiki/List_of_Unicode_characters
21
+
22
+ class TestEncoding < Minitest::Test
23
+ def setup
24
+ Encoding.default_internal = nil
25
+ end
26
+
27
+ def file_for_encoding(encoding)
28
+ file_name = "model/bands.#{encoding.name.downcase}.xml"
29
+ File.join(File.dirname(__FILE__), file_name)
30
+ end
31
+
32
+ def load_encoding(encoding)
33
+ @encoding = encoding
34
+ file = file_for_encoding(encoding)
35
+
36
+ # Strip spaces to make testing easier
37
+ XML.default_keep_blanks = false
38
+ @doc = XML::Document.file(file)
39
+ XML.default_keep_blanks = true
40
+ end
41
+
42
+ def test_encoding
43
+ doc = XML::Document.new
44
+ assert_equal(XML::Encoding::NONE, doc.encoding)
45
+ assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) if defined?(Encoding)
46
+
47
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
48
+ doc = XML::Document.file(file)
49
+ assert_equal(XML::Encoding::UTF_8, doc.encoding)
50
+ assert_equal(Encoding::UTF_8, doc.rb_encoding) if defined?(Encoding)
51
+
52
+ doc.encoding = XML::Encoding::ISO_8859_1
53
+ assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
54
+ assert_equal(Encoding::ISO8859_1, doc.rb_encoding) if defined?(Encoding)
55
+ end
56
+
57
+ def test_no_internal_encoding_iso_8859_1
58
+ Encoding.default_internal = nil
59
+ load_encoding(Encoding::ISO_8859_1)
60
+ node = @doc.root.children.first
61
+
62
+ name = node.name
63
+ assert_equal(Encoding::UTF_8, name.encoding)
64
+ assert_equal("m\u00F6tley_cr\u00FCe", name)
65
+ assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101",
66
+ name.bytes.to_a.join(" "))
67
+ assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.",
68
+ node.content)
69
+
70
+ name = name.encode(Encoding::ISO_8859_1)
71
+ assert_equal(Encoding::ISO_8859_1, name.encoding)
72
+ assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name)
73
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
74
+ name.bytes.to_a.join(" "))
75
+ assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1),
76
+ node.content.encode(Encoding::ISO_8859_1))
77
+ end
78
+
79
+ def test_internal_encoding_iso_8859_1
80
+ Encoding.default_internal = Encoding::ISO_8859_1
81
+ load_encoding(Encoding::ISO_8859_1)
82
+ node = @doc.root.children.first
83
+
84
+ name = node.name
85
+ assert_equal(Encoding::ISO_8859_1, name.encoding)
86
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
87
+ name.bytes.to_a.join(" "))
88
+ assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name)
89
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
90
+ name.bytes.to_a.join(" "))
91
+ assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1),
92
+ node.content.encode(Encoding::ISO_8859_1))
93
+ end
94
+
95
+ def test_no_internal_encoding_utf_8
96
+ Encoding.default_internal = nil
97
+ load_encoding(Encoding::UTF_8)
98
+ node = @doc.root.children.first
99
+
100
+ name = node.name
101
+ assert_equal(@encoding, name.encoding)
102
+ assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101",
103
+ name.bytes.to_a.join(" "))
104
+
105
+ name = name.encode(Encoding::ISO_8859_1)
106
+ assert_equal(Encoding::ISO_8859_1, name.encoding)
107
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
108
+ name.bytes.to_a.join(" "))
109
+ end
110
+
111
+ def test_internal_encoding_utf_8
112
+ Encoding.default_internal = Encoding::ISO_8859_1
113
+ load_encoding(Encoding::UTF_8)
114
+ node = @doc.root.children.first
115
+
116
+ name = node.name
117
+ assert_equal(Encoding::ISO_8859_1, name.encoding)
118
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
119
+ name.bytes.to_a.join(" "))
120
+ end
121
+
122
+ def test_encoding_conversions
123
+ assert_equal("UTF-8", XML::Encoding.to_s(XML::Encoding::UTF_8))
124
+ assert_equal(XML::Encoding::UTF_8, XML::Encoding.from_s("UTF-8"))
125
+ end
126
+ end