forked from helpshift/hydrox
/
midje.clj
50 lines (43 loc) · 1.67 KB
/
midje.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(ns hydrox.analyse.test.midje
(:require [jai.query :as query]
[clojure.string :as string]
[rewrite-clj.zip :as source]
[rewrite-clj.node :as node]
[hydrox.analyse.test.common :as common]))
(defn gather-fact-body
([zloc]
(gather-fact-body zloc []))
([zloc output]
(cond (nil? zloc) output
(and (= :meta (source/tag zloc))
(= [:token :hidden] (source/value zloc)))
output
(query/match zloc string?)
(recur (source/right* zloc)
(conj output (common/gather-string zloc)))
:else
(recur (source/right* zloc) (conj output (source/node zloc))))))
(defn gather-fact
"Make docstring notation out of fact form
(-> \"^{:refer example/hello-world :added \\\"0.1\\\"}
(fact \\\"Sample test program\\\"\\n (+ 1 1) => 2\\n (long? 3) => true)\"
(z/of-string)
z/down z/right z/down z/right
(gather-fact)
:docs
common/join-nodes)
=> \"\"Sample test program\"\\n (+ 1 1) => 2\\n (long? 3) => true\""
{:added "0.1"}
[zloc]
(if-let [mta (common/gather-meta zloc)]
(assoc mta :docs (gather-fact-body zloc))))
(defmethod common/frameworks 'midje.sweet [_] :midje)
(defmethod common/analyse-test :midje
([type zloc]
(let [fns (query/$ zloc [(fact | & _)] {:return :zipper :walk :top})]
(->> (keep gather-fact fns)
(reduce (fn [m {:keys [ns var docs] :as meta}]
(-> m
(assoc-in [ns var :docs] docs)
(assoc-in [ns var :meta] (dissoc meta :docs :ns :var :refer))))
{})))))