This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-01
Channels
- # announcements (3)
- # babashka (20)
- # beginners (77)
- # calva (27)
- # cider (5)
- # clara (3)
- # clj-kondo (9)
- # cljs-dev (4)
- # cljsrn (5)
- # clojure (26)
- # clojure-europe (32)
- # clojure-italy (5)
- # clojure-nl (3)
- # clojure-uk (5)
- # clojurescript (25)
- # clojureverse-ops (4)
- # core-async (49)
- # cursive (15)
- # data-science (1)
- # datahike (4)
- # datomic (3)
- # docker (1)
- # events (1)
- # helix (5)
- # holy-lambda (3)
- # introduce-yourself (1)
- # jobs (1)
- # kaocha (2)
- # lsp (15)
- # malli (42)
- # off-topic (18)
- # pathom (18)
- # pedestal (12)
- # polylith (7)
- # rdf (1)
- # re-frame (22)
- # reitit (2)
- # releases (1)
- # remote-jobs (1)
- # rewrite-clj (33)
- # shadow-cljs (85)
- # spacemacs (3)
- # vim (12)
- # xtdb (29)
@nbtheduke that reminds me of this post from CircleCI - before rewrite-clj was released :) https://circleci.com/blog/rewriting-your-test-suite-in-clojure-in-24-hours/
Interesting @pithyless! > There was a long delay between actually rewriting the test suite, and the publishing of this blog post. In the meantime, https://github.com/xsc/rewrite-clj has been released. I haven’t used it, but it looks like exactly what we were missing.
that’s a great blog post! i’d forgotten about it
i’m using the node API cuz it’s more my style, and I’m struggling a bit when a node has metadata:
(<token: deftest> <whitespace: " "> <meta:
^{:card-title "15-minutes"}
fifteen-minutes
>)
compared to a test that doesn’t have metadata: (<token: deftest> <whitespace: " "> <token: above-the-law>)
do i just have to check n/inner?
on the deftest name to see if it has metadata and then (somehow) extract the symbol?
and then when i run n/children
, i get back [<map: {:card-title "15-minutes"}> <newline: "\n"> <whitespace: " "> <token: fifteen-minutes>]
if this means i have to write a helper function to extract the symbol, then okay i guess
@nbtheduke This is one minor thing that I don't find that intuitive about rewrite-clj. What I've done in clj-kondo is make a function which turns this upside down: a meta node is a child of the other node. I can get away with this because clj-kondo doesn't write code to text. Yes, a helper function is the answer I think.
This tripped up clj-kondo badly in the beginning because metadata can be pretty much anywhere so you have to do these checks a lot.
coolio
@nbtheduke if you are interested, we https://github.com/clj-commons/rewrite-clj/issues/115.
i’ve subscribed so i can track it!
with the zipper api, the location is a point within the whole parsed text so at any point you can move forward and backwards. that doesn’t seem possible with the node API. have i missed something?
@nbtheduke yes, a zipper location and moving that location (cursor if you will ) around is only something in the zipper API
rough, okay
okay, switched to zipper api and while it’s more awkward, it’s a lot more powerful
i have filtered all of the testing
branches from inside my tests so they’re in a list:
(defn get-testing-branches [zloc]
(->> zloc
(iterate z/right)
(take 100)
(filter #(testing? (z/down %)))
doall))
which i remove and set aside with (let [testing-branches (get-testing-branches zloc) zloc (remove-testing-branches zloc)] …)
now i want to insert these into the zipper after the deftests. (z/up zloc)
gets me to the top-level, and then (z/insert-right ???)
to insert a given testing
block into the top level file?
if I just use (first testing-branches)
, i get something like:
(deftest ^{:card-title "15-minutes"}
fifteen-minutes
;; 15 Minutes - check if it works correctly from both sides
) ^{:zip/branch? #function[rewrite-clj.node.protocols/eval50757/fn--50758/G--50742--50763], :zip/children #function[clojure.core/comp/fn--5529], :zip/make-node #function[rewrite-clj.node.protocols/eval50757/fn--50791/G--50746--50798], :rewrite-clj.zip/opts {:track-position? false, :auto-resolve #function[rewrite-clj.node.protocols/default-auto-resolve]}} [(testing "in corp score area"
...
idk how to convert a seq of zloc
s to nodes i can insert into the document. everything in the node namespace seems to be about manually creating them
my apologies for the flurry of messages/spam lol
So, if I understand here… you’ve saved a bunch of zipper locations and now you want to insert them as nodes to specific spots.
You can always get the node at zipper location with rewrite-clj.zip/node
. Does that help?
I just re-read your use case @nbtheduke : > i’m considering using rewrite-clj to rewrite/rearrange my test suite. it’s currently written in the philosophy of “few `deftest`s, many `testing` branches”, which makes running specific branches hard. i’m looking to pluck each `testing` branch out of the deftests and then place them in a new `deftest` with some name. would this be possible with rewrite-clj? I’ve been meaning to beef up the examples included in the user guide. This sounds like a good one to eventually write up (so, thanks for your question!)
I’ll check out zip.node, I must have missed it. Thankfully, I don’t want to recurse to find nested testing
blocks, we’ve been careful about keeping the top-level testing
blocks as complete units.
Maybe once I’m done and have this working, I’ll show my code and we can write up a longer guide to demonstrate!
Something I noticed is that insert-right
and the related functions use item
as the argument name does the object to be placed. Without examples or further description, I didn’t/don’t know what kind of object item
is supposed to be, and my small experiments weren’t fruitful.
(I purposefully didn’t dive into the source cuz that can easily dovetail into reading the whole code base lol)
Thanks for the great feedback on the vagueness of item
! I’ll make an issue to update this and similarly vague docstrings.