StrictDoc Documentation
tests/unit/strictdoc/backend/sdoc_source_code/readers/test_writer_c.py
Source file coverage
Path:
tests/unit/strictdoc/backend/sdoc_source_code/readers/test_writer_c.py
Lines:
69
Non-empty lines:
55
Non-empty lines covered with requirements:
55 / 55 (100.0%)
Functions:
1
Functions covered by requirements:
1 / 1 (100.0%)
1
"""
2
@relation(SDOC-SRS-146, scope=file)
3
"""
4
 
5
from strictdoc.backend.sdoc_source_code.models.source_file_info import (
6
    SourceFileTraceabilityInfo,
7
)
8
from strictdoc.backend.sdoc_source_code.reader_c import (
9
    SourceFileTraceabilityReader_C,
10
)
11
from strictdoc.backend.sdoc_source_code.source_writer import SourceWriter
12
 
13
 
14
def test_02_c_functions():
15
    input_string = b"""\
16
#include <stdio.h>
17
 
18
/**
19
 * Some text.
20
 *
21
 * @relation(REQ-1, scope=function)
22
 */
23
void hello_world(void) {
24
    print("hello world\\n");
25
}
26
 
27
/**
28
 * Some text.
29
 *
30
 * @relation(REQ-2, scope=function)
31
 */
32
void hello_world_2(void) {
33
    print("hello world\\n");
34
}
35
"""
36
 
37
    reader = SourceFileTraceabilityReader_C()
38
 
39
    info: SourceFileTraceabilityInfo = reader.read(
40
        input_string, file_path="foo.c"
41
    )
42
 
43
    assert isinstance(info, SourceFileTraceabilityInfo)
44
    assert len(info.markers) == 2
45
 
46
    rewrites = {}
47
    for source_node_ in info.source_nodes:
48
        rewrites[source_node_] = b"<PATCHED>"
49
 
50
    source_writer = SourceWriter()
51
    output_string = source_writer.write(
52
        info, rewrites=rewrites, file_bytes=input_string
53
    )
54
 
55
    expected_output_string = b"""\
56
#include <stdio.h>
57
 
58
<PATCHED>
59
void hello_world(void) {
60
    print("hello world\\n");
61
}
62
 
63
<PATCHED>
64
void hello_world_2(void) {
65
    print("hello world\\n");
66
}
67
"""
68
 
69
    assert output_string == expected_output_string