Skip to content

Commit 614807d

Browse files
committed
Correct Naming/PredicateMethod
1 parent cab980b commit 614807d

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

lib/cldr/export/deep_validate_keys.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def validate(hash, component, key_path = [])
77
hash.each do |key, value|
88
full_path = key_path + [key]
99
raise ArgumentError, "Invalid key: #{full_path} in #{component}" unless key.to_s == key.to_s.underscore ||
10-
SNAKE_CASE_EXCEPTIONS.fetch(component, []).any? { |exception| paths_match(exception, full_path) }
10+
SNAKE_CASE_EXCEPTIONS.fetch(component, []).any? { |exception| paths_match?(exception, full_path) }
1111

1212
validate(value, component, full_path) if value.is_a?(Hash)
1313
end
@@ -46,7 +46,7 @@ def validate(hash, component, key_path = [])
4646
],
4747
}
4848

49-
def paths_match(pattern, key)
49+
def paths_match?(pattern, key)
5050
raise NotImplementedError, "Multiple * in pattern is unsupported" if pattern.count { |element| element == "*" } > 1
5151

5252
pattern_index = 0

test/export/deep_validate_keys_test.rb

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,44 @@
55
require File.expand_path(File.join(File.dirname(__FILE__) + "/../../lib/cldr/export/deep_validate_keys"))
66

77
class TestDeepValidateKeys < Test::Unit::TestCase
8-
test "#paths_match with empty pattern matches only empty key" do
9-
assert DeepValidateKeys.send(:paths_match, [], [])
10-
refute DeepValidateKeys.send(:paths_match, [], ["foo", "bar", "baz", "qux"])
8+
test "#paths_match? with empty pattern matches only empty key" do
9+
assert DeepValidateKeys.send(:"paths_match?", [], [])
10+
refute DeepValidateKeys.send(:"paths_match?", [], ["foo", "bar", "baz", "qux"])
1111
end
1212

13-
test "#paths_match matches with exact match" do
14-
assert DeepValidateKeys.send(:paths_match, ["foo", "bar"], ["foo", "bar"])
13+
test "#paths_match? matches with exact match" do
14+
assert DeepValidateKeys.send(:"paths_match?", ["foo", "bar"], ["foo", "bar"])
1515

16-
refute DeepValidateKeys.send(:paths_match, ["foo"], ["foo", "bar", "baz", "qux"])
17-
refute DeepValidateKeys.send(:paths_match, ["foo"], ["bar", "baz", "qux"])
18-
refute DeepValidateKeys.send(:paths_match, ["foo", "bar"], ["foo"])
19-
refute DeepValidateKeys.send(:paths_match, ["foo", "baz"], ["foo", "bar", "baz", "qux"])
16+
refute DeepValidateKeys.send(:"paths_match?", ["foo"], ["foo", "bar", "baz", "qux"])
17+
refute DeepValidateKeys.send(:"paths_match?", ["foo"], ["bar", "baz", "qux"])
18+
refute DeepValidateKeys.send(:"paths_match?", ["foo", "bar"], ["foo"])
19+
refute DeepValidateKeys.send(:"paths_match?", ["foo", "baz"], ["foo", "bar", "baz", "qux"])
2020
end
2121

22-
test "#paths_match with . matches single element" do
23-
assert DeepValidateKeys.send(:paths_match, ["foo", ".", "baz"], ["foo", "bar", "baz"])
24-
assert DeepValidateKeys.send(:paths_match, ["foo", ".", ".", "qux"], ["foo", "bar", "baz", "qux"])
25-
assert DeepValidateKeys.send(:paths_match, ["."], ["foo"])
26-
assert DeepValidateKeys.send(:paths_match, [".", "bar"], ["foo", "bar"])
22+
test "#paths_match? with . matches single element" do
23+
assert DeepValidateKeys.send(:"paths_match?", ["foo", ".", "baz"], ["foo", "bar", "baz"])
24+
assert DeepValidateKeys.send(:"paths_match?", ["foo", ".", ".", "qux"], ["foo", "bar", "baz", "qux"])
25+
assert DeepValidateKeys.send(:"paths_match?", ["."], ["foo"])
26+
assert DeepValidateKeys.send(:"paths_match?", [".", "bar"], ["foo", "bar"])
2727

28-
refute DeepValidateKeys.send(:paths_match, ["."], [])
28+
refute DeepValidateKeys.send(:"paths_match?", ["."], [])
2929
end
3030

31-
test "#paths_match with trailing * matches anything after the star" do
32-
assert DeepValidateKeys.send(:paths_match, ["foo", "*"], ["foo", "bar", "baz", "qux"])
33-
assert DeepValidateKeys.send(:paths_match, ["*"], [])
34-
assert DeepValidateKeys.send(:paths_match, ["*"], ["foo", "bar", "baz", "qux"])
31+
test "#paths_match? with trailing * matches anything after the star" do
32+
assert DeepValidateKeys.send(:"paths_match?", ["foo", "*"], ["foo", "bar", "baz", "qux"])
33+
assert DeepValidateKeys.send(:"paths_match?", ["*"], [])
34+
assert DeepValidateKeys.send(:"paths_match?", ["*"], ["foo", "bar", "baz", "qux"])
3535
end
3636

37-
test "#paths_match with * greedy matches up to the last match of the next element" do
38-
assert DeepValidateKeys.send(:paths_match, ["foo", "*", "baz", "quxx"], ["foo", "bar", "baz", "qux", "baz", "quxx"])
37+
test "#paths_match? with * greedy matches up to the last match of the next element" do
38+
assert DeepValidateKeys.send(:"paths_match?", ["foo", "*", "baz", "quxx"], ["foo", "bar", "baz", "qux", "baz", "quxx"])
3939

40-
refute DeepValidateKeys.send(:paths_match, ["foo", "*", "baz", "quxx"], ["foo", "bar", "baz", "qux"])
40+
refute DeepValidateKeys.send(:"paths_match?", ["foo", "*", "baz", "quxx"], ["foo", "bar", "baz", "qux"])
4141
end
4242

43-
test "#paths_match raise when given a pattern with multiple *" do
43+
test "#paths_match? raise when given a pattern with multiple *" do
4444
exc = assert_raises(NotImplementedError) do
45-
DeepValidateKeys.send(:paths_match, ["foo", "*", "baz", "*"], ["foo", "bar", "baz", "qux", "baz", "quxx"])
45+
DeepValidateKeys.send(:"paths_match?", ["foo", "*", "baz", "*"], ["foo", "bar", "baz", "qux", "baz", "quxx"])
4646
end
4747
assert_equal "Multiple * in pattern is unsupported", exc.message
4848
end

0 commit comments

Comments
 (0)