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
This commit is contained in:
Jeremiah Leary 2020-12-04 17:03:00 -06:00
parent 077858bc62
commit cd64cdeae0
8 changed files with 203 additions and 4 deletions

View File

@ -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 <configuring_case.html>`_ 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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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