|
4 | 4 | [clojure.set :as set]
|
5 | 5 | [clojure.string :as string]
|
6 | 6 | [clojure.test :refer [are deftest is testing]]
|
7 |
| - [orchard.java :as sut :refer [cache class-info class-info* javadoc-url member-info resolve-class resolve-javadoc-path resolve-member resolve-symbol resolve-type source-info]] |
| 7 | + [orchard.java :as sut :refer [cache class-info class-info* javadoc-url member-info resolve-class resolve-javadoc-path resolve-member resolve-symbol source-info]] |
8 | 8 | [orchard.misc :as misc]
|
9 | 9 | [orchard.test.util :as util])
|
10 | 10 | (:import
|
|
406 | 406 | (deftest symbol-resolution-test
|
407 | 407 | (let [ns (ns-name *ns*)]
|
408 | 408 | (testing "Symbol resolution"
|
| 409 | + (testing "of classes" |
| 410 | + (is (= 'java.lang.String (:class (resolve-symbol ns 'String))))) |
| 411 | + (testing "of deftype in clojure.core" |
| 412 | + (is (= 'clojure.core.Eduction (:class (resolve-symbol 'clojure.core 'Eduction))))) |
| 413 | + (testing "of constructors" |
| 414 | + (is (= 'java.lang.String (:class (resolve-symbol ns 'String.))))) |
409 | 415 | (testing "of unambiguous instance members"
|
410 | 416 | (is (= 'java.lang.SecurityManager
|
411 |
| - (:class (resolve-symbol ns 'checkPackageDefinition))))) |
| 417 | + (:class (resolve-symbol ns '.checkPackageDefinition)))) |
| 418 | + (is (nil? (:class (resolve-symbol ns '.currentThread))) |
| 419 | + "Shouldn't resolve since Thread/currentThread is a static method")) |
| 420 | + (testing "of qualified instance members" |
| 421 | + (is (= 'java.lang.Thread |
| 422 | + (:class (resolve-symbol ns 'Thread/.start))))) |
412 | 423 | (testing "of candidate instance members"
|
413 | 424 | (is (every? #(= 'toString (:member %))
|
414 | 425 | (vals (:candidates (resolve-symbol ns 'toString))))))
|
415 | 426 | (testing "of static methods"
|
416 | 427 | (is (= 'forName (:member (resolve-symbol ns 'Class/forName)))))
|
417 | 428 | (testing "of static fields"
|
418 | 429 | (is (= 'TYPE (:member (resolve-symbol ns 'Void/TYPE)))))
|
| 430 | + (testing "of java-style printed members" |
| 431 | + (is (= (resolve-symbol ns 'Thread/.start) |
| 432 | + (resolve-symbol ns 'Thread.start))) |
| 433 | + (is (= (resolve-symbol ns 'Thread/currentThread) |
| 434 | + (resolve-symbol ns 'Thread.currentThread))) |
| 435 | + (is (= (resolve-symbol ns 'clojure.lang.Compiler$DefExpr/.eval) |
| 436 | + (resolve-symbol ns 'clojure.lang.Compiler$DefExpr.eval))) |
| 437 | + (is (= 'clojure.lang.Compiler$DefExpr |
| 438 | + (:class (resolve-symbol ns 'clojure.lang.Compiler$DefExpr.eval))))) |
| 439 | + (testing "of module-prefixed classes" |
| 440 | + (is (= (resolve-symbol ns 'java.lang.Thread) |
| 441 | + (resolve-symbol ns 'java.base/java.lang.Thread)))) |
| 442 | + (testing "of java-style printed members with module prefix" |
| 443 | + (is (= (resolve-symbol ns 'java.lang.Thread/.run) |
| 444 | + (resolve-symbol ns 'java.base/java.lang.Thread.run)))) |
419 | 445 |
|
420 | 446 | (testing "equality of qualified vs unqualified"
|
421 | 447 | (testing "classes"
|
|
429 | 455 | (resolve-symbol ns 'Class/forName))))
|
430 | 456 | (testing "static fields"
|
431 | 457 | (is (= (resolve-symbol ns 'java.lang.Void/TYPE)
|
432 |
| - (resolve-symbol ns 'Void/TYPE))))) |
433 |
| - |
434 |
| - (testing "equality of dotted" |
435 |
| - (testing "constructor syntax" |
436 |
| - (is (= (resolve-symbol ns 'Exception) |
437 |
| - (resolve-symbol ns 'Exception.)))) |
438 |
| - (testing "method syntax" |
439 |
| - (is (= (resolve-symbol ns 'toString) |
440 |
| - (resolve-symbol ns '.toString))))) |
| 458 | + (resolve-symbol ns 'Void/TYPE)))) |
| 459 | + (testing "qualified members" |
| 460 | + (is (= (resolve-symbol ns 'Thread/.start) |
| 461 | + (resolve-symbol ns 'java.lang.Thread/.start)))) |
| 462 | + (testing "java-style printed members" |
| 463 | + (is (= (resolve-symbol ns 'Thread.start) |
| 464 | + (resolve-symbol ns 'java.lang.Thread.start))) |
| 465 | + (is (= (resolve-symbol ns 'Thread.currentThread) |
| 466 | + (resolve-symbol ns 'java.lang.Thread.currentThread))))) |
| 467 | + |
| 468 | + (when util/jdk-sources-present? |
| 469 | + (testing "class and constructor resolve to different lines" |
| 470 | + (is (not= (:line (resolve-symbol ns 'java.lang.String)) |
| 471 | + (:line (resolve-symbol ns 'java.lang.String.)))) |
| 472 | + (is (not= (:line (resolve-symbol ns 'Thread)) |
| 473 | + (:line (resolve-symbol ns 'Thread.)))))) |
441 | 474 |
|
442 | 475 | (testing "of things that shouldn't resolve"
|
443 | 476 | (is (nil? (resolve-symbol ns 'MissingUnqualifiedClass)))
|
|
450 | 483 | (is (nil? (resolve-symbol ns '.missingDottedMethod)))
|
451 | 484 | (is (nil? (resolve-symbol ns '.random.bunch/of$junk)))))))
|
452 | 485 |
|
453 |
| -(deftest type-resolution-test |
454 |
| - (testing "Type resolution" |
455 |
| - (testing "of Java classes/constructors in any namespace" |
456 |
| - (is (= 'java.lang.String (:class (resolve-type (ns-name *ns*) 'String))))) |
457 |
| - (testing "of deftype in clojure.core" |
458 |
| - (is (= 'clojure.core.Eduction (:class (resolve-type 'clojure.core 'Eduction))))))) |
459 |
| - |
460 | 486 | (defn- replace-last-dot [^String s]
|
461 | 487 | (if (re-find #"(.*\.)" s)
|
462 | 488 | (str (second (re-matches #"(.*)(\..*)" s))
|
|
0 commit comments