~subsetpark/fugue

3b9b508f647281a2eaea409e2fdc37a974406780 — Zach Smith 25 days ago 7a4f566 defmulti-in-module
Add test case for fugue/#4
5 files changed, 31 insertions(+), 22 deletions(-)

M fugue.janet
M test-support/a.janet
M test-support/b.janet
M test/fugue.janet
A test/namespaces.janet
M fugue.janet => fugue.janet +1 -6
@@ 408,16 408,11 @@
    (put-in store [name types] fun)))

#
# Private Multimethod State
# Multimethod Closures
#

(def- multi-cases @{})
(def- var-cases @{})

#
# Multimethod Closures
#

(defn- set-multi-default
  [name]
  (unless (dyn name)

M test-support/a.janet => test-support/a.janet +3 -0
@@ 1,4 1,7 @@
(use /fugue)

(declare-open-multi f)

(defproto A nil base-attr {:allocation :prototype})

(defmulti g [:string] [s] (string s "!"))

M test-support/b.janet => test-support/b.janet +2 -0
@@ 4,3 4,5 @@
(extend-multi a/f [:number] [n] (inc n))

(defproto B a/A child-attr {:allocation :prototype})

(defmulti g [:number] [n] (+ n 2))

M test/fugue.janet => test/fugue.janet +0 -16
@@ 343,22 343,6 @@
(deftest open-defaults
  (is (thrown? (open-headless))))

(import /test-support/a)
(import /test-support/b)

(deftest multiple-file-multi-extend 
  (is (= 11 (a/f 10))))

(deftest namespaced-allocations
  (let [a-b (:new b/B)]
    (fugue/allocate a-b :base-attr "base")
    (fugue/allocate a-b :child-attr "child")
    (is (= (a/A :base-attr) "base"))
    (is (= (a-b :base-attr) "base"))

    (is (= (b/B :child-attr) "child"))
    (is (= (a-b :child-attr) "child"))))

(fugue/defproto SlotHaver () name {})

(deftest slots-test

A test/namespaces.janet => test/namespaces.janet +25 -0
@@ 0,0 1,25 @@
(use testament)
(import /fugue)

(import /test-support/a)
(import /test-support/b)

(deftest multiple-file-multi-extend 
  (is (= 11 (a/f 10))))

(deftest namespaced-allocations
  (let [a-b (:new b/B)]
    (fugue/allocate a-b :base-attr "base")
    (fugue/allocate a-b :child-attr "child")
    (is (= (a/A :base-attr) "base"))
    (is (= (a-b :base-attr) "base"))

    (is (= (b/B :child-attr) "child"))
    (is (= (a-b :child-attr) "child"))))

(deftest overlapping-defmultis
  (is (= "ok!" (a/g "ok")))
  (is (thrown? (b/g "ok")))
  (is (= 12 (b/g 10))))

(run-tests!)