libxml-ruby 0.6.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +122 -0
- data/LICENSE +23 -0
- data/README +144 -0
- data/ext/libxml/cbg.c +76 -0
- data/ext/libxml/extconf.rb +308 -0
- data/ext/libxml/libxml.c +62 -0
- data/ext/libxml/ruby_libxml.h +93 -0
- data/ext/libxml/ruby_xml_attr.c +405 -0
- data/ext/libxml/ruby_xml_attr.h +19 -0
- data/ext/libxml/ruby_xml_document.c +1111 -0
- data/ext/libxml/ruby_xml_document.h +27 -0
- data/ext/libxml/ruby_xml_dtd.c +168 -0
- data/ext/libxml/ruby_xml_dtd.h +17 -0
- data/ext/libxml/ruby_xml_html_parser.c +449 -0
- data/ext/libxml/ruby_xml_html_parser.h +29 -0
- data/ext/libxml/ruby_xml_input_cbg.c +158 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- data/ext/libxml/ruby_xml_node.c +2410 -0
- data/ext/libxml/ruby_xml_node.h +27 -0
- data/ext/libxml/ruby_xml_node_set.c +170 -0
- data/ext/libxml/ruby_xml_node_set.h +20 -0
- data/ext/libxml/ruby_xml_ns.c +153 -0
- data/ext/libxml/ruby_xml_ns.h +21 -0
- data/ext/libxml/ruby_xml_parser.c +1425 -0
- data/ext/libxml/ruby_xml_parser.h +31 -0
- data/ext/libxml/ruby_xml_parser_context.c +750 -0
- data/ext/libxml/ruby_xml_parser_context.h +22 -0
- data/ext/libxml/ruby_xml_reader.c +900 -0
- data/ext/libxml/ruby_xml_reader.h +14 -0
- data/ext/libxml/ruby_xml_sax_parser.c +485 -0
- data/ext/libxml/ruby_xml_sax_parser.h +56 -0
- data/ext/libxml/ruby_xml_schema.c +146 -0
- data/ext/libxml/ruby_xml_schema.h +16 -0
- data/ext/libxml/ruby_xml_state.c +113 -0
- data/ext/libxml/ruby_xml_state.h +12 -0
- data/ext/libxml/ruby_xml_tree.c +43 -0
- data/ext/libxml/ruby_xml_tree.h +12 -0
- data/ext/libxml/ruby_xml_xinclude.c +20 -0
- data/ext/libxml/ruby_xml_xinclude.h +13 -0
- data/ext/libxml/ruby_xml_xpath.c +243 -0
- data/ext/libxml/ruby_xml_xpath.h +23 -0
- data/ext/libxml/ruby_xml_xpath_context.c +118 -0
- data/ext/libxml/ruby_xml_xpath_context.h +20 -0
- data/ext/libxml/ruby_xml_xpath_object.c +293 -0
- data/ext/libxml/ruby_xml_xpath_object.h +28 -0
- data/ext/libxml/ruby_xml_xpointer.c +100 -0
- data/ext/libxml/ruby_xml_xpointer.h +27 -0
- data/ext/libxml/ruby_xml_xpointer_context.c +21 -0
- data/ext/libxml/ruby_xml_xpointer_context.h +18 -0
- data/ext/libxml/sax_parser_callbacks.inc +213 -0
- data/ext/libxml/version.h +9 -0
- data/lib/libxml.rb +125 -0
- data/lib/libxml_ruby.so +0 -0
- data/lib/xml/libxml.rb +5 -0
- data/mingw/libiconv-2.dll +0 -0
- data/mingw/libxml2-2.dll +0 -0
- data/mingw/libxml_ruby.so +0 -0
- data/mingw/mingw.rake +36 -0
- data/test/dtd-test.rb +24 -0
- data/test/etc_doc_to_s.rb +19 -0
- data/test/ets_copy_bug.rb +21 -0
- data/test/ets_copy_bug2.rb +32 -0
- data/test/ets_copy_bug3.rb +38 -0
- data/test/ets_doc_file.rb +15 -0
- data/test/ets_doc_to_s.rb +21 -0
- data/test/ets_gpx.rb +26 -0
- data/test/ets_node_gc.rb +21 -0
- data/test/ets_test.xml +2 -0
- data/test/ets_tsr.rb +9 -0
- data/test/gc.log +0 -0
- data/test/merge_bug.rb +55 -0
- data/test/schema-test.rb +74 -0
- data/test/tc_well_formed.rb +11 -0
- data/test/tc_xml_document.rb +52 -0
- data/test/tc_xml_document_write.rb +24 -0
- data/test/tc_xml_document_write2.rb +54 -0
- data/test/tc_xml_document_write3.rb +96 -0
- data/test/tc_xml_html_parser.rb +63 -0
- data/test/tc_xml_node.rb +59 -0
- data/test/tc_xml_node2.rb +25 -0
- data/test/tc_xml_node3.rb +27 -0
- data/test/tc_xml_node4.rb +86 -0
- data/test/tc_xml_node5.rb +52 -0
- data/test/tc_xml_node6.rb +27 -0
- data/test/tc_xml_node7.rb +35 -0
- data/test/tc_xml_node8.rb +32 -0
- data/test/tc_xml_node9.rb +32 -0
- data/test/tc_xml_node_copy.rb +40 -0
- data/test/tc_xml_node_set.rb +24 -0
- data/test/tc_xml_node_set2.rb +37 -0
- data/test/tc_xml_node_text.rb +17 -0
- data/test/tc_xml_node_xlink.rb +28 -0
- data/test/tc_xml_parser.rb +190 -0
- data/test/tc_xml_parser2.rb +16 -0
- data/test/tc_xml_parser3.rb +23 -0
- data/test/tc_xml_parser4.rb +33 -0
- data/test/tc_xml_parser5.rb +27 -0
- data/test/tc_xml_parser6.rb +23 -0
- data/test/tc_xml_parser7.rb +28 -0
- data/test/tc_xml_parser8.rb +32 -0
- data/test/tc_xml_parser9.rb +11 -0
- data/test/tc_xml_parser_context.rb +88 -0
- data/test/tc_xml_reader.rb +112 -0
- data/test/tc_xml_sax_parser.rb +104 -0
- data/test/tc_xml_sax_parser2.rb +51 -0
- data/test/tc_xml_xinclude.rb +30 -0
- data/test/tc_xml_xpath.rb +38 -0
- data/test/tc_xml_xpath2.rb +14 -0
- data/test/tc_xml_xpointer.rb +78 -0
- data/vc/libxml.sln +20 -0
- data/vc/libxml.vcproj +389 -0
- data/work/Rakefile +247 -0
- data/work/task/make +26 -0
- data/work/task/memory +37 -0
- data/work/task/rdoc +39 -0
- data/work/task/setup +1616 -0
- data/work/task/test +29 -0
- data/work/test/ets_runner.rb +33 -0
- data/work/test/libxml_test.rb +3 -0
- data/work/test/runner.rb +0 -0
- data/work/test/runner_ets.rb +33 -0
- data/work/vc/debug/libxml.exp +0 -0
- data/work/vc/debug/libxml.ilk +0 -0
- data/work/vc/debug/libxml.lib +0 -0
- data/work/vc/debug/libxml.pdb +0 -0
- data/work/vc/debug/libxml.so +0 -0
- metadata +224 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
require "libxml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_XML_Parser2 < Test::Unit::TestCase
|
5
|
+
def setup()
|
6
|
+
@xp = XML::Parser.new()
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown()
|
10
|
+
@xp = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_ruby_xml_parser_new()
|
14
|
+
assert_instance_of(XML::Parser, @xp)
|
15
|
+
end
|
16
|
+
end # TC_XML_Document
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# $Id: tc_xml_parser3.rb 251 2008-01-22 18:12:00Z transami $
|
2
|
+
require "libxml"
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TC_XML_Parser3 < Test::Unit::TestCase
|
6
|
+
def setup()
|
7
|
+
@xp = XML::Parser.new()
|
8
|
+
assert_instance_of(XML::Parser, @xp)
|
9
|
+
s = @xp.string = '<u>a</u>'
|
10
|
+
assert_instance_of(String, s)
|
11
|
+
assert_instance_of(String, @xp.string)
|
12
|
+
assert_equal(s, @xp.string)
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown()
|
16
|
+
@xp = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_ruby_xml_parser_new()
|
20
|
+
assert_instance_of(XML::Parser, @xp)
|
21
|
+
assert_instance_of(String, @xp.string)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# $Id: tc_xml_parser4.rb 251 2008-01-22 18:12:00Z transami $
|
2
|
+
require "libxml"
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TC_XML_Parser4 < Test::Unit::TestCase
|
6
|
+
def setup()
|
7
|
+
@xp1 = XML::Parser.new()
|
8
|
+
assert_instance_of(XML::Parser, @xp1)
|
9
|
+
s1 = @xp1.string = '<u>a</u>'
|
10
|
+
assert_instance_of(String, s1)
|
11
|
+
assert_instance_of(String, @xp1.string)
|
12
|
+
assert_equal(s1, @xp1.string)
|
13
|
+
|
14
|
+
@xp2 = XML::Parser.string('<u>a</u>')
|
15
|
+
assert_instance_of(XML::Parser, @xp2)
|
16
|
+
assert_instance_of(String, @xp2.string)
|
17
|
+
assert_equal(s1, @xp2.string)
|
18
|
+
assert_equal(@xp1.string, @xp2.string)
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown()
|
22
|
+
@xp1 = nil
|
23
|
+
@xp2 = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_ruby_xml_parser_new()
|
27
|
+
assert_instance_of(XML::Parser, @xp1)
|
28
|
+
assert_instance_of(String, @xp1.string)
|
29
|
+
assert_instance_of(XML::Parser, @xp2)
|
30
|
+
assert_instance_of(String, @xp2.string)
|
31
|
+
assert_equal(@xp1.string, @xp2.string)
|
32
|
+
end
|
33
|
+
end # TC_XML_Document
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# $Id: tc_xml_parser5.rb 251 2008-01-22 18:12:00Z transami $
|
2
|
+
require "libxml"
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TC_XML_Parser5 < Test::Unit::TestCase
|
6
|
+
def setup()
|
7
|
+
@xp = XML::Parser.new()
|
8
|
+
assert_instance_of(XML::Parser, @xp)
|
9
|
+
s = @xp.string = '<u>a</u>'
|
10
|
+
assert_instance_of(String, s)
|
11
|
+
assert_instance_of(String, @xp.string)
|
12
|
+
assert_equal(s, @xp.string)
|
13
|
+
@doc = @xp.parse
|
14
|
+
assert_instance_of(XML::Document, @doc)
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown()
|
18
|
+
@xp = nil
|
19
|
+
@doc = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_ruby_xml_parser_new()
|
23
|
+
assert_instance_of(XML::Parser, @xp)
|
24
|
+
assert_instance_of(String, @xp.string)
|
25
|
+
assert_instance_of(XML::Document, @doc)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# $Id: tc_xml_parser6.rb 283 2008-07-01 06:48:35Z cfis $
|
2
|
+
require "libxml"
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TC_XML_Parser6 < Test::Unit::TestCase
|
6
|
+
def setup()
|
7
|
+
@xp = XML::Parser.new()
|
8
|
+
assert_instance_of(XML::Parser, @xp)
|
9
|
+
f = File.open('model/rubynet.xml')
|
10
|
+
f1 = @xp.io = f
|
11
|
+
assert_instance_of(File, f1)
|
12
|
+
assert_instance_of(File, @xp.io)
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown()
|
16
|
+
@xp = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_ruby_xml_parser_new()
|
20
|
+
assert_instance_of(XML::Parser, @xp)
|
21
|
+
assert_instance_of(File, @xp.io)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# $Id: tc_xml_parser7.rb 283 2008-07-01 06:48:35Z cfis $
|
2
|
+
require "libxml"
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TC_XML_Parser7 < Test::Unit::TestCase
|
6
|
+
def setup()
|
7
|
+
@xp = XML::Parser.new()
|
8
|
+
assert_instance_of(XML::Parser, @xp)
|
9
|
+
f = File.open('model/rubynet.xml')
|
10
|
+
f1 = @xp.io = f
|
11
|
+
assert_instance_of(File, f1)
|
12
|
+
assert_instance_of(File, @xp.io)
|
13
|
+
@doc = @xp.parse
|
14
|
+
assert_instance_of(XML::Document, @doc)
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown()
|
18
|
+
@xp = nil
|
19
|
+
@doc = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_ruby_xml_parser_new()
|
23
|
+
assert_instance_of(XML::Parser, @xp)
|
24
|
+
assert_instance_of(File, @xp.io)
|
25
|
+
assert_instance_of(XML::Document, @doc)
|
26
|
+
assert_instance_of(String, @doc.version)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# $Id: tc_xml_parser8.rb 251 2008-01-22 18:12:00Z transami $
|
2
|
+
require "libxml"
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TC_XML_Parser8 < Test::Unit::TestCase
|
6
|
+
def test_ruby_xml_parser_error_handler
|
7
|
+
$stderr.puts "\nEXPECTING: TWO ERRORS:"
|
8
|
+
# this will send message to stderr
|
9
|
+
assert_raise(XML::Parser::ParseError) {
|
10
|
+
d = XML::Parser.string('<foo><bar/></foz>').parse
|
11
|
+
}
|
12
|
+
|
13
|
+
ary = []
|
14
|
+
assert_nil XML::Parser.register_error_handler(lambda { |msg| ary << msg })
|
15
|
+
|
16
|
+
# this will use our error handler
|
17
|
+
assert_raise(XML::Parser::ParseError) {
|
18
|
+
d = XML::Parser.string('<foo><bar/></foz>').parse
|
19
|
+
}
|
20
|
+
|
21
|
+
assert (first_len = ary.length) > 0
|
22
|
+
|
23
|
+
assert_instance_of Proc, XML::Parser.register_error_handler(nil)
|
24
|
+
|
25
|
+
# this will go to stderr again
|
26
|
+
assert_raise(XML::Parser::ParseError) {
|
27
|
+
d = XML::Parser.string('<foo><bar/></foz>').parse
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_equal first_len, ary.length
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "libxml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_XML_Parser_Context < Test::Unit::TestCase
|
5
|
+
def setup()
|
6
|
+
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
7
|
+
xp = XML::Parser.string(str)
|
8
|
+
assert_equal(str, xp.string = str)
|
9
|
+
doc = xp.parse
|
10
|
+
assert_instance_of(XML::Document, doc)
|
11
|
+
@ctxt = xp.parser_context()
|
12
|
+
assert_instance_of(XML::Parser::Context, @ctxt)
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown()
|
16
|
+
@ctxt = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_libxml_parser_context_well_formed()
|
20
|
+
if @ctxt.well_formed?
|
21
|
+
assert_instance_of(TrueClass, @ctxt.well_formed?)
|
22
|
+
else
|
23
|
+
assert_instance_of(FalseClass, @ctxt.well_formed?)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_ruby_xml_parser_context_version_info()
|
28
|
+
assert_instance_of(String, @ctxt.version)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_ruby_xml_parser_context_depth()
|
32
|
+
assert_instance_of(Fixnum, @ctxt.depth)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_ruby_xml_parser_context_doc()
|
36
|
+
assert_instance_of(XML::Document, @ctxt.doc)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_ruby_xml_parser_context_disable_sax()
|
40
|
+
assert(!@ctxt.disable_sax?)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_ruby_xml_parser_context_docbook()
|
44
|
+
assert(!@ctxt.docbook?)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_ruby_xml_parser_context_encoding()
|
48
|
+
assert(!@ctxt.encoding)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_ruby_xml_parser_context_html()
|
52
|
+
assert(!@ctxt.html?)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_ruby_xml_parser_context_keep_blanks()
|
56
|
+
if @ctxt.keep_blanks?
|
57
|
+
assert_instance_of(TrueClass, @ctxt.keep_blanks?)
|
58
|
+
else
|
59
|
+
assert_instance_of(FalseClass, @ctxt.keep_blanks?)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if ENV['NOTWORKING']
|
64
|
+
def test_ruby_xml_parser_context_num_chars()
|
65
|
+
assert_equal(17, @ctxt.num_chars)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_ruby_xml_parser_context_replace_entities()
|
70
|
+
if @ctxt.replace_entities?
|
71
|
+
assert_instance_of(TrueClass, @ctxt.replace_entities?)
|
72
|
+
else
|
73
|
+
assert_instance_of(FalseClass, @ctxt.replace_entities?)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_ruby_xml_parser_context_space_depth()
|
78
|
+
assert_equal(1, @ctxt.space_depth)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_ruby_xml_parser_context_subset_external()
|
82
|
+
assert(!@ctxt.subset_external?)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_ruby_xml_parser_context_data_directory_get()
|
86
|
+
# assert_instance_of(String, @ctxt.data_directory)
|
87
|
+
end
|
88
|
+
end # TC_XML_Parser_Context
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'libxml'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_XML_Reader < Test::Unit::TestCase
|
5
|
+
|
6
|
+
SIMPLE_XML = File.join(File.dirname(__FILE__), 'model/simple.xml')
|
7
|
+
|
8
|
+
def test_new_file
|
9
|
+
reader = XML::Reader.file(SIMPLE_XML)
|
10
|
+
do_test_simple(reader)
|
11
|
+
assert_raises(RuntimeError) { XML::Reader.file('/does/not/exist') }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_new_data
|
15
|
+
reader = XML::Reader.new(File.read(SIMPLE_XML))
|
16
|
+
do_test_simple(reader)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_new_walker
|
20
|
+
reader = XML::Reader.walker(XML::Document.file(SIMPLE_XML))
|
21
|
+
do_test_simple(reader)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_reader_error
|
25
|
+
reader = XML::Reader.new('<foo/>')
|
26
|
+
assert_raises(RuntimeError) { reader.set_error_handler }
|
27
|
+
called = false
|
28
|
+
reader.set_error_handler { |*a| called = true }
|
29
|
+
while reader.read > 0; end
|
30
|
+
assert(!called)
|
31
|
+
reader = XML::Reader.new('<foo blah')
|
32
|
+
reader.set_error_handler do |*a|
|
33
|
+
assert_equal(5, a.size)
|
34
|
+
assert_equal(reader, a[0])
|
35
|
+
assert_equal(XML::Reader::SEVERITY_ERROR, a[2])
|
36
|
+
assert_nil(a[3])
|
37
|
+
assert_equal(1, a[4])
|
38
|
+
called = true
|
39
|
+
end
|
40
|
+
while reader.read > 0; end
|
41
|
+
assert(called)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_attr
|
45
|
+
parser = XML::Reader.new("<foo x='1' y='2'/>")
|
46
|
+
assert_equal(1, parser.read)
|
47
|
+
assert_equal('foo', parser.name)
|
48
|
+
assert_equal('1', parser['x'])
|
49
|
+
assert_equal('1', parser[0])
|
50
|
+
assert_equal('2', parser['y'])
|
51
|
+
assert_equal('2', parser[1])
|
52
|
+
assert_equal(nil, parser['z'])
|
53
|
+
assert_equal(nil, parser[2])
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_value
|
57
|
+
parser = XML::Reader.new("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
|
58
|
+
assert_equal(1, parser.read)
|
59
|
+
assert_equal('foo', parser.name)
|
60
|
+
assert_equal(nil, parser.value)
|
61
|
+
3.times do |i|
|
62
|
+
assert_equal(1, parser.read)
|
63
|
+
assert_equal(XML::Reader::TYPE_ELEMENT, parser.node_type)
|
64
|
+
assert_equal('bar', parser.name)
|
65
|
+
assert_equal(1, parser.read)
|
66
|
+
assert_equal(XML::Reader::TYPE_TEXT, parser.node_type)
|
67
|
+
assert_equal((i + 1).to_s, parser.value)
|
68
|
+
assert_equal(1, parser.read)
|
69
|
+
assert_equal(XML::Reader::TYPE_END_ELEMENT, parser.node_type)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_expand
|
74
|
+
reader = XML::Reader.file(SIMPLE_XML)
|
75
|
+
reader.read
|
76
|
+
node = reader.expand
|
77
|
+
doc = node.doc
|
78
|
+
reader.close
|
79
|
+
GC.start
|
80
|
+
|
81
|
+
doc.standalone?
|
82
|
+
end
|
83
|
+
|
84
|
+
def do_test_simple(reader)
|
85
|
+
node_types = []
|
86
|
+
19.times do
|
87
|
+
assert_equal(1, reader.read)
|
88
|
+
node_types << reader.node_type
|
89
|
+
end
|
90
|
+
assert_equal(0, reader.read)
|
91
|
+
assert_equal(node_types,
|
92
|
+
[XML::Reader::TYPE_ELEMENT,
|
93
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
94
|
+
XML::Reader::TYPE_ELEMENT,
|
95
|
+
XML::Reader::TYPE_TEXT,
|
96
|
+
XML::Reader::TYPE_END_ELEMENT,
|
97
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
98
|
+
XML::Reader::TYPE_ELEMENT,
|
99
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
100
|
+
XML::Reader::TYPE_ELEMENT,
|
101
|
+
XML::Reader::TYPE_TEXT,
|
102
|
+
XML::Reader::TYPE_END_ELEMENT,
|
103
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
104
|
+
XML::Reader::TYPE_ELEMENT,
|
105
|
+
XML::Reader::TYPE_TEXT,
|
106
|
+
XML::Reader::TYPE_END_ELEMENT,
|
107
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
108
|
+
XML::Reader::TYPE_END_ELEMENT,
|
109
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
110
|
+
XML::Reader::TYPE_END_ELEMENT])
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'libxml'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
# TODO this is woefully inadequate
|
5
|
+
|
6
|
+
class TC_XML_SaxParser2 < Test::Unit::TestCase
|
7
|
+
class TestCaseCallbacks
|
8
|
+
include XML::SaxParser::Callbacks
|
9
|
+
|
10
|
+
attr_accessor :test
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@test = Hash.new { |h,k| h[k] = [] }
|
14
|
+
@i = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_start_document
|
18
|
+
@test[:startdoc] << @i+=1
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_start_element(name, attr_hash)
|
22
|
+
@test[:startel] << [@i+=1,name,attr_hash]
|
23
|
+
end
|
24
|
+
|
25
|
+
def on_characters(chars)
|
26
|
+
@test[:chars] << [@i+=1,chars]
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_comment(msg)
|
30
|
+
@test[:comment] << [@i+=1,msg]
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_processing_instruction(target, data)
|
34
|
+
@test[:pinstr] << [@i+=1, target, data]
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_cdata_block(cdata)
|
38
|
+
@test[:cdata] << [@i+=1,cdata]
|
39
|
+
end
|
40
|
+
|
41
|
+
def on_end_element(name)
|
42
|
+
@test[:endel] << [@i+=1,name]
|
43
|
+
end
|
44
|
+
|
45
|
+
def on_end_document
|
46
|
+
@test[:enddoc] << @i+=1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def setup()
|
51
|
+
@xp = XML::SaxParser.new
|
52
|
+
end
|
53
|
+
|
54
|
+
def teardown()
|
55
|
+
@xp = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_string_without_callbacks
|
59
|
+
@xp.string = File.read(File.join(File.dirname(__FILE__), 'model/saxtest.xml'))
|
60
|
+
assert_equal true, @xp.parse
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_file_without_callbacks
|
64
|
+
@xp.filename = File.join(File.dirname(__FILE__), 'model/saxtest.xml')
|
65
|
+
assert_equal true, @xp.parse
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_callbacks_with_string
|
69
|
+
@xp.callbacks = TestCaseCallbacks.new
|
70
|
+
@xp.string = File.read(File.join(File.dirname(__FILE__), 'model/saxtest.xml'))
|
71
|
+
do_test
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_callbacks_with_file
|
75
|
+
@xp.callbacks = TestCaseCallbacks.new
|
76
|
+
@xp.filename = File.join(File.dirname(__FILE__), 'model/saxtest.xml')
|
77
|
+
do_test
|
78
|
+
end
|
79
|
+
|
80
|
+
def do_test
|
81
|
+
@xp.parse
|
82
|
+
assert_equal [1], @xp.callbacks.test[:startdoc]
|
83
|
+
assert_equal [[2,'test',{'uga'=>'booga','foo'=>'bar'}],[3,'fixnum',{}],[6,'fixnum',{}]],
|
84
|
+
@xp.callbacks.test[:startel]
|
85
|
+
assert_equal [[4,'one'],[7,'two'],[9,"\n "],[11,"\n "],[13,"\n "],[15,"\n"]],
|
86
|
+
@xp.callbacks.test[:chars]
|
87
|
+
assert_equal [[10, ' msg ']], @xp.callbacks.test[:comment]
|
88
|
+
assert_equal [[12, 'custom', 'foo="bar"']], @xp.callbacks.test[:pinstr]
|
89
|
+
assert_equal [[14, 'here it goes']], @xp.callbacks.test[:cdata]
|
90
|
+
assert_equal [[5,'fixnum'],[8,'fixnum'],[16,'test']], @xp.callbacks.test[:endel]
|
91
|
+
assert_equal [17], @xp.callbacks.test[:enddoc]
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_doctype
|
95
|
+
@xp.callbacks = TestCaseCallbacks.new
|
96
|
+
@xp.string = <<-EOS
|
97
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
98
|
+
<!DOCTYPE ONIXmessage SYSTEM "http://www.editeur.org/onix/2.1/short/onix-international.dtd">
|
99
|
+
<ONIXmessage release="2.1">
|
100
|
+
</ONIXmessage>
|
101
|
+
EOS
|
102
|
+
@xp.parse
|
103
|
+
end
|
104
|
+
end # TC_XML_Sax_Parser
|