Debian Codegraph @

clang/bindings/python/tests/cindex/test_exception_specification_kind.py

raw
1 from clang.cindex import CursorKind, ExceptionSpecificationKind
2
3
4 import unittest
5
6 from .util import get_tu
7
8
9 def find_function_declarations(node, declarations=[]):
10 if node.kind == CursorKind.FUNCTION_DECL:
11 declarations.append(node)
12 for child in node.get_children():
13 declarations = find_function_declarations(child, declarations)
14 return declarations
15
16
17 class TestExceptionSpecificationKind(unittest.TestCase):
18 def test_exception_specification_kind(self):
19 source = """int square1(int x);
20 int square2(int x) noexcept;
21 int square3(int x) noexcept(noexcept(x * x));"""
22
23 tu = get_tu(source, lang="cpp", flags=["-std=c++14"])
24
25 declarations = find_function_declarations(tu.cursor)
26 expected = [
27 ("square1", ExceptionSpecificationKind.NONE),
28 ("square2", ExceptionSpecificationKind.BASIC_NOEXCEPT),
29 ("square3", ExceptionSpecificationKind.COMPUTED_NOEXCEPT),
30 ]
31 from_cursor = [
32 (node.spelling, node.exception_specification_kind) for node in declarations
33 ]
34 from_type = [
35 (node.spelling, node.type.get_exception_specification_kind())
36 for node in declarations
37 ]
38 self.assertListEqual(from_cursor, expected)
39 self.assertListEqual(from_type, expected)