Skip to content
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 exhaustive match #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add exhaustive match #26

wants to merge 2 commits into from

Conversation

baweaver
Copy link
Owner

Adds the idea of an exhaustive match to the API that will fail if a match has not been found as a response to #25

@bolshakov
Copy link
Contributor

Need to add the same option to PatternMatch.mixin method

@baweaver
Copy link
Owner Author

Added a few more enhancements to the idea to provide better error messages, as well as a pessimistic and optimistic version of failure. Thoughts?

#
# @return [Boolean]
def all_branches_provided?
available_branch_names == @provided_matchers.uniq
Copy link
Contributor

@bolshakov bolshakov Feb 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May fail if you provide branches in order other than order of registration

Suggested change
available_branch_names == @provided_matchers.uniq
available_branch_names.sort == @provided_matchers.uniq.sort

or you can store names as an instance of Set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to integrate latest changes into my PR, and got this error:

     Qo::Exceptions::ExhaustiveMatchMissingBranches:
       Exhaustive match required: pattern does not specify all branches.
         Expected Branches: right, left
         Given Branches:    left, right

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may jump back to implementing this with sets, silly mistake on my part.

#
# @author baweaver
# @since 0.99.1
class ExhaustiveMatchMissingBranches < StandardError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest having common ancestor for all Qo errors and, probably for exhaustive match errors. So end users will be able to catch errors with desired granularity. For example Qo::Error, Qo, MatchError, ExhaustiveMatchNotMet etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants