~subsetpark/fugue

9c7f4300ad08b9634162323e559bd72d7b0a889d — Zach Smith 3 years ago e28cd6b
Bugfix: dont include proto attributes in defined fields
2 files changed, 7 insertions(+), 2 deletions(-)

M fugue.janet
M test/fugue.janet
M fugue.janet => fugue.janet +1 -1
@@ 322,7 322,7 @@
  [name parent-name & fields]
  (let [has-proto-attributes (not (zero? (mod (length fields) 2)))
        fields (partition 2 fields)
        defined-fields (map (comp keyword 0) fields)
        defined-fields (map (comp keyword 0) (if has-proto-attributes (array/slice fields 0 -2) fields))
        field-definitions (field-definitions name fields defined-fields)
        [prototype-attributes-entry] (if has-proto-attributes (last fields) [{}])
        prototype-attributes (prototype-attributes name prototype-attributes-entry)]

M test/fugue.janet => test/fugue.janet +6 -1
@@ 48,6 48,8 @@
    (is (= "John Doe" (a-human :name)))
    # But it's not on the Prototype.
    (is (nil? (Human :name)))
    (is (== @[:name] (fugue/fields Human)))
    (is (== @[:name] (fugue/fields a-human)))
    (accessor-tests name [a-human Human])))

(fugue/defproto Light () speed {:default math/inf})


@@ 351,8 353,11 @@
  (fugue/defproto NoConstructor nil {:constructor false})

  (is (BasicConstructor? (new-BasicConstructor)))
  (is (== @[] (fugue/fields BasicConstructor)))
  (is (NameConstructor? (another-name)))
  (is (nil? (dyn 'new-NoConstructor))))
  (is (== @[] (fugue/fields NameConstructor)))
  (is (nil? (dyn 'new-NoConstructor)))
  (is (== @[] (fugue/fields NoConstructor))))

(deftest defgeneric-in-test
  (fugue/defgeneric in-test [x] (string x " ok"))