Back
to-str (clj)
(source)protocol
(to-str x)
Convert a value into a string.
Examples
hiccup
(ns hiccup.util_test
(:require [clojure.test :refer :all]
[hiccup.util :refer :all])
(:import java.net.URI))
(deftest test-to-uri
(testing "with no base URL"
(is (= (to-str (to-uri "foo")) "foo"))
(is (= (to-str (to-uri "/foo/bar")) "/foo/bar"))
(is (= (to-str (to-uri "/foo#bar")) "/foo#bar")))
(testing "with base URL"
(with-base-url "/foo"
(is (= (to-str (to-uri "/bar")) "/foo/bar"))
(is (= (to-str (to-uri "http://example.com")) "http://example.com"))
(is (= (to-str (to-uri "https://example.com/bar")) "https://example.com/bar"))
(is (= (to-str (to-uri "bar")) "bar"))
(is (= (to-str (to-uri "../bar")) "../bar"))
(is (= (to-str (to-uri "//example.com/bar")) "//example.com/bar"))))
(testing "with base URL for root context"
(with-base-url "/"
(is (= (to-str (to-uri "/bar")) "/bar"))
(is (= (to-str (to-uri "http://example.com")) "http://example.com"))
(is (= (to-str (to-uri "https://example.com/bar")) "https://example.com/bar"))
(is (= (to-str (to-uri "bar")) "bar"))
(is (= (to-str (to-uri "../bar")) "../bar"))
(is (= (to-str (to-uri "//example.com/bar")) "//example.com/bar"))))
(testing "with base URL containing trailing slash"
(with-base-url "/foo/"
(is (= (to-str (to-uri "/bar")) "/foo/bar"))
(is (= (to-str (to-uri "http://example.com")) "http://example.com"))
(is (= (to-str (to-uri "https://example.com/bar")) "https://example.com/bar"))
(is (= (to-str (to-uri "bar")) "bar"))
(is (= (to-str (to-uri "../bar")) "../bar"))
(is (= (to-str (to-uri "//example.com/bar")) "//example.com/bar")))))
weavejester/hiccup
(ns hiccup.util_test
(:require [clojure.test :refer :all]
[hiccup.util :refer :all])
(:import java.net.URI))
(deftest test-to-uri
(testing "with no base URL"
(is (= (to-str (to-uri "foo")) "foo"))
(is (= (to-str (to-uri "/foo/bar")) "/foo/bar"))
(is (= (to-str (to-uri "/foo#bar")) "/foo#bar")))
(testing "with base URL"
(with-base-url "/foo"
(is (= (to-str (to-uri "/bar")) "/foo/bar"))
(is (= (to-str (to-uri "http://example.com")) "http://example.com"))
(is (= (to-str (to-uri "https://example.com/bar")) "https://example.com/bar"))
(is (= (to-str (to-uri "bar")) "bar"))
(is (= (to-str (to-uri "../bar")) "../bar"))
(is (= (to-str (to-uri "//example.com/bar")) "//example.com/bar"))))
(testing "with base URL for root context"
(with-base-url "/"
(is (= (to-str (to-uri "/bar")) "/bar"))
(is (= (to-str (to-uri "http://example.com")) "http://example.com"))
(is (= (to-str (to-uri "https://example.com/bar")) "https://example.com/bar"))
(is (= (to-str (to-uri "bar")) "bar"))
(is (= (to-str (to-uri "../bar")) "../bar"))
(is (= (to-str (to-uri "//example.com/bar")) "//example.com/bar"))))
(testing "with base URL containing trailing slash"
(with-base-url "/foo/"
(is (= (to-str (to-uri "/bar")) "/foo/bar"))
(is (= (to-str (to-uri "http://example.com")) "http://example.com"))
(is (= (to-str (to-uri "https://example.com/bar")) "https://example.com/bar"))
(is (= (to-str (to-uri "bar")) "bar"))
(is (= (to-str (to-uri "../bar")) "../bar"))
(is (= (to-str (to-uri "//example.com/bar")) "//example.com/bar")))))
clojars/clojars-web
(ns clojars.unit.web.common-test
(:require
[clojars.web.common :as common]
[clojure.test :refer [deftest is]]
[hiccup.util :refer [to-str]]))
(letfn [(cook-content [v]
(conj (vec (butlast v)) (to-str (last v))))]