Debian Codegraph @

clang/bindings/python/tests/cindex/test_comment.py

raw
1 from clang.cindex import TranslationUnit
2
3
4 import unittest
5
6 from .util import get_cursor
7
8
9 class TestComment(unittest.TestCase):
10 def test_comment(self):
11 files = [
12 (
13 "fake.c",
14 """
15 /// Aaa.
16 int test1;
17
18 /// Bbb.
19 /// x
20 void test2(void);
21
22 void f() {
23
24 }
25 """,
26 )
27 ]
28 # make a comment-aware TU
29 tu = TranslationUnit.from_source(
30 "fake.c",
31 ["-std=c99"],
32 unsaved_files=files,
33 options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION,
34 )
35 test1 = get_cursor(tu, "test1")
36 self.assertIsNotNone(test1, "Could not find test1.")
37 self.assertTrue(test1.type.is_pod())
38 raw = test1.raw_comment
39 brief = test1.brief_comment
40 self.assertEqual(raw, """/// Aaa.""")
41 self.assertEqual(brief, """Aaa.""")
42
43 test2 = get_cursor(tu, "test2")
44 raw = test2.raw_comment
45 brief = test2.brief_comment
46 self.assertEqual(raw, """/// Bbb.\n/// x""")
47 self.assertEqual(brief, """Bbb. x""")
48
49 f = get_cursor(tu, "f")
50 raw = f.raw_comment
51 brief = f.brief_comment
52 self.assertEqual(raw, "")
53 self.assertEqual(brief, "")