-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add predicates for checking V1, V2, V3, V5 UUIDs. #75
Conversation
Here is an overview of what got changed by this pull request: Issues
======
- Added 44
Clones added
============
- spec/unit/predicates/uuid_v3_spec.rb 1
- spec/unit/predicates/uuid_v1_spec.rb 1
- spec/unit/predicates/uuid_v5_spec.rb 1
- spec/unit/predicates/uuid_v2_spec.rb 1
See the complete overview on Codacy |
[['f2d26c57-e07c-1416-a749-57e937930e04']] | ||
end | ||
|
||
it_behaves_like 'a passing predicate' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -206,11 +206,31 @@ def case?(pattern, input) | |||
pattern === input | |||
end | |||
|
|||
def uuid_v1?(input) | |||
uuid_v1_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codacy found an issue: Line is too long. [101/100]
|
||
context 'when value is a valid V5 UUID' do | ||
let(:arguments_list) do | ||
[['f2d26c57-e07c-5416-a749-57e937930e04']] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it_behaves_like 'a passing predicate' | ||
end | ||
|
||
context 'with value is not a valid V1 UUID' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it_behaves_like 'a passing predicate' | ||
end | ||
|
||
context 'with value is not a valid V4 UUID' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe '#uuid_v2?' do | ||
let(:predicate_name) { :uuid_v2? } | ||
|
||
context 'when value is a valid V1 UUID' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require 'dry/logic/predicates' | ||
|
||
RSpec.describe Dry::Logic::Predicates do | ||
describe '#uuid_v3?' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe '#uuid_v1?' do | ||
let(:predicate_name) { :uuid_v1? } | ||
|
||
context 'when value is a valid V1 UUID' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,31 @@ | |||
# frozen_string_literal: true | |||
|
|||
require 'dry/logic/predicates' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ | ||
["not-a-uuid-at-all\nf2d26c57-e07c-2416-a749-57e937930e04"], # V2 with invalid prefix | ||
["f2d26c57-e07c-2416-a749-57e937930e04\nnot-a-uuid-at-all"], # V2 with invalid suffix | ||
['f2d26c57-e07c-3416-a749-57e937930e04'], # wrong version number (3, not 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[['f2d26c57-e07c-2416-a749-57e937930e04']] | ||
end | ||
|
||
it_behaves_like 'a passing predicate' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,31 @@ | |||
# frozen_string_literal: true | |||
|
|||
require 'dry/logic/predicates' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def uuid_v4?(input) | ||
uuid_v4_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i | ||
format?(uuid_v4_format, input) | ||
end | ||
|
||
def uuid_v5?(input) | ||
uuid_v5_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codacy found an issue: Line is too long. [101/100]
require 'dry/logic/predicates' | ||
|
||
RSpec.describe Dry::Logic::Predicates do | ||
describe '#uuid_v5?' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe '#uuid_v3?' do | ||
let(:predicate_name) { :uuid_v3? } | ||
|
||
context 'when value is a valid V3 UUID' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require 'dry/logic/predicates' | ||
|
||
RSpec.describe Dry::Logic::Predicates do | ||
describe '#uuid_v2?' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
] | ||
end | ||
|
||
it_behaves_like 'a failing predicate' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["f2d26c57-e07c-5416-a749-57e937930e04\nnot-a-uuid-at-all"], # V4 with invalid suffix | ||
['f2d26c57-e07c-3416-a749-57e937930e04'], # wrong version number (3, not 5) | ||
['20633928-6a07-11e9-a923-1681be663d3e'], # UUID V1 | ||
['not-a-uuid-at-all'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
context 'when value is a valid V3 UUID' do | ||
let(:arguments_list) do | ||
[['f2d26c57-e07c-3416-a749-57e937930e04']] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["not-a-uuid-at-all\nf2d26c57-e07c-3416-a749-57e937930e04"], # V3 with invalid prefix | ||
["f2d26c57-e07c-3416-a749-57e937930e04\nnot-a-uuid-at-all"], # V3 with invalid suffix | ||
['f2d26c57-e07c-4416-a749-57e937930e04'], # wrong version number (4, not 3) | ||
['20633928-6a07-11e9-a923-1681be663d3e'], # UUID V1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["f2d26c57-e07c-2416-a749-57e937930e04\nnot-a-uuid-at-all"], # V2 with invalid suffix | ||
['f2d26c57-e07c-3416-a749-57e937930e04'], # wrong version number (3, not 2) | ||
['20633928-6a07-11e9-a923-1681be663d3e'], # UUID V1 | ||
['not-a-uuid-at-all'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["f2d26c57-e07c-3416-a749-57e937930e04\nnot-a-uuid-at-all"], # V3 with invalid suffix | ||
['f2d26c57-e07c-4416-a749-57e937930e04'], # wrong version number (4, not 3) | ||
['20633928-6a07-11e9-a923-1681be663d3e'], # UUID V1 | ||
['not-a-uuid-at-all'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["not-a-uuid-at-all\nf2d26c57-e07c-2416-a749-57e937930e04"], # V2 with invalid prefix | ||
["f2d26c57-e07c-2416-a749-57e937930e04\nnot-a-uuid-at-all"], # V2 with invalid suffix | ||
['f2d26c57-e07c-3416-a749-57e937930e04'], # wrong version number (3, not 2) | ||
['20633928-6a07-11e9-a923-1681be663d3e'], # UUID V1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,31 @@ | |||
# frozen_string_literal: true | |||
|
|||
require 'dry/logic/predicates' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ | ||
["not-a-uuid-at-all\nf2d26c57-e07c-5416-a749-57e937930e04"], # V4 with invalid prefix | ||
["f2d26c57-e07c-5416-a749-57e937930e04\nnot-a-uuid-at-all"], # V4 with invalid suffix | ||
['f2d26c57-e07c-3416-a749-57e937930e04'], # wrong version number (3, not 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamesbrauman thank you James, you can now enjoy your new predicates in the freshly released dry-logic 1.0.7 😄 |
@solnic Thank-you for responsiveness, and the |
I have a need to validate other versions of UUIDs than just V4. Because the
uuid_v4?
predicate exists, can we also add predicates for other UUID versions?Should I also add a
uuid?
predicate that checks for V1-V5 UUIDs?Reference: https://stackoverflow.com/a/38191104