mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
304ca6ef0f | ||
| 103ff33f21 | |||
|
|
8b928de086 | ||
| 6edce88d79 | |||
|
|
6196f7796b | ||
| 5672aa635e | |||
| 3eefac93b1 | |||
| 774f452689 | |||
| 448066b173 | |||
|
|
a7eca6064a | ||
| a4ecbd4dc8 | |||
|
|
a9e9783e6a | ||
| 04edf1e532 | |||
|
|
8dcb69aa2c | ||
| db2a72c18b | |||
|
|
0e28a06799 | ||
| 2218b01b81 | |||
| f777b04eb8 | |||
| 7831bbd735 | |||
| 6efb39b2db | |||
| f2b49e6d6c | |||
| 5cb3c65b24 |
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(
|
||||
ssp
|
||||
VERSION 0.0.1
|
||||
DESCRIPTION "Static split parser"
|
||||
VERSION 1.4.0
|
||||
DESCRIPTION "csv parser"
|
||||
HOMEPAGE_URL "https://github.com/red0124/ssp"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
@@ -11,22 +11,23 @@ project(
|
||||
# ---- Warning guard ----
|
||||
|
||||
# Protect dependents from this project's warnings if the guard isn't disabled
|
||||
set(ssp_warning_guard SYSTEM)
|
||||
if(ssp_INCLUDE_WITHOUT_SYSTEM)
|
||||
set(ssp_warning_guard "")
|
||||
set(SSP_WARNING_GUARD SYSTEM)
|
||||
if(SSP_INCLUDE_WITHOUT_SYSTEM)
|
||||
set(SSP_WARNING_GUARD "")
|
||||
endif()
|
||||
|
||||
# ---- Dependencies ----
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
fast_float
|
||||
GIT_REPOSITORY https://github.com/red0124/fast_float.git
|
||||
GIT_TAG origin/meson
|
||||
GIT_SHALLOW TRUE)
|
||||
fetchcontent_declare(
|
||||
fast_float
|
||||
GIT_REPOSITORY https://github.com/red0124/fast_float.git
|
||||
GIT_TAG origin/meson
|
||||
GIT_SHALLOW TRUE
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(fast_float)
|
||||
set(fast_float_source_dir "${FETCHCONTENT_BASE_DIR}/fast_float-src")
|
||||
fetchcontent_makeavailable(fast_float)
|
||||
set(FAST_FLOAT_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/fast_float-src")
|
||||
|
||||
# ---- Declare library ----
|
||||
|
||||
@@ -35,10 +36,10 @@ add_library(ssp::ssp ALIAS ssp)
|
||||
|
||||
target_include_directories(
|
||||
ssp
|
||||
${ssp_warning_guard}
|
||||
${SSP_WARNING_GUARD}
|
||||
INTERFACE
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/fast_float>"
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/fast_float>"
|
||||
)
|
||||
|
||||
target_compile_features(ssp INTERFACE cxx_std_17)
|
||||
@@ -46,8 +47,8 @@ target_compile_features(ssp INTERFACE cxx_std_17)
|
||||
target_link_libraries(
|
||||
ssp
|
||||
INTERFACE
|
||||
"$<$<AND:$<CXX_COMPILER_ID:AppleClang,Clang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:c++fs>"
|
||||
"$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.1>>:stdc++fs>"
|
||||
"$<$<AND:$<CXX_COMPILER_ID:AppleClang,Clang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:c++fs>"
|
||||
"$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.1>>:stdc++fs>"
|
||||
)
|
||||
|
||||
# ---- Install ----
|
||||
@@ -55,19 +56,21 @@ target_link_libraries(
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(ssp_directory "ssp-${PROJECT_VERSION}")
|
||||
set(ssp_include_directory "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
set(SSP_DIRECTORY "ssp-${PROJECT_VERSION}")
|
||||
set(SSP_INCLUDE_DIRECTORY "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
|
||||
install(
|
||||
DIRECTORY "${PROJECT_SOURCE_DIR}/include/" "${fast_float_source_dir}/include/"
|
||||
DESTINATION "${ssp_include_directory}"
|
||||
DIRECTORY
|
||||
"${PROJECT_SOURCE_DIR}/include/"
|
||||
"${FAST_FLOAT_SOURCE_DIR}/include/"
|
||||
DESTINATION "${SSP_INCLUDE_DIRECTORY}"
|
||||
COMPONENT ssp_Development
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS ssp
|
||||
EXPORT sspTargets
|
||||
INCLUDES DESTINATION "${ssp_include_directory}"
|
||||
INCLUDES DESTINATION "${SSP_INCLUDE_DIRECTORY}"
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
@@ -76,11 +79,11 @@ write_basic_package_version_file(
|
||||
ARCH_INDEPENDENT
|
||||
)
|
||||
|
||||
set(ssp_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/${ssp_directory}")
|
||||
set(SSP_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${SSP_DIRECTORY}")
|
||||
|
||||
install(
|
||||
FILES "${PROJECT_BINARY_DIR}/ssp-config-version.cmake"
|
||||
DESTINATION "${ssp_install_cmakedir}"
|
||||
DESTINATION "${SSP_INSTALL_CMAKEDIR}"
|
||||
COMPONENT ssp_Development
|
||||
)
|
||||
|
||||
@@ -88,10 +91,10 @@ install(
|
||||
EXPORT sspTargets
|
||||
FILE ssp-config.cmake
|
||||
NAMESPACE ssp::
|
||||
DESTINATION "${ssp_install_cmakedir}"
|
||||
DESTINATION "${SSP_INSTALL_CMAKEDIR}"
|
||||
COMPONENT ssp_Development
|
||||
)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
include(CPack)
|
||||
include(CPack)
|
||||
endif()
|
||||
|
||||
24
README.md
24
README.md
@@ -53,20 +53,20 @@ Brian S. Wolfe 40 1.9
|
||||
Bill (Heath) Gates 65 3.3
|
||||
```
|
||||
# Features
|
||||
* [Works on any type](#Custom-conversions)
|
||||
* [Works on any type](#custom-conversions)
|
||||
* Easy to use
|
||||
* No exceptions
|
||||
* [Works with headers](#Headers)
|
||||
* [Works with quotes, escapes and spacings](#Setup)
|
||||
* [Works with values containing new lines](#Multiline)
|
||||
* [Columns and rows can be ignored](#Special-types)
|
||||
* [Works with headers](#headers)
|
||||
* [Works with quotes, escapes and spacings](#setup)
|
||||
* [Works with values containing new lines](#multiline)
|
||||
* [Columns and rows can be ignored](#special-types)
|
||||
* Works with any type of delimiter
|
||||
* Can return whole objects composed of converted values
|
||||
* [Descriptive error handling can be enabled](#Error-handling)
|
||||
* [Restrictions can be added for each column](#Restrictions)
|
||||
* [Works with `std::optional` and `std::variant`](#Special-types)
|
||||
* [Descriptive error handling can be enabled](#error-handling)
|
||||
* [Restrictions can be added for each column](#restrictions)
|
||||
* [Works with `std::optional` and `std::variant`](#special-types)
|
||||
* Works with **`CRLF`** and **`LF`**
|
||||
* [Conversions can be chained if invalid](#Substitute-conversions)
|
||||
* [Conversions can be chained if invalid](#substitute-conversions)
|
||||
* Fast
|
||||
|
||||
# Single header
|
||||
@@ -378,7 +378,7 @@ if(std::holds_alternative<float>(grade)) {
|
||||
```
|
||||
## Restrictions
|
||||
|
||||
Custom **`restrictions`** can be used to narrow down the conversions of unwanted values. **`ss::ir`** (in range) and **`ss::ne`** (none empty) are one of those:
|
||||
Custom **`restrictions`** can be used to narrow down the conversions of unwanted values. **`ss::ir`** (in range) and **`ss::ne`** (none empty) are some of those:
|
||||
```cpp
|
||||
// ss::ne makes sure that the name is not empty
|
||||
// ss::ir makes sure that the grade will be in range [0, 10]
|
||||
@@ -472,7 +472,6 @@ The delimiter is " ", and the number of columns varies depending on which shape
|
||||
```cpp
|
||||
ss::parser p{"shapes.txt", " "};
|
||||
if (!p.valid()) {
|
||||
std::cout << p.error_msg() << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -632,6 +631,5 @@ revision = origin/master
|
||||
```
|
||||
Then simply fetch the dependency and it is ready to be used:
|
||||
```meson
|
||||
ssp_sub = subproject('ssp')
|
||||
ssp_dep = ssp_sub.get_variable('ssp_dep')
|
||||
ssp_dep = dependency('ssp')
|
||||
```
|
||||
|
||||
@@ -102,7 +102,7 @@ class converter {
|
||||
constexpr static auto string_error = setup<Matchers...>::string_error;
|
||||
constexpr static auto default_delimiter = ",";
|
||||
|
||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
||||
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||
|
||||
public:
|
||||
// parses line with given delimiter, returns a 'T' object created with
|
||||
@@ -194,7 +194,7 @@ private:
|
||||
////////////////
|
||||
|
||||
const split_data& resplit(line_ptr_type new_line, ssize_t new_size,
|
||||
const std::string& delim = default_delimiter) {
|
||||
const std::string& delim) {
|
||||
return splitter_.resplit(new_line, new_size, delim);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class parser {
|
||||
constexpr static auto string_error = setup<Matchers...>::string_error;
|
||||
|
||||
using multiline = typename setup<Matchers...>::multiline;
|
||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
||||
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||
|
||||
constexpr static bool escaped_multiline_enabled =
|
||||
multiline::enabled && setup<Matchers...>::escape::enabled;
|
||||
@@ -151,8 +151,8 @@ public:
|
||||
template <bool get_object, typename T, typename... Ts>
|
||||
struct iterable {
|
||||
struct iterator {
|
||||
using value =
|
||||
ss::ternary_t<get_object, T, no_void_validator_tup_t<T, Ts...>>;
|
||||
using value = std::conditional_t<get_object, T,
|
||||
no_void_validator_tup_t<T, Ts...>>;
|
||||
|
||||
iterator() : parser_{nullptr} {
|
||||
}
|
||||
@@ -623,7 +623,8 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
next_line_converter_.resplit(next_line_buffer_, size);
|
||||
next_line_converter_.resplit(next_line_buffer_, size,
|
||||
delim_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,10 +109,10 @@ struct get_matcher<Matcher, T, Ts...> {
|
||||
struct is_matcher : is_instance_of_matcher<U, Matcher> {};
|
||||
|
||||
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
||||
"the same matcher is cannot"
|
||||
"the same matcher cannot"
|
||||
"be defined multiple times");
|
||||
using type = ternary_t<is_matcher<T>::value, T,
|
||||
typename get_matcher<Matcher, Ts...>::type>;
|
||||
using type = std::conditional_t<is_matcher<T>::value, T,
|
||||
typename get_matcher<Matcher, Ts...>::type>;
|
||||
};
|
||||
|
||||
template <template <char...> class Matcher>
|
||||
@@ -149,8 +149,8 @@ struct get_multiline;
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
struct get_multiline<T, Ts...> {
|
||||
using type = ternary_t<is_instance_of_multiline<T>::value, T,
|
||||
typename get_multiline<Ts...>::type>;
|
||||
using type = std::conditional_t<is_instance_of_multiline<T>::value, T,
|
||||
typename get_multiline<Ts...>::type>;
|
||||
};
|
||||
|
||||
template <>
|
||||
@@ -227,8 +227,10 @@ public:
|
||||
using quote = get_matcher_t<quote, Ts...>;
|
||||
using escape = get_matcher_t<escape, Ts...>;
|
||||
|
||||
using trim_left = ternary_t<trim_all::enabled, trim_all, trim_left_only>;
|
||||
using trim_right = ternary_t<trim_all::enabled, trim_all, trim_right_only>;
|
||||
using trim_left =
|
||||
std::conditional_t<trim_all::enabled, trim_all, trim_left_only>;
|
||||
using trim_right =
|
||||
std::conditional_t<trim_all::enabled, trim_all, trim_right_only>;
|
||||
|
||||
using multiline = get_multiline_t<Ts...>;
|
||||
constexpr static bool string_error = (count_string_error == 1);
|
||||
|
||||
@@ -23,10 +23,10 @@ private:
|
||||
constexpr static auto string_error = setup<Ts...>::string_error;
|
||||
constexpr static auto is_const_line = !quote::enabled && !escape::enabled;
|
||||
|
||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
||||
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||
|
||||
public:
|
||||
using line_ptr_type = ternary_t<is_const_line, const char*, char*>;
|
||||
using line_ptr_type = std::conditional_t<is_const_line, const char*, char*>;
|
||||
|
||||
bool valid() const {
|
||||
if constexpr (string_error) {
|
||||
|
||||
@@ -357,26 +357,6 @@ struct is_instance_of<Template, Template<Ts...>> {
|
||||
template <template <typename...> class Template, typename... Ts>
|
||||
constexpr bool is_instance_of_v = is_instance_of<Template, Ts...>::value;
|
||||
|
||||
////////////////
|
||||
// ternary
|
||||
////////////////
|
||||
|
||||
template <bool B, typename T, typename U>
|
||||
struct ternary;
|
||||
|
||||
template <typename T, typename U>
|
||||
struct ternary<true, T, U> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct ternary<false, T, U> {
|
||||
using type = U;
|
||||
};
|
||||
|
||||
template <bool B, typename T, typename U>
|
||||
using ternary_t = typename ternary<B, T, U>::type;
|
||||
|
||||
////////////////
|
||||
// tuple to struct
|
||||
////////////////
|
||||
|
||||
19
meson.build
19
meson.build
@@ -1,17 +1,24 @@
|
||||
project('ssp', 'cpp',
|
||||
project(
|
||||
'ssp',
|
||||
['cpp'],
|
||||
default_options :
|
||||
['warning_level=3',
|
||||
'cpp_std=c++17',
|
||||
'buildtype=debugoptimized'])
|
||||
['warning_level=3',
|
||||
'cpp_std=c++17',
|
||||
'buildtype=debugoptimized',
|
||||
'wrap_mode=forcefallback'],
|
||||
version: '1.4.0',
|
||||
meson_version:'>=0.54.0')
|
||||
|
||||
fast_float_sub = subproject('fast_float')
|
||||
fast_float_dep = fast_float_sub.get_variable('fast_float_dep')
|
||||
fast_float_dep = dependency('fast_float')
|
||||
|
||||
ssp_dep = declare_dependency(
|
||||
include_directories: include_directories('include'),
|
||||
dependencies: fast_float_dep
|
||||
)
|
||||
|
||||
meson.override_dependency('ssp', ssp_dep)
|
||||
|
||||
if not meson.is_subproject()
|
||||
subdir('test')
|
||||
endif
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ BUILD_TYPE=Debug
|
||||
|
||||
set -eux
|
||||
|
||||
git clone https://github.com/onqtam/doctest -b 2.4.4 --depth 1
|
||||
git clone https://github.com/red0124/doctest -b master --depth 1
|
||||
|
||||
cmake -S doctest -B doctest/build \
|
||||
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
|
||||
|
||||
53
ssp.hpp
53
ssp.hpp
@@ -372,26 +372,6 @@ struct is_instance_of<Template, Template<Ts...>> {
|
||||
template <template <typename...> class Template, typename... Ts>
|
||||
constexpr bool is_instance_of_v = is_instance_of<Template, Ts...>::value;
|
||||
|
||||
////////////////
|
||||
// ternary
|
||||
////////////////
|
||||
|
||||
template <bool B, typename T, typename U>
|
||||
struct ternary;
|
||||
|
||||
template <typename T, typename U>
|
||||
struct ternary<true, T, U> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct ternary<false, T, U> {
|
||||
using type = U;
|
||||
};
|
||||
|
||||
template <bool B, typename T, typename U>
|
||||
using ternary_t = typename ternary<B, T, U>::type;
|
||||
|
||||
////////////////
|
||||
// tuple to struct
|
||||
////////////////
|
||||
@@ -797,10 +777,10 @@ struct get_matcher<Matcher, T, Ts...> {
|
||||
struct is_matcher : is_instance_of_matcher<U, Matcher> {};
|
||||
|
||||
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
||||
"the same matcher is cannot"
|
||||
"the same matcher cannot"
|
||||
"be defined multiple times");
|
||||
using type = ternary_t<is_matcher<T>::value, T,
|
||||
typename get_matcher<Matcher, Ts...>::type>;
|
||||
using type = std::conditional_t<is_matcher<T>::value, T,
|
||||
typename get_matcher<Matcher, Ts...>::type>;
|
||||
};
|
||||
|
||||
template <template <char...> class Matcher>
|
||||
@@ -837,8 +817,8 @@ struct get_multiline;
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
struct get_multiline<T, Ts...> {
|
||||
using type = ternary_t<is_instance_of_multiline<T>::value, T,
|
||||
typename get_multiline<Ts...>::type>;
|
||||
using type = std::conditional_t<is_instance_of_multiline<T>::value, T,
|
||||
typename get_multiline<Ts...>::type>;
|
||||
};
|
||||
|
||||
template <>
|
||||
@@ -915,8 +895,10 @@ public:
|
||||
using quote = get_matcher_t<quote, Ts...>;
|
||||
using escape = get_matcher_t<escape, Ts...>;
|
||||
|
||||
using trim_left = ternary_t<trim_all::enabled, trim_all, trim_left_only>;
|
||||
using trim_right = ternary_t<trim_all::enabled, trim_all, trim_right_only>;
|
||||
using trim_left =
|
||||
std::conditional_t<trim_all::enabled, trim_all, trim_left_only>;
|
||||
using trim_right =
|
||||
std::conditional_t<trim_all::enabled, trim_all, trim_right_only>;
|
||||
|
||||
using multiline = get_multiline_t<Ts...>;
|
||||
constexpr static bool string_error = (count_string_error == 1);
|
||||
@@ -973,10 +955,10 @@ private:
|
||||
constexpr static auto string_error = setup<Ts...>::string_error;
|
||||
constexpr static auto is_const_line = !quote::enabled && !escape::enabled;
|
||||
|
||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
||||
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||
|
||||
public:
|
||||
using line_ptr_type = ternary_t<is_const_line, const char*, char*>;
|
||||
using line_ptr_type = std::conditional_t<is_const_line, const char*, char*>;
|
||||
|
||||
bool valid() const {
|
||||
if constexpr (string_error) {
|
||||
@@ -1838,7 +1820,7 @@ class converter {
|
||||
constexpr static auto string_error = setup<Matchers...>::string_error;
|
||||
constexpr static auto default_delimiter = ",";
|
||||
|
||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
||||
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||
|
||||
public:
|
||||
// parses line with given delimiter, returns a 'T' object created with
|
||||
@@ -1930,7 +1912,7 @@ private:
|
||||
////////////////
|
||||
|
||||
const split_data& resplit(line_ptr_type new_line, ssize_t new_size,
|
||||
const std::string& delim = default_delimiter) {
|
||||
const std::string& delim) {
|
||||
return splitter_.resplit(new_line, new_size, delim);
|
||||
}
|
||||
|
||||
@@ -2227,7 +2209,7 @@ class parser {
|
||||
constexpr static auto string_error = setup<Matchers...>::string_error;
|
||||
|
||||
using multiline = typename setup<Matchers...>::multiline;
|
||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
||||
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||
|
||||
constexpr static bool escaped_multiline_enabled =
|
||||
multiline::enabled && setup<Matchers...>::escape::enabled;
|
||||
@@ -2361,8 +2343,8 @@ public:
|
||||
template <bool get_object, typename T, typename... Ts>
|
||||
struct iterable {
|
||||
struct iterator {
|
||||
using value =
|
||||
ss::ternary_t<get_object, T, no_void_validator_tup_t<T, Ts...>>;
|
||||
using value = std::conditional_t<get_object, T,
|
||||
no_void_validator_tup_t<T, Ts...>>;
|
||||
|
||||
iterator() : parser_{nullptr} {
|
||||
}
|
||||
@@ -2833,7 +2815,8 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
next_line_converter_.resplit(next_line_buffer_, size);
|
||||
next_line_converter_.resplit(next_line_buffer_, size,
|
||||
delim_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/onqtam/doctest
|
||||
revision = 2.4.4
|
||||
url = https://github.com/red0124/doctest
|
||||
revision = master
|
||||
|
||||
@@ -4,34 +4,38 @@ project(ssp_tests CXX)
|
||||
|
||||
# ---- Dependencies ----
|
||||
|
||||
set(
|
||||
ssp_INCLUDE_WITHOUT_SYSTEM
|
||||
YES
|
||||
CACHE
|
||||
INTERNAL
|
||||
"Turn the warning guard off to have errors appear in test builds"
|
||||
)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(ssp SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
|
||||
FetchContent_MakeAvailable(ssp)
|
||||
fetchcontent_declare(ssp SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
|
||||
fetchcontent_makeavailable(ssp)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(ssp INTERFACE -Wall -Wextra)
|
||||
target_compile_options(ssp INTERFACE -Wall -Wextra)
|
||||
endif()
|
||||
|
||||
find_package(doctest 2.4.4 CONFIG REQUIRED)
|
||||
# for doctest_discover_tests
|
||||
include(doctest)
|
||||
include(FetchContent)
|
||||
fetchcontent_declare(
|
||||
DOCTEST
|
||||
GIT_REPOSITORY https://github.com/red0124/doctest
|
||||
GIT_TAG origin/master
|
||||
GIT_SHALLOW TRUE
|
||||
)
|
||||
|
||||
fetchcontent_makeavailable(DOCTEST)
|
||||
set(DOCTEST "${FETCHCONTENT_BASE_DIR}/doctest-src")
|
||||
|
||||
# ---- Test ----
|
||||
|
||||
enable_testing()
|
||||
|
||||
foreach(name IN ITEMS test_splitter test_parser test_converter test_extractions)
|
||||
add_executable("${name}" "${name}.cpp")
|
||||
target_link_libraries("${name}" PRIVATE ssp::ssp fast_float doctest::doctest)
|
||||
target_compile_definitions("${name}" PRIVATE
|
||||
DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN CMAKE_GITHUB_CI)
|
||||
doctest_discover_tests("${name}")
|
||||
add_executable("${name}" "${name}.cpp")
|
||||
target_link_libraries(
|
||||
"${name}"
|
||||
PRIVATE ssp::ssp fast_float doctest::doctest
|
||||
)
|
||||
target_compile_definitions(
|
||||
"${name}"
|
||||
PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN CMAKE_GITHUB_CI
|
||||
)
|
||||
add_test(NAME "${name}" COMMAND "${name}")
|
||||
endforeach()
|
||||
|
||||
@@ -7,8 +7,7 @@ test_sources = files([
|
||||
'test_extractions_without_fast_float.cpp',
|
||||
])
|
||||
|
||||
doctest_proj = subproject('doctest')
|
||||
doctest_dep = doctest_proj.get_variable('doctest_dep')
|
||||
doctest_dep = dependency('doctest')
|
||||
|
||||
test_exe = executable(
|
||||
'test_ssp',
|
||||
|
||||
@@ -610,8 +610,6 @@ struct xyz {
|
||||
};
|
||||
|
||||
TEST_CASE("parser test the moving of parsed values") {
|
||||
size_t move_called_one_col;
|
||||
|
||||
{
|
||||
unique_file_name f;
|
||||
{
|
||||
@@ -621,8 +619,7 @@ TEST_CASE("parser test the moving of parsed values") {
|
||||
|
||||
ss::parser p{f.name, ","};
|
||||
auto x = p.get_next<my_string>();
|
||||
CHECK_LT(move_called, 3);
|
||||
move_called_one_col = move_called;
|
||||
CHECK_LE(move_called, 1);
|
||||
move_called = 0;
|
||||
}
|
||||
|
||||
@@ -636,21 +633,21 @@ TEST_CASE("parser test the moving of parsed values") {
|
||||
|
||||
ss::parser p{f.name, ","};
|
||||
auto x = p.get_next<my_string, my_string, my_string>();
|
||||
CHECK_LE(move_called, 3 * move_called_one_col);
|
||||
CHECK_LE(move_called, 3);
|
||||
move_called = 0;
|
||||
}
|
||||
|
||||
{
|
||||
ss::parser p{f.name, ","};
|
||||
auto x = p.get_object<xyz, my_string, my_string, my_string>();
|
||||
CHECK_LE(move_called, 6 * move_called_one_col);
|
||||
CHECK_LE(move_called, 6);
|
||||
move_called = 0;
|
||||
}
|
||||
|
||||
{
|
||||
ss::parser p{f.name, ","};
|
||||
auto x = p.get_next<xyz>();
|
||||
CHECK_LE(move_called, 6 * move_called_one_col);
|
||||
CHECK_LE(move_called, 6);
|
||||
move_called = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user