Skip to content

Commit 8f94258

Browse files
committed
Basic tests
1 parent f0711b9 commit 8f94258

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/basilisp/lang/compiler/analyzer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,11 @@ def _import_ast(form: ISeq, ctx: AnalyzerContext) -> Import:
26472647
form=module_refers,
26482648
)
26492649

2650+
if len(module_refers) == 0:
2651+
raise ctx.AnalyzerException(
2652+
"Must refer at least one name", form=module_refers
2653+
)
2654+
26502655
for refer in module_refers:
26512656
if not isinstance(refer, sym.Symbol):
26522657
raise ctx.AnalyzerException(

tests/basilisp/compiler_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,31 @@ def test_import_aliased_module_format(self, lcompile: CompileFn, code: str):
34863486
with pytest.raises(compiler.CompilerException):
34873487
lcompile(code)
34883488

3489+
@pytest.mark.parametrize(
3490+
"code",
3491+
[
3492+
"(import* [math :refer ()])",
3493+
"(import* [math :refer {}])",
3494+
"(import* [math :refer #{}])",
3495+
],
3496+
)
3497+
def test_import_refer_name_collection_must_be_a_vector(
3498+
self, lcompile: CompileFn, code: str
3499+
):
3500+
with pytest.raises(compiler.CompilerException):
3501+
lcompile(code)
3502+
3503+
def test_import_refer_names_must_have_one_name(self, lcompile: CompileFn):
3504+
with pytest.raises(compiler.CompilerException):
3505+
lcompile("(import* [math :refer []])")
3506+
3507+
@pytest.mark.parametrize(
3508+
"code", ["(import* [math :refer [:sqrt]])", '(import* [math :refer ["sqrt"]])']
3509+
)
3510+
def test_import_refer_names_must_by_symbols(self, lcompile: CompileFn, code: str):
3511+
with pytest.raises(compiler.CompilerException):
3512+
lcompile(code)
3513+
34893514
def test_import_module_must_exist(self, lcompile: CompileFn):
34903515
with pytest.raises(ImportError):
34913516
lcompile("(import* real.fake.module)")

0 commit comments

Comments
 (0)