testunitxml 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/docs/html/classes/REXML.html +111 -0
  2. data/docs/html/classes/REXML/Attributes.html +151 -0
  3. data/docs/html/classes/REXML/Attributes.src/M000001.html +24 -0
  4. data/docs/html/classes/Test.html +131 -0
  5. data/docs/html/classes/Test/Unit.html +124 -0
  6. data/docs/html/classes/Test/Unit/TestCase.html +125 -0
  7. data/docs/html/classes/Test/Unit/XML.html +237 -0
  8. data/docs/html/classes/Test/Unit/XML.src/M000002.html +23 -0
  9. data/docs/html/classes/Test/Unit/XML/NodeIterator.html +195 -0
  10. data/docs/html/classes/Test/Unit/XML/NodeIterator.src/M000003.html +27 -0
  11. data/docs/html/classes/Test/Unit/XML/NodeIterator.src/M000004.html +19 -0
  12. data/docs/html/classes/Test/Unit/XML/NodeIterator.src/M000005.html +18 -0
  13. data/docs/html/classes/Test/Unit/XML/NodeIterator.src/M000006.html +20 -0
  14. data/docs/html/classes/Test/Unit/XML/NodeIterator/NullNodeFilter.html +137 -0
  15. data/docs/html/classes/Test/Unit/XML/NodeIterator/NullNodeFilter.src/M000007.html +18 -0
  16. data/docs/html/classes/Test/Unit/XML/XmlEqualFilter.html +144 -0
  17. data/docs/html/classes/Test/Unit/XML/XmlEqualFilter.src/M000008.html +23 -0
  18. data/docs/html/created.rid +1 -0
  19. data/docs/html/files/MIT-LICENSE.html +130 -0
  20. data/docs/html/files/README.html +226 -0
  21. data/docs/html/files/lib/test/unit/xml/attributes_mixin_rb.html +101 -0
  22. data/docs/html/files/lib/test/unit/xml/nodeiterator_rb.html +101 -0
  23. data/docs/html/files/lib/test/unit/xml/xml_assertions_rb.html +112 -0
  24. data/docs/html/files/lib/test/unit/xml/xmlequalfilter_rb.html +101 -0
  25. data/docs/html/files/lib/test/unit/xml_rb.html +120 -0
  26. data/docs/html/fr_class_index.html +35 -0
  27. data/docs/html/fr_file_index.html +33 -0
  28. data/docs/html/fr_method_index.html +34 -0
  29. data/docs/html/index.html +24 -0
  30. data/lib/test/unit/xml.rb +21 -0
  31. data/lib/test/unit/xml/attributes_mixin.rb +21 -0
  32. data/lib/test/unit/xml/nodeiterator.rb +61 -0
  33. data/lib/test/unit/xml/xml_assertions.rb +187 -0
  34. data/lib/test/unit/xml/xmlequalfilter.rb +27 -0
  35. data/test/data/test1.xml +23 -0
  36. data/test/tc_testunitxml.rb +123 -0
  37. metadata +101 -0
