Skip to content

Commit

Permalink
address #29 by adding more-of hook
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Oct 23, 2023
1 parent 92fb663 commit 53cfc09
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .clj-kondo/com.github.seancorfield/expectations/config.edn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{:hooks
{:analyze-call
{expectations.clojure.test/more->
hooks.com.github.seancorfield.expectations/more->}}
hooks.com.github.seancorfield.expectations/more->
expectations.clojure.test/more-of
hooks.com.github.seancorfield.expectations/more-of}}
:lint-as
{expectations.clojure.test/defexpect clojure.test/deftest
expectations.clojure.test/from-each clojure.core/for
expectations.clojure.test/more-of clj-kondo.lint-as/def-catch-all
expectations.clojure.test/=? clojure.core/=}}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,20 @@
(api/token-node 'nil)
tail))]
{:node rewritten}))

(defn more-of [{:keys [node]}]
(let [bindings (fnext (:children node))
pairs (partition 2 (nnext (:children node)))
rewritten
(api/list-node
(list*
(api/token-node 'let)
(api/vector-node (vector bindings (api/token-node 'nil)))
(map (fn [[e a]]
(api/list-node
(list
(api/token-node '=?)
e
a)))
pairs)))]
{:node rewritten}))
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Only accretive/fixative changes will be made from now on.

* 2.1.next in progress
* Address [#29](https://github.com/clojure-expectations/clojure-test/issues/29) by providing a "hook" for `more-of`.
* Update `tools.build` to 0.9.6 (and get rid of `template/pom.xml` in favor of new `:pom-data` option to `b/write-pom`).

* 2.1.182 -- 2023-09-29
Expand Down
2 changes: 2 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
:1.11 {:override-deps {org.clojure/clojure {:mvn/version "1.11.1"}}}
:master {:override-deps {org.clojure/clojure {:mvn/version "1.12.0-master-SNAPSHOT"}}}

:kondo ; for debugging hooks
{:extra-deps {clj-kondo/clj-kondo {:mvn/version "RELEASE"}}}
;; running tests/checks of various kinds:
:test ; can also run clojure -X:test
{:extra-paths ["test"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{:hooks
{:analyze-call
{expectations.clojure.test/more->
hooks.com.github.seancorfield.expectations/more->}}
hooks.com.github.seancorfield.expectations/more->
expectations.clojure.test/more-of
hooks.com.github.seancorfield.expectations/more-of}}
:lint-as
{expectations.clojure.test/defexpect clojure.test/deftest
expectations.clojure.test/from-each clojure.core/for
expectations.clojure.test/more-of clj-kondo.lint-as/def-catch-all
expectations.clojure.test/=? clojure.core/=}}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,20 @@
(api/token-node 'nil)
tail))]
{:node rewritten}))

(defn more-of [{:keys [node]}]
(let [bindings (fnext (:children node))
pairs (partition 2 (nnext (:children node)))
rewritten
(api/list-node
(list*
(api/token-node 'let)
(api/vector-node (vector bindings (api/token-node 'nil)))
(map (fn [[e a]]
(api/list-node
(list
(api/token-node '=?)
e
a)))
pairs)))]
{:node rewritten}))
1 change: 1 addition & 0 deletions test/expectations/clojure/test_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
[from-each in more more-> more-of =?] :as sut]
:cljs [expectations.clojure.test
:include-macros true
:refer-macros [from-each in more more-> more-of =?]
:as sut])))

; The macros are in test_macros.cljc to support ClojureScript.
Expand Down

0 comments on commit 53cfc09

Please sign in to comment.