[#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.common :as common]
[babashka.impl.curl :refer [curl-namespace]] [babashka.impl.curl :refer [curl-namespace]]
[babashka.impl.features :as features] [babashka.impl.features :as features]
[babashka.impl.ordered :refer [ordered-map-ns]]
[babashka.impl.pods :as pods] [babashka.impl.pods :as pods]
[babashka.impl.repl :as repl] [babashka.impl.repl :as repl]
[babashka.impl.socket-repl :as socket-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 'clojure.pprint pprint-namespace
'babashka.curl curl-namespace 'babashka.curl curl-namespace
'babashka.pods pods/pods-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/xml? (assoc 'clojure.data.xml @(resolve 'babashka.impl.xml/xml-namespace))
features/yaml? (assoc 'clj-yaml.core @(resolve 'babashka.impl.yaml/yaml-namespace)) features/yaml? (assoc 'clj-yaml.core @(resolve 'babashka.impl.yaml/yaml-namespace))
features/jdbc? (assoc 'next.jdbc @(resolve 'babashka.impl.jdbc/njdbc-namespace) features/jdbc? (assoc 'next.jdbc @(resolve 'babashka.impl.jdbc/njdbc-namespace)

View file

@ -46,9 +46,11 @@
op (read-string op) op (read-string op)
op (keyword op)] op (keyword op)]
(case op (case op
:describe (do (write {"format" (if (= format :json) :describe
(do (write {"format" (if (= format :json)
"json" "json"
"edn") "edn")
"readers" {"ordered/map" "flatland.ordered.map/ordered-map"}
"namespaces" "namespaces"
[{"name" "pod.test-pod" [{"name" "pod.test-pod"
"vars" [{"name" "add-sync"} "vars" [{"name" "add-sync"}
@ -61,7 +63,8 @@
{"name" "assoc"} {"name" "assoc"}
{"name" "error"} {"name" "error"}
{"name" "print"} {"name" "print"}
{"name" "print-err"}]}] {"name" "print-err"}
{"name" "ordered-map"}]}]
"ops" {"shutdown" {}}}) "ops" {"shutdown" {}}})
(recur)) (recur))
:invoke (let [var (-> (get message "var") :invoke (let [var (-> (get message "var")
@ -112,7 +115,12 @@
"id" id}) "id" id})
(write (write
{"status" ["done"] {"status" ["done"]
"id" id}))) "id" id}))
pod.test-pod/ordered-map
(write
{"value" "#ordered/map([:a 1] [:b 2])"
"status" ["done"]
"id" id}))
(recur)) (recur))
:shutdown (System/exit 0)))))))) :shutdown (System/exit 0))))))))
@ -144,4 +152,8 @@
(debug "Running print test") (debug "Running print test")
((resolve 'pod.test-pod/print) "hello" "print" "this" "debugging" "message") ((resolve 'pod.test-pod/print) "hello" "print" "this" "debugging" "message")
(debug "Running print-err test") (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.java.shell :refer [sh]]
[clojure.string :as str] [clojure.string :as str]
[clojure.test :as test :refer [deftest is testing]] [clojure.test :as test :refer [deftest is testing]]
[flatland.ordered.map :refer [ordered-map]]
[sci.core :as sci])) [sci.core :as sci]))
(defmethod clojure.test/report :begin-test-var [m] (defmethod clojure.test/report :begin-test-var [m]
@ -14,7 +15,10 @@
(println)) (println))
(defn bb [input & args] (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 (deftest parse-opts-test
(is (= {:nrepl "1667"} (is (= {:nrepl "1667"}
@ -469,6 +473,9 @@
(deftest data-readers-test (deftest data-readers-test
(is (= 2 (bb nil "(set! *data-readers* {'t/tag inc}) #t/tag 1")))) (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 ;;;; Scratch
(comment (comment

View file

@ -11,7 +11,7 @@
native? native?
(conj "--native"))) (conj "--native")))
err (str sw)] 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? (when-not tu/native?
(is (= "(\"hello\" \"print\" \"this\" \"error\")\n" err))) (is (= "(\"hello\" \"print\" \"this\" \"error\")\n" err)))
(is (= {:a 1 :b 2} (is (= {:a 1 :b 2}