test_comment.py 957 B

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