@@ -0,0 +1,187 @@
1
+ #! /usr/bin/ruby
2
+
3
+ require 'rexml/document'
4
+ require 'test/unit/xml/attributes_mixin' # Must be required after rexml/document
5
+ require 'test/unit'
6
+ require 'test/unit/xml/xmlequalfilter'
7
+ require 'test/unit/xml/nodeiterator'
8
+
9
+ =begin rdoc
10
+ This module contains assertions about XML documents. The assertions are
11
+ meant to be mixed in to test classes such as Test::Unit::TestCase.
12
+ =end
13
+ module Test
14
+ module Unit
15
+ module XML
16
+
17
+ # This method checks whether two well-formed XML documents are equal.
18
+ # Doctype declarations are ignored for the purposes of comparison.
19
+ # Two XML documents are considered equal if:
20
+ # * They contain the same type of nodes, in the same order,
21
+ # except for text nodes that are empty, or contain only
22
+ # whitespace. Such text nodes are ignored.
23
+ # * The corresponding nodes in the two documents are equal.
24
+ #
25
+ # Nodes are tested for equality as follows:
26
+ # XML Declarations::
27
+ # XML declarations are equal if they have the same version,
28
+ # encoding, and stand-alone pseudo-attributes.
29
+ # Doctype::
30
+ # Doctype declarations are ignored.
31
+ # Elements::
32
+ # Elements are considered equal if they have the same generic
33
+ # identifier (tag name) and belong to the same namespace. The
34
+ # namespace _prefixes_ may be different.
35
+ # Attributes::
36
+ # Attributes are equal if they belong to the same namespace,
37
+ # have the same name, and the same value.
38
+ # Namespace Declarations::
39
+ # Namespace _declarations_ (attributes named <tt>xmlns:<em>prefix</em></tt>)
40
+ # are ignored. There are several reasons for this:
41
+ # - As long as two elements or attributes
42
+ # belong to the same namespace, it does not matter what prefixes
43
+ # are used. XML processors may also change prefixes in unpredictable
44
+ # ways without this being an error.
45
+ # - XML processors may _move_ namespace
46
+ # declarations from one element to another (usually an ancestor,
47
+ # sometimes a descendant) without this being an error, or under
48
+ # control by the programmer.
49
+ # - XML processors may _add_ extraneous namespace declarations
50
+ # in a manner that is hard for programmers to control.
51
+ # Processing Instructions::
52
+ # Processing instructions are considered equal if the string
53
+ # values of their targets and contents are equal.
54
+ # Text::
55
+ # Text nodes are equal if their values are equal. However, empty
56
+ # text nodes, and text nodes containing only whitespace are ignored.
57
+ # CDATA::
58
+ # CDATA nodes are equal if their text content is equal. Whitespace
59
+ # is _not_ normalized.
60
+ # Comments::
61
+ # Comments are equal if they have the same content.
62
+ #
63
+ # The +expected_doc+ and +actual_doc+ arguments to this method may be of
64
+ # the following types:
65
+ # * A +REXML+ node, usually a <tt>REXML::Document</tt> or <tt>REXML::Element</tt>
66
+ # * A +File+ or other +IO+ object representing an XML document
67
+ # * A string containing an XML document
68
+ def assert_xml_equal(expected_doc, actual_doc, message = nil)
69
+ expected_doc = parse_xml(expected_doc)
70
+ actual_doc = parse_xml(actual_doc)
71
+ _wrap_assertion do
72
+ full_message = build_message(message, <<EOT, actual_doc.inspect, expected_doc.inspect)
73
+
74
+ <?> expected to be equal to
75
+ <?> but was not.
76
+ EOT
77
+ assert_block(full_message){are_equal?(expected_doc, actual_doc)}
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def parse_xml(xml)
84
+ case xml
85
+ when IO
86
+ REXML::Document.new(xml)
87
+ when String
88
+ REXML::Document.new(xml)
89
+ else
90
+ xml
91
+ end
92
+ end
93
+
94
+ def are_equal?(expected_doc, actual_doc)
95
+ iterate(expected_doc, actual_doc) do |expected_node, actual_node|
96
+ unless compare_xml_nodes(expected_node, actual_node)
97
+ return false
98
+ end
99
+ end
100
+ true
101
+ end
102
+
103
+ def iterate(expected_doc, actual_doc)
104
+ filter = Test::Unit::XML::XmlEqualFilter.new()
105
+ expected_iterator = NodeIterator.new(expected_doc, filter)
106
+ actual_iterator = NodeIterator.new(actual_doc, filter)
107
+ while expected_iterator.has_next()
108
+ expected_node = expected_iterator.next()
109
+ actual_node = actual_iterator.next()
110
+ yield expected_node, actual_node
111
+ end
112
+ end
113
+
114
+ def compare_xml_nodes(expected_node, actual_node)
115
+ return false unless actual_node.instance_of? expected_node.class
116
+ case actual_node
117
+ when REXML::Document
118
+ # TODO: Implement Document comparison
119
+ true
120
+ when REXML::DocType
121
+ # TODO: Implement DOCTYPE comparison
122
+ true
123
+ when REXML::Element :
124
+ compare_elements(expected_node, actual_node)
125
+ when REXML::CData
126
+ compare_texts(expected_node, actual_node)
127
+ when REXML::Text
128
+ compare_texts(expected_node, actual_node)
129
+ when REXML::Comment
130
+ compare_comments(expected_node, actual_node)
131
+ when REXML::Instruction
132
+ compare_pi(expected_node, actual_node)
133
+ when REXML::XMLDecl
134
+ compare_xml_declaration(expected_node, actual_node)
135
+ else
136
+ puts "Unknown node type #{actual_node.class}"
137
+ false
138
+ end
139
+ end
140
+
141
+ def compare_elements(expected_node, actual_node)
142
+ return expected_node.name == actual_node.name &&
143
+ expected_node.namespace() == actual_node.namespace() &&
144
+ compare_attributes(expected_node.attributes, actual_node.attributes)
145
+ end
146
+
147
+ def compare_attributes(expected_attributes, actual_attributes)
148
+ return false unless attribute_count(expected_attributes) == attribute_count(actual_attributes)
149
+ expected_attributes.each_attribute do |expected_attribute|
150
+ expected_prefix = expected_attribute.prefix()
151
+ unless expected_prefix == 'xmlns' then
152
+ expected_name = expected_attribute.name
153
+ expected_namespace = expected_attribute.namespace
154
+ actual_attribute = actual_attributes.get_attribute_ns(expected_namespace, expected_name)
155
+ return false unless actual_attribute
156
+ return false if expected_attribute != actual_attribute
157
+ end
158
+ end
159
+ true
160
+ end
161
+
162
+ def attribute_count(attributes)
163
+ # Do not count namespace declarations
164
+ attributes.size - attributes.prefixes.size
165
+ end
166
+
167
+ def compare_texts(expected_node, actual_node)
168
+ expected_node.value.eql?(actual_node.value)
169
+ end
170
+
171
+ def compare_comments(expected_node, actual_node)
172
+ expected_node == actual_node
173
+ end
174
+
175
+ def compare_pi(expected_pi, actual_pi)
176
+ return expected_pi.target == actual_pi.target &&
177
+ expected_pi.content == actual_pi.content
178
+ end
179
+
180
+ def compare_xml_declaration(expected_decl, actual_decl)
181
+ return expected_decl == actual_decl
182
+ end
183
+
184
+ end
185
+ end
186
+ end
187
+
@@ -0,0 +1,27 @@
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
+ else
15
+ true
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def is_significant?(string)
22
+ string =~ /^\s*$/ ? false : true
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -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,123 @@
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(" &#81;")
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
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: testunitxml
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.3
7
+ date: 2006-01-11 00:00:00 +01:00
8
+ summary: Unit test suite for XML documents
9
+ require_paths:
10
+ - lib
11
+ email: self@henrikmartensson.org
12
+ homepage: http://testunitxml.rubyforge.org/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: test/unit/xml
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Henrik Martensson
30
+ files:
31
+ - docs/html
32
+ - docs/html/created.rid
33
+ - docs/html/files
34
+ - docs/html/classes
35
+ - docs/html/fr_file_index.html
36
+ - docs/html/fr_class_index.html
37
+ - docs/html/fr_method_index.html
38
+ - docs/html/index.html
39
+ - docs/html/files/README.html
40
+ - docs/html/files/MIT-LICENSE.html
41
+ - docs/html/files/lib
42
+ - docs/html/files/lib/test
43
+ - docs/html/files/lib/test/unit
44
+ - docs/html/files/lib/test/unit/xml_rb.html
45
+ - docs/html/files/lib/test/unit/xml
46
+ - docs/html/files/lib/test/unit/xml/xmlequalfilter_rb.html
47
+ - docs/html/files/lib/test/unit/xml/nodeiterator_rb.html
48
+ - docs/html/files/lib/test/unit/xml/attributes_mixin_rb.html
49
+ - docs/html/files/lib/test/unit/xml/xml_assertions_rb.html
50
+ - docs/html/classes/REXML
51
+ - docs/html/classes/Test
52
+ - docs/html/classes/REXML.html
53
+ - docs/html/classes/Test.html
54
+ - docs/html/classes/REXML/Attributes.src
55
+ - docs/html/classes/REXML/Attributes.html
56
+ - docs/html/classes/REXML/Attributes.src/M000001.html
57
+ - docs/html/classes/Test/Unit
58
+ - docs/html/classes/Test/Unit.html
59
+ - docs/html/classes/Test/Unit/XML.src
60
+ - docs/html/classes/Test/Unit/XML
61
+ - docs/html/classes/Test/Unit/XML.html
62
+ - docs/html/classes/Test/Unit/TestCase.html
63
+ - docs/html/classes/Test/Unit/XML.src/M000002.html
64
+ - docs/html/classes/Test/Unit/XML/NodeIterator.src
65
+ - docs/html/classes/Test/Unit/XML/NodeIterator
66
+ - docs/html/classes/Test/Unit/XML/XmlEqualFilter.src
67
+ - docs/html/classes/Test/Unit/XML/NodeIterator.html
68
+ - docs/html/classes/Test/Unit/XML/XmlEqualFilter.html
69
+ - docs/html/classes/Test/Unit/XML/NodeIterator.src/M000003.html
70
+ - docs/html/classes/Test/Unit/XML/NodeIterator.src/M000004.html
71
+ - docs/html/classes/Test/Unit/XML/NodeIterator.src/M000005.html
72
+ - docs/html/classes/Test/Unit/XML/NodeIterator.src/M000006.html
73
+ - docs/html/classes/Test/Unit/XML/NodeIterator/NullNodeFilter.src
74
+ - docs/html/classes/Test/Unit/XML/NodeIterator/NullNodeFilter.html
75
+ - docs/html/classes/Test/Unit/XML/NodeIterator/NullNodeFilter.src/M000007.html
76
+ - docs/html/classes/Test/Unit/XML/XmlEqualFilter.src/M000008.html
77
+ - lib/test
78
+ - lib/test/unit
79
+ - lib/test/unit/xml
80
+ - lib/test/unit/xml.rb
81
+ - lib/test/unit/xml/xmlequalfilter.rb
82
+ - lib/test/unit/xml/nodeiterator.rb
83
+ - lib/test/unit/xml/attributes_mixin.rb
84
+ - lib/test/unit/xml/xml_assertions.rb
85
+ - test/data
86
+ - test/tc_testunitxml.rb
87
+ - test/data/test1.xml
88
+ test_files:
89
+ - test/tc_testunitxml.rb
90
+ rdoc_options: []
91
+
92
+ extra_rdoc_files: []
93
+
94
+ executables: []
95
+
96
+ extensions: []
97
+
98
+ requirements: []
99
+
100
+ dependencies: []
101
+