hy/tests/native_tests/with_decorator.hy

32 lines
611 B
Hy
Raw Normal View History

(defn foodec [func]
(lambda [] (+ 1 1)))
(with-decorator foodec
(defn tfunction []
(* 2 2)))
2014-11-14 21:21:16 +01:00
(defn bardec [cls]
(setv cls.my_attr 123)
cls)
2014-11-14 21:21:16 +01:00
(with-decorator bardec
(defclass cls []
[[my_attr 456]]))
(defn test-decorator-clobbing []
"NATIVE: Tests whether nested decorators work"
(do
(defn dec1 [f] (defn k [] (+ (f) 1)))
(defn dec2 [f] (defn k [] (+ (f) 2)))
(with-decorator dec1
(with-decorator dec2
(defn f [] 1)))
(assert (= (f) 4))))
2014-11-14 21:21:16 +01:00
(defn test-decorators []
"NATIVE: test decorators."
2014-11-14 21:21:16 +01:00
(assert (= (tfunction) 2))
(assert (= cls.my_attr 123)))