aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/pyunit/dom
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/pyunit/dom')
-rw-r--r--testsuite/pyunit/dom/Expressions.py61
-rw-r--r--testsuite/pyunit/dom/Literals.py2
-rw-r--r--testsuite/pyunit/dom/Sanity.py15
3 files changed, 57 insertions, 21 deletions
diff --git a/testsuite/pyunit/dom/Expressions.py b/testsuite/pyunit/dom/Expressions.py
index f9c066f52..4de36a2b2 100644
--- a/testsuite/pyunit/dom/Expressions.py
+++ b/testsuite/pyunit/dom/Expressions.py
@@ -30,17 +30,20 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
+import ctypes
+from inspect import currentframe
from pathlib import Path
from textwrap import dedent
from unittest import TestCase
-from pyGHDL.dom.DesignUnit import Package
from pyGHDL.dom import Expression
from pyGHDL.dom.NonStandard import Design, Document
+from pyGHDL.dom.DesignUnit import Package
from pyGHDL.dom.Symbol import SimpleObjectOrFunctionCallSymbol
from pyGHDL.dom.Object import Constant
-from pyGHDL.dom.Expression import InverseExpression
+from pyGHDL.dom.Expression import InverseExpression, AbsoluteExpression
+
if __name__ == "__main__":
print("ERROR: you called a testcase declaration file as an executable module.")
@@ -50,34 +53,60 @@ if __name__ == "__main__":
class Expressions(TestCase):
_root = Path(__file__).resolve().parent.parent
-
- def test_NotExpression(self):
- self._filename: Path = self._root / "{className}.vhdl".format(
- className=self.__class__.__name__
- )
-
- sourceCode = dedent(
+ _design = Design()
+ _packageTemplate = dedent(
"""\
package package_1 is
- constant c0 : boolean := not true;
+ {code}
end package;
"""
)
- with self._filename.open(mode="w", encoding="utf-8") as file:
- file.write(sourceCode)
+ def parse(self, filename: Path, code: str) -> Expression:
+ sourceCode = self._packageTemplate.format(code=code)
- design = Design()
- document = Document(self._filename)
- design.Documents.append(document)
+ document = Document(filename, sourceCode)
+ self._design.Documents.append(document)
- package: Package = design.Documents[0].Packages[0]
+ # Traverse already to default value expression
+ package: Package = document.Packages[0]
item: Constant = package.DeclaredItems[0]
default: Expression = item.DefaultExpression
+
+ return default
+
+ def test_NotExpression(self):
+ filename: Path = self._root / "{className}_{funcName}.vhdl".format(
+ className=self.__class__.__name__, funcName= currentframe().f_code.co_name[5:]
+ )
+
+ # Define test data
+ constantDeclartion = "constant c0 : boolean := not true;"
+
+ # Parse in-memory
+ default: Expression = self.parse(filename, constantDeclartion)
+
+ # Start checks
self.assertTrue(isinstance(default, InverseExpression))
self.assertTrue(isinstance(default.Operand, SimpleObjectOrFunctionCallSymbol))
self.assertTrue(default.Operand.SymbolName == "true")
+ # def test_AbsExpression(self):
+ # filename: Path = self._root / "{className}_{funcName}.vhdl".format(
+ # className=self.__class__.__name__, funcName= currentframe().f_code.co_name[5:]
+ # )
+ #
+ # # Define test data
+ # constantDeclartion = "constant c0 : integer := abs 3;"
+ #
+ # # Parse in-memory
+ # default: Expression = self.parse(filename, constantDeclartion)
+ #
+ # # Start checks
+ # self.assertTrue(isinstance(default, AbsoluteExpression))
+ # self.assertTrue(isinstance(default.Operand, SimpleObjectOrFunctionCallSymbol))
+ # self.assertTrue(default.Operand.SymbolName == "-3")
+
# def test_Aggregare(self):
# self._filename: Path = self._root / "{className}.vhdl".format(className=self.__class__.__name__)
#
diff --git a/testsuite/pyunit/dom/Literals.py b/testsuite/pyunit/dom/Literals.py
index ebd702f5e..a69481ef4 100644
--- a/testsuite/pyunit/dom/Literals.py
+++ b/testsuite/pyunit/dom/Literals.py
@@ -80,6 +80,6 @@ class Literals(TestCase):
item: Constant = package.DeclaredItems[i]
self.assertTrue(isinstance(item, Constant))
self.assertTrue(item.Name == "c{}".format(i))
- self.assertTrue(item.SubType.SymbolName == "integer")
+ self.assertTrue(str(item.SubType.SymbolName) == "integer")
self.assertTrue(isinstance(item.DefaultExpression, IntegerLiteral))
self.assertTrue(item.DefaultExpression.Value == expected[i])
diff --git a/testsuite/pyunit/dom/Sanity.py b/testsuite/pyunit/dom/Sanity.py
index 10258c38c..dc415446b 100644
--- a/testsuite/pyunit/dom/Sanity.py
+++ b/testsuite/pyunit/dom/Sanity.py
@@ -30,11 +30,13 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
-from sys import executable
-from subprocess import check_call, STDOUT
from pathlib import Path
+from subprocess import check_call, STDOUT
+
from pytest import mark
+from pyGHDL.dom.NonStandard import Design, Document
+
if __name__ == "__main__":
print("ERROR: you called a testcase declaration file as an executable module.")
print("Use: 'python -m unitest <testcase module>'")
@@ -44,7 +46,12 @@ _TESTSUITE_ROOT = Path(__file__).parent.parent.parent.resolve()
_GHDL_ROOT = _TESTSUITE_ROOT.parent
+design = Design()
+
@mark.xfail
-@mark.parametrize("file", [str(f) for f in _TESTSUITE_ROOT.glob("sanity/**/*.vhdl")])
+@mark.parametrize("file", [str(f.relative_to(_TESTSUITE_ROOT)) for f in _TESTSUITE_ROOT.glob("sanity/**/*.vhdl")])
def test_AllVHDLSources(file):
- check_call([executable, _GHDL_ROOT / "pyGHDL/cli/DOM.py", file], stderr=STDOUT)
+ check_call(["python", _GHDL_ROOT / "pyGHDL/cli/DOM.py", file], stderr=STDOUT)
+
+# document = Document(Path(file))
+# design.Documents.append(document)