Updates for issue #491:
Adding allow_library_clause option to rule library_003 to allow consecutive library clauses. 1) Added tests 2) Added option allow_library_clause to rule library_003 3) Updated documentation
This commit is contained in:
parent
e80c16da15
commit
eb31465fb5
|
|
@ -46,11 +46,21 @@ This rule checks for a blank line above the **library** keyword.
|
|||
|
||||
Refer to the section `Configuring Blank Lines <configuring_blank_lines.html>`_ for options regarding comments.
|
||||
|
||||
There is an additional **allow_library_clause** option which can be set.
|
||||
Refer to section `Reporting Single Rule Configuration <configuring.html>`_ for details on finding configuration options for individual rules.
|
||||
|
||||
allow_library_clause
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
When set to **True**, it allows consecutive library clauses.
|
||||
|
||||
**Violation**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
library top_dsn;
|
||||
library fifo_dsn;
|
||||
|
||||
**Fix**
|
||||
|
|
@ -58,7 +68,9 @@ Refer to the section `Configuring Blank Lines <configuring_blank_lines.html>`_ f
|
|||
.. code-block:: vhdl
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
|
||||
library top_dsn;
|
||||
library fifo_dsn;
|
||||
|
||||
library_004
|
||||
|
|
|
|||
|
|
@ -37,7 +37,11 @@ class blank_line_above_line_starting_with_token(rule.Rule):
|
|||
else:
|
||||
return oFile.get_line_above_line_starting_with_token_with_hierarchy(self.lTokens, self.lHierarchyLimits)
|
||||
|
||||
def _set_allow_tokens(self):
|
||||
return
|
||||
|
||||
def _analyze(self, lToi):
|
||||
self._set_allow_tokens()
|
||||
for oToi in lToi:
|
||||
lTokens = oToi.get_tokens()
|
||||
bSkip = False
|
||||
|
|
|
|||
|
|
@ -14,3 +14,10 @@ class rule_003(blank_line_above_line_starting_with_token):
|
|||
|
||||
def __init__(self):
|
||||
blank_line_above_line_starting_with_token.__init__(self, 'library', '003', lTokens)
|
||||
self.allow_library_clause = False
|
||||
self.configuration.append('allow_library_clause')
|
||||
|
||||
def _set_allow_tokens(self):
|
||||
if self.allow_library_clause:
|
||||
self.lAllowTokens = []
|
||||
self.lAllowTokens.append(token.library_clause.keyword)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
library ieee;
|
||||
library ieee;
|
||||
-- Some comment
|
||||
|
||||
library ieee;
|
||||
library ieee;
|
||||
library ieee;
|
||||
|
||||
|
|
@ -10,9 +10,13 @@ sTestDir = os.path.dirname(__file__)
|
|||
|
||||
lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_003_test_input.vhd'))
|
||||
|
||||
lExpected = []
|
||||
lExpected.append('')
|
||||
utils.read_file(os.path.join(sTestDir, 'rule_003_test_input.fixed.vhd'), lExpected)
|
||||
lExpected_default = []
|
||||
lExpected_default.append('')
|
||||
utils.read_file(os.path.join(sTestDir, 'rule_003_test_input.fixed_default.vhd'), lExpected_default)
|
||||
|
||||
lExpected_allow_library_clause = []
|
||||
lExpected_allow_library_clause.append('')
|
||||
utils.read_file(os.path.join(sTestDir, 'rule_003_test_input.fixed_allow_library_clause.vhd'), lExpected_allow_library_clause)
|
||||
|
||||
|
||||
class test_library_rule(unittest.TestCase):
|
||||
|
|
@ -23,6 +27,7 @@ class test_library_rule(unittest.TestCase):
|
|||
def test_rule_003(self):
|
||||
oRule = library.rule_003()
|
||||
oRule.allow_comments = True
|
||||
oRule.allow_library_clause = False
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'library')
|
||||
self.assertEqual(oRule.identifier, '003')
|
||||
|
|
@ -35,12 +40,37 @@ class test_library_rule(unittest.TestCase):
|
|||
def test_fix_rule_003(self):
|
||||
oRule = library.rule_003()
|
||||
oRule.allow_comments = True
|
||||
oRule.allow_library_clause = False
|
||||
|
||||
oRule.fix(self.oFile)
|
||||
|
||||
lActual = self.oFile.get_lines()
|
||||
|
||||
self.assertEqual(lExpected, lActual)
|
||||
self.assertEqual(lExpected_default, lActual)
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, [])
|
||||
|
||||
def test_rule_003_w_allow_library_clause(self):
|
||||
oRule = library.rule_003()
|
||||
oRule.allow_comments = False
|
||||
oRule.allow_library_clause = True
|
||||
|
||||
lExpected = [5]
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
||||
|
||||
def test_fix_rule_003_w_allow_library_clause(self):
|
||||
oRule = library.rule_003()
|
||||
oRule.allow_comments = False
|
||||
oRule.allow_library_clause = True
|
||||
|
||||
oRule.fix(self.oFile)
|
||||
|
||||
lActual = self.oFile.get_lines()
|
||||
|
||||
self.assertEqual(lExpected_allow_library_clause, lActual)
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, [])
|
||||
|
|
|
|||
Loading…
Reference in New Issue