Browse Source

test all config options and fix two bugs in module

python
Jørgen Lien Sellæg 7 years ago committed by Jørgen Sverre Lien Sellæg
parent
commit
6afde6fe37
  1. 3
      src/config_module.cc
  2. 82
      tests/python_bindings/Config_tests/config_test.cc
  3. 88
      tests/python_bindings/Config_tests/config_test.py

3
src/config_module.cc

@ -1,5 +1,6 @@
#include "config.h"
#include <pybind11/stl.h>
#include "python_type_casters.h"
void Config::init_module(py::module &api) {
py::class_<Config, std::unique_ptr<Config, py::nodelete>> config(api, "Config");
@ -51,7 +52,7 @@ void Config::init_module(py::module &api) {
py::class_<Config::Source::DocumentationSearch>(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

82
tests/python_bindings/Config_tests/config_test.cc

@ -2,13 +2,89 @@
#include <iostream>
int main() {
const auto suite_name = "Config_tests";
const auto doTest = [&](const std::string &test, const std::function<void(Config & config)> &assertions) {
auto &config = Config::get();
auto suite_name = "Config_tests";
suite test_suite(suite_name);
try {
py::module::import("config_test");
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){
}
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");
});
}

88
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
def theme():
theme = Config.Theme()
theme.name = "Star Wars"
theme.variant = "Instrumental"
theme.font = "Imperial"
config = Config()
config.theme = theme
def terminal():
terminal = Config.Terminal()
terminal.font = "Comic Sans"
terminal.history_size = 3
Config().terminal = terminal
menu = Config.Menu()
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
menu.keys = {
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"

Loading…
Cancel
Save