Skip to content

Commit 3b62656

Browse files
committed
Add two more regexes to format matcher
Add the configuration for integer and uuid to format matchers. These option will be used for the wildcard url validation.
1 parent 7985c3f commit 3b62656

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

lib/alchemy/configurations/format_matchers.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class FormatMatchers < Alchemy::Configuration
66
option :email, :regexp, default: /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
77
option :url, :regexp, default: /\A[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?\z/ix
88
option :link_url, :regexp, default: /^(tel:|mailto:|\/|[a-z]+:\/\/)/
9+
option :integer, :regexp, default: /\A\d+\z/
10+
option :uuid, :regexp, default: /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i
911
end
1012
end
1113
end

spec/libraries/alchemy/configurations/format_matchers_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,29 @@
5252
expect("relative/path").not_to match(format_matchers.link_url)
5353
end
5454
end
55+
56+
describe "#integer" do
57+
it "matches integers" do
58+
expect("123").to match(format_matchers.integer)
59+
expect("0").to match(format_matchers.integer)
60+
end
61+
62+
it "does not match non-integers" do
63+
expect("12.3").not_to match(format_matchers.integer)
64+
expect("abc").not_to match(format_matchers.integer)
65+
expect("12a").not_to match(format_matchers.integer)
66+
end
67+
end
68+
69+
describe "#uuid" do
70+
it "matches valid UUIDs" do
71+
expect("550e8400-e29b-41d4-a716-446655440000").to match(format_matchers.uuid)
72+
expect("550E8400-E29B-41D4-A716-446655440000").to match(format_matchers.uuid)
73+
end
74+
75+
it "does not match invalid UUIDs" do
76+
expect("not-a-uuid").not_to match(format_matchers.uuid)
77+
expect("550e8400e29b41d4a716446655440000").not_to match(format_matchers.uuid)
78+
end
79+
end
5580
end

0 commit comments

Comments
 (0)