From ef824a393884d2defdcdcc7a53badc0e8800873e Mon Sep 17 00:00:00 2001 From: nucccc Date: Tue, 12 Dec 2023 19:14:37 +0100 Subject: [PATCH] added tests for names_to_typs --- markarth/convert/typs/names_to_typs.py | 2 +- tests/test_names_to_typs.py | 90 ++++++++++++++------------ 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/markarth/convert/typs/names_to_typs.py b/markarth/convert/typs/names_to_typs.py index 02eefac..6662625 100644 --- a/markarth/convert/typs/names_to_typs.py +++ b/markarth/convert/typs/names_to_typs.py @@ -152,7 +152,7 @@ def get_input_varname_typ(self, varname : str) -> Typ | None: return self._input_typs.get_typ(varname) - def get_varname_typ_from_global(self, varname : str) -> Typ | None: + def get_global_varname_typ(self, varname : str) -> Typ | None: return self._global_typs.get_typ(varname) diff --git a/tests/test_names_to_typs.py b/tests/test_names_to_typs.py index 4207586..ebb0f71 100644 --- a/tests/test_names_to_typs.py +++ b/tests/test_names_to_typs.py @@ -60,6 +60,8 @@ def test_dict_type_store(): assert d_typ is None assert len(tp) == 2 + assert tp.size() == 2 + def test_names_to_typs(): @@ -142,52 +144,54 @@ def test_names_to_typs(): assert wtg.get_varname_typ('k') is None assert wtg.get_varname_typ('l') is None - #wtg.delete_varname('a') - - #assert wtg.get_varname_type('a') is None + a_typ = wtg.get_varname_typ( + varname = 'a', + source = names_to_typs.VarNameSource.LOCAL + ) + assert a_typ is not None + assert a_typ.is_int() - #v1_tp.delete_name('a') + a_typ = wtg.get_varname_typ( + varname = 'a', + source = names_to_typs.VarNameSource.GLOBAL + ) + assert a_typ is None - #assert wtg.get_varname_type('a') is None - #assert wtg.get_varname_type('b') == 'float' - #assert wtg.get_varname_type('c') == 'float' - #assert wtg.get_varname_type('d') == 'float' - #assert wtg.get_varname_type('e') == 'int' - #assert wtg.get_varname_type('f') == 'int' ''' + d_typ = wtg.get_varname_typ( + varname = 'd', + source = names_to_typs.VarNameSource.INPUT + ) + assert d_typ is not None + assert d_typ.is_float() -'''def test_py2cy_dict_store(): - origin_type_store=names_to_typs.DictTypStore() - origin_type_store.add_type('an_int', 'int') - origin_type_store.add_type('a_float', 'float') - origin_type_store.add_type('a_whatever', 'whatever') - origin_type_store.add_type('a_bool', 'bool') + d_typ = wtg.get_varname_typ( + varname = 'd', + source = names_to_typs.VarNameSource.GLOBAL + ) + assert d_typ is None - py2cy_map={ - 'int':'long', - 'float':'float', - 'bool':'char', - } - new_type_store = names_to_typs.py2cy_dict_store( - origin_type_store=origin_type_store, - py2cy_map=py2cy_map + g_typ = wtg.get_varname_typ( + varname = 'g', + source = names_to_typs.VarNameSource.GLOBAL ) - assert len(new_type_store) == 3 - assert new_type_store.size() == 3 - assert new_type_store.get_type('an_int') == 'long' - assert new_type_store.get_type('a_float') == 'float' - assert new_type_store.get_type('a_bool') == 'char' - - py2cy_map={ - 'int':'int', - 'float':'double', - 'bool':'char', - } - new_type_store = names_to_typs.py2cy_dict_store( - origin_type_store=origin_type_store, - py2cy_map=py2cy_map + assert g_typ is not None + assert g_typ.is_float() + + g_typ = wtg.get_varname_typ( + varname = 'g', + source = names_to_typs.VarNameSource.INPUT ) - assert len(new_type_store) == 3 - assert new_type_store.size() == 3 - assert new_type_store.get_type('an_int') == 'int' - assert new_type_store.get_type('a_float') == 'double' - assert new_type_store.get_type('a_bool') == 'char' ''' \ No newline at end of file + assert g_typ is None + + wtg._update_varname_no_source('a', TypAny()) + wtg._update_varname_no_source('d', TypAny()) + wtg._update_varname_no_source('g', TypAny()) + + assert wtg.get_local_varname_typ('a') is not None + assert wtg.get_local_varname_typ('a').is_any() + + assert wtg.get_input_varname_typ('d') is not None + assert wtg.get_input_varname_typ('d').is_any() + + assert wtg.get_global_varname_typ('g') is not None + assert wtg.get_global_varname_typ('g').is_any()