rubyjedi-testunitxml 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +19 -0
- data/MIT-LICENSE +21 -0
- data/README +119 -0
- data/lib/test/unit/xml/attributes_mixin.rb +21 -0
- data/lib/test/unit/xml/conditionals.rb +147 -0
- data/lib/test/unit/xml/doctype_mixin.rb +54 -0
- data/lib/test/unit/xml/nodeiterator.rb +67 -0
- data/lib/test/unit/xml/notationdecl_mixin.rb +54 -0
- data/lib/test/unit/xml/xml_assertions.rb +163 -0
- data/lib/test/unit/xml/xmlequalfilter.rb +31 -0
- data/lib/test/unit/xml.rb +21 -0
- data/test/data/test1.xml +23 -0
- data/test/tc_attributes_mixin.rb +37 -0
- data/test/tc_doctype_mixin.rb +71 -0
- data/test/tc_notationdecl_mixin.rb +68 -0
- data/test/tc_testunitxml.rb +315 -0
- data/test/tc_testunitxml2.rb +34 -0
- data/test/ts_testunitxml.rb +12 -0
- metadata +79 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
module Test
|
4
|
+
module Unit
|
5
|
+
module XML
|
6
|
+
|
7
|
+
# This filter class accepts any node except text nodes
|
8
|
+
# that contain non-significant whitespace
|
9
|
+
class XmlEqualFilter
|
10
|
+
def accept(node)
|
11
|
+
case
|
12
|
+
when node.kind_of?(REXML::Text)
|
13
|
+
is_significant?(node.value)
|
14
|
+
when node.kind_of?(REXML::Entity)
|
15
|
+
false
|
16
|
+
when node.kind_of?(REXML::NotationDecl)
|
17
|
+
false
|
18
|
+
else
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def is_significant?(string)
|
26
|
+
string =~ /^\s*$/ ? false : true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
This file mixes in XML assertions in the Test::Unit::TestCase
|
3
|
+
class.
|
4
|
+
|
5
|
+
See #xml_assertions.rb for information about the assertions
|
6
|
+
that are mixed in.
|
7
|
+
=end
|
8
|
+
|
9
|
+
require 'test/unit/xml/xml_assertions'
|
10
|
+
|
11
|
+
module Test
|
12
|
+
module Unit
|
13
|
+
|
14
|
+
# The module Test::Unit::XML is mixed in into the class
|
15
|
+
# Test::Unit::TestCase
|
16
|
+
class TestCase
|
17
|
+
include Test::Unit::XML
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/test/data/test1.xml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" standalone="yes" encoding="utf-8"?>
|
2
|
+
<book xmlns="http://www.henrikmartensson.org/ns/testunitxml/test1">
|
3
|
+
<chapter id="a" type="">
|
4
|
+
<title>First Chapter</title>
|
5
|
+
<p>This <em type="medium">is</em> the first chapter.</p>
|
6
|
+
<section>
|
7
|
+
<title>First Chapter, First Section</title>
|
8
|
+
<?pi1?>
|
9
|
+
<?pi2 content?>
|
10
|
+
<?pi3 more content?>
|
11
|
+
</section>
|
12
|
+
</chapter>
|
13
|
+
<chapter id="b" type="" xmlns="http://www.henrikmartensson.org/ns/testunitxml/test2">
|
14
|
+
<title>Second Chapter</title>
|
15
|
+
<p>This is the second chapter.</p>
|
16
|
+
<t3:section xmlns:t3="http://www.henrikmartensson.org/ns/testunitxml/test3">
|
17
|
+
<t3:title>Second Chapter, Second Section</t3:title>
|
18
|
+
<p><![CDATA[This is a
|
19
|
+
|
20
|
+
CDATA section.]]></p>
|
21
|
+
</t3:section>
|
22
|
+
</chapter>
|
23
|
+
</book>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#! /usr/local/bin/ruby
|
2
|
+
|
3
|
+
|
4
|
+
@@lib_path = File.join(File.dirname(__FILE__), "..", "lib")
|
5
|
+
$:.unshift @@lib_path
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'rexml/document'
|
9
|
+
require 'test/unit/xml/attributes_mixin.rb'
|
10
|
+
|
11
|
+
class TestAttributes < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@ns_a = "urn:x-test:a"
|
15
|
+
@ns_b = "urn:x-test:b"
|
16
|
+
element_string = <<-"XMLEND"
|
17
|
+
<test xmlns:a="#{@ns_a}"
|
18
|
+
xmlns:b="#{@ns_b}"
|
19
|
+
a = "1"
|
20
|
+
b = '2'
|
21
|
+
a:c = "3"
|
22
|
+
a:d = '4'
|
23
|
+
a:e = "5"
|
24
|
+
b:f = "6"/>
|
25
|
+
XMLEND
|
26
|
+
@attributes = REXML::Document.new(element_string).root.attributes
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_get_attribute_ns
|
30
|
+
assert_equal("1", @attributes.get_attribute_ns("", "a").value)
|
31
|
+
assert_equal("2", @attributes.get_attribute_ns("", "b").value)
|
32
|
+
assert_equal("3", @attributes.get_attribute_ns(@ns_a, "c").value)
|
33
|
+
assert_equal("4", @attributes.get_attribute_ns(@ns_a, "d").value)
|
34
|
+
assert_equal("5", @attributes.get_attribute_ns(@ns_a, "e").value)
|
35
|
+
assert_equal("6", @attributes.get_attribute_ns(@ns_b, "f").value)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#! /usr/local/bin/ruby
|
2
|
+
|
3
|
+
|
4
|
+
@@lib_path = File.join(File.dirname(__FILE__), "..", "lib")
|
5
|
+
$:.unshift @@lib_path
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'rexml/document'
|
9
|
+
require 'test/unit/xml/doctype_mixin.rb'
|
10
|
+
|
11
|
+
class TestDoctype < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@sysid = "urn:x-test:sysid1"
|
15
|
+
@notid1 = "urn:x-test:notation1"
|
16
|
+
@notid2 = "urn:x-test:notation2"
|
17
|
+
document_string1 = <<-"XMLEND"
|
18
|
+
<!DOCTYPE r SYSTEM "#{@sysid}" [
|
19
|
+
<!NOTATION n1 SYSTEM "#{@notid1}">
|
20
|
+
<!NOTATION n2 SYSTEM "#{@notid2}">
|
21
|
+
]>
|
22
|
+
<r/>
|
23
|
+
XMLEND
|
24
|
+
@doctype1 = REXML::Document.new(document_string1).doctype
|
25
|
+
|
26
|
+
@pubid = "TEST_ID"
|
27
|
+
document_string2 = <<-"XMLEND"
|
28
|
+
<!DOCTYPE r PUBLIC "#{@pubid}">
|
29
|
+
<r/>
|
30
|
+
XMLEND
|
31
|
+
@doctype2 = REXML::Document.new(document_string2).doctype
|
32
|
+
|
33
|
+
document_string3 = <<-"XMLEND"
|
34
|
+
<!DOCTYPE r PUBLIC "#{@pubid}" "#{@sysid}">
|
35
|
+
<r/>
|
36
|
+
XMLEND
|
37
|
+
@doctype3 = REXML::Document.new(document_string3).doctype
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_public
|
42
|
+
assert_equal(nil, @doctype1.public)
|
43
|
+
assert_equal(@pubid, @doctype2.public)
|
44
|
+
assert_equal(@pubid, @doctype3.public)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_system
|
48
|
+
assert_equal(@sysid, @doctype1.system)
|
49
|
+
assert_equal(nil, @doctype2.system)
|
50
|
+
assert_equal(@sysid, @doctype3.system)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_notation
|
54
|
+
assert_equal(@notid1, @doctype1.notation("n1").system)
|
55
|
+
assert_equal(@notid2, @doctype1.notation("n2").system)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_notations
|
59
|
+
notations = @doctype1.notations
|
60
|
+
assert_equal(2, notations.length)
|
61
|
+
assert_equal(@notid1, find_notation(notations, "n1").system)
|
62
|
+
assert_equal(@notid2, find_notation(notations, "n2").system)
|
63
|
+
end
|
64
|
+
|
65
|
+
def find_notation(notations, name)
|
66
|
+
notations.find { |notation|
|
67
|
+
name == notation.name
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#! /usr/local/bin/ruby
|
2
|
+
|
3
|
+
|
4
|
+
@@lib_path = File.join(File.dirname(__FILE__), "..", "lib")
|
5
|
+
$:.unshift @@lib_path
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'rexml/document'
|
9
|
+
require 'test/unit/xml/doctype_mixin'
|
10
|
+
require 'test/unit/xml/notationdecl_mixin'
|
11
|
+
|
12
|
+
class TestNotationDecl < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@pubid1 = "TEST1"
|
16
|
+
@pubid2 = "TEST2"
|
17
|
+
@sysid2 = "urn:x-henrikmartensson.org:test2"
|
18
|
+
@pubid3 = "TEST3"
|
19
|
+
@pubid4 = "TEST4"
|
20
|
+
@sysid4 = "urn:x-henrikmartensson.org:test4"
|
21
|
+
@pubid5 = "TEST5"
|
22
|
+
@sysid5 = "urn:x-henrikmartensson.org:test5"
|
23
|
+
@pubid6 = "TEST6"
|
24
|
+
@sysid6 = "urn:x-henrikmartensson.org:test6"
|
25
|
+
@sysid7 = "urn:x-henrikmartensson.org:test7"
|
26
|
+
doc_string = <<-"XMLEND"
|
27
|
+
<!DOCTYPE r SYSTEM "urn:x-henrikmartensson:test" [
|
28
|
+
<!NOTATION n1 PUBLIC "#{@pubid1}">
|
29
|
+
<!NOTATION n2 PUBLIC "#{@pubid2}" "#{@sysid2}">
|
30
|
+
<!NOTATION n3 PUBLIC '#{@pubid3}'>
|
31
|
+
<!NOTATION n4 PUBLIC '#{@pubid4}' '#{@sysid4}'>
|
32
|
+
<!NOTATION n5 PUBLIC "#{@pubid5}" '#{@sysid5}'>
|
33
|
+
<!NOTATION n6 PUBLIC '#{@pubid6}' "#{@sysid6}">
|
34
|
+
<!NOTATION n7 SYSTEM "#{@sysid7}">
|
35
|
+
]>
|
36
|
+
<r/>
|
37
|
+
XMLEND
|
38
|
+
@doctype = REXML::Document.new(doc_string).doctype
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_name
|
42
|
+
assert_equal('n1', @doctype.notation('n1').name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_public
|
46
|
+
assert_equal(@pubid1, @doctype.notation('n1').public)
|
47
|
+
assert_equal(@pubid2, @doctype.notation('n2').public)
|
48
|
+
assert_equal(@pubid3, @doctype.notation('n3').public)
|
49
|
+
assert_equal(@pubid4, @doctype.notation('n4').public)
|
50
|
+
# The TEST5 and TEST6 assertions have been commented out because
|
51
|
+
# REXML 3.1.2 does not parse the notations correctly.
|
52
|
+
#assert_equal(@pubid5, @doctype.notation('n5').public)
|
53
|
+
#assert_equal(@pubid6, @doctype.notation('n6').public)
|
54
|
+
assert_nil(@doctype.notation('n7').public)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_system
|
58
|
+
assert_equal(@sysid2, @doctype.notation('n2').system)
|
59
|
+
assert_nil(@doctype.notation('n3').system)
|
60
|
+
assert_equal(@sysid4, @doctype.notation('n4').system)
|
61
|
+
# The TEST5 and TEST6 assertions have been commented out because
|
62
|
+
# REXML 3.1.2 does not parse the notations correctly.
|
63
|
+
#assert_equal(@sysid5, @doctype.notation('n5').system)
|
64
|
+
#assert_equal(@sysid6, @doctype.notation('n6').system)
|
65
|
+
assert_equal(@sysid7, @doctype.notation('n7').system)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,315 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
@@lib_path = File.join(File.dirname(__FILE__), "..", "lib")
|
4
|
+
$:.unshift @@lib_path
|
5
|
+
|
6
|
+
require 'test/unit/xml'
|
7
|
+
require 'rexml/document'
|
8
|
+
require 'stringio'
|
9
|
+
|
10
|
+
class TestTestUnitXml < Test::Unit::TestCase
|
11
|
+
TEST_1_PATH = "test/data/test1.xml"
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@file = File.new(TEST_1_PATH)
|
15
|
+
@doc1 = REXML::Document.new(@file)
|
16
|
+
@io1 = File.new(TEST_1_PATH)
|
17
|
+
@io2 = File.new(TEST_1_PATH)
|
18
|
+
@string1 = %Q{<t:root xmlns:t="urn:x-hm:test" xmlns:x="urn:x-hm:test2" id="a" t:type="test1"/>}
|
19
|
+
@element1 = REXML::Document.new(%Q{<t:root xmlns:t="urn:x-hm:test" xmlns:x="urn:x-hm:test2" id="a" t:type="test1"/>}).root
|
20
|
+
@element2 = REXML::Document.new(%Q{<root xmlns:t="urn:x-hm:test" xmlns:x="urn:x-hm:test2" id="a" t:type="test1"/>}).root
|
21
|
+
@element3 = REXML::Document.new(%Q{<t:root xmlns:t="urn:x-hm:other" xmlns:x="urn:x-hm:test2" id="a" t:type="test1"/>}).root
|
22
|
+
@element4 = REXML::Document.new(%Q{<t:root xmlns:t="urn:x-hm:test" xmlns:x="urn:x-hm:test2" id="a" x:type="test1"/>}).root
|
23
|
+
@element5 = REXML::Document.new(%Q{<t:root xmlns:t="urn:x-hm:test" xmlns:x="urn:x-hm:test2" id="a" t:type="test2"/>}).root
|
24
|
+
@element6 = REXML::Document.new(%Q{<t:root id="a" xmlns:t="urn:x-hm:test" xmlns:x="urn:x-hm:test2" t:type="test1"/>}).root
|
25
|
+
@element7 = REXML::Document.new(%Q{<s:root xmlns:s="urn:x-hm:test" xmlns:x="urn:x-hm:test" id="a" s:type="test1"/>}).root
|
26
|
+
@element8 = REXML::Document.new(%Q{<t:root xmlns:t="urn:x-hm:test" id="a" t:type="test1"/>}).root
|
27
|
+
@text1 = REXML::Text.new(" Q")
|
28
|
+
@text2 = REXML::Text.new(" Q")
|
29
|
+
@text3 = REXML::Text.new(" Q ")
|
30
|
+
@cdata1 = REXML::CData.new("Test text")
|
31
|
+
@cdata2 = REXML::CData.new("Test \ntext")
|
32
|
+
@comment1 = REXML::Comment.new("This is a comment.")
|
33
|
+
@comment2 = REXML::Comment.new("This is another comment.")
|
34
|
+
@pi1 = REXML::Instruction.new('pi1', 'content')
|
35
|
+
@pi2 = REXML::Instruction.new('pi2', 'content')
|
36
|
+
@pi3 = REXML::Instruction.new('pi1', 'other content')
|
37
|
+
@whitespace1 = REXML::Document.new(%Q{<r><a>Some <b>text</b>.</a></r>})
|
38
|
+
@whitespace2 = REXML::Document.new(%Q{<r> <a>Some <b>text</b>.</a>\n \n </r>})
|
39
|
+
@whitespace3 = REXML::Document.new(%Q{<r><a>Some <b> text</b>.</a></r>})
|
40
|
+
# REXML:XMLDecl.new(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
|
41
|
+
@xml_decl1 = REXML::XMLDecl.new(1.0, "utf-8", "yes")
|
42
|
+
@xml_decl2 = REXML::XMLDecl.new(1.1, "utf-8", "yes")
|
43
|
+
@xml_decl3 = REXML::XMLDecl.new(1.0, "utf-16", "yes")
|
44
|
+
@xml_decl4 = REXML::XMLDecl.new(1.0, "utf-8", "no")
|
45
|
+
end
|
46
|
+
|
47
|
+
def teardown
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_assert_xml_equal_document
|
51
|
+
assert_xml_equal(@doc1, @doc1, "Comparing two REXML::Document objects")
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_assert_xml_equal_io
|
55
|
+
assert_xml_equal(@io1, @io2, "Comparing two IO objects")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_assert_xml_equal_string
|
59
|
+
assert_xml_equal(@string1, @string1, "Comparing two XML strings")
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_assert_xml_equal_element
|
63
|
+
assert_instance_of(REXML::Element, @element1)
|
64
|
+
assert_xml_equal(@element1, @element1)
|
65
|
+
check_assertion_failure(@element1, @element2)
|
66
|
+
check_assertion_failure(@element1, @element3)
|
67
|
+
check_assertion_failure(@element1, @element4)
|
68
|
+
check_assertion_failure(@element1, @element5)
|
69
|
+
assert_xml_equal(@element1, @element6)
|
70
|
+
assert_xml_equal(@element1, @element7)
|
71
|
+
assert_xml_equal(@element1, @element8)
|
72
|
+
end
|
73
|
+
|
74
|
+
def check_assertion_failure(expected, actual)
|
75
|
+
assert_raise(Test::Unit::AssertionFailedError) {
|
76
|
+
assert_xml_equal(expected, actual)
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_assert_xml_equal_text
|
81
|
+
assert_instance_of(REXML::Text, @text1)
|
82
|
+
assert_instance_of(REXML::Text, @text1)
|
83
|
+
assert_xml_equal(@text1, @text1)
|
84
|
+
assert_xml_equal(@text1, @text2)
|
85
|
+
check_assertion_failure(@text1, @text3)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_assert_xml_equal_cdata
|
89
|
+
assert_instance_of(REXML::CData, @cdata1)
|
90
|
+
assert_instance_of(REXML::CData, @cdata2)
|
91
|
+
assert_xml_equal(@cdata1, @cdata1)
|
92
|
+
check_assertion_failure(@cdata1, @cdata2)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_assert_xml_equal_comment
|
96
|
+
assert_instance_of(REXML::Comment, @comment1)
|
97
|
+
assert_instance_of(REXML::Comment, @comment2)
|
98
|
+
assert_xml_equal(@comment1, @comment1)
|
99
|
+
check_assertion_failure(@comment1, @comment2)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_assert_xml_equal_pi
|
103
|
+
assert_instance_of(REXML::Instruction, @pi1)
|
104
|
+
assert_instance_of(REXML::Instruction, @pi2)
|
105
|
+
assert_instance_of(REXML::Instruction, @pi3)
|
106
|
+
assert_xml_equal(@pi1, @pi1)
|
107
|
+
check_assertion_failure(@pi1, @pi2)
|
108
|
+
check_assertion_failure(@pi1, @pi3)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_assert_xml_equal_whitespace
|
112
|
+
assert_xml_equal(@whitespace1, @whitespace1)
|
113
|
+
assert_xml_equal(@whitespace1, @whitespace2, "Check if extraneous whitespace is skipped")
|
114
|
+
check_assertion_failure(@whitespace1, @whitespace3)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_assert_xml_equal_xmldecl
|
118
|
+
assert_instance_of(REXML::XMLDecl, @xml_decl1)
|
119
|
+
assert_xml_equal(@xml_decl1, @xml_decl1)
|
120
|
+
check_assertion_failure(@xml_decl1, @xml_decl2)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_assert_xml_equal_doctype
|
124
|
+
string1 = <<-'XMLEND'
|
125
|
+
<!DOCTYPE r PUBLIC "TEST1" "http://www.henrikmartensson.org/dtd1">
|
126
|
+
<r/>
|
127
|
+
XMLEND
|
128
|
+
string2 = <<-'XMLEND'
|
129
|
+
<!DOCTYPE r PUBLIC "TEST1" "http://www.henrikmartensson.org/dtd2">
|
130
|
+
<r/>
|
131
|
+
XMLEND
|
132
|
+
string3 = <<-'XMLEND'
|
133
|
+
<!DOCTYPE r PUBLIC "TEST2" "http://www.henrikmartensson.org/dtd1">
|
134
|
+
<r/>
|
135
|
+
XMLEND
|
136
|
+
string4 = <<-'XMLEND'
|
137
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1">
|
138
|
+
<r/>
|
139
|
+
XMLEND
|
140
|
+
string5 = <<-'XMLEND'
|
141
|
+
<!DOCTYPE r SYSTEM "urn:x-henrikmartensson.org:dtd1">
|
142
|
+
<r/>
|
143
|
+
XMLEND
|
144
|
+
string6 = <<-'XMLEND'
|
145
|
+
<!DOCTYPE r SYSTEM "urn:x-henrikmartensson.org:dtd2">
|
146
|
+
<r/>
|
147
|
+
XMLEND
|
148
|
+
assert_xml_equal(string1, string1)
|
149
|
+
assert_xml_equal(string1, string2)
|
150
|
+
check_assertion_failure(string1, string3)
|
151
|
+
check_assertion_failure(string1, string4)
|
152
|
+
check_assertion_failure(string1, string5)
|
153
|
+
assert_xml_equal(string5, string5)
|
154
|
+
check_assertion_failure(string5, string6)
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_assert_xml_equal_internal_entity_decl
|
158
|
+
string1 = <<-'XMLEND'
|
159
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
160
|
+
<!ENTITY internal1 "This is an internal entity">
|
161
|
+
]>
|
162
|
+
<r/>
|
163
|
+
XMLEND
|
164
|
+
string2 = <<-'XMLEND'
|
165
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
166
|
+
<!ENTITY internal1 "This is another internal entity">
|
167
|
+
]>
|
168
|
+
<r>&internal1;</r>
|
169
|
+
XMLEND
|
170
|
+
string3 = <<-'XMLEND'
|
171
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
172
|
+
<!ENTITY internal1 "This is an internal entity">
|
173
|
+
<!ENTITY internal2 "This is another internal entity">
|
174
|
+
]>
|
175
|
+
<r>&internal1;</r>
|
176
|
+
XMLEND
|
177
|
+
string4 = <<-'XMLEND'
|
178
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
179
|
+
<!ENTITY internal2 "This is another internal entity">
|
180
|
+
<!ENTITY internal1 "This is an internal entity">
|
181
|
+
]>
|
182
|
+
<r>&internal1;</r>
|
183
|
+
XMLEND
|
184
|
+
string5 = <<-'XMLEND'
|
185
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
186
|
+
<!ENTITY internal1 "This is an internal entity">
|
187
|
+
<!ENTITY internal2 "This is another internal entity">
|
188
|
+
<!ENTITY internal3 "This is a third internal entity">
|
189
|
+
]>
|
190
|
+
<r>&internal1;</r>
|
191
|
+
XMLEND
|
192
|
+
assert_xml_equal(string1, string1)
|
193
|
+
check_assertion_failure(string1, string2)
|
194
|
+
check_assertion_failure(string1, string3)
|
195
|
+
check_assertion_failure(string3, string1)
|
196
|
+
assert_xml_equal(string3, string4,"Testing that entities may be declared in any order")
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_assert_xml_equal_external_entity_decl
|
200
|
+
string1 = <<-'XMLEND'
|
201
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
202
|
+
<!NOTATION pdf SYSTEM "pdf">
|
203
|
+
<!NOTATION word SYSTEM "word">
|
204
|
+
<!ENTITY external1 SYSTEM "urn:x-henrikmartensson.org:resource1" NDATA pdf>
|
205
|
+
]>
|
206
|
+
<r/>
|
207
|
+
XMLEND
|
208
|
+
string2 = <<-'XMLEND'
|
209
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
210
|
+
<!NOTATION pdf SYSTEM "pdf">
|
211
|
+
<!NOTATION word SYSTEM "word">
|
212
|
+
<!ENTITY external1 SYSTEM "urn:x-henrikmartensson.org:resource1" NDATA word>
|
213
|
+
]>
|
214
|
+
<r/>
|
215
|
+
XMLEND
|
216
|
+
string3 = <<-'XMLEND'
|
217
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
218
|
+
<!NOTATION pdf SYSTEM "pdf">
|
219
|
+
<!ENTITY external1 SYSTEM "urn:x-henrikmartensson.org:resource1" NDATA pdf>
|
220
|
+
<!NOTATION word SYSTEM "word">
|
221
|
+
]>
|
222
|
+
<r/>
|
223
|
+
XMLEND
|
224
|
+
assert_xml_equal(string1, string1)
|
225
|
+
check_assertion_failure(string1, string2)
|
226
|
+
assert_xml_equal(string1, string3)
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_assert_xml_equal_notation_decl
|
230
|
+
string1 = <<-'XMLEND'
|
231
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
232
|
+
<!NOTATION pdf SYSTEM "pdf">
|
233
|
+
]>
|
234
|
+
<r/>
|
235
|
+
XMLEND
|
236
|
+
string2 = <<-'XMLEND'
|
237
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
238
|
+
<!NOTATION pdf PUBLIC "pdf">
|
239
|
+
]>
|
240
|
+
<r/>
|
241
|
+
XMLEND
|
242
|
+
string3 = <<-'XMLEND'
|
243
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
244
|
+
<!NOTATION pdf SYSTEM "word">
|
245
|
+
]>
|
246
|
+
<r/>
|
247
|
+
XMLEND
|
248
|
+
assert_xml_equal(string1, string1)
|
249
|
+
check_assertion_failure(string1, string2)
|
250
|
+
check_assertion_failure(string1, string3)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_assert_xml_equal_doctype_comment
|
254
|
+
string1 = <<-'XMLEND'
|
255
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
256
|
+
<!NOTATION pdf SYSTEM "pdf">
|
257
|
+
<!-- A comment -->
|
258
|
+
]>
|
259
|
+
<r/>
|
260
|
+
XMLEND
|
261
|
+
string2 = <<-'XMLEND'
|
262
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
263
|
+
<!-- A comment -->
|
264
|
+
<!NOTATION pdf SYSTEM "pdf">
|
265
|
+
]>
|
266
|
+
<r/>
|
267
|
+
XMLEND
|
268
|
+
string3 = <<-'XMLEND'
|
269
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
270
|
+
<!NOTATION pdf SYSTEM "pdf">
|
271
|
+
<!-- A different comment -->
|
272
|
+
]>
|
273
|
+
<r/>
|
274
|
+
XMLEND
|
275
|
+
string4 = <<-'XMLEND'
|
276
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
277
|
+
<!-- A comment -->
|
278
|
+
<!-- Another comment -->
|
279
|
+
]>
|
280
|
+
<r/>
|
281
|
+
XMLEND
|
282
|
+
string5 = <<-'XMLEND'
|
283
|
+
<!DOCTYPE r SYSTEM "http://www.henrikmartensson.org/dtd1" [
|
284
|
+
<!-- Another comment -->
|
285
|
+
<!-- A comment -->
|
286
|
+
]>
|
287
|
+
<r/>
|
288
|
+
XMLEND
|
289
|
+
assert_xml_equal(string1, string2)
|
290
|
+
check_assertion_failure(string1, string3)
|
291
|
+
check_assertion_failure(string4, string5)
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_xml_not_equal
|
295
|
+
assert_xml_not_equal(@element1, @element2)
|
296
|
+
assert_xml_not_equal(@element1, @element3)
|
297
|
+
assert_xml_not_equal(@element1, @element4)
|
298
|
+
assert_xml_not_equal(@element1, @element5)
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_entity_in_attribute
|
302
|
+
# This test was propmpted by a bug report from
|
303
|
+
# Paul Battley
|
304
|
+
xml_string = '<root text="This & that"/>'
|
305
|
+
doc_original = REXML::Document.new(xml_string)
|
306
|
+
doc_clone = doc_original.dup
|
307
|
+
assert_xml_equal(doc_original, doc_clone)
|
308
|
+
|
309
|
+
xml_different = '<root text="this & that"/>'
|
310
|
+
doc_different = REXML::Document.new(xml_different)
|
311
|
+
assert_xml_not_equal(doc_original, doc_different)
|
312
|
+
end
|
313
|
+
|
314
|
+
|
315
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Henrik Mårtensson on 2007-02-17.
|
4
|
+
# Copyright (c) 2007. All rights reserved.
|
5
|
+
@@lib_path = File.join(File.dirname(__FILE__), "..", "lib")
|
6
|
+
$:.unshift @@lib_path
|
7
|
+
|
8
|
+
require "test/unit"
|
9
|
+
|
10
|
+
require "test/unit/xml"
|
11
|
+
|
12
|
+
class TestTestUnitXml2 < Test::Unit::TestCase
|
13
|
+
|
14
|
+
# <?xml version="1.0" encoding="utf-8"?>
|
15
|
+
def test_soap_message
|
16
|
+
expected = <<-end_xml
|
17
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
18
|
+
<soap:Body>
|
19
|
+
<TestThing><SomeStringValue>soaptastic</SomeStringValue></TestThing>
|
20
|
+
</soap:Body>
|
21
|
+
</soap:Envelope>
|
22
|
+
end_xml
|
23
|
+
actual = <<-end_xml
|
24
|
+
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
25
|
+
<soap:Body>
|
26
|
+
<TestThing/>
|
27
|
+
</soap:Body>
|
28
|
+
</soap:Envelope>
|
29
|
+
end_xml
|
30
|
+
assert_xml_not_equal expected, actual, "Documents expected not to be equal, but were equal."
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
@@lib_path = File.join(File.dirname(__FILE__), "..", "lib")
|
4
|
+
$:.unshift @@lib_path
|
5
|
+
$:.unshift File.dirname(__FILE__)
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
Dir.foreach(File.dirname(__FILE__)) { |file|
|
10
|
+
load file if file =~ /^tc.+\.rb$/
|
11
|
+
}
|
12
|
+
|