diff --git a/vsg/rules/entity/rule_019.py b/vsg/rules/entity/rule_019.py index 2b250221..2cf60725 100644 --- a/vsg/rules/entity/rule_019.py +++ b/vsg/rules/entity/rule_019.py @@ -1,5 +1,6 @@ from vsg import rule +from vsg import utils import re @@ -15,9 +16,21 @@ class rule_019(rule.rule): self.identifier = '019' self.solution = 'Add the entity name.' self.phase = 1 - self.fixable = False + + def _pre_analyze(self): + self.sEntityName = '' def _analyze(self, oFile, oLine, iLineNumber): + if oLine.isEntityDeclaration: + self.sEntityName = utils.extract_entity_identifier(oLine)[0] if oLine.isEndEntityDeclaration and re.match('^\s*end\s+entity', oLine.line, re.IGNORECASE): if not re.match('^\s*end\s+entity\s+\w+', oLine.line, re.IGNORECASE): self.add_violation(iLineNumber) + self.dFix['violations'][iLineNumber] = self.sEntityName + + def _fix_violations(self, oFile): + for iLineNumber in self.violations: + oLine = oFile.lines[iLineNumber] + sLine = oLine.line + iIndex = oLine.lineLower.find('entity') + len('entity') + oLine.update_line(sLine[:iIndex] + ' ' + self.dFix['violations'][iLineNumber] + sLine[iIndex:]) diff --git a/vsg/tests/entity/test_fix_rule_entity.py b/vsg/tests/entity/test_fix_rule_entity.py index 63770dac..529a7317 100644 --- a/vsg/tests/entity/test_fix_rule_entity.py +++ b/vsg/tests/entity/test_fix_rule_entity.py @@ -8,119 +8,129 @@ from vsg.tests import utils lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','entity','entity_test_input.vhd')) -oFile = vhdlFile.vhdlFile(lFile) class testFixRuleEntityMethods(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + def test_fix_rule_001(self): oRule = entity.rule_001() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_002(self): oRule = entity.rule_002() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_003(self): oRule = entity.rule_003() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_004(self): oRule = entity.rule_004() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_005(self): oRule = entity.rule_005() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) - self.assertEqual(oFile.lines[51].line, ' generic (') + self.assertEqual(self.oFile.lines[49].line, 'entity ENTITY1 is') + self.assertEqual(self.oFile.lines[50].line, ' generic (') def test_fix_rule_006(self): oRule = entity.rule_006() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_007(self): oRule = entity.rule_007() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_008(self): oRule = entity.rule_008() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_009(self): oRule = entity.rule_009() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_010(self): oRule = entity.rule_010() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_011(self): oRule = entity.rule_011() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_012(self): oRule = entity.rule_012() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_013(self): oRule = entity.rule_013() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_014(self): oRule = entity.rule_014() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_015(self): oRule = entity.rule_015() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) - self.assertEqual(oFile.lines[103].line, 'end entity ENT1;') + self.assertEqual(self.oFile.lines[103].line, 'end entity ENT1;') def test_fix_rule_016(self): oRule = entity.rule_016() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_017(self): oRule = entity.rule_017() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) def test_fix_rule_018(self): oRule = entity.rule_018() - oRule.fix(oFile) - oRule.analyze(oFile) + oRule.fix(self.oFile) + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + self.assertEqual(self.oFile.lines[21].line, ' G_GENERIC1 : std_logic :=\'0\'; -- Comment') + self.assertEqual(self.oFile.lines[22].line, ' G_generic2 : std_logic := \'1\' -- Comment') + + def test_fix_rule_019(self): + oRule = entity.rule_019() + oRule.fix(self.oFile) + oRule.analyze(self.oFile) + self.assertEqual(self.oFile.lines[133].line, 'end entity ENTITY1;') self.assertEqual(oRule.violations, []) - self.assertEqual(oFile.lines[21].line, ' G_GENERIC1 : std_logic :=\'0\'; -- Comment') - self.assertEqual(oFile.lines[22].line, ' G_generic2 : std_logic := \'1\' -- Comment')