From cd64cdeae0c3afb9a0d1fb90eb8e867b59b701cc Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Fri, 4 Dec 2020 17:03:00 -0600 Subject: [PATCH] Updates for issue #474 Adding rule function_017 to handle the case of function designators. 1) Added documentation 2) Added test 3) Added rule function_017 --- docs/function_rules.rst | 21 +++++- vsg/rules/function/__init__.py | 1 + vsg/rules/function/rule_017.py | 16 ++++ .../rule_017_test_input.fixed_lower.vhd | 30 ++++++++ .../rule_017_test_input.fixed_upper.vhd | 30 ++++++++ vsg/tests/function/rule_017_test_input.vhd | 30 ++++++++ vsg/tests/function/test_rule_017.py | 73 +++++++++++++++++++ .../FrameBuffer2.fixed.vhd | 6 +- 8 files changed, 203 insertions(+), 4 deletions(-) create mode 100644 vsg/rules/function/rule_017.py create mode 100644 vsg/tests/function/rule_017_test_input.fixed_lower.vhd create mode 100644 vsg/tests/function/rule_017_test_input.fixed_upper.vhd create mode 100644 vsg/tests/function/rule_017_test_input.vhd create mode 100644 vsg/tests/function/test_rule_017.py diff --git a/docs/function_rules.rst b/docs/function_rules.rst index e28d3295..c021f8da 100644 --- a/docs/function_rules.rst +++ b/docs/function_rules.rst @@ -243,7 +243,7 @@ This rule checks for consistent capitalization of function names. end architecture rtl; -**Violation** +**Fix** .. code-block:: vhdl @@ -380,3 +380,22 @@ This rule checks the indent of return statements in function bodies. return 99; return 99; end func1; + +function_017 +############ + +This rule checks the function designator has proper case. + +Refer to the section `Configuring Uppercase and Lowercase Rules `_ for information on changing the default case. + +**Violation** + +.. code-block:: vhdl + + function OVERflow (a: integer) return integer is + +**Fix** + +.. code-block:: vhdl + + function overflow (a: integer) return integer is diff --git a/vsg/rules/function/__init__.py b/vsg/rules/function/__init__.py index 0f218902..7db360e5 100644 --- a/vsg/rules/function/__init__.py +++ b/vsg/rules/function/__init__.py @@ -15,3 +15,4 @@ from .rule_013 import rule_013 from .rule_014 import rule_014 from .rule_015 import rule_015 from .rule_016 import rule_016 +from .rule_017 import rule_017 diff --git a/vsg/rules/function/rule_017.py b/vsg/rules/function/rule_017.py new file mode 100644 index 00000000..37b74b4f --- /dev/null +++ b/vsg/rules/function/rule_017.py @@ -0,0 +1,16 @@ + +from vsg.rules import token_case + +from vsg import token + +lTokens = [] +lTokens.append(token.function_specification.designator) + + +class rule_017(token_case): + ''' + Checks the function designator has proper case. + ''' + + def __init__(self): + token_case.__init__(self, 'function', '017', lTokens) diff --git a/vsg/tests/function/rule_017_test_input.fixed_lower.vhd b/vsg/tests/function/rule_017_test_input.fixed_lower.vhd new file mode 100644 index 00000000..1df10e57 --- /dev/null +++ b/vsg/tests/function/rule_017_test_input.fixed_lower.vhd @@ -0,0 +1,30 @@ + +architecture RTL of FIFO is + + function func1 return integer; + + pure function func1 return integer; + + impure function func1 return integer; + + function func1 return integer is + + begin + + end function func1; + + -- Violations follow + + function func1 return integer; + + function func1 return integer; + + pure function func1 return integer; + pure function func1 return integer; + + impure function func1 return integer; + impure function func1 return integer; + +begin + +end architecture RTL; diff --git a/vsg/tests/function/rule_017_test_input.fixed_upper.vhd b/vsg/tests/function/rule_017_test_input.fixed_upper.vhd new file mode 100644 index 00000000..71eb98c9 --- /dev/null +++ b/vsg/tests/function/rule_017_test_input.fixed_upper.vhd @@ -0,0 +1,30 @@ + +architecture RTL of FIFO is + + function FUNC1 return integer; + + pure function FUNC1 return integer; + + impure function FUNC1 return integer; + + function FUNC1 return integer is + + begin + + end function func1; + + -- Violations follow + + function FUNC1 return integer; + + function FUNC1 return integer; + + pure function FUNC1 return integer; + pure function FUNC1 return integer; + + impure function FUNC1 return integer; + impure function FUNC1 return integer; + +begin + +end architecture RTL; diff --git a/vsg/tests/function/rule_017_test_input.vhd b/vsg/tests/function/rule_017_test_input.vhd new file mode 100644 index 00000000..8632692f --- /dev/null +++ b/vsg/tests/function/rule_017_test_input.vhd @@ -0,0 +1,30 @@ + +architecture RTL of FIFO is + + function func1 return integer; + + pure function func1 return integer; + + impure function func1 return integer; + + function func1 return integer is + + begin + + end function func1; + + -- Violations follow + + function Func1 return integer; + + function FUNC1 return integer; + + pure function fUNc1 return integer; + pure function funC1 return integer; + + impure function FUNC1 return integer; + impure function func1 return integer; + +begin + +end architecture RTL; diff --git a/vsg/tests/function/test_rule_017.py b/vsg/tests/function/test_rule_017.py new file mode 100644 index 00000000..93f48fa8 --- /dev/null +++ b/vsg/tests/function/test_rule_017.py @@ -0,0 +1,73 @@ + +import os +import unittest + +from vsg.rules import function +from vsg import vhdlFile +from vsg.tests import utils + +sTestDir = os.path.dirname(__file__) + +lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_017_test_input.vhd')) + +lExpected_lower = [] +lExpected_lower.append('') +utils.read_file(os.path.join(sTestDir, 'rule_017_test_input.fixed_lower.vhd'), lExpected_lower) + +lExpected_upper = [] +lExpected_upper.append('') +utils.read_file(os.path.join(sTestDir, 'rule_017_test_input.fixed_upper.vhd'), lExpected_upper) + +class test_function_rule(unittest.TestCase): + + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + + def test_rule_017_lower(self): + oRule = function.rule_017() + self.assertTrue(oRule) + self.assertEqual(oRule.name, 'function') + self.assertEqual(oRule.identifier, '017') + + lExpected = [18, 20, 22, 23, 25] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_rule_017_upper(self): + oRule = function.rule_017() + oRule.case = 'upper' + self.assertTrue(oRule) + self.assertEqual(oRule.name, 'function') + self.assertEqual(oRule.identifier, '017') + + lExpected = [4, 6, 8, 10, 18, 22, 23, 26] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_fix_rule_017_lower(self): + oRule = function.rule_017() + + 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_017_upper(self): + oRule = function.rule_017() + 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/tests/styles/jcl/graphicsaccelerator/FrameBuffer2.fixed.vhd b/vsg/tests/styles/jcl/graphicsaccelerator/FrameBuffer2.fixed.vhd index 9bbde400..f9f70b22 100644 --- a/vsg/tests/styles/jcl/graphicsaccelerator/FrameBuffer2.fixed.vhd +++ b/vsg/tests/styles/jcl/graphicsaccelerator/FrameBuffer2.fixed.vhd @@ -21,7 +21,7 @@ architecture BEHAVIORAL of FRAMEBUFFER is type fbuffer is array (0 to 524288 / 16 - 1) of std_logic_vector(2 downto 0); - impure function initFB return fbuffer is + impure function initfb return fbuffer is variable temp : fbuffer; variable i : integer; begin @@ -29,9 +29,9 @@ architecture BEHAVIORAL of FRAMEBUFFER is temp(i) := "000"; end loop; return temp; - end initFB; + end initfb; - signal mybuffer : fbuffer := initFB; + signal mybuffer : fbuffer := initfb; signal addresswrite, addressread : std_logic_vector(14 downto 0); signal temp : std_logic_vector(2 downto 0);