Skip to content
/ janet Public
forked from janet-lang/janet

Commit

Permalink
Merge pull request janet-lang#671 from pyrmont/feature.metadata
Browse files Browse the repository at this point in the history
Support adding arbitrary metadata to bindings
  • Loading branch information
bakpakin authored Mar 24, 2021
2 parents 8ede16d + ec2d7bf commit 83f7de3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/specials.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ static JanetTable *handleattr(JanetCompiler *c, int32_t argn, const Janet *argv)
case JANET_STRING:
janet_table_put(tab, janet_ckeywordv("doc"), attr);
break;
case JANET_STRUCT:
janet_table_merge_struct(tab, janet_unwrap_struct(attr));
break;
}
}
return tab;
Expand Down
12 changes: 12 additions & 0 deletions test/suite0004.janet
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,17 @@
(assert (= ~(,defn 1 2 3) [defn 1 2 3]) "bracket tuples are never macros")
(assert (= ~(,+ 1 2 3) [+ 1 2 3]) "bracket tuples are never function calls")

# Metadata

(def foo-with-tags :a-tag :bar)
(assert (get (dyn 'foo-with-tags) :a-tag) "extra keywords in def are metadata tags")

(def foo-with-meta {:baz :quux} :bar)
(assert (= :quux (get (dyn 'foo-with-meta) :baz)) "extra struct in def is metadata")

(defn foo-fn-with-meta {:baz :quux} "This is a function" [x] (identity x))
(assert (= :quux (get (dyn 'foo-fn-with-meta) :baz)) "extra struct in defn is metadata")
(assert (= "(foo-fn-with-meta x)\n\nThis is a function" (get (dyn 'foo-fn-with-meta) :doc)) "extra string in defn is docstring")

(end-suite)

0 comments on commit 83f7de3

Please sign in to comment.