-
Notifications
You must be signed in to change notification settings - Fork 179
Sort printed maps in test output #917
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
Changes from 5 commits
e74c58d
f8cfb95
027b453
025658d
a6dd36b
ec61b70
e95b9ed
c446656
ee36478
12777fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,19 @@ | |
(str/starts-with? frame-cname class-name)))) | ||
first)))) | ||
|
||
(defn deep-sorted-maps | ||
"Recursively converts all nested maps to sorted maps." | ||
[m] | ||
(try | ||
(walk/postwalk | ||
(fn [x] | ||
(if (map? x) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't it be better to check around the call site if something's map? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which call site do you mean? If you are referring to the call in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an example nested map in the test: |
||
(with-meta (into (sorted-map) x) (meta x)) | ||
x)) | ||
m) | ||
(catch Exception _ | ||
m))) | ||
|
||
(defn- print-object | ||
"Print `object` using println for matcher-combinators results and pprint | ||
otherwise. The matcher-combinators library uses a custom print-method | ||
|
@@ -91,7 +104,7 @@ | |
print-fn (if matcher-combinators-result? | ||
println | ||
pp/pprint) | ||
result (with-out-str (print-fn object))] | ||
result (with-out-str (print-fn (deep-sorted-maps object)))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably add a note here why we're sorting maps. |
||
;; Replace extra newlines at the end, as sometimes returned by matchers-combinators: | ||
(str/replace result #"\n\n+$" "\n"))) | ||
|
||
|
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.
Is there a chance for this to throw an exception?
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.
No, I suppose not. I had that in there when I was first testing it out locally and never removed it. But I don't see it being necessary. I'll remove it.
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.
In general, this will throw if the keys of any nested map are not comparable.
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.
@frenchy64 That's a great catch! (no pun intended) I'll add a comment explaining the rationale for the try/catch here.