From 5b651304c5a961945b71bdbca40a23505b9ac844 Mon Sep 17 00:00:00 2001 From: Burak Bilge Yalcinkaya Date: Fri, 19 Jan 2024 03:58:02 +0300 Subject: [PATCH] add table unit test --- pykwasm/pyproject.toml | 1 + pykwasm/src/tests/unit/test_wasm2kast.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 pykwasm/src/tests/unit/test_wasm2kast.py diff --git a/pykwasm/pyproject.toml b/pykwasm/pyproject.toml index 58fb5d506..a62f96f55 100644 --- a/pykwasm/pyproject.toml +++ b/pykwasm/pyproject.toml @@ -55,6 +55,7 @@ disallow_untyped_defs = true exclude = [ 'src/pykwasm/wasm2kast\.py', 'src/wasm/*', + 'src/tests/unit/test_wasm2kast\.py', ] [tool.poetry.scripts] diff --git a/pykwasm/src/tests/unit/test_wasm2kast.py b/pykwasm/src/tests/unit/test_wasm2kast.py new file mode 100644 index 000000000..4c5d188e1 --- /dev/null +++ b/pykwasm/src/tests/unit/test_wasm2kast.py @@ -0,0 +1,21 @@ +import pytest +from pyk.kast.inner import KApply, KInner +from wasm.datatypes import ExternAddress, FunctionAddress, Limits, Table, TableType + +from pykwasm import wasm2kast +from pykwasm.kwasm_ast import KInt, externref, funcref + +TABLE_TEST_DATA = ( + (Table(TableType(Limits(0, None), FunctionAddress)), KApply('limitsMin', [KInt(0)]), funcref), + (Table(TableType(Limits(0, 100), ExternAddress)), KApply('limitsMinMax', [KInt(0), KInt(100)]), externref), +) + + +@pytest.mark.parametrize(('input', 'limits', 'typ'), TABLE_TEST_DATA) +def test_table(input: Table, limits: KInner, typ: KInner) -> None: + # When + t = wasm2kast.table(input) + + # Then + assert limits == t.args[0] + assert typ == t.args[1]