xref: /llvm-project-15.0.7/clang/bindings/python/tests/cindex/test_cursor_kind.py (revision fb912657)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from clang.cindex import CursorKind
2
3def test_name():
4    assert CursorKind.UNEXPOSED_DECL.name is 'UNEXPOSED_DECL'
5
6def test_get_all_kinds():
7    assert CursorKind.UNEXPOSED_DECL in CursorKind.get_all_kinds()
8    assert CursorKind.TRANSLATION_UNIT in CursorKind.get_all_kinds()
9
10def test_kind_groups():
11    """Check that every kind classifies to exactly one group."""
12
13    assert CursorKind.UNEXPOSED_DECL.is_declaration()
14    assert CursorKind.TYPE_REF.is_reference()
15    assert CursorKind.DECL_REF_EXPR.is_expression()
16    assert CursorKind.UNEXPOSED_STMT.is_statement()
17    assert CursorKind.INVALID_FILE.is_invalid()
18
19    assert CursorKind.TRANSLATION_UNIT.is_translation_unit()
20    assert not CursorKind.TYPE_REF.is_translation_unit()
21
22    assert CursorKind.PREPROCESSING_DIRECTIVE.is_preprocessing()
23    assert not CursorKind.TYPE_REF.is_preprocessing()
24
25    assert CursorKind.UNEXPOSED_DECL.is_unexposed()
26    assert not CursorKind.TYPE_REF.is_unexposed()
27
28    for k in CursorKind.get_all_kinds():
29        group = [n for n in ('is_declaration', 'is_reference', 'is_expression',
30                             'is_statement', 'is_invalid', 'is_attribute')
31                 if getattr(k, n)()]
32
33        if k in (   CursorKind.TRANSLATION_UNIT,
34                    CursorKind.MACRO_DEFINITION,
35                    CursorKind.MACRO_INSTANTIATION,
36                    CursorKind.INCLUSION_DIRECTIVE,
37                    CursorKind.PREPROCESSING_DIRECTIVE):
38            assert len(group) == 0
39        else:
40            assert len(group) == 1
41

served by {OpenGrok

Last Index Update: Fri May 15 20:09:11 GMT 2026