-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
java_interop_test.clj
114 lines (99 loc) · 5.52 KB
/
java_interop_test.clj
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(ns integration.java-interop-test
(:require
[clojure.java.io :as io]
[clojure.string :as string]
[clojure.test :refer [deftest is testing]]
[integration.fixture :as fixture]
[integration.helper :as h]
[integration.lsp :as lsp]))
(lsp/clean-after-test)
(deftest find-definition-of-java-class-when-source-exists
(lsp/start-process!)
(lsp/request! (fixture/initialize-request
{:initializationOptions (dissoc fixture/default-init-options :java)}))
(lsp/notify! (fixture/initialized-notification))
(lsp/notify! (fixture/did-open-source-path-notification "java_interop/a.clj"))
(testing "We find java source class"
(h/assert-submap
{:uri (h/source-path->uri "java_interop/SampleClass.java")
:range {:start {:line 0 :character 0}
:end {:line 0 :character 0}}}
(lsp/request! (fixture/definition-request (h/source-path->uri "java_interop/a.clj") 8 5)))))
(deftest find-definition-of-java-class-when-source-in-a-jar-for-zipfile-scheme
(lsp/start-process!)
(lsp/request! (fixture/initialize-request
{:initializationOptions (-> fixture/default-init-options
(assoc :dependency-scheme "zipfile"))}))
(lsp/notify! (fixture/initialized-notification))
(lsp/notify! (fixture/did-open-source-path-notification "java_interop/a.clj"))
(testing "We find java source class"
(h/assert-submap
{:uri (str "zip" h/maven-repository-uri
"com/googlecode/java-diff-utils/diffutils/1.3.0/diffutils-1.3.0-sources.jar::difflib/DiffUtils.java")
:range {:start {:line 0 :character 0}
:end {:line 0 :character 0}}}
(lsp/request! (fixture/definition-request (h/source-path->uri "java_interop/a.clj") 10 12)))))
(deftest find-definition-of-java-class-when-source-in-a-jar-for-jar-scheme
(lsp/start-process!)
(lsp/request! (fixture/initialize-request
{:initializationOptions (-> fixture/default-init-options
(assoc :dependency-scheme "jar"))}))
(lsp/notify! (fixture/initialized-notification))
(lsp/notify! (fixture/did-open-source-path-notification "java_interop/a.clj"))
(testing "We find java source class"
(h/assert-submap
{:uri (str "jar:" h/maven-repository-uri
"com/googlecode/java-diff-utils/diffutils/1.3.0/diffutils-1.3.0-sources.jar!/difflib/DiffUtils.java")
:range {:start {:line 0 :character 0}
:end {:line 0 :character 0}}}
(lsp/request! (fixture/definition-request (h/source-path->uri "java_interop/a.clj") 10 12)))))
(deftest find-definition-of-java-class-when-source-does-not-exists-for-jar-scheme
(h/delete-project-file "../../.lsp/.cache")
(lsp/start-process!)
(lsp/request! (fixture/initialize-request
{:initializationOptions (-> fixture/default-init-options
(assoc :dependency-scheme "jar")
(dissoc :java)
(assoc-in [:java :decompile-jar-as-project?] false))}))
(lsp/notify! (fixture/initialized-notification))
(lsp/notify! (fixture/did-open-source-path-notification "java_interop/a.clj"))
(let [result (lsp/request! (fixture/definition-request (h/source-path->uri "java_interop/a.clj") 9 5))]
(testing "We find java compiled class first"
(h/assert-submap
{:uri (-> "integration-test/sample-test/.lsp/.cache/java/decompiled/clojure/lang/PersistentVector.java"
io/as-relative-path
io/file
h/file->uri)
:range {:start {:line 0 :character 0}
:end {:line 0 :character 0}}}
result))
(testing "we decompile the class file and get its contents"
(let [class-content (lsp/request! (fixture/clojure-dependency-contents-request (:uri result)))]
(is (string/includes? class-content "Decompiled with CFR"))
(is (string/includes? class-content "class PersistentVector")))))
(h/delete-project-file "../../.lsp/.cache"))
(deftest find-definition-of-java-class-when-source-does-not-exists-for-zipfile-scheme
(h/delete-project-file "../../.lsp/.cache")
(lsp/start-process!)
(lsp/request! (fixture/initialize-request
{:initializationOptions (-> fixture/default-init-options
(assoc :dependency-scheme "zipfile")
(dissoc :java)
(assoc-in [:java :decompile-jar-as-project?] false))}))
(lsp/notify! (fixture/initialized-notification))
(lsp/notify! (fixture/did-open-source-path-notification "java_interop/a.clj"))
(let [result (lsp/request! (fixture/definition-request (h/source-path->uri "java_interop/a.clj") 9 5))]
(testing "We find java compiled class first"
(h/assert-submap
{:uri (-> "integration-test/sample-test/.lsp/.cache/java/decompiled/clojure/lang/PersistentVector.java"
io/as-relative-path
io/file
h/file->uri)
:range {:start {:line 0 :character 0}
:end {:line 0 :character 0}}}
result))
(testing "we decompile the class file and get its contents"
(let [class-content (lsp/request! (fixture/clojure-dependency-contents-request (:uri result)))]
(is (string/includes? class-content "Decompiled with CFR"))
(is (string/includes? class-content "class PersistentVector")))))
(h/delete-project-file "../../.lsp/.cache"))