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

Consider supporting a line by line matcher #182

Closed
lread opened this issue Nov 11, 2022 · 4 comments
Closed

Consider supporting a line by line matcher #182

lread opened this issue Nov 11, 2022 · 4 comments

Comments

@lread
Copy link
Contributor

lread commented Nov 11, 2022

The Idea

On Slack @borkdude raised the idea of a matcher that would show differences from a blob of text by line.

Given expectation of a blob of text

a
b
c
d
e

And actual blob of text

a 
x
c
e

line x would show as different from line b and line d would show as missing.

Related

To be extra useful, this matcher assumes the comparison behaviour described in #177.

Alternatives

Something I sometimes do when using kaocha is to preprocess text blobs into a vector of line strings and then compare. Because kaocha uses deep-diff2 which implements #177, the diffs can be pretty nice.

Fleshing it out

  • what text sources should this support? Strings for sure. Files would be nice. URLs? Streams?
  • should we somehow show character differences within a line? Perhaps an idea for some later iteration.
  • what would be a good name for the matcher? by-line sounds like a good name to me.
  • would this matcher be invoked automatically? probably not, would probably want to explicitly specify this matcher, am I right?
  • what about OS newline differences? Maybe ignore them? Thoughts?
  • other?
@philomates
Copy link
Collaborator

I think via might help you here:

(require 'clojure.string)
(require '[clojure.test :refer [is]])
(require '[matcher-combinators.test :refer [match?]])
(require '[matcher-combinators.matchers :as m])

(is (match? (m/via clojure.string/split-lines [":foo" ":bar" ":baz" ":qux"])
            ":foo\n:bar\n:baz\n:qux"))

@lread
Copy link
Contributor Author

lread commented Dec 7, 2022

Hmmm... yeah, thanks! That just might work!

Feel free to close this issue.

@borkdude
Copy link

borkdude commented Dec 7, 2022

@philomates Nice!

@lread
Copy link
Contributor Author

lread commented Jan 6, 2023

Since via does the trick, I don't see an issue here, closing (and thanks @philomates!).

@lread lread closed this as completed Jan 6, 2023
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

No branches or pull requests

3 participants