|
1 | 1 | (ns cider.nrepl.middleware.info-test |
2 | 2 | (:require |
3 | | - [clojure.data] |
4 | | - [clojure.test :refer :all] |
5 | | - [clojure.string :as str] |
6 | 3 | [cider.nrepl.middleware.info :as info] |
7 | 4 | [cider.nrepl.test-session :as session] |
8 | | - [cider.test-ns.first-test-ns :as test-ns]) |
| 5 | + [cider.test-ns.first-test-ns :as test-ns] |
| 6 | + [clojure.data] |
| 7 | + [clojure.java.io :as io] |
| 8 | + [clojure.string :as str] |
| 9 | + [clojure.test :refer :all]) |
9 | 10 | (:import |
10 | | - [cider.nrepl.test TestClass AnotherTestClass YetAnotherTest] |
11 | | - [org.apache.commons.lang3 SystemUtils])) |
| 11 | + (cider.nrepl.test AnotherTestClass TestClass YetAnotherTest) |
| 12 | + (org.apache.commons.lang3 SystemUtils))) |
12 | 13 |
|
13 | 14 | (defprotocol FormatResponseTest |
14 | 15 | (proto-foo [this]) |
15 | 16 | (proto-bar [this] "baz")) |
16 | 17 |
|
| 18 | +(def enriched-classpath? |
| 19 | + "Is enrich-classpath (or something equivalent) augmenting the classpath?" |
| 20 | + (boolean (or (io/resource "java/lang/Thread.java") |
| 21 | + (io/resource "java.base/java/lang/Thread.java")))) |
| 22 | + |
17 | 23 | (deftest format-response-test |
18 | 24 | (is (re-find #"^(https?|file|jar|zip):" ; resolved either locally or online |
19 | 25 | (-> (info/info {:class "java.lang.Object" :member "toString"}) |
|
32 | 38 | (is (nil? (info/format-response (info/info {:ns "cider.nrepl.middleware.info" :sym "notincanter.core"})))) |
33 | 39 | ;; unfound nses should fall through |
34 | 40 | (is (nil? (info/format-response (info/info {:ns "cider.nrepl.middleware.nonexistent-namespace" :sym "a-var"})))) |
35 | | - ;; protorol docstring |
| 41 | + ;; protocol docstring |
36 | 42 | (is (-> (info/format-response (info/info {:ns "cider.nrepl.middleware.info-test" :sym "proto-foo"})) |
37 | 43 | (contains? "doc") |
38 | 44 | not)) |
|
106 | 112 | (is (= (:doc response) "a macro for testing")) |
107 | 113 | (is (nil? (:spec response))))) |
108 | 114 |
|
| 115 | + (when enriched-classpath? |
| 116 | + (testing "'fragments' attributes are returned" |
| 117 | + (let [{:keys [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments] |
| 118 | + :as response} |
| 119 | + (session/message {:op "info" |
| 120 | + :class "java.lang.Thread" |
| 121 | + :member "sleep"})] |
| 122 | + (testing (pr-str response) |
| 123 | + (doseq [f [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments]] |
| 124 | + (is (vector? f)) |
| 125 | + (is (map? (first f)))) |
| 126 | + (is (= #{"done"} (:status response))))))) |
| 127 | + |
109 | 128 | (testing "get info of a java instance method with return value" |
110 | 129 | (let [response (session/message {:op "info" |
111 | 130 | :class "cider.nrepl.test.TestClass" |
|
317 | 336 | (is (not (contains? response :ns))) |
318 | 337 | (is (= (:type response) "function")))) |
319 | 338 |
|
| 339 | + (when enriched-classpath? |
| 340 | + (testing "Fragments for java interop method with single class" |
| 341 | + (let [{:keys [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments] |
| 342 | + :as response} |
| 343 | + (session/message {:op "eldoc" :member "sleep" :class "java.lang.Thread"})] |
| 344 | + (testing (pr-str response) |
| 345 | + |
| 346 | + (doseq [f [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments]] |
| 347 | + (is (vector? f)) |
| 348 | + (is (map? (first f)))))))) |
| 349 | + |
320 | 350 | (testing "java interop method with single class" |
321 | 351 | (let [response (session/message {:op "eldoc" :sym ".startsWith" :ns "cider.nrepl.middleware.info-test"})] |
322 | 352 | (is (= (:class response) ["java.lang.String"]) |
|
0 commit comments