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