From cc678cb21fdff2d547d12f96a9a7744cc43dffe6 Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Sun, 19 Jan 2025 23:18:53 +0000 Subject: [PATCH] Issue#1383: Added case rules for file declarations (#1396) * Issue#1383: Added case rules for file declarations. * Issue#1383: Added tests for case rules for file declarations. * Issue#1383: Added documentation for case rules for file declarations. * Issue#1383: Added case rules for file type declarations. * Issue#1383: Added tests for case rules for file type declarations. * Issue#1383: Added documentation for case rules for file type declarations. * Issue#1383: Corrected "file type declaration" to "file type definition". --- ...figuring_uppercase_and_lowercase_rules.rst | 8 ++ docs/file_open_information_rules.rst | 91 +++++++++++++++++++ docs/file_rules.rst | 29 ++++++ docs/file_type_definition_rules.rst | 56 ++++++++++++ docs/rule_groups/case_keyword_rule_group.rst | 5 + docs/rule_groups/case_name_rule_group.rst | 1 + docs/rule_groups/case_rule_group.rst | 6 ++ docs/rules.rst | 2 + tests/file_open_information/__init__.py | 0 .../rule_500_test_input.fixed_lower.vhd | 12 +++ .../rule_500_test_input.fixed_upper.vhd | 12 +++ .../rule_500_test_input.vhd | 12 +++ .../rule_501_test_input.fixed_lower.vhd | 18 ++++ .../rule_501_test_input.fixed_upper.vhd | 18 ++++ .../rule_501_test_input.vhd | 18 ++++ .../rule_502_test_input.fixed_lower.vhd | 12 +++ .../rule_502_test_input.fixed_upper.vhd | 12 +++ .../rule_502_test_input.vhd | 12 +++ tests/file_open_information/test_rule_500.py | 73 +++++++++++++++ tests/file_open_information/test_rule_501.py | 73 +++++++++++++++ tests/file_open_information/test_rule_502.py | 73 +++++++++++++++ .../rule_500_test_input.fixed_lower.vhd | 12 +++ .../rule_500_test_input.fixed_upper.vhd | 12 +++ tests/file_statement/rule_500_test_input.vhd | 12 +++ tests/file_statement/test_rule_500.py | 73 +++++++++++++++ tests/file_type_definition/__init__.py | 0 .../rule_500_test_input.fixed_lower.vhd | 12 +++ .../rule_500_test_input.fixed_upper.vhd | 12 +++ .../rule_500_test_input.vhd | 12 +++ .../rule_501_test_input.fixed_lower.vhd | 12 +++ .../rule_501_test_input.fixed_upper.vhd | 12 +++ .../rule_501_test_input.vhd | 12 +++ tests/file_type_definition/test_rule_500.py | 73 +++++++++++++++ tests/file_type_definition/test_rule_501.py | 73 +++++++++++++++ vsg/rules/__init__.py | 2 + vsg/rules/file_open_information/__init__.py | 5 + vsg/rules/file_open_information/rule_500.py | 39 ++++++++ vsg/rules/file_open_information/rule_501.py | 39 ++++++++ vsg/rules/file_open_information/rule_502.py | 39 ++++++++ vsg/rules/file_statement/__init__.py | 1 + vsg/rules/file_statement/rule_500.py | 39 ++++++++ vsg/rules/file_type_definition/__init__.py | 4 + vsg/rules/file_type_definition/rule_500.py | 36 ++++++++ vsg/rules/file_type_definition/rule_501.py | 36 ++++++++ 44 files changed, 1110 insertions(+) create mode 100644 docs/file_open_information_rules.rst create mode 100644 docs/file_type_definition_rules.rst create mode 100644 tests/file_open_information/__init__.py create mode 100644 tests/file_open_information/rule_500_test_input.fixed_lower.vhd create mode 100644 tests/file_open_information/rule_500_test_input.fixed_upper.vhd create mode 100644 tests/file_open_information/rule_500_test_input.vhd create mode 100644 tests/file_open_information/rule_501_test_input.fixed_lower.vhd create mode 100644 tests/file_open_information/rule_501_test_input.fixed_upper.vhd create mode 100644 tests/file_open_information/rule_501_test_input.vhd create mode 100644 tests/file_open_information/rule_502_test_input.fixed_lower.vhd create mode 100644 tests/file_open_information/rule_502_test_input.fixed_upper.vhd create mode 100644 tests/file_open_information/rule_502_test_input.vhd create mode 100644 tests/file_open_information/test_rule_500.py create mode 100644 tests/file_open_information/test_rule_501.py create mode 100644 tests/file_open_information/test_rule_502.py create mode 100644 tests/file_statement/rule_500_test_input.fixed_lower.vhd create mode 100644 tests/file_statement/rule_500_test_input.fixed_upper.vhd create mode 100644 tests/file_statement/rule_500_test_input.vhd create mode 100644 tests/file_statement/test_rule_500.py create mode 100644 tests/file_type_definition/__init__.py create mode 100644 tests/file_type_definition/rule_500_test_input.fixed_lower.vhd create mode 100644 tests/file_type_definition/rule_500_test_input.fixed_upper.vhd create mode 100644 tests/file_type_definition/rule_500_test_input.vhd create mode 100644 tests/file_type_definition/rule_501_test_input.fixed_lower.vhd create mode 100644 tests/file_type_definition/rule_501_test_input.fixed_upper.vhd create mode 100644 tests/file_type_definition/rule_501_test_input.vhd create mode 100644 tests/file_type_definition/test_rule_500.py create mode 100644 tests/file_type_definition/test_rule_501.py create mode 100644 vsg/rules/file_open_information/__init__.py create mode 100644 vsg/rules/file_open_information/rule_500.py create mode 100644 vsg/rules/file_open_information/rule_501.py create mode 100644 vsg/rules/file_open_information/rule_502.py create mode 100644 vsg/rules/file_statement/rule_500.py create mode 100644 vsg/rules/file_type_definition/__init__.py create mode 100644 vsg/rules/file_type_definition/rule_500.py create mode 100644 vsg/rules/file_type_definition/rule_501.py diff --git a/docs/configuring_uppercase_and_lowercase_rules.rst b/docs/configuring_uppercase_and_lowercase_rules.rst index f9c5660d..0ba739d2 100644 --- a/docs/configuring_uppercase_and_lowercase_rules.rst +++ b/docs/configuring_uppercase_and_lowercase_rules.rst @@ -356,7 +356,15 @@ Rules Enforcing Case * `external_variable_name_500 `_ +* `file_open_information_500 `_ +* `file_open_information_501 `_ +* `file_open_information_502 `_ + * `file_002 `_ +* `file_500 `_ + +* `file_type_definition_500 `_ +* `file_type_definition_501 `_ * `for_generate_statement_500 `_ * `for_generate_statement_501 `_ diff --git a/docs/file_open_information_rules.rst b/docs/file_open_information_rules.rst new file mode 100644 index 00000000..22baeba9 --- /dev/null +++ b/docs/file_open_information_rules.rst @@ -0,0 +1,91 @@ +.. include:: includes.rst + +File Open Information Rules +--------------------------- + +file_open_information_500 +######################### + +|phase_6| |error| |case| |case_keyword| + +This rule checks the **open** keyword has proper case. + +|configuring_uppercase_and_lowercase_rules_link| + +**Violation** + +.. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type OPEN read_mode is load_file_name; + + begin + +**Fix** + +.. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + begin + +file_open_information_501 +######################### + +|phase_6| |error| |case| |case_keyword| + +This rule checks the file open kind expression has proper case. + +|configuring_uppercase_and_lowercase_rules_link| + +**Violation** + +.. code-block:: vhdl + + architecture rtl of fifo is + + FILE defaultImage : load_file_type open READ_MODE is load_file_name; + + begin + +**Fix** + +.. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + begin + +file_open_information_502 +######################### + +|phase_6| |error| |case| |case_keyword| + +This rule checks the **is** keyword has proper case. + +|configuring_uppercase_and_lowercase_rules_link| + +**Violation** + +.. code-block:: vhdl + + architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode IS load_file_name; + + begin + +**Fix** + +.. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + begin diff --git a/docs/file_rules.rst b/docs/file_rules.rst index b869ffe9..fbb50ace 100644 --- a/docs/file_rules.rst +++ b/docs/file_rules.rst @@ -95,3 +95,32 @@ This rule checks for a single space before the identifier. .. code-block:: vhdl file defaultImage : load_file_type open read_mode is load_file_name; + +file_500 +######## + +|phase_6| |error| |case| |case_name| + +This rule checks the file identifier has proper case. + +|configuring_uppercase_and_lowercase_rules_link| + +**Violation** + +.. code-block:: vhdl + + architecture rtl of fifo is + + file DEFAULTIMAGE : load_file_type open read_mode is load_file_name; + + begin + +**Fix** + +.. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + begin diff --git a/docs/file_type_definition_rules.rst b/docs/file_type_definition_rules.rst new file mode 100644 index 00000000..7cca8a32 --- /dev/null +++ b/docs/file_type_definition_rules.rst @@ -0,0 +1,56 @@ +.. include:: includes.rst + +File Type Definition Rules +-------------------------- + +file_type_definition_500 +######################## + +|phase_6| |error| |case| |case_keyword| + +This rule checks the **file** keyword has proper case. + +|configuring_uppercase_and_lowercase_rules_link| + +**Violation** + +.. code-block:: vhdl + + type integer_file is FILE of integer; + + +**Fix** + +.. code-block:: vhdl + + architecture rtl of fifo is + + type integer_file is file of integer; + + begin + +file_type_definition_501 +######################## + +|phase_6| |error| |case| |case_keyword| + +This rule checks the **of** keyword has proper case. + +|configuring_uppercase_and_lowercase_rules_link| + +**Violation** + +.. code-block:: vhdl + + type integer_file is file OF integer; + + +**Fix** + +.. code-block:: vhdl + + architecture rtl of fifo is + + type integer_file is file of integer; + + begin diff --git a/docs/rule_groups/case_keyword_rule_group.rst b/docs/rule_groups/case_keyword_rule_group.rst index 5145001b..a00d65c9 100644 --- a/docs/rule_groups/case_keyword_rule_group.rst +++ b/docs/rule_groups/case_keyword_rule_group.rst @@ -69,7 +69,12 @@ Rules Enforcing Case::Keyword Rule Group * `external_constant_name_500 <../external_constant_name_rules.html#external-constant-name-500>`_ * `external_signal_name_500 <../external_signal_name_rules.html#external-signal-name-500>`_ * `external_variable_name_500 <../external_variable_name_rules.html#external-variable-name-500>`_ +* `file_open_information_500 <../file_open_information_rules.html#file-open-information-500>`_ +* `file_open_information_501 <../file_open_information_rules.html#file-open-information-501>`_ +* `file_open_information_502 <../file_open_information_rules.html#file-open-information-502>`_ * `file_002 <../file_rules.html#file-002>`_ +* `file_type_definition_500 <../file_type_definition_rules.html#file-type-definition-500>`_ +* `file_type_definition_501 <../file_type_definition_rules.html#file-type-definition-501>`_ * `for_generate_statement_500 <../for_generate_statement_rules.html#for-generate-statement-500>`_ * `for_generate_statement_501 <../for_generate_statement_rules.html#for-generate-statement-501>`_ * `function_004 <../function_rules.html#function-004>`_ diff --git a/docs/rule_groups/case_name_rule_group.rst b/docs/rule_groups/case_name_rule_group.rst index e0fcb3ef..66f0059a 100644 --- a/docs/rule_groups/case_name_rule_group.rst +++ b/docs/rule_groups/case_name_rule_group.rst @@ -22,6 +22,7 @@ Rules Enforcing Case::Name Rule Group * `entity_008 <../entity_rules.html#entity-008>`_ * `entity_012 <../entity_rules.html#entity-012>`_ * `entity_specification_503 <../entity_specification_rules.html#entity-specification-503>`_ +* `file_500 `_ * `function_017 <../function_rules.html#function-017>`_ * `function_506 <../function_rules.html#function-506>`_ * `function_507 <../function_rules.html#function-507>`_ diff --git a/docs/rule_groups/case_rule_group.rst b/docs/rule_groups/case_rule_group.rst index a1079b43..11dc890a 100644 --- a/docs/rule_groups/case_rule_group.rst +++ b/docs/rule_groups/case_rule_group.rst @@ -95,7 +95,13 @@ Rules Enforcing Case Rule Group * `external_constant_name_500 <../external_constant_name_rules.html#external-constant-name-500>`_ * `external_signal_name_500 <../external_signal_name_rules.html#external-signal-name-500>`_ * `external_variable_name_500 <../external_variable_name_rules.html#external-variable-name-500>`_ +* `file_open_information_500 <../file_open_information_rules.html#file-open-information-500>`_ +* `file_open_information_501 <../file_open_information_rules.html#file-open-information-501>`_ +* `file_open_information_502 <../file_open_information_rules.html#file-open-information-502>`_ * `file_002 <../file_rules.html#file-002>`_ +* `file_500 <../file_rules.html#file-500>`_ +* `file_type_definition_500 <../file_type_definition_rules.html#file-type-definition-500>`_ +* `file_type_definition_501 <../file_type_definition_rules.html#file-type-definition-501>`_ * `for_generate_statement_500 <../for_generate_statement_rules.html#for-generate-statement-500>`_ * `for_generate_statement_501 <../for_generate_statement_rules.html#for-generate-statement-501>`_ * `function_004 <../function_rules.html#function-004>`_ diff --git a/docs/rules.rst b/docs/rules.rst index dda88a8f..c012785f 100644 --- a/docs/rules.rst +++ b/docs/rules.rst @@ -42,6 +42,8 @@ The rules are divided into categories depending on the part of the VHDL code bei external_signal_name_rules.rst external_variable_name_rules.rst file_rules.rst + file_open_information_rules.rst + file_type_definition_rules.rst for_loop_rules.rst for_generate_statement_rules.rst function_rules.rst diff --git a/tests/file_open_information/__init__.py b/tests/file_open_information/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/file_open_information/rule_500_test_input.fixed_lower.vhd b/tests/file_open_information/rule_500_test_input.fixed_lower.vhd new file mode 100644 index 00000000..cc4748b5 --- /dev/null +++ b/tests/file_open_information/rule_500_test_input.fixed_lower.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode is load_file_name; + + file defaultimage : load_file_type open read_mode is load_file_name; + + file defaultimage : load_file_type open read_mode is load_file_name; + +begin + +end; diff --git a/tests/file_open_information/rule_500_test_input.fixed_upper.vhd b/tests/file_open_information/rule_500_test_input.fixed_upper.vhd new file mode 100644 index 00000000..a179a95b --- /dev/null +++ b/tests/file_open_information/rule_500_test_input.fixed_upper.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type OPEN read_mode is load_file_name; + + file defaultimage : load_file_type OPEN read_mode is load_file_name; + + file defaultimage : load_file_type OPEN read_mode is load_file_name; + +begin + +end; diff --git a/tests/file_open_information/rule_500_test_input.vhd b/tests/file_open_information/rule_500_test_input.vhd new file mode 100644 index 00000000..ab968ba9 --- /dev/null +++ b/tests/file_open_information/rule_500_test_input.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode is load_file_name; + + file defaultimage : load_file_type OPEN read_mode is load_file_name; + + file defaultimage : load_file_type Open read_mode is load_file_name; + +begin + +end; diff --git a/tests/file_open_information/rule_501_test_input.fixed_lower.vhd b/tests/file_open_information/rule_501_test_input.fixed_lower.vhd new file mode 100644 index 00000000..72b73b81 --- /dev/null +++ b/tests/file_open_information/rule_501_test_input.fixed_lower.vhd @@ -0,0 +1,18 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode is load_file_name; + file defaultimage : load_file_type open write_mode is load_file_name; + file defaultimage : load_file_type open append_mode is load_file_name; + + file defaultimage : load_file_type open read_mode is load_file_name; + file defaultimage : load_file_type open write_mode is load_file_name; + file defaultimage : load_file_type open append_mode is load_file_name; + + file defaultimage : load_file_type open read_mode is load_file_name; + file defaultimage : load_file_type open write_mode is load_file_name; + file defaultimage : load_file_type open append_mode is load_file_name; + +begin + +end; diff --git a/tests/file_open_information/rule_501_test_input.fixed_upper.vhd b/tests/file_open_information/rule_501_test_input.fixed_upper.vhd new file mode 100644 index 00000000..4d838e49 --- /dev/null +++ b/tests/file_open_information/rule_501_test_input.fixed_upper.vhd @@ -0,0 +1,18 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open READ_MODE is load_file_name; + file defaultimage : load_file_type open WRITE_MODE is load_file_name; + file defaultimage : load_file_type open APPEND_MODE is load_file_name; + + file defaultimage : load_file_type open READ_MODE is load_file_name; + file defaultimage : load_file_type open WRITE_MODE is load_file_name; + file defaultimage : load_file_type open APPEND_MODE is load_file_name; + + file defaultimage : load_file_type open READ_MODE is load_file_name; + file defaultimage : load_file_type open WRITE_MODE is load_file_name; + file defaultimage : load_file_type open APPEND_MODE is load_file_name; + +begin + +end; diff --git a/tests/file_open_information/rule_501_test_input.vhd b/tests/file_open_information/rule_501_test_input.vhd new file mode 100644 index 00000000..835b2f2c --- /dev/null +++ b/tests/file_open_information/rule_501_test_input.vhd @@ -0,0 +1,18 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode is load_file_name; + file defaultimage : load_file_type open write_mode is load_file_name; + file defaultimage : load_file_type open append_mode is load_file_name; + + file defaultimage : load_file_type open READ_MODE is load_file_name; + file defaultimage : load_file_type open WRITE_MODE is load_file_name; + file defaultimage : load_file_type open APPEND_MODE is load_file_name; + + file defaultimage : load_file_type open Read_Mode is load_file_name; + file defaultimage : load_file_type open Write_Mode is load_file_name; + file defaultimage : load_file_type open Append_Mode is load_file_name; + +begin + +end; diff --git a/tests/file_open_information/rule_502_test_input.fixed_lower.vhd b/tests/file_open_information/rule_502_test_input.fixed_lower.vhd new file mode 100644 index 00000000..cc4748b5 --- /dev/null +++ b/tests/file_open_information/rule_502_test_input.fixed_lower.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode is load_file_name; + + file defaultimage : load_file_type open read_mode is load_file_name; + + file defaultimage : load_file_type open read_mode is load_file_name; + +begin + +end; diff --git a/tests/file_open_information/rule_502_test_input.fixed_upper.vhd b/tests/file_open_information/rule_502_test_input.fixed_upper.vhd new file mode 100644 index 00000000..1cc5f74e --- /dev/null +++ b/tests/file_open_information/rule_502_test_input.fixed_upper.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode IS load_file_name; + + file defaultimage : load_file_type open read_mode IS load_file_name; + + file defaultimage : load_file_type open read_mode IS load_file_name; + +begin + +end; diff --git a/tests/file_open_information/rule_502_test_input.vhd b/tests/file_open_information/rule_502_test_input.vhd new file mode 100644 index 00000000..647abacf --- /dev/null +++ b/tests/file_open_information/rule_502_test_input.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode is load_file_name; + + file defaultimage : load_file_type open read_mode IS load_file_name; + + file defaultimage : load_file_type open read_mode Is load_file_name; + +begin + +end; diff --git a/tests/file_open_information/test_rule_500.py b/tests/file_open_information/test_rule_500.py new file mode 100644 index 00000000..19dee61c --- /dev/null +++ b/tests/file_open_information/test_rule_500.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_open_information + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_500_test_input.vhd")) + +lExpected_lower = [] +lExpected_lower.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_lower.vhd"), lExpected_lower) + +lExpected_upper = [] +lExpected_upper.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_upper.vhd"), lExpected_upper) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_500_lower(self): + oRule = file_open_information.rule_500() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "500") + + lExpected = [6, 8] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_rule_500_upper(self): + oRule = file_open_information.rule_500() + oRule.case = "upper" + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "500") + + lExpected = [4, 8] + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_fix_rule_500_lower(self): + oRule = file_open_information.rule_500() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_lower, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_500_upper(self): + oRule = file_open_information.rule_500() + oRule.case = "upper" + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_upper, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/file_open_information/test_rule_501.py b/tests/file_open_information/test_rule_501.py new file mode 100644 index 00000000..10ab859d --- /dev/null +++ b/tests/file_open_information/test_rule_501.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_open_information + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_501_test_input.vhd")) + +lExpected_lower = [] +lExpected_lower.append("") +utils.read_file(os.path.join(sTestDir, "rule_501_test_input.fixed_lower.vhd"), lExpected_lower) + +lExpected_upper = [] +lExpected_upper.append("") +utils.read_file(os.path.join(sTestDir, "rule_501_test_input.fixed_upper.vhd"), lExpected_upper) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_501_lower(self): + oRule = file_open_information.rule_501() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "501") + + lExpected = [8, 9, 10, 12, 13, 14] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_rule_501_upper(self): + oRule = file_open_information.rule_501() + oRule.case = "upper" + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "501") + + lExpected = [4, 5, 6, 12, 13, 14] + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_fix_rule_501_lower(self): + oRule = file_open_information.rule_501() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_lower, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_501_upper(self): + oRule = file_open_information.rule_501() + oRule.case = "upper" + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_upper, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/file_open_information/test_rule_502.py b/tests/file_open_information/test_rule_502.py new file mode 100644 index 00000000..bd736981 --- /dev/null +++ b/tests/file_open_information/test_rule_502.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_open_information + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_502_test_input.vhd")) + +lExpected_lower = [] +lExpected_lower.append("") +utils.read_file(os.path.join(sTestDir, "rule_502_test_input.fixed_lower.vhd"), lExpected_lower) + +lExpected_upper = [] +lExpected_upper.append("") +utils.read_file(os.path.join(sTestDir, "rule_502_test_input.fixed_upper.vhd"), lExpected_upper) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_502_lower(self): + oRule = file_open_information.rule_502() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "502") + + lExpected = [6, 8] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_rule_502_upper(self): + oRule = file_open_information.rule_502() + oRule.case = "upper" + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "502") + + lExpected = [4, 8] + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_fix_rule_502_lower(self): + oRule = file_open_information.rule_502() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_lower, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_502_upper(self): + oRule = file_open_information.rule_502() + oRule.case = "upper" + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_upper, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/file_statement/rule_500_test_input.fixed_lower.vhd b/tests/file_statement/rule_500_test_input.fixed_lower.vhd new file mode 100644 index 00000000..cc4748b5 --- /dev/null +++ b/tests/file_statement/rule_500_test_input.fixed_lower.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode is load_file_name; + + file defaultimage : load_file_type open read_mode is load_file_name; + + file defaultimage : load_file_type open read_mode is load_file_name; + +begin + +end; diff --git a/tests/file_statement/rule_500_test_input.fixed_upper.vhd b/tests/file_statement/rule_500_test_input.fixed_upper.vhd new file mode 100644 index 00000000..a0cc8a2f --- /dev/null +++ b/tests/file_statement/rule_500_test_input.fixed_upper.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + file DEFAULTIMAGE : load_file_type open read_mode is load_file_name; + + file DEFAULTIMAGE : load_file_type open read_mode is load_file_name; + + file DEFAULTIMAGE : load_file_type open read_mode is load_file_name; + +begin + +end; diff --git a/tests/file_statement/rule_500_test_input.vhd b/tests/file_statement/rule_500_test_input.vhd new file mode 100644 index 00000000..e30afc4b --- /dev/null +++ b/tests/file_statement/rule_500_test_input.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode is load_file_name; + + file DEFAULTIMAGE : load_file_type open read_mode is load_file_name; + + file DefaultImage : load_file_type open read_mode is load_file_name; + +begin + +end; diff --git a/tests/file_statement/test_rule_500.py b/tests/file_statement/test_rule_500.py new file mode 100644 index 00000000..7fb510a1 --- /dev/null +++ b/tests/file_statement/test_rule_500.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_statement + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_500_test_input.vhd")) + +lExpected_lower = [] +lExpected_lower.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_lower.vhd"), lExpected_lower) + +lExpected_upper = [] +lExpected_upper.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_upper.vhd"), lExpected_upper) + + +class test_file_statement_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_500_lower(self): + oRule = file_statement.rule_500() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file") + self.assertEqual(oRule.identifier, "500") + + lExpected = [6, 8] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_rule_500_upper(self): + oRule = file_statement.rule_500() + oRule.case = "upper" + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file") + self.assertEqual(oRule.identifier, "500") + + lExpected = [4, 8] + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_fix_rule_500_lower(self): + oRule = file_statement.rule_500() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_lower, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_500_upper(self): + oRule = file_statement.rule_500() + oRule.case = "upper" + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_upper, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/file_type_definition/__init__.py b/tests/file_type_definition/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/file_type_definition/rule_500_test_input.fixed_lower.vhd b/tests/file_type_definition/rule_500_test_input.fixed_lower.vhd new file mode 100644 index 00000000..25c39b4a --- /dev/null +++ b/tests/file_type_definition/rule_500_test_input.fixed_lower.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + type integer_file is file of integer; + + type integer_file is file of integer; + + type integer_file is file of integer; + +begin + +end; diff --git a/tests/file_type_definition/rule_500_test_input.fixed_upper.vhd b/tests/file_type_definition/rule_500_test_input.fixed_upper.vhd new file mode 100644 index 00000000..724e9764 --- /dev/null +++ b/tests/file_type_definition/rule_500_test_input.fixed_upper.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + type integer_file is FILE of integer; + + type integer_file is FILE of integer; + + type integer_file is FILE of integer; + +begin + +end; diff --git a/tests/file_type_definition/rule_500_test_input.vhd b/tests/file_type_definition/rule_500_test_input.vhd new file mode 100644 index 00000000..daf5f81a --- /dev/null +++ b/tests/file_type_definition/rule_500_test_input.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + type integer_file is file of integer; + + type integer_file is FILE of integer; + + type integer_file is File of integer; + +begin + +end; diff --git a/tests/file_type_definition/rule_501_test_input.fixed_lower.vhd b/tests/file_type_definition/rule_501_test_input.fixed_lower.vhd new file mode 100644 index 00000000..25c39b4a --- /dev/null +++ b/tests/file_type_definition/rule_501_test_input.fixed_lower.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + type integer_file is file of integer; + + type integer_file is file of integer; + + type integer_file is file of integer; + +begin + +end; diff --git a/tests/file_type_definition/rule_501_test_input.fixed_upper.vhd b/tests/file_type_definition/rule_501_test_input.fixed_upper.vhd new file mode 100644 index 00000000..4767ddd0 --- /dev/null +++ b/tests/file_type_definition/rule_501_test_input.fixed_upper.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + type integer_file is file OF integer; + + type integer_file is file OF integer; + + type integer_file is file OF integer; + +begin + +end; diff --git a/tests/file_type_definition/rule_501_test_input.vhd b/tests/file_type_definition/rule_501_test_input.vhd new file mode 100644 index 00000000..61d70948 --- /dev/null +++ b/tests/file_type_definition/rule_501_test_input.vhd @@ -0,0 +1,12 @@ + +architecture rtl of fifo is + + type integer_file is file of integer; + + type integer_file is file OF integer; + + type integer_file is file Of integer; + +begin + +end; diff --git a/tests/file_type_definition/test_rule_500.py b/tests/file_type_definition/test_rule_500.py new file mode 100644 index 00000000..507c9fdf --- /dev/null +++ b/tests/file_type_definition/test_rule_500.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_type_definition + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_500_test_input.vhd")) + +lExpected_lower = [] +lExpected_lower.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_lower.vhd"), lExpected_lower) + +lExpected_upper = [] +lExpected_upper.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_upper.vhd"), lExpected_upper) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_500_lower(self): + oRule = file_type_definition.rule_500() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_type_definition") + self.assertEqual(oRule.identifier, "500") + + lExpected = [6, 8] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_rule_500_upper(self): + oRule = file_type_definition.rule_500() + oRule.case = "upper" + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_type_definition") + self.assertEqual(oRule.identifier, "500") + + lExpected = [4, 8] + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_fix_rule_500_lower(self): + oRule = file_type_definition.rule_500() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_lower, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_500_upper(self): + oRule = file_type_definition.rule_500() + oRule.case = "upper" + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_upper, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/file_type_definition/test_rule_501.py b/tests/file_type_definition/test_rule_501.py new file mode 100644 index 00000000..609f6b43 --- /dev/null +++ b/tests/file_type_definition/test_rule_501.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_type_definition + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_501_test_input.vhd")) + +lExpected_lower = [] +lExpected_lower.append("") +utils.read_file(os.path.join(sTestDir, "rule_501_test_input.fixed_lower.vhd"), lExpected_lower) + +lExpected_upper = [] +lExpected_upper.append("") +utils.read_file(os.path.join(sTestDir, "rule_501_test_input.fixed_upper.vhd"), lExpected_upper) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_501_lower(self): + oRule = file_type_definition.rule_501() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_type_definition") + self.assertEqual(oRule.identifier, "501") + + lExpected = [6, 8] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_rule_501_upper(self): + oRule = file_type_definition.rule_501() + oRule.case = "upper" + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_type_definition") + self.assertEqual(oRule.identifier, "501") + + lExpected = [4, 8] + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_fix_rule_501_lower(self): + oRule = file_type_definition.rule_501() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_lower, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_501_upper(self): + oRule = file_type_definition.rule_501() + oRule.case = "upper" + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_upper, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/vsg/rules/__init__.py b/vsg/rules/__init__.py index 39c52a90..a2456c55 100644 --- a/vsg/rules/__init__.py +++ b/vsg/rules/__init__.py @@ -141,6 +141,8 @@ from vsg.rules import external_signal_name from vsg.rules import external_constant_name from vsg.rules import external_variable_name from vsg.rules import file_statement +from vsg.rules import file_open_information +from vsg.rules import file_type_definition from vsg.rules import for_loop from vsg.rules import for_generate_statement from vsg.rules import function diff --git a/vsg/rules/file_open_information/__init__.py b/vsg/rules/file_open_information/__init__.py new file mode 100644 index 00000000..f3535725 --- /dev/null +++ b/vsg/rules/file_open_information/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +from .rule_500 import rule_500 +from .rule_501 import rule_501 +from .rule_502 import rule_502 diff --git a/vsg/rules/file_open_information/rule_500.py b/vsg/rules/file_open_information/rule_500.py new file mode 100644 index 00000000..6d5090ae --- /dev/null +++ b/vsg/rules/file_open_information/rule_500.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_case + +lTokens = [] +lTokens.append(token.file_open_information.open_keyword) + + +class rule_500(token_case): + """ + This rule checks the **open** keyword has proper case. + + |configuring_uppercase_and_lowercase_rules_link| + + **Violation** + + .. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type OPEN read_mode is load_file_name; + + begin + + **Fix** + + .. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + begin + """ + + def __init__(self): + super().__init__(lTokens) + self.groups.append("case::keyword") diff --git a/vsg/rules/file_open_information/rule_501.py b/vsg/rules/file_open_information/rule_501.py new file mode 100644 index 00000000..25bf873a --- /dev/null +++ b/vsg/rules/file_open_information/rule_501.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_case + +lTokens = [] +lTokens.append(token.file_open_information.file_open_kind_expression) + + +class rule_501(token_case): + """ + This rule checks the file open kind expression has proper case. + + |configuring_uppercase_and_lowercase_rules_link| + + **Violation** + + .. code-block:: vhdl + + architecture rtl of fifo is + + FILE defaultImage : load_file_type open READ_MODE is load_file_name; + + begin + + **Fix** + + .. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + begin + """ + + def __init__(self): + super().__init__(lTokens) + self.groups.append("case::keyword") diff --git a/vsg/rules/file_open_information/rule_502.py b/vsg/rules/file_open_information/rule_502.py new file mode 100644 index 00000000..18856cdb --- /dev/null +++ b/vsg/rules/file_open_information/rule_502.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_case + +lTokens = [] +lTokens.append(token.file_open_information.is_keyword) + + +class rule_502(token_case): + """ + This rule checks the **is** keyword has proper case. + + |configuring_uppercase_and_lowercase_rules_link| + + **Violation** + + .. code-block:: vhdl + + architecture rtl of fifo is + + file defaultimage : load_file_type open read_mode IS load_file_name; + + begin + + **Fix** + + .. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + begin + """ + + def __init__(self): + super().__init__(lTokens) + self.groups.append("case::keyword") diff --git a/vsg/rules/file_statement/__init__.py b/vsg/rules/file_statement/__init__.py index 96ef48c6..4790a7f7 100644 --- a/vsg/rules/file_statement/__init__.py +++ b/vsg/rules/file_statement/__init__.py @@ -4,3 +4,4 @@ from .rule_001 import rule_001 from .rule_002 import rule_002 from .rule_003 import rule_003 from .rule_100 import rule_100 +from .rule_500 import rule_500 diff --git a/vsg/rules/file_statement/rule_500.py b/vsg/rules/file_statement/rule_500.py new file mode 100644 index 00000000..3d9b6859 --- /dev/null +++ b/vsg/rules/file_statement/rule_500.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_case + +lTokens = [] +lTokens.append(token.file_declaration.identifier) + + +class rule_500(token_case): + """ + This rule checks the file identifier has proper case. + + |configuring_uppercase_and_lowercase_rules_link| + + **Violation** + + .. code-block:: vhdl + + architecture rtl of fifo is + + file DEFAULTIMAGE : load_file_type open read_mode is load_file_name; + + begin + + **Fix** + + .. code-block:: vhdl + + architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + begin + """ + + def __init__(self): + super().__init__(lTokens) + self.groups.append("case::name") diff --git a/vsg/rules/file_type_definition/__init__.py b/vsg/rules/file_type_definition/__init__.py new file mode 100644 index 00000000..3c6ea275 --- /dev/null +++ b/vsg/rules/file_type_definition/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from .rule_500 import rule_500 +from .rule_501 import rule_501 diff --git a/vsg/rules/file_type_definition/rule_500.py b/vsg/rules/file_type_definition/rule_500.py new file mode 100644 index 00000000..8afb7a88 --- /dev/null +++ b/vsg/rules/file_type_definition/rule_500.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_case + +lTokens = [] +lTokens.append(token.file_type_definition.file_keyword) + + +class rule_500(token_case): + """ + This rule checks the **file** keyword has proper case. + + |configuring_uppercase_and_lowercase_rules_link| + + **Violation** + + .. code-block:: vhdl + + type integer_file is FILE of integer; + + + **Fix** + + .. code-block:: vhdl + + architecture rtl of fifo is + + type integer_file is file of integer; + + begin + """ + + def __init__(self): + super().__init__(lTokens) + self.groups.append("case::keyword") diff --git a/vsg/rules/file_type_definition/rule_501.py b/vsg/rules/file_type_definition/rule_501.py new file mode 100644 index 00000000..12a13477 --- /dev/null +++ b/vsg/rules/file_type_definition/rule_501.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_case + +lTokens = [] +lTokens.append(token.file_type_definition.of_keyword) + + +class rule_501(token_case): + """ + This rule checks the **of** keyword has proper case. + + |configuring_uppercase_and_lowercase_rules_link| + + **Violation** + + .. code-block:: vhdl + + type integer_file is file OF integer; + + + **Fix** + + .. code-block:: vhdl + + architecture rtl of fifo is + + type integer_file is file of integer; + + begin + """ + + def __init__(self): + super().__init__(lTokens) + self.groups.append("case::keyword")