1010(ns clojure.test-clojure.method-thunks
1111 (:use clojure.test)
1212 #_ (:require [clojure.java.io :as jio])
13- #_ (:import # (clojure.lang Compiler Tuple)
13+ #_ (:import (clojure.lang Compiler ) ; ;; Tuple -- can't import -- conflicts with System.Tuple. We will qualify it below.
1414 (java.util Arrays UUID Locale)
1515 (java.io File FileFilter)
1616 clojure.lang.IFn$LL))
1717
1818(set! *warn-on-reflection* true )
1919
20- #_ (deftest method-arity-selection
20+ (deftest method-arity-selection
2121 (is (= '([] [] [])
22- (take 3 (repeatedly ^[] Tuple/create))))
22+ (take 3 (repeatedly ^[] clojure.lang. Tuple/create)))) ; ;; added clojure.lang.
2323 (is (= '([1 ] [2 ] [3 ])
24- (map ^[_] Tuple/create [1 2 3 ])))
24+ (map ^[_] clojure.lang. Tuple/create [1 2 3 ]))) ; ;; added clojure.lang.
2525 (is (= '([1 4 ] [2 5 ] [3 6 ])
26- (map ^[_ _] Tuple/create [1 2 3 ] [4 5 6 ]))))
26+ (map ^[_ _] clojure.lang. Tuple/create [1 2 3 ] [4 5 6 ])))) ; ;; added clojure.lang.
2727
28- #_ (deftest method-signature-selection
28+ (deftest method-signature-selection
2929 (is (= [1.23 3.14 ]
30- (map ^[double] Math/abs [1.23 -3.14 ])))
30+ (map ^[double] Math/Abs [1.23 -3.14 ]))) ; ;; abs
3131 (is (= [(float 1.23 ) (float 3.14 )]
32- (map ^[float] Math/abs [1.23 -3.14 ])))
32+ (map ^[float] Math/Abs [1.23 -3.14 ]))) ; ;; abs
3333 (is (= [1 2 3 ]
34- (map ^[long] Math/abs [1 2 -3 ])))
35- (is (= [#uuid " 00000000-0000-0001-0000-000000000002" ]
34+ (map ^[long] Math/Abs [1 2 -3 ]))) ; ;; abs
35+ # _ (is (= [#uuid " 00000000-0000-0001-0000-000000000002" ] ; ;; System.GUID doesn't have conventient constructors for testing
3636 (map ^[long long] UUID/new [1 ] [2 ])))
37- (is (= '(" a" " 12" )
37+ (is (= [" abc" " abc" ] (let [s (.ToCharArray " abc" )] (map ^[chars] String/new [s s])))) ; ; ADDED
38+ #_ (is (= '(" a" " 12" ) ; ;; I'm not sure what is being tested here
3839 (map ^[Object] String/valueOf [" a" 12 ])))
39- (is (= [" A" " B" " C" ]
40+ # _ (is (= [" A" " B" " C" ] ; ;; Im not sure what is being tested here -- .toUpperCase has only one overload with a single argument
4041 (map ^[java.util.Locale] String/.toUpperCase [" a" " b" " c" ] (repeat java.util.Locale/ENGLISH))))
41- (is (thrown? ClassCastException
42- (doall (map ^[long] String/valueOf [12 " a" ]))))
42+ (is (= [" A" " B" " C" ]
43+ (map ^[System.Globalization.CultureInfo] String/.ToUpper [" a" " b" " c" ] (repeat System.Globalization.CultureInfo/CurrentCulture)))) ; ;; ADDED -- but we'll do the same here anyway
44+ #_ (is (thrown? ClassCastException
45+ (doall (map ^[long] String/valueOf [12 " a" ])))
46+ (is (thrown? Exception (doall (map ^[double] Math/Abs [1.23 DateTime/Now])))) ; ; "abc" we'd try to convert the string and get a format exception
47+ )
4348 (testing " bad method names"
44- (is (thrown-with-msg? Exception #"static method" (eval 'java.lang. String/foo)))
45- (is (thrown-with-msg? Exception #"instance method" (eval 'java.lang. String/.foo)))
49+ (is (thrown-with-msg? Exception #"static method" (eval 'String/foo))) ; ;; java.lang.String
50+ (is (thrown-with-msg? Exception #"instance method" (eval 'String/.foo))) ; ;;java.lang.String
4651 (is (thrown-with-msg? Exception #"constructor" (eval 'Math/new)))))
4752
48- #_ (def mt ^[_] Tuple /create )
49- #_ (def mts {:fromString ^[_] UUID/fromString})
50- #_ (def gbs ^[] String /.getBytes )
53+ (def mt ^[_] clojure.lang. Tuple /create ) ; ;; added clojure.lang.
54+ (def mts {:fromString ^[String] Guid/Parse}) ; ;; [ _] UUID/fromString
55+ (def gbs ^[] String /.ToCharArray ) ; ;; /.getBytes
5156
52- #_ (deftest method-thunks-in-structs
57+ (deftest method-thunks-in-structs
5358 (is (= #uuid " 00000000-0000-0001-0000-000000000002"
5459 ((:fromString mts) " 00000000-0000-0001-0000-000000000002" )))
5560 (is (= [1 ] (mt 1 )))
56- (is (= 97 (first (seq (gbs " a" ))))))
61+ (is (= \a (first (seq (gbs " a" )))))) ; ;; 97
5762
58- #_(deftest hinted-method-values
63+ #_(deftest hinted-method-values ; ;; Not sure what to translate this to
5964 (is (thrown? Exception (eval '(.listFiles (jio/file " ." ) #(File/.isDirectory %)))))
6065 (is (seq (.listFiles (jio/file " ." ) ^FileFilter File/.isDirectory)))
6166 (is (seq (File/.listFiles (jio/file " ." ) ^FileFilter File/.isDirectory)))
62- (is (seq (^[FileFilter] File/.listFiles (jio/file " ." ) ^FileFilter File/.isDirectory))))
67+ (is (seq (^[FileFilter] File/.listFiles (jio/file " ." ) ^FileFilter File/.isDirectory))))
68+
69+ ; ;; ADDED
70+
71+ (deftest type-args-work
72+ (is (= [2 2 2 ] (take 3 (System.Linq.Enumerable/Repeat (type-args Int32) 2 5 )))))
73+
0 commit comments