1from clang.cindex import TranslationUnit
2
3def test_code_complete():
4    files = [('fake.c', """
5/// Aaa.
6int test1;
7
8/// Bbb.
9void test2(void);
10
11void f() {
12
13}
14""")]
15
16    tu = TranslationUnit.from_source('fake.c', ['-std=c99'], unsaved_files=files,
17            options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION)
18
19    cr = tu.codeComplete('fake.c', 9, 1, unsaved_files=files, include_brief_comments=True)
20    assert cr is not None
21    assert len(cr.diagnostics) == 0
22
23    completions = []
24    for c in cr.results:
25        completions.append(str(c))
26
27    expected = [
28      "{'int', ResultType} | {'test1', TypedText} || Priority: 50 || Availability: Available || Brief comment: Aaa.",
29      "{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 50 || Availability: Available || Brief comment: Bbb.",
30      "{'return', TypedText} || Priority: 40 || Availability: Available || Brief comment: None"
31    ]
32
33    for c in expected:
34        assert c in completions
35
36