diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:44:14 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:44:14 +0000 |
commit | 2b6b257f4e5503a7a2675bdb8735693db769f75c (patch) | |
tree | e85e046ae7003fe3bcc8b5454cd0fa3f7407b470 /bindings/python/tests/cindex | |
parent | b4348ed0b7e90c0831b925fbee00b5f179a99796 (diff) |
Notes
Diffstat (limited to 'bindings/python/tests/cindex')
-rw-r--r-- | bindings/python/tests/cindex/test_cdb.py | 17 | ||||
-rw-r--r-- | bindings/python/tests/cindex/test_cursor.py | 82 | ||||
-rw-r--r-- | bindings/python/tests/cindex/test_diagnostics.py | 12 |
3 files changed, 106 insertions, 5 deletions
diff --git a/bindings/python/tests/cindex/test_cdb.py b/bindings/python/tests/cindex/test_cdb.py index e1f824f797f22..35fe3e108a12e 100644 --- a/bindings/python/tests/cindex/test_cdb.py +++ b/bindings/python/tests/cindex/test_cdb.py @@ -38,27 +38,34 @@ def test_all_compilecommand(): cmds = cdb.getAllCompileCommands() assert len(cmds) == 3 expected = [ + { 'wd': '/home/john.doe/MyProject', + 'file': '/home/john.doe/MyProject/project.cpp', + 'line': ['clang++', '-o', 'project.o', '-c', + '/home/john.doe/MyProject/project.cpp']}, { 'wd': '/home/john.doe/MyProjectA', + 'file': '/home/john.doe/MyProject/project2.cpp', 'line': ['clang++', '-o', 'project2.o', '-c', '/home/john.doe/MyProject/project2.cpp']}, { 'wd': '/home/john.doe/MyProjectB', + 'file': '/home/john.doe/MyProject/project2.cpp', 'line': ['clang++', '-DFEATURE=1', '-o', 'project2-feature.o', '-c', '/home/john.doe/MyProject/project2.cpp']}, - { 'wd': '/home/john.doe/MyProject', - 'line': ['clang++', '-o', 'project.o', '-c', - '/home/john.doe/MyProject/project.cpp']} + ] for i in range(len(cmds)): assert cmds[i].directory == expected[i]['wd'] + assert cmds[i].filename == expected[i]['file'] for arg, exp in zip(cmds[i].arguments, expected[i]['line']): assert arg == exp def test_1_compilecommand(): """Check file with single compile command""" cdb = CompilationDatabase.fromDirectory(kInputsDir) - cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp') + file = '/home/john.doe/MyProject/project.cpp' + cmds = cdb.getCompileCommands(file) assert len(cmds) == 1 - assert cmds[0].directory == '/home/john.doe/MyProject' + assert cmds[0].directory == os.path.dirname(file) + assert cmds[0].filename == file expected = [ 'clang++', '-o', 'project.o', '-c', '/home/john.doe/MyProject/project.cpp'] for arg, exp in zip(cmds[0].arguments, expected): diff --git a/bindings/python/tests/cindex/test_cursor.py b/bindings/python/tests/cindex/test_cursor.py index c5ea50516ad21..6c8230d4283c4 100644 --- a/bindings/python/tests/cindex/test_cursor.py +++ b/bindings/python/tests/cindex/test_cursor.py @@ -112,6 +112,88 @@ def test_is_const_method(): assert foo.is_const_method() assert not bar.is_const_method() +def test_is_converting_constructor(): + """Ensure Cursor.is_converting_constructor works.""" + source = 'class X { explicit X(int); X(double); X(); };' + tu = get_tu(source, lang='cpp') + + xs = get_cursors(tu, 'X') + + assert len(xs) == 4 + assert xs[0].kind == CursorKind.CLASS_DECL + cs = xs[1:] + assert cs[0].kind == CursorKind.CONSTRUCTOR + assert cs[1].kind == CursorKind.CONSTRUCTOR + assert cs[2].kind == CursorKind.CONSTRUCTOR + + assert not cs[0].is_converting_constructor() + assert cs[1].is_converting_constructor() + assert not cs[2].is_converting_constructor() + + +def test_is_copy_constructor(): + """Ensure Cursor.is_copy_constructor works.""" + source = 'class X { X(); X(const X&); X(X&&); };' + tu = get_tu(source, lang='cpp') + + xs = get_cursors(tu, 'X') + assert xs[0].kind == CursorKind.CLASS_DECL + cs = xs[1:] + assert cs[0].kind == CursorKind.CONSTRUCTOR + assert cs[1].kind == CursorKind.CONSTRUCTOR + assert cs[2].kind == CursorKind.CONSTRUCTOR + + assert not cs[0].is_copy_constructor() + assert cs[1].is_copy_constructor() + assert not cs[2].is_copy_constructor() + +def test_is_default_constructor(): + """Ensure Cursor.is_default_constructor works.""" + source = 'class X { X(); X(int); };' + tu = get_tu(source, lang='cpp') + + xs = get_cursors(tu, 'X') + assert xs[0].kind == CursorKind.CLASS_DECL + cs = xs[1:] + assert cs[0].kind == CursorKind.CONSTRUCTOR + assert cs[1].kind == CursorKind.CONSTRUCTOR + + assert cs[0].is_default_constructor() + assert not cs[1].is_default_constructor() + +def test_is_move_constructor(): + """Ensure Cursor.is_move_constructor works.""" + source = 'class X { X(); X(const X&); X(X&&); };' + tu = get_tu(source, lang='cpp') + + xs = get_cursors(tu, 'X') + assert xs[0].kind == CursorKind.CLASS_DECL + cs = xs[1:] + assert cs[0].kind == CursorKind.CONSTRUCTOR + assert cs[1].kind == CursorKind.CONSTRUCTOR + assert cs[2].kind == CursorKind.CONSTRUCTOR + + assert not cs[0].is_move_constructor() + assert not cs[1].is_move_constructor() + assert cs[2].is_move_constructor() + +def test_is_default_method(): + """Ensure Cursor.is_default_method works.""" + source = 'class X { X() = default; }; class Y { Y(); };' + tu = get_tu(source, lang='cpp') + + xs = get_cursors(tu, 'X') + ys = get_cursors(tu, 'Y') + + assert len(xs) == 2 + assert len(ys) == 2 + + xc = xs[1] + yc = ys[1] + + assert xc.is_default_method() + assert not yc.is_default_method() + def test_is_mutable_field(): """Ensure Cursor.is_mutable_field works.""" source = 'class X { int x_; mutable int y_; };' diff --git a/bindings/python/tests/cindex/test_diagnostics.py b/bindings/python/tests/cindex/test_diagnostics.py index 48ab6176fd1df..ba6e545e8b1ab 100644 --- a/bindings/python/tests/cindex/test_diagnostics.py +++ b/bindings/python/tests/cindex/test_diagnostics.py @@ -80,3 +80,15 @@ def test_diagnostic_option(): assert d.option == '-Wunused-parameter' assert d.disable_option == '-Wno-unused-parameter' + +def test_diagnostic_children(): + tu = get_tu('void f(int x) {} void g() { f(); }') + assert len(tu.diagnostics) == 1 + d = tu.diagnostics[0] + + children = d.children + assert len(children) == 1 + assert children[0].severity == Diagnostic.Note + assert children[0].spelling.endswith('declared here') + assert children[0].location.line == 1 + assert children[0].location.column == 1 |