Updates for if rules:
1) Added rule to catch sequential assignments on same line as then keyword.
This commit is contained in:
parent
2302960e03
commit
f909c944d1
|
|
@ -203,5 +203,21 @@ class rule_011(if_rule):
|
|||
if oLine.isElseKeyword and not oFile.lines[iLineNumber + 2].isCaseKeyword:
|
||||
self._is_no_blank_line_after(oFile, iLineNumber)
|
||||
|
||||
|
||||
class rule_012(if_rule):
|
||||
'''If rule 012 checks for code after the "then" keyword.'''
|
||||
|
||||
def __init__(self):
|
||||
if_rule.__init__(self)
|
||||
self.identifier = '012'
|
||||
self.solution = 'Move code after "then" keyword to the next line.'
|
||||
self.phase = 1
|
||||
|
||||
def analyze(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if oLine.isThenKeyword:
|
||||
if re.match('^.*\sthen\s+\w', oLine.lineLower):
|
||||
self.add_violation(iLineNumber)
|
||||
|
||||
#TODO:
|
||||
# check if, then, elsif, end if keywords are lower case
|
||||
|
|
|
|||
|
|
@ -95,6 +95,10 @@ begin
|
|||
g <= z;
|
||||
end if;
|
||||
|
||||
if (a = 2) then b <= d;
|
||||
elsif (b = 3) then c <= e;
|
||||
elsif (c = 4) then -- Not an error
|
||||
end if;
|
||||
|
||||
|
||||
end process PROC_NAME;
|
||||
|
|
|
|||
|
|
@ -137,5 +137,14 @@ class testRuleIfMethods(unittest.TestCase):
|
|||
oRule.analyze(oFileCase)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
def test_rule_012(self):
|
||||
oRule = if_statement.rule_012()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'if')
|
||||
self.assertEqual(oRule.identifier, '012')
|
||||
dExpected = [98,99]
|
||||
oRule.analyze(oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class testVhdlFileIfAssignments(unittest.TestCase):
|
|||
|
||||
|
||||
def test_insideIf_assignment(self):
|
||||
lExpected = [8,13,14,19,20,21,24,30,31,32,33,41,42,43,46,52,53,54,57,66,67,68,73,80,91]
|
||||
lExpected = [8,13,14,19,20,21,24,30,31,32,33,41,42,43,46,52,53,54,57,66,67,68,73,80,91,98,99,100]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
|
|
@ -19,7 +19,7 @@ class testVhdlFileIfAssignments(unittest.TestCase):
|
|||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_isElseIfKeyword_assignment(self):
|
||||
lExpected = [24,73]
|
||||
lExpected = [24,73,99,100]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
|
|
@ -29,7 +29,7 @@ class testVhdlFileIfAssignments(unittest.TestCase):
|
|||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_isEndIfKeyword_assignment(self):
|
||||
lExpected = [11,17,27,36,39,49,50,60,62,78,89,96]
|
||||
lExpected = [11,17,27,36,39,49,50,60,62,78,89,96,101]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
|
|
@ -39,7 +39,7 @@ class testVhdlFileIfAssignments(unittest.TestCase):
|
|||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_isIfKeyword_assignment(self):
|
||||
lExpected = [8,13,19,30,33,41,46,52,57,66,80,91]
|
||||
lExpected = [8,13,19,30,33,41,46,52,57,66,80,91,98]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
|
|
@ -49,7 +49,7 @@ class testVhdlFileIfAssignments(unittest.TestCase):
|
|||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_isThenKeyword_assignment(self):
|
||||
lExpected = [8,14,21,24,32,33,43,46,54,57,68,73,80,91]
|
||||
lExpected = [8,14,21,24,32,33,43,46,54,57,68,73,80,91,98,99,100]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
|
|
|
|||
Loading…
Reference in New Issue