From 3df4bf18cebd2168b4e635e0e47b357f448c9d14 Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 14 Apr 2020 09:56:07 +0200 Subject: [PATCH] Added ctags_grep_test --- tests/CMakeLists.txt | 5 ++ tests/ctags_grep_test.cc | 169 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 tests/ctags_grep_test.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 420bb5f..29063bd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -76,3 +76,8 @@ endif() add_executable(git_test git_test.cc $) target_link_libraries(git_test juci_shared) add_test(git_test git_test) + +add_executable(ctags_grep_test ctags_grep_test.cc $) +target_link_libraries(ctags_grep_test juci_shared) +add_test(ctags_grep_test ctags_grep_test) + diff --git a/tests/ctags_grep_test.cc b/tests/ctags_grep_test.cc new file mode 100644 index 0000000..737072a --- /dev/null +++ b/tests/ctags_grep_test.cc @@ -0,0 +1,169 @@ +#include "config.h" +#include "ctags.h" +#include "grep.h" +#include +#include + +void ctags_grep_test_function() { +} + +int main() { + auto app = Gtk::Application::create(); + Config::get().project.ctags_command = "ctags"; + Config::get().project.grep_command = "grep"; + Config::get().project.debug_build_path = "build"; + + auto tests_path = boost::filesystem::canonical(JUCI_TESTS_PATH); + + // Ctags tests + { + auto result = Ctags::get_result(tests_path); + g_assert(result.first == tests_path.parent_path()); + bool found = false; + std::string line; + while(std::getline(*result.second, line)) { + if(line.find("ctags_grep_test_function") != std::string::npos) { + { + auto location = Ctags::get_location(line, false); + g_assert(location.source == "void ctags_grep_test_function() {"); + g_assert(result.first / location.file_path == tests_path / "ctags_grep_test.cc"); + g_assert_cmpint(location.line, ==, 6); + g_assert_cmpint(location.index, ==, 5); + g_assert(location.symbol == "ctags_grep_test_function"); + g_assert(location.scope.empty()); + g_assert(location.kind.empty()); + } + { + auto location = Ctags::get_location(line, true); + g_assert(location.source == "void ctags_grep_test_function() {"); + g_assert(result.first / location.file_path == tests_path / "ctags_grep_test.cc"); + g_assert_cmpint(location.line, ==, 6); + g_assert_cmpint(location.index, ==, 5); + g_assert(location.symbol == "ctags_grep_test_function"); + g_assert(location.scope.empty()); + g_assert(location.kind.empty()); + } + found = true; + break; + } + } + g_assert(found == true); + } + { + auto result = Ctags::get_result(tests_path, true); + g_assert(result.first == tests_path.parent_path()); + bool found = false; + std::string line; + while(std::getline(*result.second, line)) { + if(line.find("ctags_grep_test_function") != std::string::npos) { + { + auto location = Ctags::get_location(line, false, true); + g_assert(location.source == "void ctags_grep_test_function() {"); + g_assert(result.first / location.file_path == tests_path / "ctags_grep_test.cc"); + g_assert_cmpint(location.line, ==, 6); + g_assert_cmpint(location.index, ==, 5); + g_assert(location.symbol == "ctags_grep_test_function"); + g_assert(location.scope.empty()); + g_assert(location.kind == "function"); + } + { + auto location = Ctags::get_location(line, true, true); + g_assert(location.source == "void ctags_grep_test_function() {"); + g_assert(result.first / location.file_path == tests_path / "ctags_grep_test.cc"); + g_assert_cmpint(location.line, ==, 6); + g_assert_cmpint(location.index, ==, 5); + g_assert(location.symbol == "ctags_grep_test_function"); + g_assert(location.scope.empty()); + g_assert(location.kind == "function"); + } + found = true; + break; + } + } + g_assert(found == true); + } + + // Grep tests + { + auto result = Grep::get_result(tests_path, "ctags_grep_test_function", true, false); + g_assert(result.first == tests_path.parent_path()); + bool found = false; + std::string line; + while(std::getline(*result.second, line)) { + if(line.find("ctags_grep_test_function") != std::string::npos) { + { + auto location = Grep::get_location(line, true, true); + g_assert(location.markup == "tests/ctags_grep_test.cc:7:void ctags_grep_test_function() {"); + g_assert(result.first / location.file_path == tests_path / "ctags_grep_test.cc"); + g_assert_cmpint(location.line, ==, 6); + g_assert_cmpint(location.offset, ==, 5); + { + auto location2 = Grep::get_location(location.markup, false, true); + g_assert(location2.markup == "tests/ctags_grep_test.cc:7:void ctags_grep_test_function() {"); + g_assert(result.first / location2.file_path == tests_path / "ctags_grep_test.cc"); + g_assert_cmpint(location2.line, ==, 6); + g_assert_cmpint(location2.offset, ==, 5); + } + } + { + auto location = Grep::get_location(line, true, false); + g_assert(location.markup == "tests/ctags_grep_test.cc:7:void ctags_grep_test_function() {"); + g_assert(result.first / location.file_path == tests_path / "ctags_grep_test.cc"); + g_assert_cmpint(location.line, ==, 6); + g_assert_cmpint(location.offset, ==, 0); + { + auto location2 = Grep::get_location(location.markup, false, false); + g_assert(location2.markup == "tests/ctags_grep_test.cc:7:void ctags_grep_test_function() {"); + g_assert(result.first / location2.file_path == tests_path / "ctags_grep_test.cc"); + g_assert_cmpint(location2.line, ==, 6); + g_assert_cmpint(location2.offset, ==, 0); + } + } + { + auto location = Grep::get_location(line, true, true, (boost::filesystem::path("tests") / "ctags_grep_test.cc").string()); + g_assert(location.markup == "tests/ctags_grep_test.cc:7:void ctags_grep_test_function() {"); + g_assert(result.first / location.file_path == tests_path / "ctags_grep_test.cc"); + g_assert(location); + g_assert_cmpint(location.line, ==, 6); + g_assert_cmpint(location.offset, ==, 5); + } + { + auto location = Grep::get_location(line, true, true, "CMakeLists.txt"); + g_assert(location.markup == "tests/ctags_grep_test.cc:7:void ctags_grep_test_function() {"); + g_assert(location.file_path.empty()); + g_assert(!location); + } + found = true; + break; + } + else + g_assert(false); + } + g_assert(found == true); + } + { + auto pattern = std::string("C") + "tags_grep_test_function"; + { + auto result = Grep::get_result(tests_path, pattern, true, false); + g_assert(result.first == tests_path.parent_path()); + bool found = false; + std::string line; + while(std::getline(*result.second, line)) { + if(line.find("ctags_grep_test_function") != std::string::npos) + found = true; + } + g_assert(found == false); + } + { + auto result = Grep::get_result(tests_path, pattern, false, false); + g_assert(result.first == tests_path.parent_path()); + bool found = false; + std::string line; + while(std::getline(*result.second, line)) { + if(line.find("ctags_grep_test_function") != std::string::npos) + found = true; + } + g_assert(found == true); + } + } +}