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

Allow Matches and ErrorMatches matches to use an already-compiled regexp.Regexp #137

Merged
merged 4 commits into from
Apr 11, 2023

Conversation

pajlada
Copy link
Contributor

@pajlada pajlada commented Mar 27, 2022

This allows users to have full control over the regular expression used for matching.

My use-case was matching a multiline string pattern, and the way MatchString was used in the match-function made that infeasible.

With this change, I was able to use the Matches matcher like this:

c.Assert("asd\nasd", qt.Matches, regexp.MustCompile(`asd.*`))

Happy to update naming of variables on request.
I left naming of parameters/arguments on purpose to keep the diff minimal, but happy to change that too.

As an alternative, if this change is not acceptable, I know I could implement my own Checker handles regular expressions like this, so no worries if this change does not fit into the project!

Copy link
Owner

@frankban frankban left a comment

Choose a reason for hiding this comment

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

I think this is an interesting feature.
If you want, please go ahead!

@pajlada
Copy link
Contributor Author

pajlada commented Sep 18, 2022

@frankban I've gone ahead and pushed missing tests for this functionality to maintain the 100% test coverage of checker.go, let me know if you prefer this to be rebased or something before being approved/merged in 🙂

Copy link
Owner

@frankban frankban left a comment

Choose a reason for hiding this comment

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

The code looks good!
Could you please add:

  • similar tests for ErrorMatches and PanicMatches;
  • updated docs for the 3 involved checkers.
    Thanks!

@pajlada
Copy link
Contributor Author

pajlada commented Sep 24, 2022

I added the following tests:
qt.ErrorMatches single-line match expectedNegateFailure
qt.ErrorMatches multi-line match expectedNegateFailure
qt.ErrorMatches multi-line match expectedCheckFailure
qt.PanicMatches single-line match expectedNegateFailure
qt.PanicMatches multi-line match expectedNegateFailure
qt.PanicMatches multi-line match expectedCheckFailure

I added the following documentation:
Added example for Matches checker in checker.go and in README.md
Added example for ErrorMatches checker in checker.go and in README.md
Added example for PanicMatches checker in checker.go and in README.md

…exp.Regexp

This allows users to have full control over the pattern used for
matching, and all of its flags (multiline)
 - qt.ErrorMatches single-line match `expectedNegateFailure`
 - qt.ErrorMatches multi-line match `expectedNegateFailure`
 - qt.ErrorMatches multi-line match `expectedCheckFailure`
 - qt.PanicMatches single-line match `expectedNegateFailure`
 - qt.PanicMatches multi-line match `expectedNegateFailure`
 - qt.PanicMatches multi-line match `expectedCheckFailure`
…atches

Documentation added both to the checker.go file and the README.md file
@frankban frankban merged commit 1af932f into frankban:master Apr 11, 2023
@pajlada pajlada deleted the feat/checker-accept-regexp branch April 11, 2023 21:52
@frankban
Copy link
Owner

Released as v1.14.5

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