|
21 | 21 | [clojure.tools.analyzer.passes.jvm.fix-case-test :refer [fix-case-test]] |
22 | 22 | [clojure.tools.analyzer.passes.jvm.analyze-host-expr :refer [analyze-host-expr]] |
23 | 23 | [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 |
25 | 25 | PersistentVector PersistentArrayMap PersistentHashSet ISeq) |
26 | 26 | java.util.regex.Pattern |
27 | | - (java.io File))) |
| 27 | + (java.io File) |
| 28 | + (java.util UUID Arrays))) |
28 | 29 |
|
29 | 30 | (defn validate [ast] |
30 | 31 | (env/with-env (ana.jvm/global-env) |
|
294 | 295 |
|
295 | 296 | (let [a (ast1 Boolean/TYPE)] |
296 | 297 | (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