Skip to content

Commit 1fc3b38

Browse files
alexander-yakushevbbatsov
authored andcommitted
[test] Update parser tests
1 parent db280f6 commit 1fc3b38

File tree

1 file changed

+80
-87
lines changed

1 file changed

+80
-87
lines changed

test/orchard/java/parser_next_test.clj

Lines changed: 80 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
[clojure.java.io :as io]
44
[clojure.string :as str]
55
[clojure.test :refer [deftest is testing]]
6+
[matcher-combinators.matchers :as mc]
67
[orchard.java :as java]
78
[orchard.misc :as misc]
8-
[orchard.test.util :as util])
9+
[orchard.test.util :as util :refer [is+]])
910
(:import
1011
(orchard.java DummyClass)))
1112

@@ -30,85 +31,80 @@
3031
(parse-java (io/resource "orchard/java/InvalidClass.java") nil)
3132
(assert false)
3233
(catch Exception e
33-
(is (-> e ex-data :out (str/includes? "illegal start of expression"))))))))
34+
(is+ {:out #"illegal start of expression"} (ex-data e)))))))
3435

3536
(when jdk11+?
3637
(deftest source-info-test
3738
(is (class? DummyClass))
3839

3940
(testing "file on the filesystem"
40-
(is (= '{:doc-first-sentence-fragments
41-
[{:type "text", :content "Class level docstring."}],
42-
:column 1,
43-
:line 12,
44-
:class orchard.java.DummyClass,
45-
:doc-fragments
46-
[{:type "text", :content "Class level docstring.\n\n"}
47-
{:type "html",
48-
:content
49-
"<pre> \n DummyClass dc = new DummyClass();\n </pre>"}],
50-
:members
51-
{dummyMethod
52-
{[]
53-
{:name dummyMethod,
54-
:type java.lang.String,
55-
:doc-first-sentence-fragments
56-
[{:type "text", :content "Method-level docstring."}],
57-
:column 5,
58-
:argtypes [],
59-
:non-generic-argtypes []
60-
:line 18,
61-
:argnames [],
62-
:doc-fragments
63-
[{:type "text", :content "Method-level docstring."}],
64-
:doc-block-tags-fragments
65-
[{:content "\n", :type "text"}
66-
{:content "<i>Returns</i>:&nbsp;", :type "html"}
67-
{:content "the string \"hello\"", :type "text"}],
68-
:doc
69-
"Method-level docstring.\n\n @return the string \"hello\""}}
70-
orchard.java.DummyClass
71-
{[]
72-
{:non-generic-argtypes [],
73-
:name orchard.java.DummyClass,
74-
:type void,
75-
:doc-first-sentence-fragments [],
76-
:column 8,
77-
:argtypes [],
78-
:line 12,
79-
:argnames [],
80-
:doc-fragments [],
81-
:doc-block-tags-fragments [],
82-
:doc nil}}},
83-
:doc-block-tags-fragments [],
84-
:doc
85-
"Class level docstring.\n\n <pre>\n DummyClass dc = new DummyClass();\n </pre>\n\n @author Arne Brasseur"}
86-
(dissoc (source-info 'orchard.java.DummyClass)
87-
:path
88-
:resource-url))))))
41+
(is+ '{:doc-first-sentence-fragments
42+
[{:type "text", :content "Class level docstring."}],
43+
:column 1,
44+
:line 12,
45+
:class orchard.java.DummyClass,
46+
:doc-fragments
47+
[{:type "text", :content "Class level docstring.\n\n"}
48+
{:type "html",
49+
:content
50+
#"<pre> \n\s+DummyClass dc = new DummyClass\(\);\n\s+</pre>"}],
51+
:members
52+
{dummyMethod
53+
{[]
54+
{:name dummyMethod,
55+
:type java.lang.String,
56+
:doc-first-sentence-fragments
57+
[{:type "text", :content "Method-level docstring."}],
58+
:column 5,
59+
:argtypes [],
60+
:non-generic-argtypes []
61+
:line 18,
62+
:argnames [],
63+
:doc-fragments
64+
[{:type "text", :content "Method-level docstring."}],
65+
:doc-block-tags-fragments
66+
[{:content "\n", :type "text"}
67+
{:content "<i>Returns</i>:&nbsp;", :type "html"}
68+
{:content "the string \"hello\"", :type "text"}],
69+
:doc
70+
"Method-level docstring.\n\n @return the string \"hello\""}}
71+
orchard.java.DummyClass
72+
{[]
73+
{:non-generic-argtypes [],
74+
:name orchard.java.DummyClass,
75+
:type void,
76+
:doc-first-sentence-fragments [],
77+
:column 8,
78+
:argtypes [],
79+
:line 12,
80+
:argnames [],
81+
:doc-fragments [],
82+
:doc-block-tags-fragments [],
83+
:doc nil}}},
84+
:doc-block-tags-fragments [],
85+
:doc
86+
"Class level docstring.\n\n <pre>\n DummyClass dc = new DummyClass();\n </pre>\n\n @author Arne Brasseur"}
87+
(source-info 'orchard.java.DummyClass)))))
8988

9089
(when (and jdk11+? util/jdk-sources-present?)
9190
(deftest doc-fragments-test
92-
(is (= [{:type "text", :content "Inserts the specified element at the tail of this queue if it is
91+
(is+ [{:type "text", :content "Inserts the specified element at the tail of this queue if it is
9392
possible to do so immediately without exceeding the queue's capacity,
9493
returning "}
95-
{:type "html", :content "<pre>true</pre> "}
96-
{:type "text", :content " upon success and throwing an\n"}
97-
{:type "html", :content "<pre>IllegalStateException</pre> "}
98-
{:type "text", :content " if this queue is full."}]
99-
(-> 'java.util.concurrent.ArrayBlockingQueue
100-
source-info
101-
(get-in [:members 'add '[java.lang.Object] :doc-fragments])))
102-
"Returns a data structure with carefully managed whitespace location")
94+
{:type "html", :content "<pre>true</pre> "}
95+
{:type "text", :content " upon success and throwing an\n"}
96+
{:type "html", :content "<pre>IllegalStateException</pre> "}
97+
{:type "text", :content " if this queue is full."}]
98+
(-> (source-info 'java.util.concurrent.ArrayBlockingQueue)
99+
(get-in [:members 'add '[java.lang.Object] :doc-fragments]))
100+
"Returns a data structure with carefully managed whitespace location")
103101

104-
(is (= {:content "<i>Param</i>&nbsp;<pre>obj</pre>:&nbsp;", :type "html"}
105-
(-> `Thread
106-
source-info
107-
(get-in [:members 'holdsLock '[java.lang.Object] :doc-block-tags-fragments 1])))
108-
"Formats params correctly")
102+
(is+ {:content "<i>Param</i>&nbsp;<pre>obj</pre>:&nbsp;", :type "html"}
103+
(-> (source-info `Thread)
104+
(get-in [:members 'holdsLock '[java.lang.Object] :doc-block-tags-fragments 1]))
105+
"Formats params correctly")
109106

110-
(let [fragments (-> `String
111-
source-info
107+
(let [fragments (-> (source-info `String)
112108
(get-in [:members
113109
'format
114110
['java.util.Locale 'java.lang.String (symbol "java.lang.Object[]")]
@@ -123,28 +119,25 @@ returning "}
123119

124120
(when (and jdk11+? util/jdk-sources-present?)
125121
(deftest smoke-test
126-
(let [annotations #{'java.lang.Override
127-
'java.lang.Deprecated
128-
'java.lang.SuppressWarnings}
122+
(let [exclusions '#{java.lang.Cloneable
123+
java.lang.Override
124+
java.lang.Deprecated
125+
java.lang.SuppressWarnings}
129126
corpus (->> ::_
130127
namespace
131128
symbol
132129
util/imported-classes
133-
(remove annotations)
130+
(remove exclusions)
134131
(into ['java.io.File]))]
135-
(assert (> (count corpus)
136-
50))
137-
(doseq [class-sym corpus
138-
:let [{:keys [members] :as info} (source-info class-sym)]]
139-
(testing class-sym
140-
(is (contains? info :doc))
141-
(is (contains? info :doc-fragments))
142-
(is (contains? info :doc-first-sentence-fragments))
143-
(is (contains? info :members))
144-
(let [v (mapcat vals (vals members))]
145-
(when-not (#{`Cloneable} class-sym)
146-
(is (seq v) (pr-str class-sym)))
147-
(doseq [m v]
148-
(is (contains? m :doc))
149-
(is (contains? m :doc-fragments))
150-
(is (contains? m :doc-first-sentence-fragments)))))))))
132+
(when (is (> (count corpus) 50))
133+
(doseq [class-sym corpus
134+
:let [info (source-info class-sym)]]
135+
(testing class-sym
136+
(is+ {:doc any?, :doc-fragments any?, :doc-first-sentence-fragments any?
137+
:members (mc/via
138+
#(mapcat vals (vals %))
139+
(mc/all-of not-empty
140+
(mc/seq-of {:doc any?
141+
:doc-fragments any?
142+
:doc-first-sentence-fragments any?})))}
143+
info)))))))

0 commit comments

Comments
 (0)