~subsetpark/fugue

aedb09f5ac48bb81e6bd4e951d9d2a0021d01f9d — Zach Smith 5 months ago c506c36
Fix infinite loop in with-slots-as
2 files changed, 13 insertions(+), 3 deletions(-)

M fugue.janet
M test/fugue.janet
M fugue.janet => fugue.janet +3 -3
@@ 654,7 654,7 @@
        ~(,as ,field-name))
      sym)))

(defn- with-slots-as
(defn- do-with-slots-as
  [proto obj as body]
  (let [f (-> proto (eval) (fields) (field-transformer as proto))]
    ~(let [,as ,obj]


@@ 691,7 691,7 @@
  ```
  ````
  [proto obj & body]
  (with-slots-as proto obj 'this body))
  (do-with-slots-as proto obj 'this body))

(defmacro with-slots-as
  ```


@@ 702,7 702,7 @@
  See `with-slots` documentation for more details.
  ```
  [proto obj as & body]
  (with-slots-as proto obj as body))
  (do-with-slots-as proto obj as body))

(defmacro @
  ```

M test/fugue.janet => test/fugue.janet +10 -0
@@ 359,6 359,16 @@
    (is (= res a-slot-haver))
    (is (= "will shortz" (a-slot-haver :name)))))

(deftest slots-as-test
  (let [a-slot-haver (:new SlotHaver)]
    (def res (fugue/with-slots-as SlotHaver a-slot-haver s
                               (set (@ name) "will shortz")
                               (is (= "will shortz" (@ name)))
                               (is (= "will shortz" (s :name)))
                               (is (= "will shortz" (name s)))))
    (is (= res a-slot-haver))
    (is (= "will shortz" (a-slot-haver :name)))))

(deftest slots-validation
  (is (thrown? (apply fugue/with-slots '[SlotHaver {} (@ other)]))))