diff --git a/src/ctags.cpp b/src/ctags.cpp index 17c8199..9a82a07 100644 --- a/src/ctags.cpp +++ b/src/ctags.cpp @@ -282,6 +282,7 @@ std::vector Ctags::get_locations(const boost::filesystem::path void Ctags::init_module(py::module &api) { py::class_ ctags(api, "Ctags"); py::class_(api, "Location") + .def(py::init<>()) .def_readwrite("file_path", &Ctags::Location::file_path) .def_readwrite("line", &Ctags::Location::line) .def_readwrite("index", &Ctags::Location::index) @@ -293,8 +294,6 @@ void Ctags::init_module(py::module &api) { ; ctags - .def_static("get_result", &Ctags::get_result, - py::arg("path")) .def_static("get_location", &Ctags::get_location, py::arg("line"), py::arg("markup")) @@ -304,4 +303,4 @@ void Ctags::init_module(py::module &api) { py::arg("type")) ; -} \ No newline at end of file +} diff --git a/tests/python_bindings/CMakeLists.txt b/tests/python_bindings/CMakeLists.txt index e66c281..a49ce81 100644 --- a/tests/python_bindings/CMakeLists.txt +++ b/tests/python_bindings/CMakeLists.txt @@ -23,3 +23,7 @@ add_test(pb_compile_commands_test pb_compile_commands_test) add_executable(pb_config_test Config_tests/config_test.cc $) target_link_libraries(pb_config_test test_suite) add_test(pb_config_test pb_config_test) + +add_executable(pb_ctags_test Ctags_tests/ctags_test.cc $) +target_link_libraries(pb_ctags_test test_suite) +add_test(pb_ctags_test pb_ctags_test) diff --git a/tests/python_bindings/Ctags_tests/ctags_test.cc b/tests/python_bindings/Ctags_tests/ctags_test.cc new file mode 100644 index 0000000..6d62afc --- /dev/null +++ b/tests/python_bindings/Ctags_tests/ctags_test.cc @@ -0,0 +1,39 @@ +#include "test_suite.h" +#include + +int main() { + auto &config = Config::get(); + config.project.ctags_command = "ctags"; +#ifdef _WIN32 + std::string slash = "\\"; + config.project.cmake.command = + "cmake -G\"MSYS Makefiles\" -DCMAKE_INSTALL_PREFIX=/mingw64"; +#else + auto slash = "/"; + config.project.cmake.command = "cmake"; +#endif + auto suite_name = "Ctags_tests"; + + { + auto doTest = [&](auto test) { + auto test_suite = suite(suite_name); + { + auto module = py::module::import("ctags_test"); + test_suite.has_assertion = false; + auto project_path = (test_suite.test_file_path / "cmake_project") + .make_preferred() + .string(); + try { + module.attr(test)(project_path, slash); + test_suite.has_assertion = true; + } + catch(const std::exception &error) { + std::cout << error.what(); + } + } + }; + + doTest("get_location"); + doTest("get_locations"); + } +} diff --git a/tests/python_bindings/Ctags_tests/ctags_test.py b/tests/python_bindings/Ctags_tests/ctags_test.py new file mode 100644 index 0000000..2f2e713 --- /dev/null +++ b/tests/python_bindings/Ctags_tests/ctags_test.py @@ -0,0 +1,27 @@ +from Jucipp import Ctags +from jucipp_test import assert_equal + +def get_location(a, b): + line = 'main main.cpp /^int main() { return 0; }$/;" line:1' + location = Ctags.get_location(line, False) + if location: + assert_equal('main.cpp', location.file_path) + assert_equal(0, location.line) + assert_equal(4, location.index) + assert_equal('main', location.symbol) + assert_equal('', location.scope) + assert_equal('int main() { return 0; }', location.source) + else: + raise ValueError('File path was empty') + +def get_locations(project_path, slash): + path = project_path + slash + 'main.cpp' + locations = Ctags.get_locations(project_path + slash + 'main.cpp', 'main', 'int ()') + assert_equal(len(locations), 1) + location = locations[0]; + assert_equal(path, location.file_path) + assert_equal(0, location.line) + assert_equal(4, location.index) + assert_equal('main', location.symbol) + assert_equal('', location.scope) + assert_equal('int main() { return 0; }', location.source)