2017-04-27 23:16:57 +02:00
|
|
|
;; Copyright 2017 the authors.
|
|
|
|
;; This file is part of Hy, which is free software licensed under the Expat
|
|
|
|
;; license. See the LICENSE.
|
|
|
|
|
2014-01-26 03:53:44 +01:00
|
|
|
(import [hy.contrib.walk [*]])
|
|
|
|
|
|
|
|
(def walk-form '(print {"foo" "bar"
|
|
|
|
"array" [1 2 3 [4]]
|
|
|
|
"something" (+ 1 2 3 4)
|
2014-02-01 18:36:57 +01:00
|
|
|
"cons!" (cons 1 2)
|
2014-01-26 03:53:44 +01:00
|
|
|
"quoted?" '(foo)}))
|
|
|
|
|
|
|
|
(defn collector [acc x]
|
|
|
|
(.append acc x)
|
2016-11-24 03:35:17 +01:00
|
|
|
None)
|
2014-01-26 03:53:44 +01:00
|
|
|
|
|
|
|
(defn test-walk-identity []
|
|
|
|
(assert (= (walk identity identity walk-form)
|
|
|
|
walk-form)))
|
|
|
|
|
|
|
|
(defn test-walk []
|
2017-02-04 18:07:27 +01:00
|
|
|
(setv acc '())
|
|
|
|
(assert (= (walk (partial collector acc) identity walk-form)
|
|
|
|
[None None]))
|
|
|
|
(assert (= acc walk-form))
|
|
|
|
(setv acc [])
|
|
|
|
(assert (= (walk identity (partial collector acc) walk-form)
|
|
|
|
None))
|
|
|
|
(assert (= acc [walk-form])))
|
2014-01-26 03:59:47 +01:00
|
|
|
|
2015-07-15 16:59:49 +02:00
|
|
|
(defn test-walk-iterators []
|
2017-02-04 18:07:27 +01:00
|
|
|
(setv acc [])
|
|
|
|
(assert (= (walk (fn [x] (* 2 x)) (fn [x] x)
|
|
|
|
(drop 1 [1 [2 [3 [4]]]]))
|
|
|
|
[[2 [3 [4]] 2 [3 [4]]]])))
|
2015-07-15 16:59:49 +02:00
|
|
|
|
2014-01-26 03:59:47 +01:00
|
|
|
(defn test-macroexpand-all []
|
2015-08-13 16:37:56 +02:00
|
|
|
(assert (= (macroexpand-all '(with [a 1 b 2 c 3] (for [d c] foo)))
|
|
|
|
'(with* [a 1] (with* [b 2] (with* [c 3] (do (for* [d c] (do foo)))))))))
|