Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrink10 committed Dec 31, 2023
1 parent 32eea62 commit 9f5e32c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/basilisp/lang/compiler/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,6 @@ def _tag_ast(form: Optional[LispForm], ctx: AnalyzerContext) -> Optional[Node]:
return _analyze_form(form, ctx)



def _with_meta(gen_node):
"""Wraps the node generated by gen_node in a :with-meta AST node if the
original form has meta.
Expand Down
22 changes: 20 additions & 2 deletions tests/basilisp/compiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,17 @@ def test_compiler_metadata(
assert ns == meta.val_at(kw.keyword("ns"))
assert "Super cool docstring" == meta.val_at(kw.keyword("doc"))

def test_sets_tag_ast(self, lcompile: CompileFn, ns: runtime.Namespace):
def test_def_sets_tag_ast(self, lcompile: CompileFn, ns: runtime.Namespace):
lcompile('(def ^python/str s "a string")')
assert typing.get_type_hints(ns.module)["s"] == str
assert ns.find(sym.symbol("s")).meta.val_at(kw.keyword("tag")) == str

def test_tag_ast_can_be_complex(self, lcompile: CompileFn, ns: runtime.Namespace):
def test_def_tag_ast_can_be_complex(
self, lcompile: CompileFn, ns: runtime.Namespace
):
lcompile('(def ^{:tag #(.lower "TAG FN")} s "a string")')
assert typing.get_type_hints(ns.module)["s"]() == "tag fn"
assert ns.find(sym.symbol("s")).meta.val_at(kw.keyword("tag"))() == "tag fn"

def test_may_only_provide_tag_metadata_on_def_symbol_or_fn(
self, lcompile: CompileFn, ns: runtime.Namespace
Expand Down Expand Up @@ -3156,6 +3160,20 @@ def test_let_may_have_empty_body(self, lcompile: CompileFn):
assert None is lcompile("(let* [])")
assert None is lcompile("(let* [a :kw])")

def test_let_bindings_get_tag_ast(self, lcompile: CompileFn, ns: runtime.Namespace):
lcompile('(let [^python/str s "a string"] s)')
hints = typing.get_type_hints(ns.module)
let_var = next(iter(k for k in hints.keys() if k.startswith("s_")), None)
assert hints[let_var] == str

def test_let_binding_tag_ast_can_be_complex(
self, lcompile: CompileFn, ns: runtime.Namespace
):
lcompile('(let [^{:tag #(.lower "TAG FN")} s "a string"] s)')
hints = typing.get_type_hints(ns.module)
let_var = next(iter(k for k in hints.keys() if k.startswith("s_")), None)
assert hints[let_var]() == "tag fn"

def test_let(self, lcompile: CompileFn):
assert lcompile("(let* [a 1] a)") == 1
assert lcompile('(let* [a :keyword b "string"] a)') == kw.keyword("keyword")
Expand Down

0 comments on commit 9f5e32c

Please sign in to comment.