[#447] expose flatland.ordered.map/ordered-map

This commit is contained in:
Michiel Borkent 2020-05-22 18:18:42 +02:00 committed by GitHub
parent d92496faaa
commit 03fba08e31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 20 deletions

@ -1 +1 @@
Subproject commit 1ff8316d02ddeca3a27fa4032e66d0c77c66e64e
Subproject commit 62e0a1b074cb9e2779f73ae4ea88088bf56e4a6a

View file

@ -0,0 +1,9 @@
(ns babashka.impl.ordered
{:no-doc true}
(:require [flatland.ordered.map :as omap]
[sci.core :as sci]))
(def omap-ns (sci/create-ns 'flatland.ordered.map nil))
(def ordered-map-ns
{'ordered-map (sci/copy-var omap/ordered-map omap-ns)})

View file

@ -15,6 +15,7 @@
[babashka.impl.common :as common]
[babashka.impl.curl :refer [curl-namespace]]
[babashka.impl.features :as features]
[babashka.impl.ordered :refer [ordered-map-ns]]
[babashka.impl.pods :as pods]
[babashka.impl.repl :as repl]
[babashka.impl.socket-repl :as socket-repl]
@ -359,7 +360,8 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
'clojure.pprint pprint-namespace
'babashka.curl curl-namespace
'babashka.pods pods/pods-namespace
'bencode.core bencode-namespace}
'bencode.core bencode-namespace
'flatland.ordered.map ordered-map-ns}
features/xml? (assoc 'clojure.data.xml @(resolve 'babashka.impl.xml/xml-namespace))
features/yaml? (assoc 'clj-yaml.core @(resolve 'babashka.impl.yaml/yaml-namespace))
features/jdbc? (assoc 'next.jdbc @(resolve 'babashka.impl.jdbc/njdbc-namespace)

View file

@ -46,24 +46,27 @@
op (read-string op)
op (keyword op)]
(case op
:describe (do (write {"format" (if (= format :json)
"json"
"edn")
"namespaces"
[{"name" "pod.test-pod"
"vars" [{"name" "add-sync"}
{"name" "range-stream"
"code" "
:describe
(do (write {"format" (if (= format :json)
"json"
"edn")
"readers" {"ordered/map" "flatland.ordered.map/ordered-map"}
"namespaces"
[{"name" "pod.test-pod"
"vars" [{"name" "add-sync"}
{"name" "range-stream"
"code" "
(defn range-stream [val-cb done-cb & args]
(babashka.pods/invoke \"pod.test-pod\" 'pod.test-pod/range-stream* args
{:handlers {:success val-cb :done done-cb}})
nil)"}
{"name" "assoc"}
{"name" "error"}
{"name" "print"}
{"name" "print-err"}]}]
"ops" {"shutdown" {}}})
(recur))
{"name" "assoc"}
{"name" "error"}
{"name" "print"}
{"name" "print-err"}
{"name" "ordered-map"}]}]
"ops" {"shutdown" {}}})
(recur))
:invoke (let [var (-> (get message "var")
read-string
symbol)
@ -112,7 +115,12 @@
"id" id})
(write
{"status" ["done"]
"id" id})))
"id" id}))
pod.test-pod/ordered-map
(write
{"value" "#ordered/map([:a 1] [:b 2])"
"status" ["done"]
"id" id}))
(recur))
:shutdown (System/exit 0))))))))
@ -144,4 +152,8 @@
(debug "Running print test")
((resolve 'pod.test-pod/print) "hello" "print" "this" "debugging" "message")
(debug "Running print-err test")
((resolve 'pod.test-pod/print-err) "hello" "print" "this" "error"))))))
((resolve 'pod.test-pod/print-err) "hello" "print" "this" "error")
(debug "Running reader test")
(require '[flatland.ordered.map :refer [ordered-map]])
(prn (= ((resolve 'flatland.ordered.map/ordered-map) :a 1 :b 2)
((resolve 'pod.test-pod/ordered-map)))))))))

View file

@ -7,6 +7,7 @@
[clojure.java.shell :refer [sh]]
[clojure.string :as str]
[clojure.test :as test :refer [deftest is testing]]
[flatland.ordered.map :refer [ordered-map]]
[sci.core :as sci]))
(defmethod clojure.test/report :begin-test-var [m]
@ -14,7 +15,10 @@
(println))
(defn bb [input & args]
(edn/read-string (apply test-utils/bb (when (some? input) (str input)) (map str args))))
(edn/read-string
{:readers *data-readers*
:eof nil}
(apply test-utils/bb (when (some? input) (str input)) (map str args))))
(deftest parse-opts-test
(is (= {:nrepl "1667"}
@ -469,6 +473,9 @@
(deftest data-readers-test
(is (= 2 (bb nil "(set! *data-readers* {'t/tag inc}) #t/tag 1"))))
(deftest ordered-test
(is (= (ordered-map :a 1 :b 2) (bb nil "(flatland.ordered.map/ordered-map :a 1 :b 2)"))))
;;;; Scratch
(comment

View file

@ -11,7 +11,7 @@
native?
(conj "--native")))
err (str sw)]
(is (= "6\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\"Illegal arguments / {:args (1 2 3)}\"\n(\"hello\" \"print\" \"this\" \"debugging\" \"message\")\n" res))
(is (= "6\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\"Illegal arguments / {:args (1 2 3)}\"\n(\"hello\" \"print\" \"this\" \"debugging\" \"message\")\ntrue\n" res))
(when-not tu/native?
(is (= "(\"hello\" \"print\" \"this\" \"error\")\n" err)))
(is (= {:a 1 :b 2}