diff --git a/docs/configuring_uppercase_and_lowercase_rules.rst b/docs/configuring_uppercase_and_lowercase_rules.rst index f2c9604d..34be68ac 100644 --- a/docs/configuring_uppercase_and_lowercase_rules.rst +++ b/docs/configuring_uppercase_and_lowercase_rules.rst @@ -371,6 +371,7 @@ Rules Enforcing Case * `instantiation_027 `_ * `instantiation_028 `_ * `instantiation_031 `_ +* `instantiation_500 `_ * `iteration_scheme_500 `_ * `iteration_scheme_501 `_ diff --git a/docs/instantiation_rules.rst b/docs/instantiation_rules.rst index 55f97e7d..1d6eeb0f 100644 --- a/docs/instantiation_rules.rst +++ b/docs/instantiation_rules.rst @@ -548,6 +548,27 @@ This rule checks the semicolon is not on its own line. A => B, B => C); +instantiation_500 +################# + +|phase_6| |error| |case| |case_name| + +This rule checks the component library name has proper case. + +|configuring_uppercase_and_lowercase_rules_link| + +**Violation** + +.. code-block:: vhdl + + u_fifo : entity WORK.FIFO + +**Fix** + +.. code-block:: vhdl + + u_fifo : entity work.FIFO + instantiation_600 ################# diff --git a/docs/rule_groups/case_name_rule_group.rst b/docs/rule_groups/case_name_rule_group.rst index 2a299a45..40779c00 100644 --- a/docs/rule_groups/case_name_rule_group.rst +++ b/docs/rule_groups/case_name_rule_group.rst @@ -28,6 +28,7 @@ Rules Enforcing Case::Name Rule Group * `generic_map_002 <../generic_map_rules.html#generic-map-002>`_ * `instantiation_009 <../instantiation_rules.html#instantiation-009>`_ * `instantiation_028 <../instantiation_rules.html#instantiation-028>`_ +* `instantiation_500 <../instantiation_rules.html#instantiation-500>`_ * `library_500 <../library_rules.html#library-500>`_ * `package_008 <../package_rules.html#package-008>`_ * `package_010 <../package_rules.html#package-010>`_ diff --git a/docs/rule_groups/case_rule_group.rst b/docs/rule_groups/case_rule_group.rst index b57a19ef..c1ce8204 100644 --- a/docs/rule_groups/case_rule_group.rst +++ b/docs/rule_groups/case_rule_group.rst @@ -128,6 +128,7 @@ Rules Enforcing Case Rule Group * `instantiation_027 <../instantiation_rules.html#instantiation-027>`_ * `instantiation_028 <../instantiation_rules.html#instantiation-028>`_ * `instantiation_031 <../instantiation_rules.html#instantiation-031>`_ +* `instantiation_500 <../instantiation_rules.html#instantiation-500>`_ * `iteration_scheme_500 <../iteration_scheme_rules.html#iteration-scheme-500>`_ * `iteration_scheme_501 <../iteration_scheme_rules.html#iteration-scheme-501>`_ * `iteration_scheme_502 <../iteration_scheme_rules.html#iteration-scheme-502>`_ diff --git a/tests/instantiation/rule_500_test_input.fixed_lower.vhd b/tests/instantiation/rule_500_test_input.fixed_lower.vhd new file mode 100644 index 00000000..b1ad53c1 --- /dev/null +++ b/tests/instantiation/rule_500_test_input.fixed_lower.vhd @@ -0,0 +1,27 @@ + +architecture ARCH of ENTITY1 is + +begin + + U_INST1 : entity my_lib.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 : entity my_lib.inst1 + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + +end architecture ARCH; diff --git a/tests/instantiation/rule_500_test_input.fixed_upper.vhd b/tests/instantiation/rule_500_test_input.fixed_upper.vhd new file mode 100644 index 00000000..719db6d7 --- /dev/null +++ b/tests/instantiation/rule_500_test_input.fixed_upper.vhd @@ -0,0 +1,27 @@ + +architecture ARCH of ENTITY1 is + +begin + + U_INST1 : entity MY_LIB.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 : entity MY_LIB.inst1 + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + +end architecture ARCH; diff --git a/tests/instantiation/rule_500_test_input.vhd b/tests/instantiation/rule_500_test_input.vhd new file mode 100644 index 00000000..d7b94c34 --- /dev/null +++ b/tests/instantiation/rule_500_test_input.vhd @@ -0,0 +1,27 @@ + +architecture ARCH of ENTITY1 is + +begin + + U_INST1 : entity my_lib.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 : entity MY_LIB.inst1 + port map ( + PORT_1 => w_port_1, + PORT_2 => w_port_2, + PORT_3 => w_port_3 + ); + +end architecture ARCH; diff --git a/tests/instantiation/test_rule_500.py b/tests/instantiation/test_rule_500.py new file mode 100644 index 00000000..8781949c --- /dev/null +++ b/tests/instantiation/test_rule_500.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import instantiation + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_500_test_input.vhd")) + +lExpected_lower = [] +lExpected_lower.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_lower.vhd"), lExpected_lower) + +lExpected_upper = [] +lExpected_upper.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_upper.vhd"), lExpected_upper) + + +class test_instantiation_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_500_lower(self): + oRule = instantiation.rule_500() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "instantiation") + self.assertEqual(oRule.identifier, "500") + + lExpected = [20] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_rule_500_upper(self): + oRule = instantiation.rule_500() + oRule.case = "upper" + self.assertTrue(oRule) + self.assertEqual(oRule.name, "instantiation") + self.assertEqual(oRule.identifier, "500") + + lExpected = [6] + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_fix_rule_500_lower(self): + oRule = instantiation.rule_500() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_lower, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_500_upper(self): + oRule = instantiation.rule_500() + oRule.case = "upper" + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_upper, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/vsg/rules/instantiation/__init__.py b/vsg/rules/instantiation/__init__.py index 2bc33d60..e989036b 100644 --- a/vsg/rules/instantiation/__init__.py +++ b/vsg/rules/instantiation/__init__.py @@ -34,5 +34,6 @@ from .rule_032 import rule_032 from .rule_033 import rule_033 from .rule_034 import rule_034 from .rule_035 import rule_035 +from .rule_500 import rule_500 from .rule_600 import rule_600 from .rule_601 import rule_601 diff --git a/vsg/rules/instantiation/rule_500.py b/vsg/rules/instantiation/rule_500.py new file mode 100644 index 00000000..113c1609 --- /dev/null +++ b/vsg/rules/instantiation/rule_500.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_case_with_prefix_suffix + +lTokens = [] +lTokens.append(token.instantiated_unit.library_name) + + +class rule_500(token_case_with_prefix_suffix): + """ + This rule checks the component library name has proper case. + + |configuring_uppercase_and_lowercase_rules_link| + + **Violation** + + .. code-block:: vhdl + + u_fifo : entity WORK.FIFO + + **Fix** + + .. code-block:: vhdl + + u_fifo : entity work.FIFO + """ + + def __init__(self): + super().__init__(lTokens) + self.groups.append("case::name")