check_please 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/check_please.rb +14 -0
- data/lib/check_please/comparison.rb +43 -1
- data/lib/check_please/error.rb +4 -0
- data/lib/check_please/path.rb +10 -9
- data/lib/check_please/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8c12644a3f83d1d263374a88b825a9f705f55d68582e90a50a3065ec2b0105e
|
4
|
+
data.tar.gz: 3f5ddc8b0d9e5c02bc4845e5a4ac21d07b358f75639146f32c71143bc1e6d605
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c95071934105bc8c8876287bf460a0466ecc996eab6356c64a994566824c95d2f24d6d446bc8bcc6d4d66b0a224023a4347839e75f5d8204860e9e2210e7e07d
|
7
|
+
data.tar.gz: ebdbe6bdeafd3f71bf9461f5eccd73f20772043d9e84ab01fa91c0a1dcff054a21c74d718aa40cf0c89bed3219d36d1f46e89ce37ea6d27483bb268518bb7d59
|
data/Gemfile.lock
CHANGED
data/lib/check_please.rb
CHANGED
@@ -143,6 +143,20 @@ module CheckPlease
|
|
143
143
|
EOF
|
144
144
|
end
|
145
145
|
|
146
|
+
Flags.define :match_by_value do |flag|
|
147
|
+
flag.repeatable
|
148
|
+
flag.coerce { |value| CheckPlease::Path.reify(value) }
|
149
|
+
|
150
|
+
flag.cli_long = "--match-by-value FOO"
|
151
|
+
flag.description = <<~EOF
|
152
|
+
When comparing two arrays that match a specified path, the candidate
|
153
|
+
array will be scanned for each element in the reference array.
|
154
|
+
May be repeated; values will be treated as an 'OR' list.
|
155
|
+
NOTE: explodes if either array at a given path contains other collections.
|
156
|
+
NOTE: paths of 'extra' diffs use the index in the candidate array.
|
157
|
+
EOF
|
158
|
+
end
|
159
|
+
|
146
160
|
Flags.define :indifferent_keys do |flag|
|
147
161
|
flag.default = false
|
148
162
|
flag.coerce { |value| !!value }
|
@@ -42,8 +42,11 @@ module CheckPlease
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def compare_arrays(ref_array, can_array, path)
|
45
|
-
|
45
|
+
case
|
46
|
+
when ( key = path.key_to_match_by(flags) )
|
46
47
|
compare_arrays_by_key ref_array, can_array, path, key
|
48
|
+
when path.match_by_value?(flags)
|
49
|
+
compare_arrays_by_value ref_array, can_array, path
|
47
50
|
else
|
48
51
|
compare_arrays_by_index ref_array, can_array, path
|
49
52
|
end
|
@@ -107,6 +110,45 @@ module CheckPlease
|
|
107
110
|
elements_by_key
|
108
111
|
end
|
109
112
|
|
113
|
+
# FIXME: this can generate duplicate paths.
|
114
|
+
# Time to introduce lft_path, rgt_path ?
|
115
|
+
def compare_arrays_by_value(ref_array, can_array, path)
|
116
|
+
assert_can_match_by_value! ref_array
|
117
|
+
assert_can_match_by_value! can_array
|
118
|
+
|
119
|
+
matches = can_array.map { false }
|
120
|
+
|
121
|
+
# Look for missing values
|
122
|
+
ref_array.each.with_index do |ref, i|
|
123
|
+
new_path = path + (i+1) # count in human pls
|
124
|
+
|
125
|
+
# Weird, but necessary to handle duplicates properly
|
126
|
+
j = can_array.index.with_index { |can, j|
|
127
|
+
matches[j] == false && can == ref
|
128
|
+
}
|
129
|
+
|
130
|
+
if j
|
131
|
+
matches[j] = true
|
132
|
+
else
|
133
|
+
record_diff ref, nil, new_path, :missing
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Look for extra values
|
138
|
+
can_array.zip(matches).each.with_index do |(can, match), i|
|
139
|
+
next if match
|
140
|
+
new_path = path + (i+1) # count in human pls
|
141
|
+
record_diff nil, can, new_path, :extra
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def assert_can_match_by_value!(array)
|
146
|
+
if array.any? { |e| Array === e || Hash === e }
|
147
|
+
raise CheckPlease::BehaviorUndefined,
|
148
|
+
"match_by_value behavior is not defined for collections!"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
110
152
|
def compare_arrays_by_index(ref_array, can_array, path)
|
111
153
|
max_len = [ ref_array, can_array ].map(&:length).max
|
112
154
|
(0...max_len).each do |i|
|
data/lib/check_please/error.rb
CHANGED
data/lib/check_please/path.rb
CHANGED
@@ -81,13 +81,10 @@ module CheckPlease
|
|
81
81
|
"<#{self.class.name} '#{to_s}'>"
|
82
82
|
end
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
matches =
|
88
|
-
# NOTE: matching on parent because MBK '/foo/:id' should return 'id' for path '/foo'
|
89
|
-
mbk_expr.parent.match?(self)
|
90
|
-
}
|
84
|
+
def key_to_match_by(flags)
|
85
|
+
key_exprs = unpack_key_exprs(flags.match_by_key)
|
86
|
+
# NOTE: match on parent because if self.to_s == '/foo', MBK '/foo/:id' should return 'id'
|
87
|
+
matches = key_exprs.select { |e| e.parent.match?(self) }
|
91
88
|
|
92
89
|
case matches.length
|
93
90
|
when 0 ; nil
|
@@ -96,6 +93,10 @@ module CheckPlease
|
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
96
|
+
def match_by_value?(flags)
|
97
|
+
flags.match_by_value.any? { |e| e.match?(self) }
|
98
|
+
end
|
99
|
+
|
99
100
|
def match?(path_or_string)
|
100
101
|
# If the strings are literally equal, we're good..
|
101
102
|
return true if self == path_or_string
|
@@ -160,8 +161,8 @@ module CheckPlease
|
|
160
161
|
depth > flags.max_depth
|
161
162
|
end
|
162
163
|
|
163
|
-
def
|
164
|
-
|
164
|
+
def unpack_key_exprs(path_list)
|
165
|
+
path_list
|
165
166
|
.map { |path| path.send(:key_exprs) }
|
166
167
|
.flatten
|
167
168
|
.uniq { |e| e.to_s } # use the block form so we don't have to implement #hash and #eql? in horrible ways
|
data/lib/check_please/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module CheckPlease
|
2
2
|
# NOTE: 'check_please_rspec_matcher' depends on this,
|
3
3
|
# so try to keep them roughly in sync
|
4
|
-
VERSION = "0.5.
|
4
|
+
VERSION = "0.5.3" # about to release? rerun `bundle lock` to update Gemfile.lock
|
5
5
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: check_please
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Livingston-Gray
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: table_print
|