2 from clang
.cindex
import Config
4 if "CLANG_LIBRARY_PATH" in os
.environ
:
5 Config
.set_library_path(os
.environ
["CLANG_LIBRARY_PATH"])
7 from clang
.cindex
import TranslationUnit
10 from .util
import skip_if_no_fspath
11 from .util
import str_to_path
14 class TestCodeCompletion(unittest
.TestCase
):
15 def check_completion_results(self
, cr
, expected
):
16 self
.assertIsNotNone(cr
)
17 self
.assertEqual(len(cr
.diagnostics
), 0)
19 completions
= [str(c
) for c
in cr
.results
]
22 self
.assertIn(c
, completions
)
24 def test_code_complete(self
):
42 tu
= TranslationUnit
.from_source(
46 options
=TranslationUnit
.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION
,
50 "fake.c", 9, 1, unsaved_files
=files
, include_brief_comments
=True
54 "{'int', ResultType} | {'test1', TypedText} || Priority: 50 || Availability: Available || Brief comment: Aaa.",
55 "{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 50 || Availability: Available || Brief comment: Bbb.",
56 "{'return', TypedText} | {';', SemiColon} || Priority: 40 || Availability: Available || Brief comment: None",
58 self
.check_completion_results(cr
, expected
)
61 def test_code_complete_pathlike(self
):
64 str_to_path("fake.c"),
79 tu
= TranslationUnit
.from_source(
80 str_to_path("fake.c"),
83 options
=TranslationUnit
.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION
,
87 str_to_path("fake.c"),
91 include_brief_comments
=True,
95 "{'int', ResultType} | {'test1', TypedText} || Priority: 50 || Availability: Available || Brief comment: Aaa.",
96 "{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 50 || Availability: Available || Brief comment: Bbb.",
97 "{'return', TypedText} | {';', SemiColon} || Priority: 40 || Availability: Available || Brief comment: None",
99 self
.check_completion_results(cr
, expected
)
101 def test_code_complete_availability(self
):
117 x.; // member is inaccessible
118 y.; // member is accessible
124 tu
= TranslationUnit
.from_source(
125 "fake.cpp", ["-std=c++98"], unsaved_files
=files
128 cr
= tu
.codeComplete("fake.cpp", 12, 5, unsaved_files
=files
)
131 "{'const', TypedText} || Priority: 50 || Availability: Available || Brief comment: None",
132 "{'volatile', TypedText} || Priority: 50 || Availability: Available || Brief comment: None",
133 "{'operator', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
134 "{'P', TypedText} || Priority: 50 || Availability: Available || Brief comment: None",
135 "{'Q', TypedText} || Priority: 50 || Availability: Available || Brief comment: None",
137 self
.check_completion_results(cr
, expected
)
139 cr
= tu
.codeComplete("fake.cpp", 13, 5, unsaved_files
=files
)
141 "{'P', TypedText} | {'::', Text} || Priority: 75 || Availability: Available || Brief comment: None",
142 "{'P &', ResultType} | {'operator=', TypedText} | {'(', LeftParen} | {'const P &', Placeholder} | {')', RightParen} || Priority: 79 || Availability: Available || Brief comment: None",
143 "{'int', ResultType} | {'member', TypedText} || Priority: 35 || Availability: NotAccessible || Brief comment: None",
144 "{'void', ResultType} | {'~P', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 79 || Availability: Available || Brief comment: None",
146 self
.check_completion_results(cr
, expected
)