88
99; ; Original authors: Stuart Halloway, Rich Hickey
1010
11-
12- (println " Attributes 1" )
13-
1411(ns clojure.test-clojure.attributes
1512 (:use clojure.test))
1613
17- (println " Attributes 2" )
18-
1914(assembly-load-from " Clojure.Tests.Support.dll" )
2015(import '[Clojure.Tests.Support AnAttribute AnotherAttribute])
2116
22-
23- (println " Attributes 3" )
24-
2517(definterface Foo (foo []))
2618
27-
28- (println " Attributes 4" )
29-
3019(deftype ^{ObsoleteAttribute " abc"
3120 AnotherAttribute 7
3221 AnAttribute #{ " def"
@@ -43,19 +32,17 @@ Foo (^{ObsoleteAttribute "abc"
4332 { :__args [" ghi" ] :SecondaryValue " jkl" }}}
4433 foo [this] 42 ))
4534
46-
47- (println " Attributes 5" )
48-
4935(defn get-custom-attributes [x]
5036 (.GetCustomAttributes x false ))
5137
5238(defn attribute->map [attr]
53- (cond
54- (instance? NonSerializedAttribute attr) {:type NonSerializedAttribute}
55- (instance? ObsoleteAttribute attr) {:type ObsoleteAttribute :message (.Message attr)}
56- (instance? AnotherAttribute attr) {:type AnotherAttribute :primary (.PrimaryValue attr)}
57- (instance? AnAttribute attr) {:type AnAttribute :primary (.PrimaryValue attr) :secondary (.SecondaryValue attr)}
58- :else {:type (class attr)}))
39+ (cond
40+ (instance? NonSerializedAttribute attr) {:type NonSerializedAttribute}
41+ (instance? ObsoleteAttribute attr) {:type ObsoleteAttribute :message (.Message attr)}
42+ (instance? AnotherAttribute attr) {:type AnotherAttribute :primary (.PrimaryValue attr)}
43+ (instance? AnAttribute attr) {:type AnAttribute :primary (.PrimaryValue attr) :secondary (.SecondaryValue attr)}
44+ :else {:type (class attr)}))
45+
5946
6047(def expected-attributes
6148 #{ {:type ObsoleteAttribute :message " abc" }
@@ -70,13 +57,13 @@ Foo (^{ObsoleteAttribute "abc"
7057 {:type AnAttribute :primary " def" :secondary nil }
7158 {:type AnAttribute :primary " ghi" :secondary " jkl" }})
7259
60+ (println " expected-attributes: " expected-attributes)
61+ (println " expected-attributes+ser: " expected-attributes+ser)
62+
7363(def expected-attributes-field
7464 #{ {:type NonSerializedAttribute}
7565 {:type ObsoleteAttribute :message " abc" }})
7666
77-
78- (println " Attributes 6" )
79-
8067(deftest test-attributes-on-type
8168 (is (=
8269
@@ -93,9 +80,6 @@ Foo (^{ObsoleteAttribute "abc"
9380 expected-attributes
9481 (into #{} (map attribute->map (get-custom-attributes (.GetMethod Bar " foo" )))))))
9582
96-
97- (println " Attributes 7" )
98-
9983(gen-class :name foo.Bar
10084 :extends clojure.lang.Box
10185 :constructors {^{ObsoleteAttribute " help" } [Object] [Object]}
@@ -110,13 +94,8 @@ Foo (^{ObsoleteAttribute "abc"
11094(defn foo-init [obj]
11195 [[obj] nil ])
11296
113-
114- (println " Attributes 8" )
115-
11697(assembly-load " foo.Bar" )
11798
118-
119- (println " Attributes 9" )
12099(deftest test-attributes-on-constructor
121100 (is (some #(instance? ObsoleteAttribute %)
122101 (for [ctor (.GetConstructors (clojure.lang.RT/classForName " foo.Bar" ))
0 commit comments