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