From 16f94b118d3f7fbc4c562fd6189d102128b2f6dd Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Mon, 4 Nov 2024 17:21:46 +0100 Subject: [PATCH] backend/sdoc_source_code: forward C function relations: include the top comment to the range --- .../backend/sdoc_source_code/reader_c.py | 10 +++++++--- .../c/03_c_forward_function/test.itest | 20 +++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/strictdoc/backend/sdoc_source_code/reader_c.py b/strictdoc/backend/sdoc_source_code/reader_c.py index 2641f7011..d25cd26d0 100644 --- a/strictdoc/backend/sdoc_source_code/reader_c.py +++ b/strictdoc/backend/sdoc_source_code/reader_c.py @@ -1,10 +1,10 @@ # mypy: disable-error-code="no-redef,no-untyped-call,no-untyped-def,type-arg,var-annotated" import sys import traceback -from typing import List, Union +from typing import List, Optional, Union import tree_sitter_c -from tree_sitter import Language, Parser +from tree_sitter import Language, Node, Parser from strictdoc.backend.sdoc.error_handling import StrictDocSemanticError from strictdoc.backend.sdoc_source_code.marker_parser import MarkerParser @@ -68,6 +68,7 @@ def read( function_name = child_.children[0].text.decode("utf8") assert function_name is not None, "Function name" + function_comment_node: Optional[Node] = None function_comment_text = None if ( node_.prev_sibling is not None @@ -105,10 +106,13 @@ def read( function_range_marker_ ) + # The function range includes the top comment if it exists. new_function = Function( parent=None, name=function_name, - line_begin=node_.range.start_point[0] + 1, + line_begin=function_comment_node.start_point[0] + 1 + if function_comment_node is not None + else node_.range.start_point[0] + 1, line_end=node_.range.end_point[0] + 1, parts=[], ) diff --git a/tests/integration/features/file_traceability/_language_parsers/c/03_c_forward_function/test.itest b/tests/integration/features/file_traceability/_language_parsers/c/03_c_forward_function/test.itest index 125c55869..2a2e36a25 100644 --- a/tests/integration/features/file_traceability/_language_parsers/c/03_c_forward_function/test.itest +++ b/tests/integration/features/file_traceability/_language_parsers/c/03_c_forward_function/test.itest @@ -7,18 +7,24 @@ RUN: %check_exists --file "%S/Output/html/_source_files/file.c.html" RUN: %cat %S/Output/html/%THIS_TEST_FOLDER/input.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML CHECK-HTML: -CHECK-HTML: -CHECK-HTML: +CHECK-HTML: +CHECK-HTML: CHECK-HTML: CHECK-HTML: RUN: %cat %S/Output/html/_source_files/file.c.html | filecheck %s --dump-input=fail --check-prefix CHECK-SOURCE-FILE CHECK-SOURCE-FILE: [ 3-10 ] file.c, function hello_world -CHECK-SOURCE-FILE: [ 8-10 ] file.c, function hello_world -CHECK-SOURCE-FILE: [ 17-19 ] file.c, function hello_world_2 +CHECK-SOURCE-FILE: [ 3-10 ] file.c, function hello_world +CHECK-SOURCE-FILE: [ 12-19 ] file.c, function hello_world_2 CHECK-SOURCE-FILE: [ 21-28 ] file.c, function hello_world_3 CHECK-SOURCE-FILE: [ 30-38 ] file.c, function hello_world_4 +# Two forward function links from two reqs REQ-1 and REQ-2 on the first function. +CHECK-SOURCE-FILE:
+CHECK-SOURCE-FILE: href="../_source_files/file.c.html#REQ-1#3#10" +CHECK-SOURCE-FILE: href="../_source_files/file.c.html#REQ-2#3#10" +CHECK-SOURCE-FILE:
4
+ CHECK-SOURCE-FILE:
 * @relation(REQ-1, scope=function)
7
-# Two forward function links from two reqs REQ-1 and REQ-2 on the first function. -CHECK-SOURCE-FILE:
-CHECK-SOURCE-FILE: href="../_source_files/file.c.html#REQ-1#8#10" -CHECK-SOURCE-FILE: href="../_source_files/file.c.html#REQ-2#8#10" -CHECK-SOURCE-FILE:
9
- RUN: %cat %S/Output/html/source_coverage.html | filecheck %s --dump-input=fail --check-prefix CHECK-SOURCE-COVERAGE CHECK-SOURCE-COVERAGE: 86.8%