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    kinds = CursorKind.get_all_kinds()
8    assert CursorKind.UNEXPOSED_DECL in kinds
9    assert CursorKind.TRANSLATION_UNIT in kinds
10    assert CursorKind.VARIABLE_REF in kinds
11    assert CursorKind.LAMBDA_EXPR in kinds
12    assert CursorKind.OBJ_BOOL_LITERAL_EXPR in kinds
13    assert CursorKind.OBJ_SELF_EXPR in kinds
14    assert CursorKind.MS_ASM_STMT in kinds
15    assert CursorKind.MODULE_IMPORT_DECL in kinds
16
17def test_kind_groups():
18    """Check that every kind classifies to exactly one group."""
19
20    assert CursorKind.UNEXPOSED_DECL.is_declaration()
21    assert CursorKind.TYPE_REF.is_reference()
22    assert CursorKind.DECL_REF_EXPR.is_expression()
23    assert CursorKind.UNEXPOSED_STMT.is_statement()
24    assert CursorKind.INVALID_FILE.is_invalid()
25
26    assert CursorKind.TRANSLATION_UNIT.is_translation_unit()
27    assert not CursorKind.TYPE_REF.is_translation_unit()
28
29    assert CursorKind.PREPROCESSING_DIRECTIVE.is_preprocessing()
30    assert not CursorKind.TYPE_REF.is_preprocessing()
31
32    assert CursorKind.UNEXPOSED_DECL.is_unexposed()
33    assert not CursorKind.TYPE_REF.is_unexposed()
34
35    for k in CursorKind.get_all_kinds():
36        group = [n for n in ('is_declaration', 'is_reference', 'is_expression',
37                             'is_statement', 'is_invalid', 'is_attribute')
38                 if getattr(k, n)()]
39
40        if k in (   CursorKind.TRANSLATION_UNIT,
41                    CursorKind.MACRO_DEFINITION,
42                    CursorKind.MACRO_INSTANTIATION,
43                    CursorKind.INCLUSION_DIRECTIVE,
44                    CursorKind.PREPROCESSING_DIRECTIVE):
45            assert len(group) == 0
46        else:
47            assert len(group) == 1
48