Updates for issue #337

Updated rule architecture_005 to move the "of" keyword to the same line as the architecture keyword.

  1)  Updated tests
  2)  Updated code
  3)  Updated documentation
This commit is contained in:
Jeremiah C Leary 2020-02-21 22:23:28 -06:00
parent d953e29293
commit 0f4f0ba88b
6 changed files with 115 additions and 23 deletions

View File

@ -92,7 +92,8 @@ This rule checks the **of** keyword is on the same line as the **architecture**
.. code-block:: vhdl
architecture RTL of FIFO is
architecture RTL of
FIFO is
architecture_006
################

View File

@ -1,5 +1,6 @@
from vsg import rule
from vsg import utils
import re
@ -13,8 +14,26 @@ class rule_005(rule.rule):
self.identifier = '005'
self.solution = 'Ensure "of" keyword is on the same line as the "architecture" keyword.'
self.phase = 1
self.fixable = False # There is an example of this for entity
def _pre_analyze(self):
self.ofMissing = False
self.dViolation = {}
def _analyze(self, oFile, oLine, iLineNumber):
if oLine.isArchitectureKeyword:
self.ofMissing = False
# Search for of statement
if self.ofMissing and re.match('^\s*of', oLine.line, re.IGNORECASE):
self.ofMissing = False
self.dViolation['of_line'] = iLineNumber
self.add_violation(self.dViolation)
# Check architecture statement for "of"
if oLine.isArchitectureKeyword and not re.match('^\s*architecture\s+\w+\s+of', oLine.line, re.IGNORECASE):
self.add_violation({'lineNumber': iLineNumber})
self.dViolation = utils.create_violation_dict(iLineNumber)
self.ofMissing = True
def _fix_violations(self, oFile):
for dViolation in self.violations[::-1]:
oLine = oFile.lines[dViolation['lineNumber']]
oLine.update_line(re.sub(r'^(\s*architecture\s+\w+\s*)', r'\1 of', oLine.line, re.IGNORECASE))
utils.search_for_and_remove_keyword(oFile, dViolation['lineNumber'], 'of')

View File

@ -0,0 +1,46 @@
-- This should not fail
architecture rtl of entity1 is
begin
end architecture rtl;
-- These should fail
architecture rtl
of entity1 is
begin
end architecture rtl;
----------------------------
architecture rtl
of entity1 is
begin
end architecture rtl;
----------------------------
architecture rtl
of
entity1
is
begin
end architecture rtl;
----------------------------
architecture rtl
of
entity1
is
begin
end architecture rtl;

View File

@ -60,13 +60,6 @@ class testFixRuleArchitectureMethods(unittest.TestCase):
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
# def test_fix_rule_005(self):
# oRule = architecture.rule_005()
# dExpected = []
# oRule.fix(self.oFile)
# oRule.analyze(self.oFile)
# self.assertEqual(oRule.violations, dExpected)
#
def test_fix_rule_006(self):
oRule = architecture.rule_006()
dExpected = []

View File

@ -0,0 +1,46 @@
import os
import unittest
from vsg.rules import architecture
from vsg import vhdlFile
from vsg.tests import utils
# Read in test file used for all tests
lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','architecture','architecture_rule_005_test_input.vhd'))
class testRuleArchitecture(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
def test_rule_005(self):
oRule = architecture.rule_005()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'architecture')
self.assertEqual(oRule.identifier, '005')
dExpected = [{'lineNumber': 9, 'of_line': 10},
{'lineNumber': 16, 'of_line': 18},
{'lineNumber': 25, 'of_line': 26},
{'lineNumber': 34, 'of_line': 38}]
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_005(self):
oRule = architecture.rule_005()
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[9].line, 'architecture rtl of')
self.assertEqual(self.oFile.lines[10].line, ' entity1 is')
self.assertEqual(self.oFile.lines[16].line, 'architecture rtl of')
self.assertEqual(self.oFile.lines[18].line, ' entity1 is')
self.assertEqual(self.oFile.lines[25].line, 'architecture rtl of')
self.assertEqual(self.oFile.lines[26].line, 'entity1')
self.assertEqual(self.oFile.lines[33].line, 'architecture rtl of')
self.assertEqual(self.oFile.lines[38].line, 'entity1')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)

View File

@ -92,19 +92,6 @@ class testRuleArchitectureMethods(unittest.TestCase):
oRule.analyze(oFile)
self.assertEqual(oRule.violations, dExpected)
def test_rule_005_exists(self):
oRule = architecture.rule_005()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'architecture')
self.assertEqual(oRule.identifier, '005')
def test_rule_005(self):
oRule = architecture.rule_005()
dExpected = [utils.add_violation(26)]
oRule.analyze(oFile)
self.assertEqual(oRule.violations, dExpected)
def test_rule_006_exists(self):
oRule = architecture.rule_006()
self.assertTrue(oRule)