From 2a1f4a4e8f28dfea2a6e75a46b007461ddaf6e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ralf=20D=2E=20M=C3=BCller?= Date: Mon, 3 Mar 2025 21:00:23 +0100 Subject: [PATCH] Fix failing test in README.adoc Related to #18 Update `WhitespaceRule` to account for attributes and roles around section titles. * Modify `check_line` method in `asciidoc_linter/rules/whitespace_rules.py` to handle attributes and roles. * Add tests in `tests/rules/test_heading_rules.py` for attributes and roles around section titles. * Include tests for headings followed by attributes. * Include tests for headings preceded by roles. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/docToolchain/asciidoc-linter/issues/18?shareId=XXXX-XXXX-XXXX-XXXX). --- asciidoc_linter/rules/whitespace_rules.py | 4 +- tests/rules/test_heading_rules.py | 56 +++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) mode change 100755 => 100644 tests/rules/test_heading_rules.py diff --git a/asciidoc_linter/rules/whitespace_rules.py b/asciidoc_linter/rules/whitespace_rules.py index 3ea8359..c094432 100644 --- a/asciidoc_linter/rules/whitespace_rules.py +++ b/asciidoc_linter/rules/whitespace_rules.py @@ -121,7 +121,7 @@ def check_line( # Check for blank line before section title (except for first line) if line_number > 0: prev_content = self.get_line_content(context[line_number - 1]) - if prev_content.strip(): + if prev_content.strip() and not prev_content.strip().startswith(("[.", "[[")): findings.append( Finding( rule_id=self.id, @@ -135,7 +135,7 @@ def check_line( # Check for blank line after section title (except for last line) if line_number < len(context) - 1: next_content = self.get_line_content(context[line_number + 1]) - if next_content.strip(): + if next_content.strip() and not next_content.strip().startswith(":"): findings.append( Finding( rule_id=self.id, diff --git a/tests/rules/test_heading_rules.py b/tests/rules/test_heading_rules.py old mode 100755 new mode 100644 index c577188..63b4d32 --- a/tests/rules/test_heading_rules.py +++ b/tests/rules/test_heading_rules.py @@ -308,5 +308,61 @@ def test_multiple_top_level(self): ) +class TestHeadingAttributesAndRoles(unittest.TestCase): + """Tests for headings with attributes and roles. + This rule ensures that headings with attributes and roles are properly handled. + """ + + def setUp(self): + """ + Given a HeadingFormatRule instance + """ + self.rule = HeadingFormatRule() + + def test_heading_with_attributes(self): + """ + Given a document with headings followed by attributes + When the heading format rule is checked + Then no findings should be reported + """ + # Given: A document with headings followed by attributes + content = """ += Level 1 +:attribute: value + +== Level 2 +:another-attribute: value +""" + # When: We check the heading format + findings = self.rule.check(content) + + # Then: No findings should be reported + self.assertEqual( + len(findings), 0, "Headings followed by attributes should not produce findings" + ) + + def test_heading_with_roles(self): + """ + Given a document with headings preceded by roles + When the heading format rule is checked + Then no findings should be reported + """ + # Given: A document with headings preceded by roles + content = """ +[.role] += Level 1 + +[[target]] +== Level 2 +""" + # When: We check the heading format + findings = self.rule.check(content) + + # Then: No findings should be reported + self.assertEqual( + len(findings), 0, "Headings preceded by roles should not produce findings" + ) + + if __name__ == "__main__": unittest.main()