aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/pyunit/dom
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-30 20:56:30 +0200
committerPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-07-01 06:39:47 +0200
commitaf4bbc71c723c2602a1b4f82e698c005b1fb64f6 (patch)
tree2cf9d74930be2f816a4869feda38c9818298ba4d /testsuite/pyunit/dom
parentc75693ff6f5c7b05d49ce916e34aaba61b688e31 (diff)
downloadghdl-af4bbc71c723c2602a1b4f82e698c005b1fb64f6.tar.gz
ghdl-af4bbc71c723c2602a1b4f82e698c005b1fb64f6.tar.bz2
ghdl-af4bbc71c723c2602a1b4f82e698c005b1fb64f6.zip
Simplified test code for literals.
Diffstat (limited to 'testsuite/pyunit/dom')
-rw-r--r--testsuite/pyunit/dom/Literals.py59
1 files changed, 31 insertions, 28 deletions
diff --git a/testsuite/pyunit/dom/Literals.py b/testsuite/pyunit/dom/Literals.py
index 60938c52e..418a1b76d 100644
--- a/testsuite/pyunit/dom/Literals.py
+++ b/testsuite/pyunit/dom/Literals.py
@@ -34,6 +34,10 @@ from pathlib import Path
from textwrap import dedent
from unittest import TestCase
+from pyVHDLModel.VHDLModel import Expression
+
+from pyGHDL.dom.DesignUnit import Package
+
from pyGHDL.dom.NonStandard import Design, Document
from pyGHDL.dom.Object import Constant
from pyGHDL.dom.Literal import IntegerLiteral
@@ -47,39 +51,38 @@ if __name__ == "__main__":
class Literals(TestCase):
_root = Path(__file__).resolve().parent.parent
-
- def test_IntegerLiteral(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 : integer := 0;
- constant c1 : integer := 1;
- constant c2 : integer := 1024;
- constant c3 : integer := 1048576;
+ {code}
end package;
"""
)
- expected = (0, 1, 1024, 1048576)
- 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)
+
+ document = Document(filename, sourceCode)
+ self._design.Documents.append(document)
+
+ # Traverse already to default value expression
+ package: Package = document.Packages[0]
+ item: Constant = package.DeclaredItems[0]
+ default: Expression = item.DefaultExpression
+
+ return default
+
+ def test_IntegerLiteral(self):
+ _filename: Path = self._root / "{className}.vhdl".format(
+ className=self.__class__.__name__
+ )
+
+ constantDeclartion = "constant c0 : integer := 0;"
+ expected = (0, 1, 1024, 1048576)
- design = Design()
- document = Document(self._filename)
- design.Documents.append(document)
+ # Parse in-memory
+ default: Expression = self.parse(_filename, constantDeclartion)
- self.assertEqual(1, len(design.Documents[0].Packages))
- package = design.Documents[0].Packages[0]
- self.assertEqual("package_1", package.Identifier)
- self.assertEqual(len(expected), len(package.DeclaredItems))
- for i in range(len(expected)):
- item: Constant = package.DeclaredItems[i]
- self.assertIsInstance(item, Constant)
- self.assertEqual("c{}".format(i), item.Identifier)
- self.assertEqual("integer", str(item.Subtype.SymbolName))
- self.assertIsInstance(item.DefaultExpression, IntegerLiteral)
- self.assertEqual(expected[i], item.DefaultExpression.Value)
+ self.assertIsInstance(default, IntegerLiteral)
+ self.assertEqual(expected[0], default.Value)