Updates for issue #252:

Fixed a bug where comment_004 was being flagged after rule concurrent_007 was applied.
Rule concurrent_007 was not handling the comment attributes of the line being split.
It was also not handling the concurrent attributes correctly.

 1)  Updated tests
 2)  Updated rule concurrent_007
This commit is contained in:
Jeremiah C Leary 2019-09-20 06:55:38 -05:00
parent 089470d787
commit 92cd35d427
3 changed files with 55 additions and 19 deletions

View File

@ -1,5 +1,6 @@
from vsg import rule
from vsg import utils
import re
import copy
@ -26,8 +27,15 @@ class rule_007(rule.rule):
oLine = oFile.lines[iLineNumber]
iIndex = oLine.line.find(' else') + len(' else')
oFile.lines.insert(iLineNumber + 1, copy.deepcopy(oLine))
utils.remove_comment_attributes_from_line(oLine)
oLine.isEndConcurrent = False
oLine.update_line(oLine.line[:iIndex])
oLine = oFile.lines[iLineNumber + 1]
oLine.isConcurrentBegin = False
oLine.update_line(oLine.line[iIndex:])
oLine.isEndConcurrent = True
sLine = oLine.line[iIndex:]
try:
oLine.commentColumn = sLine.index('--')
except ValueError:
oLine.commentColumn = None
oLine.update_line(sLine)

View File

@ -7,63 +7,77 @@ from vsg.tests import utils
# Read in test file used for all tests
lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','concurrent','concurrent_test_input.vhd'))
oFile = vhdlFile.vhdlFile(lFile)
class testFixRuleConcurrentMethods(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
def test_fix_rule_001(self):
oRule = concurrent.rule_001()
dExpected = []
oRule.fix(oFile)
oRule.analyze(oFile)
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_002(self):
oRule = concurrent.rule_002()
dExpected = []
oRule.fix(oFile)
oRule.analyze(oFile)
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_003(self):
oRule = concurrent.rule_003()
dExpected = []
oRule.fix(oFile)
oRule.analyze(oFile)
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_004(self):
oRule = concurrent.rule_004()
dExpected = []
oRule.fix(oFile)
oRule.analyze(oFile)
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_005(self):
oRule = concurrent.rule_005()
dExpected = []
oRule.fix(oFile)
oRule.analyze(oFile)
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_006(self):
oRule = concurrent.rule_006()
dExpected = []
oRule.fix(oFile)
oRule.analyze(oFile)
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_007(self):
oRule = concurrent.rule_007()
dExpected = []
oRule.fix(oFile)
oRule.analyze(oFile)
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
self.assertEqual(oFile.lines[34].line, ' a <= b; -- this else should not trigger')
self.assertEqual(self.oFile.lines[34].line, ' label : a <= b; -- this else should not trigger')
self.assertEqual(self.oFile.lines[49].line, ' a <= b when g = \'1\' else')
self.assertFalse(self.oFile.lines[49].hasComment)
self.assertFalse(self.oFile.lines[49].hasInlineComment)
self.assertEqual(self.oFile.lines[49].commentColumn, None)
self.assertFalse(self.oFile.lines[49].isEndConcurrent)
self.assertTrue(self.oFile.lines[49].isConcurrentBegin)
self.assertEqual(self.oFile.lines[50].line, ' \'1\'; -- Not an error')
self.assertTrue(self.oFile.lines[50].hasComment)
self.assertTrue(self.oFile.lines[50].hasInlineComment)
self.assertEqual(self.oFile.lines[50].commentColumn, 6)
self.assertTrue(self.oFile.lines[50].isEndConcurrent)
self.assertFalse(self.oFile.lines[50].isConcurrentBegin)
def test_fix_rule_008(self):
oRule = concurrent.rule_007()
dExpected = []
oRule.fix(oFile)
oRule.analyze(oFile)
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)

View File

@ -582,3 +582,17 @@ def extract_variable_name(oLine):
'''
sLine = oLine.line.split(':')[0]
return sLine.split()[1]
def remove_comment_attributes_from_line(oLine):
'''
Sets all comment attributes on a line to indicate no comment is present.
Parameters:
oLine: (line object)
'''
oLine.isComment = False
oLine.hasComment = False
oLine.hasInlineComment = False
oLine.commentColumn = None