From 5bd9db3cf39a1f76d70d6ce08d0c08bbc935f4c4 Mon Sep 17 00:00:00 2001 From: Dainius Jocas Date: Fri, 24 Sep 2021 11:39:48 +0300 Subject: [PATCH] feat: add jq lang to test script (#16) --- src/polyglot.clj | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/polyglot.clj b/src/polyglot.clj index daeb435..4d0aed8 100644 --- a/src/polyglot.clj +++ b/src/polyglot.clj @@ -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))) @@ -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) @@ -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