diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff3527b..cc2d1dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,11 +4,12 @@ on: push: branches: - master - - testing + - /^feature/$/ pull_request: branches: - master + - /^feature/$/ jobs: clang_tests: diff --git a/.gitignore b/.gitignore index aae7f2c..5c1267c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ compile_commands.json .clang-format experiment/ +build/ +subprojects/* +!subprojects/*.wrap diff --git a/include/ss/converter.hpp b/include/ss/converter.hpp index 4c6c0c9..25be27c 100644 --- a/include/ss/converter.hpp +++ b/include/ss/converter.hpp @@ -9,9 +9,9 @@ #include namespace ss { -INIT_HAS_METHOD(tied); -INIT_HAS_METHOD(ss_valid); -INIT_HAS_METHOD(error); +INIT_HAS_METHOD(tied) +INIT_HAS_METHOD(ss_valid) +INIT_HAS_METHOD(error) //////////////// // replace validator @@ -147,7 +147,7 @@ public: no_void_validator_tup_t convert(const split_input& elems) { if constexpr (sizeof...(Ts) == 0 && is_instance_of::value) { - return convert_impl(elems, (T*){}); + return convert_impl(elems, static_cast(nullptr)); } else if constexpr (tied_class_v) { using arg_ref_tuple = @@ -156,7 +156,8 @@ public: using arg_tuple = typename apply_trait::type; - return to_object(convert_impl(elems, (arg_tuple*){})); + return to_object( + convert_impl(elems, static_cast(nullptr))); } else { return convert_impl(elems); } @@ -167,13 +168,9 @@ public: : bool_error_ == false; } - const std::string& error_msg() const { - return string_error_; - } + const std::string& error_msg() const { return string_error_; } - void set_error_mode(error_mode mode) { - error_mode_ = mode; - } + void set_error_mode(error_mode mode) { error_mode_ = mode; } // 'splits' string by given delimiter, returns vector of pairs which // contain the beginings and the ends of each column of the string @@ -286,9 +283,7 @@ private: return input_; } - bool no_match(const char* end, char delim) const { - return *end != delim; - } + bool no_match(const char* end, char delim) const { return *end != delim; } bool no_match(const char* end, const std::string& delim) const { return strncmp(end, delim.c_str(), delim.size()) != 0; @@ -361,7 +356,7 @@ private: no_void_validator_tup_t ret; extract_multiple<0, 0, Ts...>(ret, elems); return ret; - }; + } //////////////// // members diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index 6a4e807..a0ed111 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -181,7 +181,7 @@ public: using Ret = no_void_validator_tup_t; return try_invoke_and_make_composite< std::optional>(get_next(), std::forward(fun)); - }; + } // identical to try_next but returns composite with object instead of a // tuple @@ -189,7 +189,7 @@ public: composite> try_object(Fun&& fun = none{}) { return try_invoke_and_make_composite< std::optional>(get_object(), std::forward(fun)); - }; + } private: template diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..c59bd09 --- /dev/null +++ b/meson.build @@ -0,0 +1,8 @@ +project('ssp', 'cpp', + default_options : + ['warning_level=3', + 'cpp_std=c++17', + 'buildtype=debug']) + +includes = include_directories('include') +subdir('test') diff --git a/subprojects/doctest.wrap b/subprojects/doctest.wrap new file mode 100644 index 0000000..906440d --- /dev/null +++ b/subprojects/doctest.wrap @@ -0,0 +1,3 @@ +[wrap-git] +url = https://github.com/onqtam/doctest +revision = master diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 0000000..f6f43bc --- /dev/null +++ b/test/meson.build @@ -0,0 +1,18 @@ +test_sources = files([ + 'test_main.cpp', + 'test_converter.cpp', + 'test_parser.cpp', + 'test_extractions.cpp', + ]) + +doctest_proj = subproject('doctest') +doctest_dep = doctest_proj.get_variable('doctest_dep') + +test_exe = executable('test_ssp', + sources: test_sources, + dependencies: doctest_dep, + include_directories: includes, + cpp_args: '-lstdc++fs' + ) + +test('tests_ssp', test_exe) diff --git a/test/test_converter.cpp b/test/test_converter.cpp index dcea7f6..3e77ae7 100644 --- a/test/test_converter.cpp +++ b/test/test_converter.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST_CASE("testing split") { diff --git a/test/test_extractions.cpp b/test/test_extractions.cpp index 564ac86..8b0dbd7 100644 --- a/test/test_extractions.cpp +++ b/test/test_extractions.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include constexpr auto eps = 0.000001; diff --git a/test/test_main.cpp b/test/test_main.cpp new file mode 100644 index 0000000..b8e3a4b --- /dev/null +++ b/test/test_main.cpp @@ -0,0 +1,2 @@ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include diff --git a/test/test_parser.cpp b/test/test_parser.cpp index cb02cfc..2706103 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -1,17 +1,15 @@ -#include -#include #include +#include #include +#include +#include struct unique_file_name { const std::string name; - unique_file_name() : name{std::tmpnam(nullptr)} { - } + unique_file_name() : name{std::tmpnam(nullptr)} {} - ~unique_file_name() { - std::filesystem::remove(name); - } + ~unique_file_name() { std::filesystem::remove(name); } }; struct X { @@ -27,9 +25,7 @@ struct X { .append(delim) .append(s); } - auto tied() const { - return std::tie(i, d, s); - } + auto tied() const { return std::tie(i, d, s); } }; template @@ -165,13 +161,10 @@ struct test_struct { int i; double d; char c; - auto tied() { - return std::tie(i, d, c); - } + auto tied() { return std::tie(i, d, c); } }; -void expect_test_struct(const test_struct&) { -} +void expect_test_struct(const test_struct&) {} // various scenarios TEST_CASE("testing composite conversion") { @@ -393,9 +386,7 @@ struct my_string { my_string() = default; - ~my_string() { - delete[] data; - } + ~my_string() { delete[] data; } // make sure no object is copied my_string(const my_string&) = delete; @@ -426,9 +417,7 @@ struct xyz { my_string x; my_string y; my_string z; - auto tied() { - return std::tie(x, y, z); - } + auto tied() { return std::tie(x, y, z); } }; TEST_CASE("testing the moving of parsed values") {