libxml-ruby 1.1.3-x86-mswin32-60 → 1.1.4-x86-mswin32-60

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 (96) hide show
  1. data/CHANGES +1 -1
  2. data/LICENSE +22 -22
  3. data/README +160 -160
  4. data/Rakefile +0 -9
  5. data/ext/libxml/Makefile +156 -0
  6. data/ext/libxml/extconf.h +5 -0
  7. data/ext/libxml/extconf.rb +4 -160
  8. data/ext/libxml/libxml-ruby.so.a +0 -0
  9. data/ext/libxml/libxml.o +0 -0
  10. data/ext/libxml/libxml_ruby.so +0 -0
  11. data/ext/libxml/mkmf.log +129 -0
  12. data/ext/libxml/ruby_xml.o +0 -0
  13. data/ext/libxml/ruby_xml_attr.c +1 -1
  14. data/ext/libxml/ruby_xml_attr.h +1 -1
  15. data/ext/libxml/ruby_xml_attr.o +0 -0
  16. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  17. data/ext/libxml/ruby_xml_attributes.o +0 -0
  18. data/ext/libxml/ruby_xml_cbg.o +0 -0
  19. data/ext/libxml/ruby_xml_document.c +936 -936
  20. data/ext/libxml/ruby_xml_document.h +1 -1
  21. data/ext/libxml/ruby_xml_document.o +0 -0
  22. data/ext/libxml/ruby_xml_dtd.o +0 -0
  23. data/ext/libxml/ruby_xml_encoding.o +0 -0
  24. data/ext/libxml/ruby_xml_error.o +0 -0
  25. data/ext/libxml/ruby_xml_html_parser.c +1 -1
  26. data/ext/libxml/ruby_xml_html_parser.h +1 -1
  27. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  28. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  29. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  30. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  31. data/ext/libxml/ruby_xml_io.o +0 -0
  32. data/ext/libxml/ruby_xml_namespace.c +1 -1
  33. data/ext/libxml/ruby_xml_namespace.h +1 -1
  34. data/ext/libxml/ruby_xml_namespace.o +0 -0
  35. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  36. data/ext/libxml/ruby_xml_node.c +1386 -1386
  37. data/ext/libxml/ruby_xml_node.h +1 -1
  38. data/ext/libxml/ruby_xml_node.o +0 -0
  39. data/ext/libxml/ruby_xml_parser.c +1 -1
  40. data/ext/libxml/ruby_xml_parser.h +1 -1
  41. data/ext/libxml/ruby_xml_parser.o +0 -0
  42. data/ext/libxml/ruby_xml_parser_context.c +1 -1
  43. data/ext/libxml/ruby_xml_parser_context.h +1 -1
  44. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  45. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  46. data/ext/libxml/ruby_xml_reader.o +0 -0
  47. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  48. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  49. data/ext/libxml/ruby_xml_sax_parser.c +1 -1
  50. data/ext/libxml/ruby_xml_sax_parser.h +1 -1
  51. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  52. data/ext/libxml/ruby_xml_schema.o +0 -0
  53. data/ext/libxml/ruby_xml_version.h +3 -3
  54. data/ext/libxml/ruby_xml_xinclude.c +1 -1
  55. data/ext/libxml/ruby_xml_xinclude.h +1 -1
  56. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  57. data/ext/libxml/ruby_xml_xpath.c +1 -1
  58. data/ext/libxml/ruby_xml_xpath.h +1 -1
  59. data/ext/libxml/ruby_xml_xpath.o +0 -0
  60. data/ext/libxml/ruby_xml_xpath_context.c +1 -1
  61. data/ext/libxml/ruby_xml_xpath_context.h +1 -1
  62. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  63. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  64. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  65. data/ext/libxml/ruby_xml_xpointer.c +1 -1
  66. data/ext/libxml/ruby_xml_xpointer.h +1 -1
  67. data/ext/libxml/ruby_xml_xpointer.o +0 -0
  68. data/ext/mingw/build.rake +3 -3
  69. data/ext/mingw/libiconv-2.dll +0 -0
  70. data/ext/mingw/libxml2-2.dll +0 -0
  71. data/ext/mingw/libxml_ruby.dll.a +0 -0
  72. data/ext/mingw/libxml_ruby.so +0 -0
  73. data/lib/libxml.rb +29 -29
  74. data/test/model/merge_bug_data.xml +58 -58
  75. data/test/model/rubynet.xml +79 -79
  76. data/test/model/xinclude.xml +4 -4
  77. data/test/tc_attr.rb +170 -170
  78. data/test/tc_document.rb +113 -113
  79. data/test/tc_document_write.rb +117 -117
  80. data/test/tc_dtd.rb +123 -123
  81. data/test/tc_html_parser.rb +137 -137
  82. data/test/tc_node.rb +180 -180
  83. data/test/tc_node_cdata.rb +49 -49
  84. data/test/tc_node_comment.rb +30 -30
  85. data/test/tc_node_edit.rb +157 -157
  86. data/test/tc_node_xlink.rb +26 -26
  87. data/test/tc_parser.rb +329 -329
  88. data/test/tc_parser_context.rb +185 -185
  89. data/test/tc_reader.rb +283 -283
  90. data/test/tc_sax_parser.rb +273 -273
  91. data/test/tc_schema.rb +51 -51
  92. data/test/tc_xinclude.rb +19 -19
  93. data/test/tc_xpath.rb +193 -193
  94. data/test/tc_xpointer.rb +72 -72
  95. metadata +55 -14
  96. data/ext/libxml/build.log +0 -4
