From ab5a02ec30150494184890a169c9819ad80f545f Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 17 Oct 2020 21:13:27 +0200 Subject: [PATCH] [#601] Support clojure.java.io/Coercions --- test/babashka/impl/clojure/java/io_test.clj | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/babashka/impl/clojure/java/io_test.clj diff --git a/test/babashka/impl/clojure/java/io_test.clj b/test/babashka/impl/clojure/java/io_test.clj new file mode 100644 index 00000000..ea47075b --- /dev/null +++ b/test/babashka/impl/clojure/java/io_test.clj @@ -0,0 +1,25 @@ +(ns babashka.impl.clojure.java.io-test + (:require [babashka.test-utils :as test-utils] + [clojure.edn :as edn] + [clojure.test :as t :refer [deftest is]])) + +(defn bb [& args] + (edn/read-string + {:readers *data-readers* + :eof nil} + (apply test-utils/bb nil (map str args)))) + +(deftest nio-coercion-test + (is (true? (bb " +(require '[clojure.java.io :as io]) + +(extend-protocol io/Coercions + java.nio.file.Path + (as-file [this] (.toFile this)) + (as-url [this] (.. this (toFile) (toURL)))) + +(def path (.toPath (io/file \".\"))) +;; ^ this is a java.nio.file.Path + +(.exists (io/file path)) ;; true +"))))