Skip to content

Commit

Permalink
feat: add jq lang to test script (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
dainiusjocas authored Sep 24, 2021
1 parent fc84164 commit 5bd9db3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/polyglot.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
(:require [clojure.string :as s]
[clojure.data :as data]
[clojure.java.io :as io]
[clojure.tools.logging :as log]
[core.json :as json]
[polyglot.js :as js]
[polyglot.jq :as jq]
[polyglot.sci :as sci])
(:import (java.io File)))

Expand All @@ -29,6 +29,15 @@
{:data "{\"my\": \"data\"}"
:script "(fn [m] (assoc m :foo :bar))"}))

(defn apply-jq-transformation [{:keys [data script]}]
(let [script (jq/script->transform-fn script)]
(script data)))

(comment
(polyglot/apply-jq-transformation
{:data "{\"my\": \"data\"}"
:script ".foo = \"bar\""}))

(defn compare-with-expected [^String expected ^String actual]
(let [e (json/decode expected)
a (json/decode actual)
Expand Down Expand Up @@ -61,6 +70,7 @@
(and (nil? script) (.exists ^File (io/file file))) (assoc :script (slurp file)))]
(case lang-code
:js (apply-js-transformation req)
:jq (apply-jq-transformation req)
:sci (apply-sci-transformation req)
{:error (format "Language '%s' is not supported." lang)}))))
matches-expected? (when expected
Expand Down

0 comments on commit 5bd9db3

Please sign in to comment.