aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-19 03:03:29 +0200
committerPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-19 15:25:07 +0200
commit89f835733c4019c5cb087885a874f34cf4ff183d (patch)
treee6b986089f904e46621370cb546a1b0f2e156f9a
parent3bbdbaf0c5789baf38f6e4c57e4c669f1d8e03a0 (diff)
downloadghdl-89f835733c4019c5cb087885a874f34cf4ff183d.tar.gz
ghdl-89f835733c4019c5cb087885a874f34cf4ff183d.tar.bz2
ghdl-89f835733c4019c5cb087885a874f34cf4ff183d.zip
Testcase(s) for expressions.
-rw-r--r--testsuite/pyunit/dom/Expressions.py49
-rw-r--r--testsuite/pyunit/dom/Literals.py5
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.")