Skip to content

Commit

Permalink
backend/sdoc_source_code: forward C function relations: include the t…
Browse files Browse the repository at this point in the history
…op comment to the range
  • Loading branch information
stanislaw committed Nov 4, 2024
1 parent b98db44 commit 16f94b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
10 changes: 7 additions & 3 deletions strictdoc/backend/sdoc_source_code/reader_c.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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=[],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: <a{{.*}}href="../_source_files/file.c.html#REQ-1#3#10">
CHECK-HTML: <a{{.*}}href="../_source_files/file.c.html#REQ-1#8#10">
CHECK-HTML: <a{{.*}}href="../_source_files/file.c.html#REQ-1#17#19">
CHECK-HTML: <a{{.*}}href="../_source_files/file.c.html#REQ-1#3#10">
CHECK-HTML: <a{{.*}}href="../_source_files/file.c.html#REQ-1#12#19">
CHECK-HTML: <a{{.*}}href="../_source_files/file.c.html#REQ-1#21#28">
CHECK-HTML: <a{{.*}}href="../_source_files/file.c.html#REQ-1#30#38">

RUN: %cat %S/Output/html/_source_files/file.c.html | filecheck %s --dump-input=fail --check-prefix CHECK-SOURCE-FILE
CHECK-SOURCE-FILE: <b>[ 3-10 ]</b> file.c, function hello_world
CHECK-SOURCE-FILE: <b>[ 8-10 ]</b> file.c, function hello_world
CHECK-SOURCE-FILE: <b>[ 17-19 ]</b> file.c, function hello_world_2
CHECK-SOURCE-FILE: <b>[ 3-10 ]</b> file.c, function hello_world
CHECK-SOURCE-FILE: <b>[ 12-19 ]</b> file.c, function hello_world_2
CHECK-SOURCE-FILE: <b>[ 21-28 ]</b> file.c, function hello_world_3
CHECK-SOURCE-FILE: <b>[ 30-38 ]</b> 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: <div data-line=3 class="source__line-content">
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: <div id="line-4" class="source__line-number"><pre>4</pre></div>

CHECK-SOURCE-FILE: <pre class="sdoc-comment"> * @relation(<a
CHECK-SOURCE-FILE: class="pointer"
CHECK-SOURCE-FILE: data-reqid="REQ-1"
Expand All @@ -28,11 +34,5 @@ CHECK-SOURCE-FILE: data-traceability-file-type="this_file"
CHECK-SOURCE-FILE: href="../_source_files/file.c.html#REQ-1#3#10"
CHECK-SOURCE-FILE: >REQ-1</a>, scope=function)</pre></div><div id="line-7" class="source__line-number"><pre>7</pre></div>

# Two forward function links from two reqs REQ-1 and REQ-2 on the first function.
CHECK-SOURCE-FILE: <div data-line=8 class="source__line-content">
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: <div id="line-9" class="source__line-number"><pre>9</pre></div>

RUN: %cat %S/Output/html/source_coverage.html | filecheck %s --dump-input=fail --check-prefix CHECK-SOURCE-COVERAGE
CHECK-SOURCE-COVERAGE: 86.8%

0 comments on commit 16f94b1

Please sign in to comment.