-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test for elin.function.sexp/get-namespace
- Loading branch information
Showing
3 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(ns elin.function.sexp-test | ||
(:require | ||
[clojure.test :as t] | ||
[elin.function.sexp :as sut] | ||
[elin.test-helper :as h])) | ||
|
||
(defn- get-namespace-writer | ||
[ns-form] | ||
(let [handler #(if (h/call-function? % "elin#internal#clojure#get_ns_form") | ||
ns-form | ||
"")] | ||
(h/test-writer {:handler handler}))) | ||
|
||
(t/deftest get-namespace-test | ||
(t/testing "no metadata" | ||
(t/is (= 'foo.bar | ||
(sut/get-namespace (get-namespace-writer "(ns foo.bar)"))))) | ||
|
||
(t/testing "with metadata" | ||
(t/is (= 'foo.bar | ||
(sut/get-namespace (get-namespace-writer "(ns ^:meta foo.bar)")))) | ||
(t/is (= 'foo.bar | ||
(sut/get-namespace (get-namespace-writer "(ns ^{:meta true} foo.bar)"))))) | ||
|
||
(t/testing "in-ns" | ||
(t/is (= 'foo.bar | ||
(sut/get-namespace (get-namespace-writer "(in-ns 'foo.bar)")))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,105 @@ | ||
(ns elin.test-helper | ||
(:require | ||
[clojure.core.async :as async] | ||
[elin.protocol.rpc :as e.p.rpc] | ||
[elin.schema.server :as e.s.server] | ||
[elin.util.id :as e.u.id] | ||
[malli.core :as m] | ||
[malli.dev.pretty :as m.d.pretty] | ||
[malli.instrument :as m.inst])) | ||
|
||
(def ?TestMessageOption | ||
[:map | ||
[:handler [:=> [:cat [:sequential any?]] any?]]]) | ||
|
||
(m.inst/instrument! | ||
{:report (m.d.pretty/reporter)}) | ||
|
||
(defprotocol ITestWriter | ||
(get-outputs [this])) | ||
|
||
(defrecord TestMessage | ||
[host message] | ||
e.p.rpc/IMessage | ||
(request? [_] | ||
(= 0 (first message))) | ||
|
||
(response? [_] | ||
(= 1 (first message))) | ||
|
||
(parse-message [_] | ||
(condp = (first message) | ||
;; request | ||
0 (let [[_ id method [params]] message] | ||
{:id id | ||
:method (keyword method) | ||
:params params}) | ||
;; response | ||
1 (let [[_ id error result] message] | ||
{:id id | ||
:error error | ||
:result result}) | ||
;; notify | ||
2 (let [[_ method [params callback]] message] | ||
{:method (keyword method) | ||
:params params | ||
:callback callback}) | ||
{}))) | ||
|
||
(defrecord TestWriter | ||
[output-stream outputs option] | ||
e.p.rpc/IWriter | ||
(request! [_ content] | ||
(let [id (e.u.id/next-id) | ||
{:keys [handler]} option | ||
[result error] (try | ||
[(handler (concat [0 id] content))] | ||
(catch Exception ex | ||
[nil (ex-message ex)])) | ||
ch (async/chan)] | ||
(async/go | ||
(async/>! ch {:result result :error error})) | ||
ch)) | ||
|
||
(notify! [_ content] | ||
(let [{:keys [handler]} option] | ||
(handler (concat [2] content)) | ||
nil)) | ||
|
||
(response! [_this _error _result] | ||
nil) | ||
|
||
e.p.rpc/IFunction | ||
(call-function [this method params] | ||
(e.p.rpc/request! this ["test_call_function" [method params]])) | ||
|
||
(echo-text [_ text] | ||
(swap! outputs conj text)) | ||
(echo-message [_ text] | ||
(swap! outputs conj text)) | ||
(echo-message [_ text _highlight] | ||
(swap! outputs conj text)) | ||
|
||
ITestWriter | ||
(get-outputs [_] @outputs)) | ||
|
||
(m/=> test-message [:=> :cat e.s.server/?Message]) | ||
(defn test-message | ||
[] | ||
(map->TestMessage {:host "test" | ||
:message []})) | ||
|
||
(m/=> test-writer [:=> [:cat ?TestMessageOption] e.s.server/?Writer]) | ||
(defn test-writer | ||
[option] | ||
(map->TestWriter {:output-stream (java.io.ByteArrayOutputStream.) | ||
:outputs (atom []) | ||
:option option})) | ||
|
||
;;(0 7 test_call_function [elin#internal#clojure#get_ns_form []]) | ||
(defn call-function? [msg fn-name] | ||
(and | ||
(= "test_call_function" (nth msg 2)) | ||
(= fn-name (first (nth msg 3))))) | ||
|
||
;;(0 7 test_call_function [elin#internal#clojure#get_ns_form []]) |