@@ -1,118 +1,118 @@
1
- require 'xml'
2
- require 'tmpdir'
3
- require 'test/unit'
4
-
5
- class TestDocumentWrite < Test::Unit::TestCase
6
- def setup
7
- # Strip spaces to make testing easier
8
- XML.default_keep_blanks = false
9
- file = File.join(File.dirname(__FILE__), 'model/bands.xml')
10
- @doc = XML::Document.file(file)
11
- end
12
-
13
- def teardown
14
- XML.default_keep_blanks = true
15
- @doc = nil
16
- end
17
-
18
- # --- to_s tests ---
19
- def test_to_s_default
20
- # Default to_s has indentation
21
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
22
- @doc.to_s)
23
- end
24
-
25
- def test_to_s_no_global_indentation
26
- # No indentation due to global setting
27
- XML.indent_tree_output = false
28
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
29
- @doc.to_s)
30
- ensure
31
- XML.indent_tree_output = true
32
- end
33
-
34
- def test_to_s_no_indentation
35
- # No indentation due to local setting
36
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>\n",
37
- @doc.to_s(:indent => false))
38
- end
39
-
40
- def test_to_s_encoding
41
- # Test encodings
42
-
43
- # UTF8:
44
- # ö - c3 b6 in hex, \303\266 in octal
45
- # ü - c3 bc in hex, \303\274 in octal
46
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
47
- @doc.to_s(:encoding => XML::Encoding::UTF_8))
48
-
49
- # ISO_8859_1:
50
- # ö - f6 in hex, \366 in octal
51
- # ü - fc in hex, \374 in octal
52
- assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
53
- @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
54
-
55
-
56
- # Invalid encoding
57
- error = assert_raise(ArgumentError) do
58
- @doc.to_s(:encoding => -9999)
59
- end
60
- assert_equal('Unknown encoding value: -9999', error.to_s)
61
- end
62
-
63
- # --- save tests -----
64
- def test_save_utf8
65
- temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8.xml")
66
-
67
- bytes = @doc.save(temp_filename)
68
- assert_equal(271, bytes)
69
-
70
- contents = File.read(temp_filename)
71
- assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
72
- contents)
73
- ensure
74
- File.delete(temp_filename)
75
- end
76
-
77
- def test_save_utf8_no_indents
78
- temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8_no_indents.xml")
79
-
80
- bytes = @doc.save(temp_filename, :indent => false)
81
- assert_equal(264, bytes)
82
-
83
- contents = File.read(temp_filename)
84
- assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>\n",
85
- contents)
86
- ensure
87
- File.delete(temp_filename)
88
- end
89
-
90
- def test_save_iso_8859_1
91
- temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml")
92
- bytes = @doc.save(temp_filename, :encoding => XML::Encoding::ISO_8859_1)
93
- assert_equal(272, bytes)
94
-
95
- contents = File.read(temp_filename)
96
- assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
97
- contents)
98
- ensure
99
- File.delete(temp_filename)
100
- end
101
-
102
- def test_save_iso_8859_1_no_indent
103
- temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml")
104
- bytes = @doc.save(temp_filename, :indent => false, :encoding => XML::Encoding::ISO_8859_1)
105
- assert_equal(265, bytes)
106
-
107
- contents = File.read(temp_filename)
108
- assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\"><m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>\n",
109
- contents)
110
- ensure
111
- File.delete(temp_filename)
112
- end
113
-
114
- # --- Debug ---
115
- def test_debug
116
- assert(@doc.debug)
117
- end
1
+ require 'xml'
2
+ require 'tmpdir'
3
+ require 'test/unit'
4
+
5
+ class TestDocumentWrite < Test::Unit::TestCase
6
+ def setup
7
+ # Strip spaces to make testing easier
8
+ XML.default_keep_blanks = false
9
+ file = File.join(File.dirname(__FILE__), 'model/bands.xml')
10
+ @doc = XML::Document.file(file)
11
+ end
12
+
13
+ def teardown
14
+ XML.default_keep_blanks = true
15
+ @doc = nil
16
+ end
17
+
18
+ # --- to_s tests ---
19
+ def test_to_s_default
20
+ # Default to_s has indentation
21
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
22
+ @doc.to_s)
23
+ end
24
+
25
+ def test_to_s_no_global_indentation
26
+ # No indentation due to global setting
27
+ XML.indent_tree_output = false
28
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
29
+ @doc.to_s)
30
+ ensure
31
+ XML.indent_tree_output = true
32
+ end
33
+
34
+ def test_to_s_no_indentation
35
+ # No indentation due to local setting
36
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>\n",
37
+ @doc.to_s(:indent => false))
38
+ end
39
+
40
+ def test_to_s_encoding
41
+ # Test encodings
42
+
43
+ # UTF8:
44
+ # ö - c3 b6 in hex, \303\266 in octal
45
+ # ü - c3 bc in hex, \303\274 in octal
46
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
47
+ @doc.to_s(:encoding => XML::Encoding::UTF_8))
48
+
49
+ # ISO_8859_1:
50
+ # ö - f6 in hex, \366 in octal
51
+ # ü - fc in hex, \374 in octal
52
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
53
+ @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
54
+
55
+
56
+ # Invalid encoding
57
+ error = assert_raise(ArgumentError) do
58
+ @doc.to_s(:encoding => -9999)
59
+ end
60
+ assert_equal('Unknown encoding value: -9999', error.to_s)
61
+ end
62
+
63
+ # --- save tests -----
64
+ def test_save_utf8
65
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8.xml")
66
+
67
+ bytes = @doc.save(temp_filename)
68
+ assert_equal(271, bytes)
69
+
70
+ contents = File.read(temp_filename)
71
+ assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
72
+ contents)
73
+ ensure
74
+ File.delete(temp_filename)
75
+ end
76
+
77
+ def test_save_utf8_no_indents
78
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8_no_indents.xml")
79
+
80
+ bytes = @doc.save(temp_filename, :indent => false)
81
+ assert_equal(264, bytes)
82
+
83
+ contents = File.read(temp_filename)
84
+ assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>\n",
85
+ contents)
86
+ ensure
87
+ File.delete(temp_filename)
88
+ end
89
+
90
+ def test_save_iso_8859_1
91
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml")
92
+ bytes = @doc.save(temp_filename, :encoding => XML::Encoding::ISO_8859_1)
93
+ assert_equal(272, bytes)
94
+
95
+ contents = File.read(temp_filename)
96
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
97
+ contents)
98
+ ensure
99
+ File.delete(temp_filename)
100
+ end
101
+
102
+ def test_save_iso_8859_1_no_indent
103
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml")
104
+ bytes = @doc.save(temp_filename, :indent => false, :encoding => XML::Encoding::ISO_8859_1)
105
+ assert_equal(265, bytes)
106
+
107
+ contents = File.read(temp_filename)
108
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\"><m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>\n",
109
+ contents)
110
+ ensure
111
+ File.delete(temp_filename)
112
+ end
113
+
114
+ # --- Debug ---
115
+ def test_debug
116
+ assert(@doc.debug)
117
+ end
118
118
  end
data/test/tc_dtd.rb CHANGED
@@ -1,123 +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
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