File: api.clj

package info (click to toggle)
clojure1.6 1.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,608 kB
  • ctags: 5,838
  • sloc: java: 27,336; xml: 498; sh: 69; makefile: 45
file content (54 lines) | stat: -rw-r--r-- 1,628 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;   Copyright (c) Rich Hickey. All rights reserved.
;   The use and distribution terms for this software are covered by the
;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;   which can be found in the file epl-v10.html at the root of this distribution.
;   By using this software in any fashion, you are agreeing to be bound by
;   the terms of this license.
;   You must not remove this notice, or any other, from this software.

(ns clojure.test-clojure.api
  (:require [clojure.test.generative :refer (defspec)]
            [clojure.test-clojure.generators :as cgen])
  (:import clojure.lang.IFn
           clojure.java.api.Clojure
           clojure.lang.Var))

(set! *warn-on-reflection* true)

(defn roundtrip
  "Print an object and read it back with Clojure/read"
  [o]
  (binding [*print-length* nil
            *print-dup* nil
            *print-level* nil]
    (Clojure/read (pr-str o))))

(defn api-var-str
  [^Var v]
  (Clojure/var (str (.name (.ns v)))
               (str (.sym v))))

(defn api-var
  [^Var v]
  (Clojure/var (.name (.ns v))
               (.sym v)))

(defspec api-can-read
  roundtrip
  [^{:tag cgen/ednable} o]
  (when-not (= o %)
    (throw (ex-info "Value cannot roundtrip with Clojure/read" {:printed o :read %}))))

(defspec api-can-find-var
  api-var
  [^{:tag cgen/var} v]
  (when-not (= v %)
    (throw (ex-info "Var cannot roundtrip through Clojure/var" {:from v :to %}))))

(defspec api-can-find-var-str
  api-var-str
  [^{:tag cgen/var} v]
  (when-not (= v %)
    (throw (ex-info "Var cannot roundtrip strings through Clojure/var" {:from v :to %}))))