From 3bc4bce49af858a1d4a3a4feaef7e7ddd4271f1d Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Mon, 19 Oct 2020 17:51:17 -0500 Subject: [PATCH] Refactoring with rules for new parser. --- vsg/rules/with_statement/rule_001.py | 41 ++++++++++++++----- vsg/tests/vhdlFile/test_vhdlFile_with.py | 20 --------- ...test_input.vhd => rule_001_test_input.vhd} | 0 vsg/tests/with_statement/test_rule_001.py | 29 +++++++++++++ vsg/tests/with_statement/test_rule_with.py | 24 ----------- 5 files changed, 60 insertions(+), 54 deletions(-) delete mode 100644 vsg/tests/vhdlFile/test_vhdlFile_with.py rename vsg/tests/with_statement/{with_test_input.vhd => rule_001_test_input.vhd} (100%) create mode 100644 vsg/tests/with_statement/test_rule_001.py delete mode 100644 vsg/tests/with_statement/test_rule_with.py diff --git a/vsg/rules/with_statement/rule_001.py b/vsg/rules/with_statement/rule_001.py index c59712e4..20ec0dc2 100644 --- a/vsg/rules/with_statement/rule_001.py +++ b/vsg/rules/with_statement/rule_001.py @@ -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 diff --git a/vsg/tests/vhdlFile/test_vhdlFile_with.py b/vsg/tests/vhdlFile/test_vhdlFile_with.py deleted file mode 100644 index 43198ec4..00000000 --- a/vsg/tests/vhdlFile/test_vhdlFile_with.py +++ /dev/null @@ -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) diff --git a/vsg/tests/with_statement/with_test_input.vhd b/vsg/tests/with_statement/rule_001_test_input.vhd similarity index 100% rename from vsg/tests/with_statement/with_test_input.vhd rename to vsg/tests/with_statement/rule_001_test_input.vhd diff --git a/vsg/tests/with_statement/test_rule_001.py b/vsg/tests/with_statement/test_rule_001.py new file mode 100644 index 00000000..1ad97f4c --- /dev/null +++ b/vsg/tests/with_statement/test_rule_001.py @@ -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)) diff --git a/vsg/tests/with_statement/test_rule_with.py b/vsg/tests/with_statement/test_rule_with.py deleted file mode 100644 index 3d858c8e..00000000 --- a/vsg/tests/with_statement/test_rule_with.py +++ /dev/null @@ -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)