xqsr3 0.26.4 → 0.27.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xqsr3/version.rb +2 -2
- data/lib/xqsr3/xml/utilities/compare.rb +57 -7
- data/lib/xqsr3/xml/utilities/navigation.rb +108 -0
- data/test/unit/quality/tc_parameter_checking.rb +1 -0
- data/test/unit/xml/utilities/tc_compare.rb +68 -0
- data/test/unit/xml/utilities/tc_navigation.rb +55 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 786185c865b23fafc7fc1ebc7d81cf0bf5f39f36
|
4
|
+
data.tar.gz: a16dcecb9fed63c95545371cae951c4ced42f43f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '098d22e4dbee898ba1ab8f44ffa48114890a5c289afcf079ec5da96809e5218d387ff614fb049601d4cfadf8a3976d2066d0fe86f8a772d0ed07d75186a93f03'
|
7
|
+
data.tar.gz: 565ce70a0c6ecbc82f87d9c57e534fddceaab7a8c33c71ee568385b4edda3406693f4c7a7e82265bef85d1016fd6adf9fc3a3c8af68a7eecea166abe3035a5ea
|
data/lib/xqsr3/version.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Version for Xqsr3 library
|
6
6
|
#
|
7
7
|
# Created: 3rd April 2016
|
8
|
-
# Updated:
|
8
|
+
# Updated: 24th August 2018
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
@@ -50,7 +50,7 @@
|
|
50
50
|
module Xqsr3
|
51
51
|
|
52
52
|
# Current version of the Xqsr3 library
|
53
|
-
VERSION = '0.
|
53
|
+
VERSION = '0.27.2'
|
54
54
|
|
55
55
|
private
|
56
56
|
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# module
|
7
7
|
#
|
8
8
|
# Created: 30th July 2017
|
9
|
-
# Updated:
|
9
|
+
# Updated: 16th August 2018
|
10
10
|
#
|
11
11
|
# Home: http://github.com/synesissoftware/xqsr3
|
12
12
|
#
|
@@ -51,6 +51,8 @@
|
|
51
51
|
=begin
|
52
52
|
=end
|
53
53
|
|
54
|
+
require 'xqsr3/xml/utilities/navigation'
|
55
|
+
|
54
56
|
require 'xqsr3/quality/parameter_checking'
|
55
57
|
|
56
58
|
require 'nokogiri'
|
@@ -89,6 +91,8 @@ module Compare
|
|
89
91
|
|
90
92
|
def initialize status, reason, **options
|
91
93
|
|
94
|
+
@call_stack = caller(2)
|
95
|
+
|
92
96
|
check_parameter status, 'status', types: [ ::FalseClass, ::TrueClass ]
|
93
97
|
check_parameter reason, 'reason', type: ::Symbol, allow_nil: true
|
94
98
|
|
@@ -114,8 +118,9 @@ module Compare
|
|
114
118
|
return self.new false, reason, **options
|
115
119
|
end
|
116
120
|
|
117
|
-
attr_reader
|
118
|
-
attr_reader
|
121
|
+
attr_reader :call_stack
|
122
|
+
attr_reader :status
|
123
|
+
attr_reader :reason
|
119
124
|
|
120
125
|
def different?
|
121
126
|
|
@@ -160,6 +165,8 @@ module Compare
|
|
160
165
|
|
161
166
|
module Internal_Compare_
|
162
167
|
|
168
|
+
include ::Xqsr3::XML::Utilities::Navigation
|
169
|
+
|
163
170
|
extend ::Xqsr3::Quality::ParameterChecking
|
164
171
|
|
165
172
|
DEFAULT_OPTIONS = {
|
@@ -170,6 +177,8 @@ module Compare
|
|
170
177
|
ignore_attributes: false,
|
171
178
|
ignore_attribute_order: true,
|
172
179
|
ignore_child_node_order: true,
|
180
|
+
ignore_content: false,
|
181
|
+
ignore_content_case: false,
|
173
182
|
ignore_xml_declarations: true,
|
174
183
|
normalise_whitespace: true,
|
175
184
|
# normalize_whitespace: true,
|
@@ -181,6 +190,8 @@ module Compare
|
|
181
190
|
:element_order,
|
182
191
|
:ignore_attribute_order,
|
183
192
|
:ignore_child_node_order,
|
193
|
+
:ignore_content,
|
194
|
+
:ignore_content_case,
|
184
195
|
]
|
185
196
|
|
186
197
|
WHITESPACE_OPTIONS_SYMBOLS = [
|
@@ -384,12 +395,48 @@ module Compare
|
|
384
395
|
# ##########################
|
385
396
|
# content
|
386
397
|
|
387
|
-
|
398
|
+
unless options[:ignore_content]
|
399
|
+
|
400
|
+
lhs_texts = self.get_descendants(lhs).select { |el| el.text? }.map { |el| el.content }
|
401
|
+
rhs_texts = self.get_descendants(rhs).select { |el| el.text? }.map { |el| el.content }
|
388
402
|
|
389
|
-
|
390
|
-
rhs_content = normalise_ws ? rhs.content.gsub(/\s+/, ' ').strip : rhs.content
|
403
|
+
content_same = lhs_texts == rhs_texts
|
391
404
|
|
392
|
-
|
405
|
+
unless content_same
|
406
|
+
|
407
|
+
if options[:normalise_whitespace]
|
408
|
+
|
409
|
+
lhs_texts = lhs_texts.reject { |s| s.strip.empty? }
|
410
|
+
rhs_texts = rhs_texts.reject { |s| s.strip.empty? }
|
411
|
+
|
412
|
+
content_same = lhs_texts == rhs_texts
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
unless content_same
|
417
|
+
|
418
|
+
if options[:ignore_content_case]
|
419
|
+
|
420
|
+
lhs_texts = lhs_texts.reject { |s| s.downcase }
|
421
|
+
rhs_texts = rhs_texts.reject { |s| s.downcase }
|
422
|
+
|
423
|
+
content_same = lhs_texts == rhs_texts
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
unless content_same
|
428
|
+
|
429
|
+
if options[:ignore_child_node_order]
|
430
|
+
|
431
|
+
lhs_texts = lhs_texts.sort
|
432
|
+
rhs_texts = rhs_texts.sort
|
433
|
+
|
434
|
+
content_same = lhs_texts == rhs_texts
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
return Result.different :different_node_contents, lhs_node: lhs, rhs_node: rhs unless content_same
|
439
|
+
end
|
393
440
|
|
394
441
|
|
395
442
|
# ##########################
|
@@ -492,3 +539,6 @@ end # module Utilities
|
|
492
539
|
end # module XML
|
493
540
|
end # module Xqsr3
|
494
541
|
|
542
|
+
# ############################## end of file ############################# #
|
543
|
+
|
544
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: lib/xqsr3/xml/_utilities/navigation.rb
|
4
|
+
#
|
5
|
+
# Purpose: Definition of the ::Xqsr3::XML::Utilities::Navigation
|
6
|
+
# module
|
7
|
+
#
|
8
|
+
# Created: 7th August 2018
|
9
|
+
# Updated: 7th August 2018
|
10
|
+
#
|
11
|
+
# Home: http://github.com/synesissoftware/xqsr3
|
12
|
+
#
|
13
|
+
# Author: Matthew Wilson
|
14
|
+
#
|
15
|
+
# Copyright (c) 2018, Matthew Wilson and Synesis Software
|
16
|
+
# All rights reserved.
|
17
|
+
#
|
18
|
+
# Redistribution and use in source and binary forms, with or without
|
19
|
+
# modification, are permitted provided that the following conditions are
|
20
|
+
# met:
|
21
|
+
#
|
22
|
+
# * Redistributions of source code must retain the above copyright notice,
|
23
|
+
# this list of conditions and the following disclaimer.
|
24
|
+
#
|
25
|
+
# * Redistributions in binary form must reproduce the above copyright
|
26
|
+
# notice, this list of conditions and the following disclaimer in the
|
27
|
+
# documentation and/or other materials provided with the distribution.
|
28
|
+
#
|
29
|
+
# * Neither the names of the copyright holder nor the names of its
|
30
|
+
# contributors may be used to endorse or promote products derived from
|
31
|
+
# this software without specific prior written permission.
|
32
|
+
#
|
33
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
34
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
35
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
36
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
37
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
38
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
39
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
40
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
41
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
42
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
43
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
44
|
+
#
|
45
|
+
# ######################################################################## #
|
46
|
+
|
47
|
+
|
48
|
+
# ##########################################################
|
49
|
+
# ::Xqsr3::XML::Utilities::Navigation
|
50
|
+
|
51
|
+
=begin
|
52
|
+
=end
|
53
|
+
|
54
|
+
require 'xqsr3/quality/parameter_checking'
|
55
|
+
|
56
|
+
require 'nokogiri'
|
57
|
+
|
58
|
+
module Xqsr3
|
59
|
+
module XML
|
60
|
+
module Utilities
|
61
|
+
|
62
|
+
module Navigation
|
63
|
+
|
64
|
+
module Internal_Compare_
|
65
|
+
|
66
|
+
extend ::Xqsr3::Quality::ParameterChecking
|
67
|
+
|
68
|
+
def self.get_descendants node
|
69
|
+
|
70
|
+
descendants = []
|
71
|
+
|
72
|
+
node.children.each do |child|
|
73
|
+
|
74
|
+
descendants << child
|
75
|
+
|
76
|
+
descendants += self.get_descendants child
|
77
|
+
end
|
78
|
+
|
79
|
+
descendants
|
80
|
+
end
|
81
|
+
end # module Internal_Compare_
|
82
|
+
|
83
|
+
def self.included receiver
|
84
|
+
|
85
|
+
def receiver.get_descendants node
|
86
|
+
|
87
|
+
Internal_Compare_.get_descendants node
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.get_descendants node
|
92
|
+
|
93
|
+
Internal_Compare_.get_descendants node
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_descendants
|
97
|
+
|
98
|
+
Internal_Compare_.get_descendants self
|
99
|
+
end
|
100
|
+
end # module Navigation
|
101
|
+
|
102
|
+
end # module Utilities
|
103
|
+
end # module XML
|
104
|
+
end # module Xqsr3
|
105
|
+
|
106
|
+
# ############################## end of file ############################# #
|
107
|
+
|
108
|
+
|
@@ -184,5 +184,73 @@ END_OF_rhs_doc
|
|
184
184
|
|
185
185
|
assert r.same?, "#{r.details}"
|
186
186
|
end
|
187
|
+
|
188
|
+
def test_different_node_contents_by_child_node_order
|
189
|
+
|
190
|
+
lhs_str = <<END_OF_lhs_doc
|
191
|
+
<?xml version="1.0"?>
|
192
|
+
<outer>
|
193
|
+
<mid_1>
|
194
|
+
<inner>some text</inner>
|
195
|
+
</mid_1>
|
196
|
+
<mid_2>
|
197
|
+
<inner>some more text</inner>
|
198
|
+
</mid_2>
|
199
|
+
</outer>
|
200
|
+
END_OF_lhs_doc
|
201
|
+
|
202
|
+
rhs_str = <<END_OF_rhs_doc
|
203
|
+
<?xml version="1.0"?>
|
204
|
+
<outer>
|
205
|
+
<mid_2>
|
206
|
+
<inner>some more text</inner>
|
207
|
+
</mid_2>
|
208
|
+
<mid_1>
|
209
|
+
<inner>some text</inner>
|
210
|
+
</mid_1>
|
211
|
+
</outer>
|
212
|
+
END_OF_rhs_doc
|
213
|
+
|
214
|
+
lhs_doc = Nokogiri::XML lhs_str
|
215
|
+
rhs_doc = Nokogiri::XML rhs_str
|
216
|
+
|
217
|
+
expected = rhs_doc
|
218
|
+
actual = lhs_doc
|
219
|
+
|
220
|
+
r = xml_compare expected, actual, ignore_child_node_order: true, normalise_whitespace: true, ignore_xml_declarations: true
|
221
|
+
|
222
|
+
assert r.same?, "#{r.details}"
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_different_node_contents_by_child_node_order_and_whitespace
|
226
|
+
|
227
|
+
lhs_str = <<END_OF_lhs_doc
|
228
|
+
<?xml version="1.0"?>
|
229
|
+
<outer><mid_1><inner>some text</inner></mid_1><mid_2><inner>some more text</inner></mid_2></outer>
|
230
|
+
END_OF_lhs_doc
|
231
|
+
|
232
|
+
rhs_str = <<END_OF_rhs_doc
|
233
|
+
<?xml version="1.0"?>
|
234
|
+
<outer>
|
235
|
+
<mid_2>
|
236
|
+
<inner>some more text</inner>
|
237
|
+
</mid_2>
|
238
|
+
<mid_1>
|
239
|
+
<inner>some text</inner>
|
240
|
+
</mid_1>
|
241
|
+
</outer>
|
242
|
+
END_OF_rhs_doc
|
243
|
+
|
244
|
+
lhs_doc = Nokogiri::XML lhs_str
|
245
|
+
rhs_doc = Nokogiri::XML rhs_str
|
246
|
+
|
247
|
+
expected = rhs_doc
|
248
|
+
actual = lhs_doc
|
249
|
+
|
250
|
+
r = xml_compare expected, actual, ignore_child_node_order: true, normalise_whitespace: true, ignore_xml_declarations: true
|
251
|
+
|
252
|
+
assert r.same?, "#{r.details}"
|
253
|
+
end
|
187
254
|
end
|
188
255
|
|
256
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
|
4
|
+
|
5
|
+
require 'xqsr3/xml/utilities/navigation'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
require 'nokogiri'
|
11
|
+
|
12
|
+
class Test_Xqsr3_XML_Utilities_Navigation < Test::Unit::TestCase
|
13
|
+
|
14
|
+
include ::Xqsr3::XML::Utilities::Navigation
|
15
|
+
|
16
|
+
def test_get_descendants_1
|
17
|
+
|
18
|
+
xml_s = <<END_OF_rhs_doc
|
19
|
+
<?xml version="1.0"?>
|
20
|
+
<document>
|
21
|
+
<outer>
|
22
|
+
<mid_2>
|
23
|
+
<inner>some more text</inner>
|
24
|
+
</mid_2>
|
25
|
+
<mid_1>
|
26
|
+
<inner>some text</inner>
|
27
|
+
</mid_1>
|
28
|
+
</outer>
|
29
|
+
</document>
|
30
|
+
END_OF_rhs_doc
|
31
|
+
|
32
|
+
xml = ::Nokogiri.XML(xml_s)
|
33
|
+
doc = xml.children.first
|
34
|
+
|
35
|
+
descs = self.class.get_descendants xml.children.first
|
36
|
+
|
37
|
+
assert_not_nil descs
|
38
|
+
assert_kind_of ::Array, descs
|
39
|
+
|
40
|
+
assert_operator 7, :<=, descs.size
|
41
|
+
%w{ outer mid_1 mid_2 }.each do |name|
|
42
|
+
|
43
|
+
assert(descs.find { |el| name == el.name }, "did not find an element named '#{name}' in the collection #{descs}")
|
44
|
+
end
|
45
|
+
|
46
|
+
texts = descs.select { |el| el.text? }
|
47
|
+
|
48
|
+
[ 'some text', 'some more text' ].each do |text|
|
49
|
+
|
50
|
+
assert(texts.find { |el| text == el.text }, "did not find an element with the text '#{text}' in the collection #{texts}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xqsr3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.27.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Wilson
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/xqsr3/string_utilities/truncate.rb
|
79
79
|
- lib/xqsr3/version.rb
|
80
80
|
- lib/xqsr3/xml/utilities/compare.rb
|
81
|
+
- lib/xqsr3/xml/utilities/navigation.rb
|
81
82
|
- test/unit/array_utilities/tc_join_with_or.rb
|
82
83
|
- test/unit/array_utilities/ts_all.rb
|
83
84
|
- test/unit/command_line_utilities/tc_map_option_string.rb
|
@@ -130,6 +131,7 @@ files:
|
|
130
131
|
- test/unit/ts_all.rb
|
131
132
|
- test/unit/xml/ts_all.rb
|
132
133
|
- test/unit/xml/utilities/tc_compare.rb
|
134
|
+
- test/unit/xml/utilities/tc_navigation.rb
|
133
135
|
- test/unit/xml/utilities/ts_all.rb
|
134
136
|
homepage: http://github.com/synesissoftware/xqsr3
|
135
137
|
licenses:
|