diff --git a/src/findfn/core.clj b/src/findfn/core.clj index 847491e..431829c 100644 --- a/src/findfn/core.clj +++ b/src/findfn/core.clj @@ -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 diff --git a/test/findfn/core_test.clj b/test/findfn/core_test.clj index 11560c4..c71d850 100644 --- a/test/findfn/core_test.clj +++ b/test/findfn/core_test.clj @@ -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]))))