From e866be03e82cb0ebbd00cdab62b5cdb0ca6c89fe Mon Sep 17 00:00:00 2001 From: JHertz5 Date: Sun, 24 Aug 2025 18:58:34 +0100 Subject: [PATCH] #1491: Added tests for new rules. --- .../rule_100_test_input.fixed.vhd | 14 ++++++ .../rule_100_test_input.vhd | 14 ++++++ .../rule_101_test_input.fixed.vhd | 14 ++++++ .../rule_101_test_input.vhd | 14 ++++++ .../index_subtype_definition/test_rule_100.py | 45 +++++++++++++++++++ .../index_subtype_definition/test_rule_101.py | 45 +++++++++++++++++++ .../rule_100_test_input.fixed.vhd | 19 ++++++++ .../range_constraint/rule_100_test_input.vhd | 19 ++++++++ .../rule_101_test_input.fixed.vhd | 19 ++++++++ .../range_constraint/rule_101_test_input.vhd | 19 ++++++++ tests/range_constraint/test_rule_100.py | 45 +++++++++++++++++++ tests/range_constraint/test_rule_101.py | 45 +++++++++++++++++++ 12 files changed, 312 insertions(+) create mode 100644 tests/index_subtype_definition/rule_100_test_input.fixed.vhd create mode 100644 tests/index_subtype_definition/rule_100_test_input.vhd create mode 100644 tests/index_subtype_definition/rule_101_test_input.fixed.vhd create mode 100644 tests/index_subtype_definition/rule_101_test_input.vhd create mode 100644 tests/index_subtype_definition/test_rule_100.py create mode 100644 tests/index_subtype_definition/test_rule_101.py create mode 100644 tests/range_constraint/rule_100_test_input.fixed.vhd create mode 100644 tests/range_constraint/rule_100_test_input.vhd create mode 100644 tests/range_constraint/rule_101_test_input.fixed.vhd create mode 100644 tests/range_constraint/rule_101_test_input.vhd create mode 100644 tests/range_constraint/test_rule_100.py create mode 100644 tests/range_constraint/test_rule_101.py diff --git a/tests/index_subtype_definition/rule_100_test_input.fixed.vhd b/tests/index_subtype_definition/rule_100_test_input.fixed.vhd new file mode 100644 index 00000000..e3892bd0 --- /dev/null +++ b/tests/index_subtype_definition/rule_100_test_input.fixed.vhd @@ -0,0 +1,14 @@ + +architecture RTL of FIFO is + + -- Passing + + type my_array is array (natural range <>) of std_logic_vector(7 downto 0); + + -- Violation below + + type my_array is array (natural range <>) of std_logic_vector(7 downto 0); + +begin + +end architecture RTL; diff --git a/tests/index_subtype_definition/rule_100_test_input.vhd b/tests/index_subtype_definition/rule_100_test_input.vhd new file mode 100644 index 00000000..efcadf18 --- /dev/null +++ b/tests/index_subtype_definition/rule_100_test_input.vhd @@ -0,0 +1,14 @@ + +architecture RTL of FIFO is + + -- Passing + + type my_array is array (natural range <>) of std_logic_vector(7 downto 0); + + -- Violation below + + type my_array is array (natural range <>) of std_logic_vector(7 downto 0); + +begin + +end architecture RTL; diff --git a/tests/index_subtype_definition/rule_101_test_input.fixed.vhd b/tests/index_subtype_definition/rule_101_test_input.fixed.vhd new file mode 100644 index 00000000..e3892bd0 --- /dev/null +++ b/tests/index_subtype_definition/rule_101_test_input.fixed.vhd @@ -0,0 +1,14 @@ + +architecture RTL of FIFO is + + -- Passing + + type my_array is array (natural range <>) of std_logic_vector(7 downto 0); + + -- Violation below + + type my_array is array (natural range <>) of std_logic_vector(7 downto 0); + +begin + +end architecture RTL; diff --git a/tests/index_subtype_definition/rule_101_test_input.vhd b/tests/index_subtype_definition/rule_101_test_input.vhd new file mode 100644 index 00000000..39537ec8 --- /dev/null +++ b/tests/index_subtype_definition/rule_101_test_input.vhd @@ -0,0 +1,14 @@ + +architecture RTL of FIFO is + + -- Passing + + type my_array is array (natural range <>) of std_logic_vector(7 downto 0); + + -- Violation below + + type my_array is array (natural range <>) of std_logic_vector(7 downto 0); + +begin + +end architecture RTL; diff --git a/tests/index_subtype_definition/test_rule_100.py b/tests/index_subtype_definition/test_rule_100.py new file mode 100644 index 00000000..78f90c6a --- /dev/null +++ b/tests/index_subtype_definition/test_rule_100.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import index_subtype_definition + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_100_test_input.vhd")) + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_100_test_input.fixed.vhd"), lExpected) + + +class test_index_subtype_definition_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_100(self): + oRule = index_subtype_definition.rule_100() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "index_subtype_definition") + self.assertEqual(oRule.identifier, "100") + + lExpected = [10] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_100(self): + oRule = index_subtype_definition.rule_100() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/index_subtype_definition/test_rule_101.py b/tests/index_subtype_definition/test_rule_101.py new file mode 100644 index 00000000..4101b1b7 --- /dev/null +++ b/tests/index_subtype_definition/test_rule_101.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import index_subtype_definition + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_101_test_input.vhd")) + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_101_test_input.fixed.vhd"), lExpected) + + +class test_index_subtype_definition_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_101(self): + oRule = index_subtype_definition.rule_101() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "index_subtype_definition") + self.assertEqual(oRule.identifier, "101") + + lExpected = [10] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_101(self): + oRule = index_subtype_definition.rule_101() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/range_constraint/rule_100_test_input.fixed.vhd b/tests/range_constraint/rule_100_test_input.fixed.vhd new file mode 100644 index 00000000..969214e1 --- /dev/null +++ b/tests/range_constraint/rule_100_test_input.fixed.vhd @@ -0,0 +1,19 @@ + +architecture RTL of FIFO is + + -- Passing + + type my_array is array (natural range 0 to 7) of std_logic_vector(7 downto 0); + type my_array is array (natural range 0 to 7) of integer; + subtype my_array is natural range 7 downto 0; + + -- Violation below + + type my_array is array (natural range 0 to 7) of std_logic_vector(7 downto 0); + type my_array is array (natural range 0 to 7) of integer; + subtype my_array is natural range 7 downto 0; + + +begin + +end architecture RTL; diff --git a/tests/range_constraint/rule_100_test_input.vhd b/tests/range_constraint/rule_100_test_input.vhd new file mode 100644 index 00000000..382d2d17 --- /dev/null +++ b/tests/range_constraint/rule_100_test_input.vhd @@ -0,0 +1,19 @@ + +architecture RTL of FIFO is + + -- Passing + + type my_array is array (natural range 0 to 7) of std_logic_vector(7 downto 0); + type my_array is array (natural range 0 to 7) of integer; + subtype my_array is natural range 7 downto 0; + + -- Violation below + + type my_array is array (natural range 0 to 7) of std_logic_vector(7 downto 0); + type my_array is array (natural range 0 to 7) of integer; + subtype my_array is natural range 7 downto 0; + + +begin + +end architecture RTL; diff --git a/tests/range_constraint/rule_101_test_input.fixed.vhd b/tests/range_constraint/rule_101_test_input.fixed.vhd new file mode 100644 index 00000000..969214e1 --- /dev/null +++ b/tests/range_constraint/rule_101_test_input.fixed.vhd @@ -0,0 +1,19 @@ + +architecture RTL of FIFO is + + -- Passing + + type my_array is array (natural range 0 to 7) of std_logic_vector(7 downto 0); + type my_array is array (natural range 0 to 7) of integer; + subtype my_array is natural range 7 downto 0; + + -- Violation below + + type my_array is array (natural range 0 to 7) of std_logic_vector(7 downto 0); + type my_array is array (natural range 0 to 7) of integer; + subtype my_array is natural range 7 downto 0; + + +begin + +end architecture RTL; diff --git a/tests/range_constraint/rule_101_test_input.vhd b/tests/range_constraint/rule_101_test_input.vhd new file mode 100644 index 00000000..0bf263ec --- /dev/null +++ b/tests/range_constraint/rule_101_test_input.vhd @@ -0,0 +1,19 @@ + +architecture RTL of FIFO is + + -- Passing + + type my_array is array (natural range 0 to 7) of std_logic_vector(7 downto 0); + type my_array is array (natural range 0 to 7) of integer; + subtype my_array is natural range 7 downto 0; + + -- Violation below + + type my_array is array (natural range 0 to 7) of std_logic_vector(7 downto 0); + type my_array is array (natural range 0 to 7) of integer; + subtype my_array is natural range 7 downto 0; + + +begin + +end architecture RTL; diff --git a/tests/range_constraint/test_rule_100.py b/tests/range_constraint/test_rule_100.py new file mode 100644 index 00000000..1a4c07aa --- /dev/null +++ b/tests/range_constraint/test_rule_100.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import range_constraint + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_100_test_input.vhd")) + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_100_test_input.fixed.vhd"), lExpected) + + +class test_range_constraint_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_100(self): + oRule = range_constraint.rule_100() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "range_constraint") + self.assertEqual(oRule.identifier, "100") + + lExpected = [12, 13, 14] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_100(self): + oRule = range_constraint.rule_100() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/range_constraint/test_rule_101.py b/tests/range_constraint/test_rule_101.py new file mode 100644 index 00000000..5d76093b --- /dev/null +++ b/tests/range_constraint/test_rule_101.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import range_constraint + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_101_test_input.vhd")) + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_101_test_input.fixed.vhd"), lExpected) + + +class test_index_subtype_definition_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_101(self): + oRule = range_constraint.rule_101() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "range_constraint") + self.assertEqual(oRule.identifier, "101") + + lExpected = [12, 13, 14] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_101(self): + oRule = range_constraint.rule_101() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, [])