From c6c26e33bc7bd8973d91da545e4589c2d4ef1892 Mon Sep 17 00:00:00 2001 From: Edgar Vedvik Date: Thu, 20 Jun 2024 04:32:02 +0200 Subject: [PATCH] PR#1183: Fix bug in whitespace between tokens and add test for it (#1183) Co-authored-by: Edgar Vedvik --- .../rule_100_test_input.fixed_spaces_gte2.vhd | 29 +++++++++++++++++++ tests/element_association/test_rule_100.py | 26 +++++++++++++++++ vsg/rules/whitespace_between_tokens.py | 4 ++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/element_association/rule_100_test_input.fixed_spaces_gte2.vhd diff --git a/tests/element_association/rule_100_test_input.fixed_spaces_gte2.vhd b/tests/element_association/rule_100_test_input.fixed_spaces_gte2.vhd new file mode 100644 index 00000000..dd35baf2 --- /dev/null +++ b/tests/element_association/rule_100_test_input.fixed_spaces_gte2.vhd @@ -0,0 +1,29 @@ + +architecture rtl of fifo is + +begin + + a <= (others => (others => '0')); + + process begin + + a <= (others => (others => '0')); + + end process; + +end architecture; + + +architecture rtl of fifo is + +begin + + a <= (others => (others => '0')); + + process begin + + a <= (others => (others => '0')); + + end process; + +end architecture; diff --git a/tests/element_association/test_rule_100.py b/tests/element_association/test_rule_100.py index 1ae0e771..2c18522d 100644 --- a/tests/element_association/test_rule_100.py +++ b/tests/element_association/test_rule_100.py @@ -15,6 +15,10 @@ lExpected = [] lExpected.append("") utils.read_file(os.path.join(sTestDir, "rule_100_test_input.fixed.vhd"), lExpected) +lExpected_spaces_gte2 = [] +lExpected_spaces_gte2.append("") +utils.read_file(os.path.join(sTestDir, "rule_100_test_input.fixed_spaces_gte2.vhd"), lExpected_spaces_gte2) + class test_element_association_rule(unittest.TestCase): def setUp(self): @@ -43,3 +47,25 @@ class test_element_association_rule(unittest.TestCase): oRule.analyze(self.oFile) self.assertEqual(oRule.violations, []) + + def test_rule_100_spaces_2_plus(self): + oRule = element_association.rule_100() + oRule.number_of_spaces = "2+" + + lExpected = [6, 6, 10, 10, 21, 25] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_100_spaces_2_plus(self): + oRule = element_association.rule_100() + oRule.number_of_spaces = "2+" + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_spaces_gte2, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/vsg/rules/whitespace_between_tokens.py b/vsg/rules/whitespace_between_tokens.py index 1e97d35a..ea7a9925 100644 --- a/vsg/rules/whitespace_between_tokens.py +++ b/vsg/rules/whitespace_between_tokens.py @@ -59,6 +59,8 @@ class Rule(whitespace.Rule): return int(self.number_of_spaces[2:]) elif self.number_of_spaces_is_gt(): return int(self.number_of_spaces[1:]) + elif self.number_of_spaces_is_plus(): + return int(self.number_of_spaces[:-1]) def analyze_whitespace_token(self, oToi): if self.number_of_spaces_is_an_integer(): @@ -130,7 +132,7 @@ class Rule(whitespace.Rule): if isinstance(lTokens[1], parser.whitespace): lTokens[1].set_value(" " * dAction["spaces"]) else: - rules_utils.insert_whitespace(lTokens, dAction["spaces"]) + rules_utils.insert_whitespace(lTokens, 1, num=dAction["spaces"]) oViolation.set_tokens(lTokens)