Skip to content

Commit 2e1723d

Browse files
committed
more tests
1 parent 84bc2a4 commit 2e1723d

1 file changed

Lines changed: 74 additions & 2 deletions

File tree

src/test/clojure/clojure/tools/analyzer/jvm/passes_test.clj

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
[clojure.tools.analyzer.passes.jvm.fix-case-test :refer [fix-case-test]]
2222
[clojure.tools.analyzer.passes.jvm.analyze-host-expr :refer [analyze-host-expr]]
2323
[clojure.tools.analyzer.passes.jvm.classify-invoke :refer [classify-invoke]])
24-
(:import (clojure.lang Keyword Var Symbol AFunction
24+
(:import (clojure.lang Keyword Var Symbol AFunction ExceptionInfo
2525
PersistentVector PersistentArrayMap PersistentHashSet ISeq)
2626
java.util.regex.Pattern
27-
(java.io File)))
27+
(java.io File)
28+
(java.util UUID Arrays)))
2829

2930
(defn validate [ast]
3031
(env/with-env (ana.jvm/global-env)
@@ -294,3 +295,74 @@
294295

295296
(let [a (ast1 Boolean/TYPE)]
296297
(is (= :static-field (:op a)))))
298+
299+
(deftest bad-method-names-test
300+
(is (thrown? ExceptionInfo (ast1 String/foo)))
301+
(is (thrown? ExceptionInfo (ast1 String/.foo)))
302+
(is (thrown? ExceptionInfo (ast1 Math/new))))
303+
304+
(deftest param-tags-method-signature-selection-test
305+
(let [a (ana (r/read-string "^[double] Math/abs"))]
306+
(is (= :method-value (:op a)))
307+
(is (= 1 (count (:methods a))))
308+
(is (:validated? a)))
309+
310+
(let [a (ana (r/read-string "^[float] Math/abs"))]
311+
(is (= :method-value (:op a)))
312+
(is (= 1 (count (:methods a))))
313+
(is (:validated? a)))
314+
315+
(let [a (ana (r/read-string "^[long] Math/abs"))]
316+
(is (= :method-value (:op a)))
317+
(is (= 1 (count (:methods a))))
318+
(is (:validated? a)))
319+
320+
(let [a (ana (r/read-string "^[int] Math/abs"))]
321+
(is (= :method-value (:op a)))
322+
(is (= 1 (count (:methods a))))
323+
(is (:validated? a))))
324+
325+
(deftest param-tags-constructor-invocation-test
326+
(let [a (ana (r/read-string "(^[long long] java.util.UUID/new 1 2)"))]
327+
(is (= :new (:op a)))
328+
(is (:validated? a))
329+
(is (= '[long long] (:param-tags a))))
330+
331+
(let [a (ana (r/read-string "(^[String] String/new \"a\")"))]
332+
(is (= :new (:op a)))
333+
(is (:validated? a))
334+
(is (= '[String] (:param-tags a)))))
335+
336+
(deftest param-tags-no-arg-invocation-test
337+
(let [a (ana (r/read-string "(^[] String/.toUpperCase \"hello\")"))]
338+
(is (= :instance-call (:op a)))
339+
(is (:validated? a))
340+
(is (= '[] (:param-tags a))))
341+
342+
(let [a (ana (r/read-string "(^[] Long/.toString 42)"))]
343+
(is (= :instance-call (:op a)))
344+
(is (:validated? a))
345+
(is (= '[] (:param-tags a)))))
346+
347+
(deftest param-tags-wildcard-test
348+
(let [a (ana (r/read-string "(^[_ _] String/.substring \"hello\" 1 3)"))]
349+
(is (= :instance-call (:op a)))
350+
(is (:validated? a))
351+
(is (= '[_ _] (:param-tags a)))))
352+
353+
(deftest param-tags-array-types-test
354+
(let [a (ana (r/read-string "^[long/1 long] java.util.Arrays/binarySearch"))]
355+
(is (= :method-value (:op a)))
356+
(is (= 1 (count (:methods a))))
357+
(is (:validated? a)))
358+
359+
(let [a (ana (r/read-string "^[Object/1 _] java.util.Arrays/binarySearch"))]
360+
(is (= :method-value (:op a)))
361+
(is (= 1 (count (:methods a))))
362+
(is (:validated? a))))
363+
364+
(deftest bad-param-tags-test
365+
(is (thrown? ExceptionInfo (ana (r/read-string "^[String String] Math/abs"))))
366+
(is (thrown? ExceptionInfo (ana (r/read-string "(^[] String/foo \"a\")"))))
367+
(is (thrown? ExceptionInfo (ana (r/read-string "(^[] String/.foo \"a\")"))))
368+
(is (thrown? ExceptionInfo (ana (r/read-string "(^[String String String] java.util.UUID/new 1 2 3)")))))

0 commit comments

Comments
 (0)