Skip to content

Commit

Permalink
worked on coverage for func collect
Browse files Browse the repository at this point in the history
  • Loading branch information
nucccc committed Dec 5, 2023
1 parent 56ff04d commit 576dd67
Showing 1 changed file with 91 additions and 2 deletions.
93 changes: 91 additions & 2 deletions tests/test_func_collect.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import pytest

import ast

from markarth.convert.collect.func_collect import (
func_name_from_ast,
input_typs_from_ast,
filter_const_candidates_at_func,
return_typ_from_ast,
collect_local_typs
collect_local_typs,
collect_from_ast_body,
_record_vartyp,
CollisionEnum
)
from markarth.convert.typs.names_to_typs import DictTypStore
from markarth.convert.typs.names_to_typs import DictTypStore, NamesToTyps
from markarth.convert.typs.typs import PrimitiveCod, TypPrimitive


Expand Down Expand Up @@ -61,6 +66,90 @@ def test_filter_const_candidates_at_func(func2):
assert 'd' in global_typs


def test_record_vartyp():
names_to_typs = NamesToTyps(
local_typs = DictTypStore({'a':TypPrimitive(PrimitiveCod.INT)}),
input_typs = DictTypStore(),
global_typs = DictTypStore(),
call_typs = DictTypStore()
)

rec_coll = _record_vartyp('a', TypPrimitive(PrimitiveCod.INT), names_to_typs)
assert rec_coll == CollisionEnum.NO_COLLISION

names_to_typs = NamesToTyps(
local_typs = DictTypStore({'a':TypPrimitive(PrimitiveCod.FLOAT)}),
input_typs = DictTypStore(),
global_typs = DictTypStore(),
call_typs = DictTypStore()
)

rec_coll = _record_vartyp('a', TypPrimitive(PrimitiveCod.INT), names_to_typs)
assert rec_coll == CollisionEnum.NO_COLLISION

names_to_typs = NamesToTyps(
local_typs = DictTypStore(),
input_typs = DictTypStore({'a':TypPrimitive(PrimitiveCod.INT)}),
global_typs = DictTypStore(),
call_typs = DictTypStore()
)

rec_coll = _record_vartyp('a', TypPrimitive(PrimitiveCod.INT), names_to_typs)
assert rec_coll == CollisionEnum.NO_COLLISION

names_to_typs = NamesToTyps(
local_typs = DictTypStore(),
input_typs = DictTypStore({'a':TypPrimitive(PrimitiveCod.FLOAT)}),
global_typs = DictTypStore(),
call_typs = DictTypStore()
)

rec_coll = _record_vartyp('a', TypPrimitive(PrimitiveCod.INT), names_to_typs)
assert rec_coll == CollisionEnum.INPUT_COLLISION

names_to_typs = NamesToTyps(
local_typs = DictTypStore(),
input_typs = DictTypStore(),
global_typs = DictTypStore({'a':TypPrimitive(PrimitiveCod.FLOAT)}),
call_typs = DictTypStore()
)

rec_coll = _record_vartyp('a', TypPrimitive(PrimitiveCod.INT), names_to_typs)
assert rec_coll == CollisionEnum.GLOBAL_COLLISION


def test_collect_from_ast_body():
names_to_typs = NamesToTyps(
local_typs = DictTypStore(),
input_typs = DictTypStore({'a':TypPrimitive(PrimitiveCod.FLOAT)}),
global_typs = DictTypStore({'b':TypPrimitive(PrimitiveCod.FLOAT)}),
call_typs = DictTypStore()
)

code = '''
a = 7
b = 7
'''

colliding_input_varnames : set[str] = set()
colliding_global_varnames : set[str] = set()

mod = ast.parse(code)

body = mod.body

collect_from_ast_body(
ast_body = body,
names_to_typs = names_to_typs,
colliding_input_varnames = colliding_input_varnames,
colliding_global_varnames = colliding_global_varnames,
global_varnames = set()
)

assert colliding_input_varnames == {'a'}
assert colliding_global_varnames == {'b'}


def test_func_collect1(func1):
func_ast1, _ = func1

Expand Down

0 comments on commit 576dd67

Please sign in to comment.