Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/findfn/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,22 @@
(close [])
(flush [])))

(defn find-fn-for-pred
"Takes a predicate and expected input and runs every single function
and macro against the input, collecting the names of the ones where
(pred result) is true."
[tester pred & in]
(let [sb (sb/sandbox tester :timeout 200)]
(filter-vars
(fn [f]
(pred (sb `(~f ~@in) {#'*out* (null-writer)}))))))

(defn find-fn
"Takes expected output and expected input to produce that output and
runs every single function and macro against the input, collecting the
names of the ones that match the output."
[tester out & in]
(let [sb (sb/sandbox tester :timeout 200)]
(filter-vars
(fn [f]
(= out (sb `(~f ~@in) {#'*out* (null-writer)}))))))
(apply find-fn-for-pred tester #(= % out) in))

(defn find-arg
"Basically find-fn for finding functions to pass to higher order functions. out is
Expand Down
6 changes: 6 additions & 0 deletions test/findfn/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
[clojail.testers :only [secure-tester]]
findfn.core))

(deftest find-fn-for-pred-test
(testing "that it works"
(is (= (find-fn-for-pred secure-tester #(= (count %) 6) "lol" "omg")
'[clojure.core/lazy-cat clojure.core/concat
clojure.core/interleave clojure.core/str]))))

(deftest find-fn-test
(testing "that it works."
(is (= (find-fn secure-tester "lolomg" "lol" "omg") '[clojure.core/str]))))
Expand Down