Refactoring with rules for new parser.
This commit is contained in:
parent
9b36872f42
commit
3bc4bce49a
|
|
@ -1,19 +1,40 @@
|
|||
|
||||
from vsg import rule
|
||||
from vsg import utils
|
||||
from vsg import rule_item
|
||||
from vsg import token
|
||||
from vsg import violation
|
||||
|
||||
|
||||
class rule_001(rule.rule):
|
||||
class rule_001(rule_item.Rule):
|
||||
'''
|
||||
With rule 001 checks for "with" statements.
|
||||
Checks the case for words.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
name : string
|
||||
The group the rule belongs to.
|
||||
|
||||
identifier : string
|
||||
unique identifier. Usually in the form of 00N.
|
||||
|
||||
trigger : parser object type
|
||||
object type to apply the case check against
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
rule.rule.__init__(self, 'with', '001')
|
||||
self.fixable = False
|
||||
rule_item.Rule.__init__(self, name='with', identifier='001')
|
||||
self.solution = "Rewrite with as a process"
|
||||
self.phase = 1
|
||||
self.fixable = False
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isWithKeyword:
|
||||
dViolation = utils.create_violation_dict(iLineNumber)
|
||||
self.add_violation(dViolation)
|
||||
def analyze(self, oFile):
|
||||
lToi = oFile.get_tokens_matching([token.concurrent_selected_signal_assignment.with_keyword])
|
||||
for oToi in lToi:
|
||||
self.add_violation(violation.New(oToi.get_line_number(), oToi, self.solution))
|
||||
|
||||
|
||||
def fix(self, oFile):
|
||||
'''
|
||||
Applies fixes for any rule violations.
|
||||
'''
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
import os
|
||||
|
||||
import unittest
|
||||
from vsg import vhdlFile
|
||||
from vsg.tests import utils
|
||||
|
||||
lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','with_statement','with_test_input.vhd'))
|
||||
oFile = vhdlFile.vhdlFile(lFile)
|
||||
|
||||
class testVhdlFileMethods(unittest.TestCase):
|
||||
|
||||
def test_isWithKeyword_assignment(self):
|
||||
lExpected = [6]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
if oLine.isWithKeyword:
|
||||
lActual.append(iIndex)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from vsg import vhdlFile
|
||||
|
||||
from vsg.rules import with_statement
|
||||
from vsg.tests import utils
|
||||
|
||||
sTestDir = os.path.dirname(__file__)
|
||||
|
||||
lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_001_test_input.vhd'))
|
||||
|
||||
|
||||
class test_with_statement_rule(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.oFile = vhdlFile.vhdlFile(lFile)
|
||||
|
||||
def test_rule_001(self):
|
||||
oRule = with_statement.rule_001()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'with')
|
||||
self.assertEqual(oRule.identifier, '001')
|
||||
|
||||
lExpected = [6]
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
import os
|
||||
|
||||
import unittest
|
||||
|
||||
from vsg.rules import with_statement
|
||||
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__),'with_test_input.vhd'))
|
||||
oFile = vhdlFile.vhdlFile(lFile)
|
||||
|
||||
class testRuleWithMethods(unittest.TestCase):
|
||||
|
||||
def test_rule_001(self):
|
||||
oRule = with_statement.rule_001()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'with')
|
||||
self.assertEqual(oRule.identifier, '001')
|
||||
|
||||
dExpected = [utils.add_violation(6)]
|
||||
oRule.analyze(oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
Loading…
Reference in New Issue