From 6afde6fe372076a1948c7a5b00bb9e5c107cf660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sat, 25 May 2019 14:20:26 +0200 Subject: [PATCH] test all config options and fix two bugs in module --- src/config_module.cc | 3 +- .../Config_tests/config_test.cc | 94 +++++++++++++++++-- .../Config_tests/config_test.py | 90 +++++++++++++++++- 3 files changed, 172 insertions(+), 15 deletions(-) diff --git a/src/config_module.cc b/src/config_module.cc index c6f66c8..902a9aa 100644 --- a/src/config_module.cc +++ b/src/config_module.cc @@ -1,5 +1,6 @@ #include "config.h" #include +#include "python_type_casters.h" void Config::init_module(py::module &api) { py::class_> config(api, "Config"); @@ -51,7 +52,7 @@ void Config::init_module(py::module &api) { py::class_(source, "DocumentationSearch") .def(py::init()) .def_readwrite("separator", &Config::Source::DocumentationSearch::separator) - .def_readwrite("compile_command", &Config::Source::DocumentationSearch::queries) + .def_readwrite("queries", &Config::Source::DocumentationSearch::queries) ; source diff --git a/tests/python_bindings/Config_tests/config_test.cc b/tests/python_bindings/Config_tests/config_test.cc index 601a2d4..29c6b79 100644 --- a/tests/python_bindings/Config_tests/config_test.cc +++ b/tests/python_bindings/Config_tests/config_test.cc @@ -2,13 +2,89 @@ #include int main() { - auto &config = Config::get(); - auto suite_name = "Config_tests"; - suite test_suite(suite_name); - try { - py::module::import("config_test"); - test_suite.has_assertion = true; - } catch(const py::error_already_set &error){ - std::cout << error.what(); - } + const auto suite_name = "Config_tests"; + const auto doTest = [&](const std::string &test, const std::function &assertions) { + auto &config = Config::get(); + suite test_suite(suite_name); + try { + auto module = py::module::import("config_test"); + module.attr(test.c_str())(); + assertions(config); + test_suite.has_assertion = true; + } + catch(const py::error_already_set &error) { + std::cout << error.what(); + } + }; + + doTest("menu", [](Config &config) { + g_assert_cmpstr(config.menu.keys.at("key").c_str(), ==, "value"); + }); + + doTest("theme", [](Config &config) { + g_assert_cmpstr(config.theme.name.c_str(), ==, "Star Wars"); + g_assert_cmpstr(config.theme.variant.c_str(), ==, "Instrumental"); + g_assert_cmpstr(config.theme.font.c_str(), ==, "Imperial"); + }); + + doTest("terminal", [](Config &config) { + g_assert_cmpstr(config.terminal.font.c_str(), ==, "Comic Sans"); + g_assert_cmpuint(config.terminal.history_size, ==, 3); + }); + + doTest("project", [](Config &config) { + g_assert_cmpstr(config.project.default_build_path.c_str(), ==, "/build"); + g_assert_cmpstr(config.project.debug_build_path.c_str(), ==, "/debug"); + g_assert_cmpstr(config.project.meson.command.c_str(), ==, "meson"); + g_assert_cmpstr(config.project.meson.compile_command.c_str(), ==, "meson --build"); + g_assert_cmpstr(config.project.cmake.command.c_str(), ==, "cmake"); + g_assert_cmpstr(config.project.cmake.compile_command.c_str(), ==, "cmake --build"); + g_assert_true(config.project.save_on_compile_or_run); + g_assert_false(config.project.clear_terminal_on_compile); + g_assert_cmpstr(config.project.ctags_command.c_str(), ==, "ctags"); + g_assert_cmpstr(config.project.python_command.c_str(), ==, "python"); + }); + + doTest("source", [](Config &config) { + g_assert_cmpstr(config.source.style.c_str(), ==, "Classical"); + g_assert_cmpstr(config.source.font.c_str(), ==, "Monospaced"); + g_assert_cmpstr(config.source.spellcheck_language.c_str(), ==, "Klingon"); + g_assert_false(config.source.cleanup_whitespace_characters); + g_assert_cmpstr(config.source.show_whitespace_characters.c_str(), ==, "no"); + g_assert_false(config.source.format_style_on_save); + g_assert_false(config.source.format_style_on_save_if_style_file_found); + g_assert_false(config.source.smart_inserts); + g_assert_false(config.source.show_map); + g_assert_cmpstr(config.source.map_font_size.c_str(), ==, "10px"); + g_assert_false(config.source.show_git_diff); + g_assert_false(config.source.show_background_pattern); + g_assert_false(config.source.show_right_margin); + g_assert_cmpuint(config.source.right_margin_position, ==, 10); + g_assert_false(config.source.auto_tab_char_and_size); + g_assert_cmpint(config.source.default_tab_char, ==, 'c'); + g_assert_cmpuint(config.source.default_tab_size, ==, 1); + g_assert_false(config.source.tab_indents_line); + g_assert_false(config.source.wrap_lines); + g_assert_false(config.source.highlight_current_line); + g_assert_false(config.source.show_line_numbers); + g_assert_false(config.source.enable_multiple_cursors); + g_assert_false(config.source.auto_reload_changed_files); + g_assert_cmpstr(config.source.clang_format_style.c_str(), ==, "CFS"); + g_assert_cmpuint(config.source.clang_usages_threads, ==, 1); + g_assert_cmpuint(config.source.documentation_searches.size(), ==, 1); + auto ds = config.source.documentation_searches.at("cpp"); + g_assert_cmpstr(ds.separator.c_str(), ==, "::"); + g_assert_cmpint(ds.queries.size(), ==, 1); + g_assert_cmpstr(ds.queries.at("key").c_str(), ==, "value"); + }); + + doTest("log", [](Config &config) { + g_assert_true(config.log.libclang); + g_assert_false(config.log.language_server); + }); + + doTest("cfg", [](Config &config) { + g_assert_cmpstr(config.home_juci_path.c_str(), ==, "/away"); + g_assert_cmpstr(config.home_path.c_str(), ==, "/home"); + }); } diff --git a/tests/python_bindings/Config_tests/config_test.py b/tests/python_bindings/Config_tests/config_test.py index 468c0c8..55b5629 100644 --- a/tests/python_bindings/Config_tests/config_test.py +++ b/tests/python_bindings/Config_tests/config_test.py @@ -1,9 +1,89 @@ from Jucipp import Config -config = Config() +def menu(): + config = Config() + menu = Config.Menu() + menu.keys = { + 'key': 'value', + } + config.menu = menu -menu = Config.Menu() +def theme(): + theme = Config.Theme() + theme.name = "Star Wars" + theme.variant = "Instrumental" + theme.font = "Imperial" + config = Config() + config.theme = theme -menu.keys = { - 'key': 'value', -} \ No newline at end of file +def terminal(): + terminal = Config.Terminal() + terminal.font = "Comic Sans" + terminal.history_size = 3 + Config().terminal = terminal + +def project(): + project = Config.Project() + project.default_build_path = "/build" + project.debug_build_path = "/debug" + meson = Config.Project.Meson() + meson.command = "meson" + meson.compile_command = "meson --build" + cmake = Config.Project.CMake() + cmake.command = "cmake" + cmake.compile_command = "cmake --build" + project.meson = meson + project.cmake = cmake + project.save_on_compile_or_run = True + project.clear_terminal_on_compile = False + project.ctags_command = "ctags" + project.python_command = "python" + Config().project = project + +def source(): + source = Config.Source() + source.style = "Classical" + source.font = "Monospaced" + source.spellcheck_language = "Klingon" + source.cleanup_whitespace_characters = False + source.show_whitespace_characters = "no" + source.format_style_on_save = False + source.format_style_on_save_if_style_file_found = False + source.smart_inserts = False + source.show_map = False + source.map_font_size = "10px" + source.show_git_diff = False + source.show_background_pattern = False + source.show_right_margin = False + source.right_margin_position = 10 + source.auto_tab_char_and_size = False + source.default_tab_char = "c" + source.default_tab_size = 1 + source.tab_indents_line = False + source.wrap_lines = False + source.highlight_current_line = False + source.show_line_numbers = False + source.enable_multiple_cursors = False + source.auto_reload_changed_files = False + source.clang_format_style = "CFS" + source.clang_usages_threads = 1 + documentation_search = Config.Source.DocumentationSearch() + documentation_search.separator = '::' + documentation_search.queries = { + 'key': 'value', + } + source.documentation_searches = { + 'cpp' : documentation_search + } + Config().source = source + +def log(): + log = Config.Log() + log.libclang = True + log.language_server = False + Config().log = log + +def cfg(): + config = Config() + config.home_path = "/home" + config.home_juci_path = "/away"