Back
as-url (clj)
(source)protocol
(as-url x)
Coerce argument to a URL.
Examples
clojure/clojurescript
(ns cljs.util-tests
(:require [cljs.util :as util]
[clojure.java.io :as io])
(:use clojure.test))
(deftest test-relative-name
(if util/windows?
(let [initial (System/getProperty "user.dir")]
(System/setProperty "user.dir" "C:\\Users\\anmonteiro\\Downloads\\clojurescript-master")
(is (= (util/relative-name (io/file "C:\\Users\\anmonteiro\\Downloads\\clojurescript-master\\out\\index.js")) "out\\index.js"))
(is (= (util/relative-name (io/as-url (io/file "C:\\Users\\anmonteiro\\Downloads\\clojurescript-master\\node_modules\\lodash\\array.js"))) "node_modules\\lodash\\array.js"))
;; Check case-sensitivity:
(System/setProperty "user.dir" "c:\\users\\anmonteiro\\Downloads\\clojurescript-master")
(is (= (util/relative-name (io/file "C:\\Users\\anmonteiro\\Downloads\\clojurescript-master\\out\\index.js")) "out\\index.js"))
(is (= (util/relative-name (io/as-url (io/file "C:\\Users\\anmonteiro\\Downloads\\clojurescript-master\\node_modules\\lodash\\array.js"))) "node_modules\\lodash\\array.js"))
;; Check pass-through:
(is (= (util/relative-name (io/file "C:\\Temp\\clojurescript\\out\\index.js")) "C:\\Temp\\clojurescript\\out\\index.js"))
(System/setProperty "user.dir" initial))
;; Non-windows
(let [initial (System/getProperty "user.dir")]
(System/setProperty "user.dir" "/Users/user/clojurescript")
(is (= (util/relative-name (io/file "/Users/user/clojurescript/out/index.js")) "out/index.js"))
(is (= (util/relative-name (io/as-url (io/file "/Users/user/clojurescript/out/index.js"))) "out/index.js"))
;; Check pass-through:
(is (= (util/relative-name (io/file "/tmp/clojurescript/out/index.js")) "/tmp/clojurescript/out/index.js"))
(System/setProperty "user.dir" initial))))
(deftest test-path
(is (= (.getAbsolutePath (io/file "src/main/clojure/cljs/closure.clj"))
(util/path (io/as-url (io/file "src/main/clojure/cljs/closure.clj"))))))
defold/defold
(ns editor.image-test
(:require [clojure.java.io :refer [as-url file]]
[clojure.test.check.clojure-test :refer [defspec]]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]
[clojure.test :refer :all]
[editor.image :refer :all]
[editor.image-util :refer :all]
[editor.geom :refer :all]
[schema.test])
(:import [java.awt.image BufferedImage]))
(deftest image-loading
(let [img (make-image (as-url (file "foo")) (BufferedImage. 128 192 BufferedImage/TYPE_4BYTE_ABGR))]
(is (= 128 (.width img)))
(is (= 192 (.height img)))))
jonase/eastwood
(ns testcases.unusednss3
(:require [clojure.core.protocols :as protocols]
[clojure.core.reducers :as reducers]
[clojure.data :as data]
[clojure.java.io :as io]
[clojure.reflect :as reflect]))
(deftype Foo [whatever]
io/Coercions
(as-file [x] nil)
(as-url [x] nil))
clojure-emacs/cider-nrepl
(ns cider.nrepl.middleware.slurp-test
(:require
[cider.nrepl.middleware.slurp :refer [slurp-url-to-content+body]]
[clojure.java.io :as io]
[clojure.test :as t]
[clojure.string :as str]
[orchard.misc :refer [java-api-version]]))
(t/deftest test-project-clj-is-clj
(let [resp (-> "project.clj"
io/file
io/as-url
.toString
slurp-url-to-content+body)]
(t/is (= ["text/clojure" {}] (:content-type resp)))
(t/is (not= "base64" (:content-transfer-encoding resp)))))
(t/deftest test-directory
(let [resp (-> "test"
io/file
io/as-url
.toString
slurp-url-to-content+body)]
(t/is (= ["application/octet-stream" {}] (:content-type resp)))
(t/is (str/starts-with? (:body resp) "#binary[location="))
(t/is (str/ends-with? (:body resp) ",size=0]"))))
damballa/parkour
(ns parkour.fs-test
(:require [clojure.test :refer :all]
[clojure.java.io :as io]
[parkour (conf :as conf) (fs :as fs)]
[parkour.test-helpers :as th]))
(deftest test-path
(let [p #hadoop.fs/path "foo"]
(is (identical? p (fs/path p))))
(is (= #hadoop.fs/path "foo"
(fs/path "foo")))
(is (= #hadoop.fs/path "file:foo"
(fs/path "file:foo")
(fs/path (io/file "foo"))
(fs/path (io/as-url (io/file "foo")))
(fs/path (fs/uri (io/as-url (io/file "foo"))))))
(is (= #hadoop.fs/path "http://www.example.com/path"
(fs/path "http://www.example.com/path")
(fs/path (io/as-url "http://www.example.com/path"))
(fs/path (fs/uri (io/as-url "http://www.example.com/path"))))))