Refactored rule architecture_002 for new parser.

1)  Removed rule architecture_002
   2)  Added rules:
         architecture_030
         architecture_031
         architecture_032
         architecture_033
   3)  Updated documentation
This commit is contained in:
Jeremiah Leary 2020-09-26 10:21:53 -05:00
parent c6851eb6d6
commit b0971f5501
29 changed files with 398 additions and 733 deletions

View File

@ -23,19 +23,12 @@ This rule checks for blank spaces before the **architecture** keyword.
architecture_002
################
This rule checks for a single space between **architecture**, **of**, and **is** keywords.
This rule has been split into the following rules:
**Violation**
.. code-block:: vhdl
architecture rtl of fifo is
**Fix**
.. code-block:: vhdl
architecture rtl of fifo is
* architecture_030
* architecture_031
* architecture_032
* architecture_033
architecture_003
################
@ -595,3 +588,71 @@ Refer to the section `Configuring Identifier Alignment Rules <configuring_declar
variable v_var1 : std_logic;
type t_myType : std_logic;
architecture_030
################
This rule checks for a single space between **architecture** and the identifier.
**Violation**
.. code-block:: vhdl
architecture rtl of fifo is
**Fix**
.. code-block:: vhdl
architecture rtl of fifo is
architecture_031
################
This rule checks for a single space between the identifier and the **of** keyword.
**Violation**
.. code-block:: vhdl
architecture rtl of fifo is
**Fix**
.. code-block:: vhdl
architecture rtl of fifo is
architecture_032
################
This rule checks for a single space between the **of** keyword and the entity_name.
**Violation**
.. code-block:: vhdl
architecture rtl of fifo is
**Fix**
.. code-block:: vhdl
architecture rtl of fifo is
architecture_033
################
This rule checks for a single space between the entity_name and the **is** keyword.
**Violation**
.. code-block:: vhdl
architecture rtl of fifo is
**Fix**
.. code-block:: vhdl
architecture rtl of fifo is

View File

@ -1,5 +1,5 @@
from .rule_001 import rule_001
from .rule_002 import rule_002
#from .rule_002 import rule_002 # This was split into rules 30 through 33
from .rule_003 import rule_003
from .rule_004 import rule_004
from .rule_005 import rule_005
@ -26,3 +26,7 @@ from .rule_026 import rule_026
from .rule_027 import rule_027
from .rule_028 import rule_028
from .rule_029 import rule_029
from .rule_030 import rule_030
from .rule_031 import rule_031
from .rule_032 import rule_032
from .rule_033 import rule_033

View File

@ -0,0 +1,12 @@
from vsg.rules import single_space_between_tokens
from vsg.token import architecture_body as token
class rule_030(single_space_between_tokens):
'''
Architecture rule 030 checks for a single space between the *architecture* keyword and the identifier.
'''
def __init__(self):
single_space_between_tokens.__init__(self, 'architecture', '030', token.architecture_keyword, token.identifier)
self.solution = 'Reduce spaces between architecture keyword and identifier to a single space.'

View File

@ -0,0 +1,12 @@
from vsg.rules import single_space_between_tokens
from vsg.token import architecture_body as token
class rule_031(single_space_between_tokens):
'''
Architecture rule 031 checks for a single space between the *architecture* keyword and the identifier.
'''
def __init__(self):
single_space_between_tokens.__init__(self, 'architecture', '031', token.identifier, token.of_keyword)
self.solution = 'Reduce spaces between identifier and *of* keyword to a single space.'

View File

@ -0,0 +1,12 @@
from vsg.rules import single_space_between_tokens
from vsg.token import architecture_body as token
class rule_032(single_space_between_tokens):
'''
Architecture rule 032 checks for a single space between the *of* keyword and the entity_name.
'''
def __init__(self):
single_space_between_tokens.__init__(self, 'architecture', '032', token.of_keyword, token.entity_name)
self.solution = 'Reduce spaces between *of* keyword and entity_name to a single space.'

View File

@ -0,0 +1,12 @@
from vsg.rules import single_space_between_tokens
from vsg.token import architecture_body as token
class rule_033(single_space_between_tokens):
'''
Architecture rule 033 checks for a single space between the entity_name and the *is* keyword.
'''
def __init__(self):
single_space_between_tokens.__init__(self, 'architecture', '033', token.entity_name, token.is_keyword)
self.solution = 'Reduce spaces between the entity_name and the *is* keyword to a single space.'

View File

@ -1,34 +0,0 @@
architecture RTL of ENTITY1 is
begin
end architecture RTL;
architecture RTL of ENTITY1 is
begin
end;
architecture RTL of ENTITY1 is
begin
end architecture;
architecture
RTL
of
ENTITY1
is
begin
end
architecture
RTL
;

View File

@ -1,12 +0,0 @@
architecture ARCH of ENTITY is
signal sig1 : std_logic; -- comment
signal sig1 : std_logic; -- comment
signal sig1 : std_logic; -- comment
signal sig1 : std_logic; -- comment
signal sig1 : std_logic; -- comment
begin
end architecture ARCH;

View File

@ -1,32 +0,0 @@
architecture RTL of FIFO is
component comp_a is
port (
end_signal : in std_logic;
endsignal : in std_logic
);
end component comp_a;
begin
endPort <= w_sig1;
end_port <= w_sig1;
u_compa : comp_a
port map (
end_signal => w_sig1,
ENDAT_DATA_RC => endat_DATA_RC,
endsignal => w_sig2
);
END_PROC : process () is
begin
end process END_PROC;
ENDPROC : process () is
begin
end process ENDPROC;
end architecture RTL;

View File

@ -1,23 +0,0 @@
architecture ARCH of ENTITY is
function FUNC1 return RESULT is
variable a : integer;
variable b : integer;
begin
for i in 0 to 32 loop
a(i) := 0;
end loop;
return a;
end FUNC1;
begin
end architecture ARCH;

View File

@ -1,17 +0,0 @@
architecture ARCH of ent1 is
begin
process begin
for i in 0 to 32 loop
end loop;
end process;
end architecture ARCH;

View File

@ -1,85 +0,0 @@
architecture Arch of ENTITY is
begin
End architecture ARCH;
architecture ARCH of EntITY is
begin
end Architecture;
architecture ARCH of ENTITY is
begin
end architecture ARCH;
Architecture ARch Of entity Is
begin
eND architecture ArCh;
architecture ARch
of ENTITY is
BEGIN
end archITecture ARCH;
architecture ARCH of ENTITY iS
begin
end architecture ARCH;
architecture ARCH of ENTITY is
begin
process () is
begin
end process;
end architecture ARCH;
architecture ARCH of ENTITY is
begin
process () is
begin
end process;
end ARCH;
-- Comment
architecture ARCH of ENTITY is
begin
GEN1 : if CONDITION = 1 generate
process () is
begin
end process;
end generate;
END_PROC : process () is
begin
end process END_PROC;
end_signal <= '0';
end;
-- Comment
architecture ARCH of ent is
begin
end architecture ARCH;

View File

@ -1,18 +0,0 @@
architecture ARCH of ENTITY1 is
signal sig1 : std_logic;
file fil1 : something;
-- Comment1
type typ1 is range 31 downto 0;
subtype sub1 is resolved std_ulogic;
-- Comment1
variable var1 : integer;
constant con1 : integer := 0;
attribute att1 : some_attr;
begin
end architecture ARCH;

View File

@ -0,0 +1,11 @@
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;

View File

@ -0,0 +1,11 @@
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;

View File

@ -0,0 +1,11 @@
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;

View File

@ -0,0 +1,11 @@
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;

View File

@ -0,0 +1,11 @@
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;

View File

@ -0,0 +1,11 @@
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;

View File

@ -0,0 +1,11 @@
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;

View File

@ -0,0 +1,11 @@
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;
architecture rtl of fifo is begin end architecture rtl;

View File

@ -1,204 +0,0 @@
import os
import unittest
from vsg.rules import architecture
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__),'architecture_test_input.vhd'))
class testFixRuleArchitectureMethods(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
def test_fix_rule_001(self):
oRule = architecture.rule_001()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_002(self):
oRule = architecture.rule_002()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_003(self):
oRule = architecture.rule_003()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_004_lowercase(self):
oRule = architecture.rule_004()
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[20].line, ' architecture ARch Of entity Is')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_004_uppercase(self):
oRule = architecture.rule_004()
oRule.case = 'upper'
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[20].line, ' ARCHITECTURE ARch Of entity Is')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_007(self):
oRule = architecture.rule_007()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_008(self):
oRule = architecture.rule_008()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_009(self):
oRule = architecture.rule_009()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_012(self):
oRule = architecture.rule_012()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_014_uppercase(self):
oRule = architecture.rule_014()
oRule.case = 'upper'
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[81].line, 'architecture ARCH of ENT is')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_014_lowercase(self):
oRule = architecture.rule_014()
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[59].line, 'architecture ARCH of entity is')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_016(self):
oRule = architecture.rule_016()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_017(self):
oRule = architecture.rule_017()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_018(self):
oRule = architecture.rule_018()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_019_lowercase(self):
oRule = architecture.rule_019()
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[20].line, ' Architecture ARch of entity Is')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_019_uppercase(self):
oRule = architecture.rule_019()
oRule.case = 'upper'
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[20].line, ' Architecture ARch OF entity Is')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_020_lowercase(self):
oRule = architecture.rule_020()
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[20].line, ' Architecture ARch Of entity is')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_020_uppercase(self):
oRule = architecture.rule_020()
oRule.case = 'upper'
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[20].line, ' Architecture ARch Of entity IS')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_021_lowercase(self):
oRule = architecture.rule_021()
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[29].line, 'begin')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_021_uppercase(self):
oRule = architecture.rule_021()
oRule.case = 'upper'
dExpected = []
oRule.fix(self.oFile)
self.assertEqual(self.oFile.lines[39].line, 'BEGIN')
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_022(self):
oRule = architecture.rule_022()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_024(self):
oRule = architecture.rule_024()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(self.oFile.lines[13].line, 'end Architecture ARCH;')
self.assertEqual(self.oFile.lines[77].line, 'end ARCH;')
self.assertEqual(oRule.violations, dExpected)
def test_fix_rule_027(self):
oRule = architecture.rule_027()
dExpected = []
oRule.fix(self.oFile)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, dExpected)

View File

@ -0,0 +1,46 @@
import os
import unittest
from vsg.rules import architecture
from vsg import vhdlFile
from vsg.tests import utils
sTestDir = os.path.dirname(__file__)
lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_030_test_input.vhd'))
lExpected = []
lExpected.append('')
utils.read_file(os.path.join(sTestDir, 'rule_030_test_input.fixed.vhd'), lExpected)
class test_architecture_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
def test_rule_030(self):
oRule = architecture.rule_030()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'architecture')
self.assertEqual(oRule.identifier, '030')
lExpected = [4]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_fix_rule_030(self):
oRule = architecture.rule_030()
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,46 @@
import os
import unittest
from vsg.rules import architecture
from vsg import vhdlFile
from vsg.tests import utils
sTestDir = os.path.dirname(__file__)
lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_031_test_input.vhd'))
lExpected = []
lExpected.append('')
utils.read_file(os.path.join(sTestDir, 'rule_031_test_input.fixed.vhd'), lExpected)
class test_architecture_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
def test_rule_031(self):
oRule = architecture.rule_031()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'architecture')
self.assertEqual(oRule.identifier, '031')
lExpected = [6]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_fix_rule_031(self):
oRule = architecture.rule_031()
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,46 @@
import os
import unittest
from vsg.rules import architecture
from vsg import vhdlFile
from vsg.tests import utils
sTestDir = os.path.dirname(__file__)
lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_032_test_input.vhd'))
lExpected = []
lExpected.append('')
utils.read_file(os.path.join(sTestDir, 'rule_032_test_input.fixed.vhd'), lExpected)
class test_architecture_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
def test_rule_032(self):
oRule = architecture.rule_032()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'architecture')
self.assertEqual(oRule.identifier, '032')
lExpected = [8]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_fix_rule_032(self):
oRule = architecture.rule_032()
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,46 @@
import os
import unittest
from vsg.rules import architecture
from vsg import vhdlFile
from vsg.tests import utils
sTestDir = os.path.dirname(__file__)
lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_033_test_input.vhd'))
lExpected = []
lExpected.append('')
utils.read_file(os.path.join(sTestDir, 'rule_033_test_input.fixed.vhd'), lExpected)
class test_architecture_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
def test_rule_033(self):
oRule = architecture.rule_033()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'architecture')
self.assertEqual(oRule.identifier, '033')
lExpected = [10]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_fix_rule_033(self):
oRule = architecture.rule_033()
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

@ -1,36 +0,0 @@
import os
import unittest
from vsg.rules import architecture
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__),'..','architecture','architecture_test_input.vhd'))
oFile = vhdlFile.vhdlFile(lFile)
lFileComment = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','architecture','architecture_comment_test_input.vhd'))
oFileComment = vhdlFile.vhdlFile(lFileComment)
class testRuleArchitectureMethods(unittest.TestCase):
def test_rule_002_exists(self):
oRule = architecture.rule_002()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'architecture')
self.assertEqual(oRule.identifier, '002')
def test_rule_002(self):
oRule = architecture.rule_002()
dExpected = [utils.add_violation(14)]
oRule.analyze(oFile)
self.assertEqual(oRule.violations, dExpected)
def test_rule_003_exists(self):
oRule = architecture.rule_003()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'architecture')
self.assertEqual(oRule.identifier, '003')

View File

@ -18,8 +18,6 @@ lFileEntity = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','e
oFileEntity = vhdlFile.vhdlFile(lFileEntity)
lFileConcurrent = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','concurrent','concurrent_test_input.vhd'))
oFileConcurrent = vhdlFile.vhdlFile(lFileConcurrent)
lFileArchitectureLoop = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','architecture','architecture_loop_test_input.vhd'))
oFileArchitectureLoop = vhdlFile.vhdlFile(lFileArchitectureLoop)
lFileArchitectureFunctionLoop = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','architecture','architecture_loop_in_function_test_input.vhd'))
oFileArchitectureFunctionLoop = vhdlFile.vhdlFile(lFileArchitectureFunctionLoop)
lFileFunction = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','function','function_test_input.vhd'))
@ -212,26 +210,6 @@ class testVhdlFileMethods(unittest.TestCase):
# Compare
self.assertEqual(lActual, lExpected)
def test_isEndArchitecture_assignment_with_loop(self):
lExpected = [15]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFileArchitectureLoop.lines):
if oLine.isEndArchitecture:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_isEndArchitecture_assignment_with_loop_inside_function(self):
lExpected = [21]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFileArchitectureFunctionLoop.lines):
if oLine.isEndArchitecture:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_isEndArchitecture_function_assignment(self):
lExpected = [122, 153]
# Generic actual list

View File

@ -1,237 +0,0 @@
import os
import unittest
from vsg import vhdlFile
from vsg.tests import utils
from vsg.token import architecture_body
lFileArchitecture = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','architecture','architecture_test_input.vhd'))
oFileArchitecture = vhdlFile.vhdlFile(lFileArchitecture)
lFileArch2 = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','architecture','rule_029_test_input.vhd'))
oFileArch2 = vhdlFile.vhdlFile(lFileArch2)
lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','architecture','architecture_classification_test_input.vhd'))
oFile = vhdlFile.vhdlFile(lFile)
class testVhdlFileMethods(unittest.TestCase):
def test_insideArchitecture_assignment(self):
lExpected = [3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,20,21,22,23,24,26,27,28,29,30,31,33,34,35,37,38,39,40,41,42,43,44,45,47,48,49,50,51,52,53,54,55,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,81,82,83,84,85]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFileArchitecture.lines):
if oLine.insideArchitecture:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_isArchitectureBegin_assignment(self):
lExpected = [5,11,16,22,29,34,39,49,61,83]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFileArchitecture.lines):
if oLine.isArchitectureBegin:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_isArchitectureKeyword_assignment(self):
lExpected = [3,9,14,20,26,33,37,47,59,81]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFileArchitecture.lines):
if oLine.isArchitectureKeyword:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_isEndArchitecture_assignment(self):
lExpected = [7,13,18,24,31,35,45,55,77,85]
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFileArchitecture.lines):
if oLine.isEndArchitecture:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_insideArchitectureDeclarativeRegion(self):
lExpected = []
lExpected.extend(range(3,6))
lExpected.extend(range(9,12))
lExpected.extend(range(14,17))
lExpected.extend(range(20,23))
lExpected.extend(range(26,30))
lExpected.extend(range(33,35))
lExpected.extend(range(37,40))
lExpected.extend(range(47,50))
lExpected.extend(range(59,62))
lExpected.extend(range(81,84))
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFileArchitecture.lines):
if oLine.insideArchitectureDeclarativeRegion:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_insideArchitectureDeclarativeRegion_2(self):
lExpected = []
lExpected.extend(range(2,59))
lExpected.extend(range(64,120))
# Generic actual list
lActual = []
for iIndex, oLine in enumerate(oFileArch2.lines):
if oLine.insideArchitectureDeclarativeRegion:
lActual.append(iIndex)
# Compare
self.assertEqual(lActual, lExpected)
def test_architecture_keyword(self):
lExpected = []
lExpected.append((3,0))
lExpected.append((11,0))
lExpected.append((18,0))
lExpected.append((25,0))
# utils.print_objects(oFile, True)
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.architecture_keyword):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)
def test_architecture_semicolon(self):
lExpected = []
lExpected.append((7,5))
lExpected.append((15,1))
lExpected.append((22,3))
lExpected.append((34,0))
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.semicolon):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)
def test_architecture_end_keyword(self):
lExpected = []
lExpected.append((7,0))
lExpected.append((15,0))
lExpected.append((22,0))
lExpected.append((31,0))
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.end_keyword):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)
def test_architecture_end_architecture_keyword(self):
lExpected = []
lExpected.append((7,2))
lExpected.append((22,2))
lExpected.append((32,0))
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.end_architecture_keyword):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)
def test_architecture_simple_name(self):
lExpected = []
lExpected.append((7,4))
lExpected.append((33,0))
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.architecture_simple_name):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)
def test_architecture_identifier(self):
lExpected = []
lExpected.append((3,2))
lExpected.append((11,2))
lExpected.append((18,2))
lExpected.append((26,0))
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.identifier):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)
def test_architecture_of_keyword(self):
lExpected = []
lExpected.append((3,4))
lExpected.append((11,4))
lExpected.append((18,4))
lExpected.append((27,0))
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.of_keyword):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)
def test_architecture_entity_name(self):
lExpected = []
lExpected.append((3,6))
lExpected.append((11,6))
lExpected.append((18,6))
lExpected.append((28,0))
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.entity_name):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)
def test_architecture_is_keyword(self):
lExpected = []
lExpected.append((3,8))
lExpected.append((11,8))
lExpected.append((18,8))
lExpected.append((29,0))
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.is_keyword):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)
def test_architecture_begin_keyword(self):
lExpected = []
lExpected.append((5,0))
lExpected.append((13,0))
lExpected.append((20,0))
lExpected.append((30,0))
lActual = []
for iLine, lLine in enumerate(oFile.get_lines()):
for iItem, oItem in enumerate(lLine.objects):
if isinstance(oItem, architecture_body.begin_keyword):
lActual.append((iLine, iItem))
self.assertEqual(lExpected, lActual)