Issue#1275: Added rules for library names in entity instantiations (#1276)

* Issue#1275: Added rule instantiation_500.

* Issue#1275: Added tests for rule instantiation_500.

* Issue#1275: Added documentation for rule instantiation_500.

* Issue#1275: Reverted IEEE rule doc change.

* Issue#1275: Removed excess newline in docstring/documentation.
This commit is contained in:
JHertz5 2024-10-20 16:31:19 +01:00 committed by GitHub
parent afb9a1d56e
commit 3d3835a08d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 210 additions and 0 deletions

View File

@ -371,6 +371,7 @@ Rules Enforcing Case
* `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>`_

View File

@ -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
#################

View File

@ -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>`_

View File

@ -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>`_

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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, [])

View File

@ -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

View File

@ -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")