diff options
-rw-r--r-- | testsuite/pyunit/dom/Expressions.py | 49 | ||||
-rw-r--r-- | testsuite/pyunit/dom/Literals.py | 5 |
2 files changed, 52 insertions, 2 deletions
diff --git a/testsuite/pyunit/dom/Expressions.py b/testsuite/pyunit/dom/Expressions.py new file mode 100644 index 000000000..8ef013ef7 --- /dev/null +++ b/testsuite/pyunit/dom/Expressions.py @@ -0,0 +1,49 @@ +from pathlib import Path +from textwrap import dedent +from unittest import TestCase + +from pyGHDL.dom import Expression +from pyGHDL.dom.Misc import Design, Document +from pyGHDL.dom.Symbol import SimpleObjectSymbol +from pyGHDL.dom.Object import Constant +from pyGHDL.dom.Expression import InverseExpression + +if __name__ == "__main__": + print("ERROR: you called a testcase declaration file as an executable module.") + print("Use: 'python -m unitest <testcase module>'") + exit(1) + + +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("""\ + package package_1 is + constant c0 : boolean := not true; + end package; + """) + + with self._filename.open(mode="w", encoding="utf-8") as file: + file.write(sourceCode) + + design = Design() + document = Document(self._filename) + design.Documents.append(document) + + self.assertEqual(len(design.Documents[0].Packages), 1) + package = design.Documents[0].Packages[0] + self.assertTrue(package.Name == "package_1") + self.assertEqual(len(package.DeclaredItems), 1) + + item: Constant = package.DeclaredItems[0] + self.assertTrue(isinstance(item, Constant)) + self.assertTrue(item.Name == "c0") + self.assertTrue(item.SubType.SymbolName == "boolean") + + default: Expression = item.DefaultExpression + self.assertTrue(isinstance(default, InverseExpression)) + self.assertTrue(isinstance(default.Operand, SimpleObjectSymbol)) + self.assertTrue(default.Operand.SymbolName == "true") diff --git a/testsuite/pyunit/dom/Literals.py b/testsuite/pyunit/dom/Literals.py index 8e426a0a9..7eb80abaa 100644 --- a/testsuite/pyunit/dom/Literals.py +++ b/testsuite/pyunit/dom/Literals.py @@ -1,10 +1,11 @@ -from pyGHDL.dom.Literal import IntegerLiteral -from pyGHDL.dom.Object import Constant from pathlib import Path from textwrap import dedent from unittest import TestCase from pyGHDL.dom.Misc import Design, Document +from pyGHDL.dom.Object import Constant +from pyGHDL.dom.Literal import IntegerLiteral + if __name__ == "__main__": print("ERROR: you called a testcase declaration file as an executable module.") |