-
Notifications
You must be signed in to change notification settings - Fork 48
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
Metadata on deftest (and def) #224
Comments
Hello @arichiardi. Truly, thanks for asking. I sat down to try to figure out a fix for this problem, but ... I can't quite figure out the problem. When I try the two examples you gave, above, I get what you show (as long as my width is enough for the string in the first example). Presumably you would like these two examples to look different than they came out? Maybe it is obvious that there is a better way to format these and I'm just missing something? Perhaps you could give me your preferred output and I'll see what I can come up with to make that happen. Thanks! |
Oh dear, sorry I did not specify what the desiderata is: (def ^{:doc "Json serde. This enables our default camel-case out kebab case in behaviour."}
default-json-serde
serde/json-camel-kebab-serde) and (deftest ^{:database true ::test.hooks/system-init-keys system-keys}
websocket-diagnostic-report-measurements-updated-event
(let [foo (bar "1")]
foo)) The funny thing is that some of the (def
^{:doc
"Keys necessary for starting the application bus and the reactions.
Note that reactions will consume bus events so you won't be able to consume :chan directly."}
ws-component-keys
(into event-bus-component-keys
[:appserver.lib.ws/endpoints ;; websocket config component (fed to pedestal)
:appserver.lib.pubsub.components/pubsub ;; reaction component
:appserver.lib.transport.components/transport-processor ;; websocket message processing
:appserver.users/default-user :appserver.auth/params :appserver.uri.ws/scheme
:appserver.uri/authority :appserver.uri.ws/path])) |
First, let me say that this one is a real challenge. It turns out that metadata is parsed together with the thing to which the metadata is associated and they show up as a single element. So the usual ways I have of dealing with this don't really apply, since the metadata isn't two things when it is output from the parser (though it of course certainly looks like it is). So my usual "here is a hack in the options map to get you what you want" is not on the table. That said, I might be able to get you close to what you want. Above, you said "some of the
Except that one isn't, to my eyes anyway, actually behaving like you said you wanted it. My understanding of what you want from your first two examples is to have the metadata on the same line as the
It turns out to be rather easy to do either the normal First, the way you don't like:
Next, I think this isn't your preferred approach, but it might be better than the one just above -- at least it is like the example you gave last:
This is the same options map as the previous example, but there is no metadata, so you can see the
That is the best I can do without actually changing the code and putting out a new release. Which I will be doing soon. Here it is more readably:
Obviously you will have to change the It would be nice to have you confirm which approach is really your favorite, since I'm going to try to actually allow that. I assume it is the first two examples you gave, and not like the third one, the one that I believe you mistakenly thought was already formatted like you wanted (and that the |
Hey @kkinnear, thanks yep it appears I mistakenly seen the third the same as the first two examples. For some reason I am always bringing you hot potatoes to handle 😄
Yes that's what I would like to have, but I am ok with the workaround around zprint.core=> (czprint i224a {:parse-string? true :fn-map {"deftest" [:fn {:list {:option-fn (fn [opts n exprs] (if (meta (second exprs)) {:fn-style :flow-body} {:fn-style :arg1-body}))}}]} :style :community})
(deftest
^{:database true, ::test.hooks/system-init-keys system-keys}
websocket-diagnostic-report-measurements-updated-event
(let [foo (bar "1")] foo)) looks alright to me - I am not going to apply it to ...one additional note would be that the meta should behave like a regular map if it gets big - ideally flowing like the third example, but I am sure you've already thought about that. |
I'm working toward a real way to get you what you want. I have some questions. Which of these do you prefer if the metadata and the symbol would all fit on the same line?
Also, regarding your comment about the meta map behaving like a regular map if it get big. It doesn't flow, it hangs the elements of the map:
Does that work for you? I can get it to flow the map if it doesn't fit on one line, if you prefer that. Like this:
Is that better? |
Awesome!
I think version B is the most common and what most clojurians would expect (apologies if more work), cause most of the times you actually have the metadata map specified as For instance on (deftest ^:database websocket-diagnostic-and-a-bit-more
(let [foo (bar "1")] foo))
Yes, this second version is better imho - the previous leaves a lot of "empty space" and you have to move your eyes to the right to note the map. If the metadata map is big it is usually for an "important" reason (in my case system keys are customized) and you should have good perception of that. I hope this makes sense and thanks for asking and working on this! |
Sorry to keep asking, but I'm not having any luck guessing which you prefer. What about these, where there isn't a map, but they don't fit on the same line?
|
Hey, no problem 😄 Version B is best imho |
So, I've created a new |
Ok sounds good I'll try that and get back to you 😄 |
Started comments on the release #232 (comment) |
Back to the actual topic of this issue, I tried to format these: (deftest
^:database
foo-test
(testing "foo"
(is (= :bar :bar))))
(deftest ^{:database true :doc "This is a long comment on the test, so long that is quite
boring. Not boring in the sense that it is not really telling much but boring in the sense that it
is very long to read."} comment-test
(testing "comment"
(is (= :bar :bar))))
(deftest ^{:database true ::test.hooks/system-init-keys [reporting-service-key ordering-system-key user-service-system-key]} data-test
(testing "data"
(is (= :bar :bar)))) and I am very thankful for the result 😄 (deftest ^:database foo-test
(testing "foo"
(is (= :bar :bar))))
(deftest
^{:database true
:doc
"This is a long comment on the test, so long that is quite
boring. Not boring in the sense that it is not really telling much but boring in the sense that it
is very long to read."}
comment-test
(testing "comment"
(is (= :bar :bar))))
(deftest
^{:database true
::test.hooks/system-init-keys [reporting-service-key ordering-system-key
user-service-system-key]}
big-data-test
(testing "data"
(is (= :bar :bar)))) There is an exception though, I think this one: (deftest ^{:database true ::test.hooks/system-init-keys system-keys} small-data-test
(testing "data"
(is (= :bar :bar)))) Would be better as: (deftest ^{:database true ::test.hooks/system-init-keys system-keys}
small-data-test
(testing "data"
(is (= :bar :bar)))) There might be something in my config though, that's why I am attaching it this time. |
Turns out that in Put this in your zprint.edn:
This should replace the current Thanks! |
Hi @kkinnear,
As our use of
zprint
increases, we are slowly tackling and opening issues when we don't know how manage some of our forms (as you saw 😄)Thank you in advance for your work, we are going to try
1.2.2
soon here.In the meantime, we have many places where we declare metadata on stuff:
The meta seems to break the
arg1-body
setup and I am not sure how to handle that. I could probably go:inner
but I thought I should ask first.The text was updated successfully, but these errors were encountered: