Updates for issue #393:

Adding two new library rules:

  1)  Added rules library_010 and library_011
  2)  Added tests
  3)  Added documentation
This commit is contained in:
Jeremiah Leary 2020-07-26 14:48:02 -05:00
parent abe3cb3418
commit ba5ae10b8e
13 changed files with 225 additions and 4 deletions

View File

@ -191,3 +191,38 @@ This rule checks alignment of comments above library use statements.
-- Use standard logic library
use ieee.std_logic_1164.all;
library_010
###########
This rule checks the **library** keyword is on it's own line.
**Violation**
.. code-block:: vhdl
context c1 is library ieee; use ieee.std_logic_1164.all; end context c1;
**Fix**
.. code-block:: vhdl
context c1 is
library ieee; use ieee.std_logic_1164.all; end context c1;
library_011
###########
This rule checks the **use** keyword is on it's own line.
**Violation**
.. code-block:: vhdl
context c1 is library ieee; use ieee.std_logic_1164.all; end context c1;
**Fix**
.. code-block:: vhdl
context c1 is library ieee;
use ieee.std_logic_1164.all; end context c1;

View File

@ -8,3 +8,5 @@ from .rule_006 import rule_006
from .rule_007 import rule_007
from .rule_008 import rule_008
from .rule_009 import rule_009
from .rule_010 import rule_010
from .rule_011 import rule_011

View File

@ -0,0 +1,15 @@
from vsg import parser
from vsg.rules import move_item_and_items_to_the_right_to_next_line_rule
class rule_010(move_item_and_items_to_the_right_to_next_line_rule):
'''
Moves library keyword and code to the right to it's own line.
'''
def __init__(self):
move_item_and_items_to_the_right_to_next_line_rule.__init__(self, 'library', '010', parser.library_keyword)
self.regionBegin = parser.library_keyword
self.regionEnd = parser.library_semicolon

View File

@ -0,0 +1,15 @@
from vsg import parser
from vsg.rules import move_item_and_items_to_the_right_to_next_line_rule
class rule_011(move_item_and_items_to_the_right_to_next_line_rule):
'''
Moves use keyword and code to the right to it's own line.
'''
def __init__(self):
move_item_and_items_to_the_right_to_next_line_rule.__init__(self, 'library', '011', parser.use_keyword)
self.regionBegin = parser.use_keyword
self.regionEnd = parser.use_semicolon

View File

@ -33,19 +33,22 @@ end context c1;
-- Try single line
context c1 is
library ieee; use ieee.std_logic_1164;
library ieee;
use ieee.std_logic_1164;
end context c1;
context c1 is
library ieee; use ieee.std_logic_1164;
library ieee;
use ieee.std_logic_1164;
end context c1;
context c1 is
library ieee; use ieee.std_logic_1164;
library ieee;
use ieee.std_logic_1164;
end context c1;

View File

@ -37,7 +37,8 @@ end context c1;
-- Try single line
context c1 is
library ieee; use ieee.std_logic_1164;
library ieee;
use ieee.std_logic_1164;
context cr1,cr2;
end context c1;

View File

@ -0,0 +1,13 @@
-- This should pass
library ieee;
use ieee.std_logic_1164.all;
--- this should fail
library ieee; use ieee.std_logic_1164;
library analog; use analog.all;
library digital; use digital.gates.and;
library ieee; use ieee.std_logic_1164;
library
analog; use analog.all;

View File

@ -0,0 +1,10 @@
-- This should pass
library ieee;
use ieee.std_logic_1164.all;
--- this should fail
library ieee; use ieee.std_logic_1164; library analog; use analog.all; library digital; use digital.gates.and;
library ieee; use ieee.std_logic_1164; library
analog; use analog.all;

View File

@ -0,0 +1,17 @@
-- This should pass
library ieee;
use ieee.std_logic_1164.all;
--- this should fail
library ieee;
use ieee.std_logic_1164; library analog;
use analog.all; library digital;
use digital.gates.and;
library ieee;
use ieee.std_logic_1164; library analog;
use
analog.all;
use
analog.all;

View File

@ -0,0 +1,11 @@
-- This should pass
library ieee;
use ieee.std_logic_1164.all;
--- this should fail
library ieee; use ieee.std_logic_1164; library analog; use analog.all; library digital; use digital.gates.and;
library ieee; use ieee.std_logic_1164; library analog; use
analog.all; use
analog.all;

View File

@ -0,0 +1,47 @@
import os
import unittest
from vsg.rules import library
from vsg import vhdlFile
from vsg.tests import utils
sTestDir = os.path.dirname(__file__)
lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_010_test_input.vhd'))
lExpected = []
lExpected.append('')
utils.read_file(os.path.join(sTestDir, 'rule_010_test_input.fixed.vhd'), lExpected, False)
class test_library_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
def test_rule_010(self):
oRule = library.rule_010()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'library')
self.assertEqual(oRule.identifier, '010')
lExpected = [7, 7, 9]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines(oRule.violations))
def test_fix_rule_010(self):
self.maxDiff = None
oRule = library.rule_010()
oRule.fix(self.oFile)
lActual = []
for oLine in self.oFile.lines:
lActual.append(oLine.line)
self.assertEqual(lExpected, lActual)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, [])

View File

@ -0,0 +1,47 @@
import os
import unittest
from vsg.rules import library
from vsg import vhdlFile
from vsg.tests import utils
sTestDir = os.path.dirname(__file__)
lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_011_test_input.vhd'))
lExpected = []
lExpected.append('')
utils.read_file(os.path.join(sTestDir, 'rule_011_test_input.fixed.vhd'), lExpected, False)
class test_library_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
def test_rule_011(self):
oRule = library.rule_011()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'library')
self.assertEqual(oRule.identifier, '011')
lExpected = [7, 7, 7, 9, 9, 10]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines(oRule.violations))
def test_fix_rule_011(self):
self.maxDiff = None
oRule = library.rule_011()
oRule.fix(self.oFile)
lActual = []
for oLine in self.oFile.lines:
lActual.append(oLine.line)
self.assertEqual(lExpected, lActual)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, [])

View File

@ -68,3 +68,8 @@ def read_configuration(sFileName):
with open(sFileName) as yaml_file:
return yaml.full_load(yaml_file)
def extract_violation_lines(lViolations):
lReturn = []
for dViolation in lViolations:
lReturn.append(dViolation['lines'][0]['number'])
return lReturn