From d8d3d344a93e6daee41702a9d1006189f258ff3a Mon Sep 17 00:00:00 2001 From: JHertz5 Date: Wed, 13 Nov 2024 10:40:11 +0000 Subject: [PATCH] Issue#1320: Added tests for rules generic_map_009 and generic_map_101. --- .../generic_map/rule_009_test_input.fixed.vhd | 45 +++++++++++++++++++ tests/generic_map/rule_009_test_input.vhd | 45 +++++++++++++++++++ .../generic_map/rule_101_test_input.fixed.vhd | 32 +++++++++++++ tests/generic_map/rule_101_test_input.vhd | 32 +++++++++++++ tests/generic_map/test_rule_009.py | 45 +++++++++++++++++++ tests/generic_map/test_rule_101.py | 45 +++++++++++++++++++ 6 files changed, 244 insertions(+) create mode 100644 tests/generic_map/rule_009_test_input.fixed.vhd create mode 100644 tests/generic_map/rule_009_test_input.vhd create mode 100644 tests/generic_map/rule_101_test_input.fixed.vhd create mode 100644 tests/generic_map/rule_101_test_input.vhd create mode 100644 tests/generic_map/test_rule_009.py create mode 100644 tests/generic_map/test_rule_101.py diff --git a/tests/generic_map/rule_009_test_input.fixed.vhd b/tests/generic_map/rule_009_test_input.fixed.vhd new file mode 100644 index 00000000..837bd592 --- /dev/null +++ b/tests/generic_map/rule_009_test_input.fixed.vhd @@ -0,0 +1,45 @@ + +architecture ARCH of ENTITY1 is + +begin + + U_INST1 : INST1 + generic map ( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + + U_INST1 : INST1 + generic map( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + + -- Violations below + + U_INST1 : INST1 + generic map + ( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + +end architecture ARCH; diff --git a/tests/generic_map/rule_009_test_input.vhd b/tests/generic_map/rule_009_test_input.vhd new file mode 100644 index 00000000..81699d78 --- /dev/null +++ b/tests/generic_map/rule_009_test_input.vhd @@ -0,0 +1,45 @@ + +architecture ARCH of ENTITY1 is + +begin + + U_INST1 : INST1 + generic map ( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + + U_INST1 : INST1 + generic map( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + + -- Violations below + + U_INST1 : INST1 + generic + map ( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + +end architecture ARCH; diff --git a/tests/generic_map/rule_101_test_input.fixed.vhd b/tests/generic_map/rule_101_test_input.fixed.vhd new file mode 100644 index 00000000..57ad59fa --- /dev/null +++ b/tests/generic_map/rule_101_test_input.fixed.vhd @@ -0,0 +1,32 @@ + +architecture ARCH of ENTITY1 is + +begin + + U_INST1 : INST1 + generic map ( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + + -- Violations below + + U_INST1 : INST1 + generic map ( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + +end architecture ARCH; diff --git a/tests/generic_map/rule_101_test_input.vhd b/tests/generic_map/rule_101_test_input.vhd new file mode 100644 index 00000000..f6e56c0b --- /dev/null +++ b/tests/generic_map/rule_101_test_input.vhd @@ -0,0 +1,32 @@ + +architecture ARCH of ENTITY1 is + +begin + + U_INST1 : INST1 + generic map ( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + + -- Violations below + + U_INST1 : INST1 + generic map ( + G_GEN_1 => 3, + G_GEN_2 => 4, + G_GEN_3 => 5 + ) + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + +end architecture ARCH; diff --git a/tests/generic_map/test_rule_009.py b/tests/generic_map/test_rule_009.py new file mode 100644 index 00000000..c9acc39b --- /dev/null +++ b/tests/generic_map/test_rule_009.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import generic_map + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_009_test_input.vhd")) + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_009_test_input.fixed.vhd"), lExpected, False) + + +class test_generic_map_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_009(self): + oRule = generic_map.rule_009() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "generic_map") + self.assertEqual(oRule.identifier, "009") + + lExpected = [33] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_009(self): + oRule = generic_map.rule_009() + + 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/generic_map/test_rule_101.py b/tests/generic_map/test_rule_101.py new file mode 100644 index 00000000..d3f8ab4b --- /dev/null +++ b/tests/generic_map/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 generic_map + +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_generic_map_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_101(self): + oRule = generic_map.rule_101() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "generic_map") + self.assertEqual(oRule.identifier, "101") + + lExpected = [21] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_101(self): + oRule = generic_map.rule_101() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, [])