PR#1183: Fix bug in whitespace between tokens and add test for it (#1183)

Co-authored-by: Edgar Vedvik <edgar@radionor.no>
This commit is contained in:
Edgar Vedvik 2024-06-20 04:32:02 +02:00 committed by GitHub
parent 7adbcc0003
commit c6c26e33bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 58 additions and 1 deletions

View File

@ -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;

View File

@ -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, [])

View File

@ -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)