1from clang.cindex import TranslationUnit
2from tests.cindex.util import get_cursor
3
4def test_comment():
5    files = [('fake.c', """
6/// Aaa.
7int test1;
8
9/// Bbb.
10/// x
11void test2(void);
12
13void f() {
14
15}
16""")]
17    # make a comment-aware TU
18    tu = TranslationUnit.from_source('fake.c', ['-std=c99'], unsaved_files=files,
19            options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION)
20    test1 = get_cursor(tu, 'test1')
21    assert test1 is not None, "Could not find test1."
22    assert test1.type.is_pod()
23    raw = test1.raw_comment
24    brief = test1.brief_comment
25    assert raw == """/// Aaa."""
26    assert brief == """Aaa."""
27
28    test2 = get_cursor(tu, 'test2')
29    raw = test2.raw_comment
30    brief = test2.brief_comment
31    assert raw == """/// Bbb.\n/// x"""
32    assert brief == """Bbb. x"""
33
34    f = get_cursor(tu, 'f')
35    raw = f.raw_comment
36    brief = f.brief_comment
37    assert raw is None
38    assert brief is None
39
40
41