[C++20] [Modules] Fix may-be incorrect ADL for module local entities (#123931)
[llvm-project.git] / clang / bindings / python / tests / cindex / test_cursor_kind.py
blob3b693ff45cfd4422ba1e5a4c0a65b788c955e315
1 import os
3 from clang.cindex import Config, CursorKind
5 if "CLANG_LIBRARY_PATH" in os.environ:
6 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
8 import unittest
11 class TestCursorKind(unittest.TestCase):
12 def test_name(self):
13 self.assertEqual(CursorKind.UNEXPOSED_DECL.name, "UNEXPOSED_DECL")
15 def test_get_all_kinds(self):
16 kinds = CursorKind.get_all_kinds()
17 self.assertIn(CursorKind.UNEXPOSED_DECL, kinds)
18 self.assertIn(CursorKind.TRANSLATION_UNIT, kinds)
19 self.assertIn(CursorKind.VARIABLE_REF, kinds)
20 self.assertIn(CursorKind.LAMBDA_EXPR, kinds)
21 self.assertIn(CursorKind.OBJ_BOOL_LITERAL_EXPR, kinds)
22 self.assertIn(CursorKind.OBJ_SELF_EXPR, kinds)
23 self.assertIn(CursorKind.MS_ASM_STMT, kinds)
24 self.assertIn(CursorKind.MODULE_IMPORT_DECL, kinds)
25 self.assertIn(CursorKind.TYPE_ALIAS_TEMPLATE_DECL, kinds)
27 def test_kind_groups(self):
28 """Check that every kind classifies to exactly one group."""
30 self.assertTrue(CursorKind.UNEXPOSED_DECL.is_declaration())
31 self.assertTrue(CursorKind.TYPE_REF.is_reference())
32 self.assertTrue(CursorKind.DECL_REF_EXPR.is_expression())
33 self.assertTrue(CursorKind.UNEXPOSED_STMT.is_statement())
34 self.assertTrue(CursorKind.INVALID_FILE.is_invalid())
36 self.assertTrue(CursorKind.TRANSLATION_UNIT.is_translation_unit())
37 self.assertFalse(CursorKind.TYPE_REF.is_translation_unit())
39 self.assertTrue(CursorKind.PREPROCESSING_DIRECTIVE.is_preprocessing())
40 self.assertFalse(CursorKind.TYPE_REF.is_preprocessing())
42 self.assertTrue(CursorKind.UNEXPOSED_DECL.is_unexposed())
43 self.assertFalse(CursorKind.TYPE_REF.is_unexposed())
45 for k in CursorKind.get_all_kinds():
46 group = [
48 for n in (
49 "is_declaration",
50 "is_reference",
51 "is_expression",
52 "is_statement",
53 "is_invalid",
54 "is_attribute",
56 if getattr(k, n)()
59 if k in (
60 CursorKind.TRANSLATION_UNIT,
61 CursorKind.MACRO_DEFINITION,
62 CursorKind.MACRO_INSTANTIATION,
63 CursorKind.INCLUSION_DIRECTIVE,
64 CursorKind.PREPROCESSING_DIRECTIVE,
65 CursorKind.OVERLOAD_CANDIDATE,
67 self.assertEqual(len(group), 0)
68 else:
69 self.assertEqual(len(group), 1)