mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 04:55:20 +01:00
Merge pull request #30 from red0124/feature/coverage_ci
Feature/coverage ci
This commit is contained in:
commit
4db88c0490
71
.github/workflows/coverage.yml
vendored
Normal file
71
.github/workflows/coverage.yml
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
name: coverage-ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- feature/**
|
||||||
|
- improvement/**
|
||||||
|
- bugfix/**
|
||||||
|
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- feature/**
|
||||||
|
- improvement/**
|
||||||
|
- bugfix/**
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test_coverage:
|
||||||
|
if: >-
|
||||||
|
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||||
|
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
name: "Coverage"
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: gcc:latest
|
||||||
|
options: -v /usr/local:/host_usr_local
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- uses: friendlyanon/fetch-core-count@v1
|
||||||
|
id: cores
|
||||||
|
|
||||||
|
- name: CMake
|
||||||
|
run: echo "/host_usr_local/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: script/ci_install_deps.sh
|
||||||
|
|
||||||
|
- name: Install test coverage tools
|
||||||
|
run: |
|
||||||
|
apt update
|
||||||
|
apt install -y gcovr lcov
|
||||||
|
|
||||||
|
- name: Configure
|
||||||
|
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug -D CMAKE_CXX_FLAGS="-Wall -fprofile-arcs -ftest-coverage --coverage"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build -j ${{steps.cores.outputs.count}}
|
||||||
|
|
||||||
|
- name: Run
|
||||||
|
working-directory: build
|
||||||
|
run: ctest --output-on-failure -j ${{steps.cores.outputs.count}}
|
||||||
|
|
||||||
|
- name: Generate coverage report
|
||||||
|
run: |
|
||||||
|
lcov -d . -c -o out.info --rc lcov_branch_coverage=1 --no-external
|
||||||
|
lcov -e out.info '*include/ss*hpp' -o filtered.info
|
||||||
|
|
||||||
|
- name: Invoke coveralls
|
||||||
|
uses: coverallsapp/github-action@v2
|
||||||
|
with:
|
||||||
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
file: filtered.info
|
||||||
|
format: lcov
|
@ -15,6 +15,7 @@
|
|||||||
[![windows-msys2-clang](https://github.com/red0124/ssp/workflows/win-msys2-clang-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/win-msys2-clang.yml)
|
[![windows-msys2-clang](https://github.com/red0124/ssp/workflows/win-msys2-clang-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/win-msys2-clang.yml)
|
||||||
[![win-msvc-ci](https://github.com/red0124/ssp/workflows/win-msvc-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/win-msvc.yml)
|
[![win-msvc-ci](https://github.com/red0124/ssp/workflows/win-msvc-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/win-msvc.yml)
|
||||||
[![single-header-ci](https://github.com/red0124/ssp/workflows/single-header-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/single-header.yml)
|
[![single-header-ci](https://github.com/red0124/ssp/workflows/single-header-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/single-header.yml)
|
||||||
|
[![coverage](https://coveralls.io/repos/github/red0124/ssp/badge.svg?branch=master/coverage_ci)](https://coveralls.io/github/red0124/ssp?branch=master/coverage_ci)
|
||||||
|
|
||||||
A header only "csv" parser which is fast and versatile with modern C++ api. Requires compiler with C++17 support. [Can also be used to convert strings to specific types.](#the-converter)
|
A header only "csv" parser which is fast and versatile with modern C++ api. Requires compiler with C++17 support. [Can also be used to convert strings to specific types.](#the-converter)
|
||||||
|
|
||||||
|
@ -379,7 +379,6 @@ private:
|
|||||||
return extract_tuple<Ts...>(elems);
|
return extract_tuple<Ts...>(elems);
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not know how to specialize by return type :(
|
|
||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
||||||
const split_data& elems, const std::tuple<Ts...>*) {
|
const split_data& elems, const std::tuple<Ts...>*) {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "type_traits.hpp"
|
#include "type_traits.hpp"
|
||||||
|
#include <charconv>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <charconv>
|
|
||||||
|
|
||||||
#ifndef SSP_DISABLE_FAST_FLOAT
|
#ifndef SSP_DISABLE_FAST_FLOAT
|
||||||
#include <fast_float/fast_float.h>
|
#include <fast_float/fast_float.h>
|
||||||
@ -16,7 +16,6 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO try from_chars for integer conversions
|
|
||||||
namespace ss {
|
namespace ss {
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
@ -42,17 +41,24 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||||
const char* const begin, const char* const end) {
|
const char* const begin, const char* const end) {
|
||||||
|
static_assert(!std::is_same_v<T, long double>,
|
||||||
|
"Conversion to long double is disabled");
|
||||||
|
|
||||||
constexpr static auto buff_max = 64;
|
constexpr static auto buff_max = 64;
|
||||||
char buff[buff_max];
|
char short_buff[buff_max];
|
||||||
size_t string_range = std::distance(begin, end);
|
size_t string_range = std::distance(begin, end);
|
||||||
|
std::string long_buff;
|
||||||
|
|
||||||
|
char* buff;
|
||||||
if (string_range > buff_max) {
|
if (string_range > buff_max) {
|
||||||
return std::nullopt;
|
long_buff = std::string{begin, end};
|
||||||
|
buff = long_buff.data();
|
||||||
|
} else {
|
||||||
|
buff = short_buff;
|
||||||
|
buff[string_range] = '\0';
|
||||||
|
std::copy_n(begin, string_range, buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::copy_n(begin, string_range, buff);
|
|
||||||
buff[string_range] = '\0';
|
|
||||||
|
|
||||||
T ret;
|
T ret;
|
||||||
char* parse_end = nullptr;
|
char* parse_end = nullptr;
|
||||||
|
|
||||||
@ -60,8 +66,6 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
|||||||
ret = std::strtof(buff, &parse_end);
|
ret = std::strtof(buff, &parse_end);
|
||||||
} else if constexpr (std::is_same_v<T, double>) {
|
} else if constexpr (std::is_same_v<T, double>) {
|
||||||
ret = std::strtod(buff, &parse_end);
|
ret = std::strtod(buff, &parse_end);
|
||||||
} else if constexpr (std::is_same_v<T, long double>) {
|
|
||||||
ret = std::strtold(buff, &parse_end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_end != buff + string_range) {
|
if (parse_end != buff + string_range) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// TODO add single header tests
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "converter.hpp"
|
#include "converter.hpp"
|
||||||
#include "exception.hpp"
|
#include "exception.hpp"
|
||||||
|
22
ssp.hpp
22
ssp.hpp
@ -1465,7 +1465,6 @@ public:
|
|||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO try from_chars for integer conversions
|
|
||||||
namespace ss {
|
namespace ss {
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
@ -1491,17 +1490,24 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||||
const char* const begin, const char* const end) {
|
const char* const begin, const char* const end) {
|
||||||
|
static_assert(!std::is_same_v<T, long double>,
|
||||||
|
"Conversion to long double is disabled");
|
||||||
|
|
||||||
constexpr static auto buff_max = 64;
|
constexpr static auto buff_max = 64;
|
||||||
char buff[buff_max];
|
char short_buff[buff_max];
|
||||||
size_t string_range = std::distance(begin, end);
|
size_t string_range = std::distance(begin, end);
|
||||||
|
std::string long_buff;
|
||||||
|
|
||||||
|
char* buff;
|
||||||
if (string_range > buff_max) {
|
if (string_range > buff_max) {
|
||||||
return std::nullopt;
|
long_buff = std::string{begin, end};
|
||||||
|
buff = long_buff.data();
|
||||||
|
} else {
|
||||||
|
buff = short_buff;
|
||||||
|
buff[string_range] = '\0';
|
||||||
|
std::copy_n(begin, string_range, buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::copy_n(begin, string_range, buff);
|
|
||||||
buff[string_range] = '\0';
|
|
||||||
|
|
||||||
T ret;
|
T ret;
|
||||||
char* parse_end = nullptr;
|
char* parse_end = nullptr;
|
||||||
|
|
||||||
@ -1509,8 +1515,6 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
|||||||
ret = std::strtof(buff, &parse_end);
|
ret = std::strtof(buff, &parse_end);
|
||||||
} else if constexpr (std::is_same_v<T, double>) {
|
} else if constexpr (std::is_same_v<T, double>) {
|
||||||
ret = std::strtod(buff, &parse_end);
|
ret = std::strtod(buff, &parse_end);
|
||||||
} else if constexpr (std::is_same_v<T, long double>) {
|
|
||||||
ret = std::strtold(buff, &parse_end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_end != buff + string_range) {
|
if (parse_end != buff + string_range) {
|
||||||
@ -2017,7 +2021,6 @@ private:
|
|||||||
return extract_tuple<Ts...>(elems);
|
return extract_tuple<Ts...>(elems);
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not know how to specialize by return type :(
|
|
||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
||||||
const split_data& elems, const std::tuple<Ts...>*) {
|
const split_data& elems, const std::tuple<Ts...>*) {
|
||||||
@ -2133,7 +2136,6 @@ private:
|
|||||||
|
|
||||||
} /* ss */
|
} /* ss */
|
||||||
|
|
||||||
// TODO add single header tests
|
|
||||||
|
|
||||||
namespace ss {
|
namespace ss {
|
||||||
|
|
||||||
|
@ -275,3 +275,20 @@ TEST_CASE("extract test functions for std::variant") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("extract test with long number string") {
|
||||||
|
{
|
||||||
|
std::string string_num =
|
||||||
|
std::string(20, '1') + "." + std::string(20, '2');
|
||||||
|
|
||||||
|
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, float, stof);
|
||||||
|
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, double, stod);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string string_num =
|
||||||
|
std::string(50, '1') + "." + std::string(50, '2');
|
||||||
|
|
||||||
|
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, double, stod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,11 +9,11 @@ TEST_CASE(
|
|||||||
CHECK_FLOATING_CONVERSION(123.456, float);
|
CHECK_FLOATING_CONVERSION(123.456, float);
|
||||||
CHECK_FLOATING_CONVERSION(123.456, double);
|
CHECK_FLOATING_CONVERSION(123.456, double);
|
||||||
|
|
||||||
CHECK_FLOATING_CONVERSION(69, float);
|
CHECK_FLOATING_CONVERSION(59, float);
|
||||||
CHECK_FLOATING_CONVERSION(69, double);
|
CHECK_FLOATING_CONVERSION(59, double);
|
||||||
|
|
||||||
CHECK_FLOATING_CONVERSION(420., float);
|
CHECK_FLOATING_CONVERSION(4210., float);
|
||||||
CHECK_FLOATING_CONVERSION(420., double);
|
CHECK_FLOATING_CONVERSION(4210., double);
|
||||||
|
|
||||||
CHECK_FLOATING_CONVERSION(0.123, float);
|
CHECK_FLOATING_CONVERSION(0.123, float);
|
||||||
CHECK_FLOATING_CONVERSION(0.123, double);
|
CHECK_FLOATING_CONVERSION(0.123, double);
|
||||||
@ -130,3 +130,20 @@ TEST_CASE("extract test functions for std::variant without fast float") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("extract test with long number string without fast float") {
|
||||||
|
{
|
||||||
|
std::string string_num =
|
||||||
|
std::string(20, '1') + "." + std::string(20, '2');
|
||||||
|
|
||||||
|
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, float, stof);
|
||||||
|
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, double, stod);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string string_num =
|
||||||
|
std::string(50, '1') + "." + std::string(50, '2');
|
||||||
|
|
||||||
|
CHECK_FLOATING_CONVERSION_LONG_NUMBER(string_num, double, stod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <filesystem>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
#ifdef CMAKE_GITHUB_CI
|
#ifdef CMAKE_GITHUB_CI
|
||||||
#include <doctest/doctest.h>
|
#include <doctest/doctest.h>
|
||||||
@ -75,6 +75,18 @@ struct unique_file_name {
|
|||||||
CHECK_LT(std::abs(t.value() - type(-input)), eps); \
|
CHECK_LT(std::abs(t.value() - type(-input)), eps); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CHECK_FLOATING_CONVERSION_LONG_NUMBER(STRING_NUMBER, TYPE, CONVERTER) \
|
||||||
|
{ \
|
||||||
|
auto begin = STRING_NUMBER.c_str(); \
|
||||||
|
auto end = begin + STRING_NUMBER.size(); \
|
||||||
|
\
|
||||||
|
auto number = ss::to_num<TYPE>(begin, end); \
|
||||||
|
REQUIRE(number.has_value()); \
|
||||||
|
\
|
||||||
|
auto expected_number = CONVERTER(STRING_NUMBER); \
|
||||||
|
CHECK_EQ(number.value(), expected_number); \
|
||||||
|
}
|
||||||
|
|
||||||
#define CHECK_INVALID_CONVERSION(input, type) \
|
#define CHECK_INVALID_CONVERSION(input, type) \
|
||||||
{ \
|
{ \
|
||||||
std::string s = input; \
|
std::string s = input; \
|
||||||
|
@ -1491,6 +1491,104 @@ TEST_CASE("parser test invalid header fields usage") {
|
|||||||
test_invalid_fields({"Int,String,Int", "1,hi,3"}, {"Int", "String", "Int"});
|
test_invalid_fields({"Int,String,Int", "1,hi,3"}, {"Int", "String", "Int"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename... Ts>
|
||||||
|
void test_invalid_rows_with_header() {
|
||||||
|
unique_file_name f{"test_parser"};
|
||||||
|
{
|
||||||
|
std::ofstream out{f.name};
|
||||||
|
out << "Int,String,Double" << std::endl;
|
||||||
|
out << "1,line1,2.34" << std::endl;
|
||||||
|
out << "2,line2" << std::endl;
|
||||||
|
out << "3,line3,67.8" << std::endl;
|
||||||
|
out << "4,line4,67.8,9" << std::endl;
|
||||||
|
out << "5,line5,9.10" << std::endl;
|
||||||
|
out << "six,line6,10.11" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ss::parser<Ts...> p{f.name};
|
||||||
|
|
||||||
|
p.use_fields("Int", "String", "Double");
|
||||||
|
using data = std::tuple<int, std::string, double>;
|
||||||
|
std::vector<data> i;
|
||||||
|
|
||||||
|
CHECK(p.valid());
|
||||||
|
|
||||||
|
while (!p.eof()) {
|
||||||
|
try {
|
||||||
|
const auto& t = p.template get_next<data>();
|
||||||
|
if (p.valid()) {
|
||||||
|
i.push_back(t);
|
||||||
|
}
|
||||||
|
} catch (const ss::exception&) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<data> expected = {{1, "line1", 2.34},
|
||||||
|
{3, "line3", 67.8},
|
||||||
|
{5, "line5", 9.10}};
|
||||||
|
CHECK_EQ(i, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ss::parser<Ts...> p{f.name};
|
||||||
|
|
||||||
|
p.use_fields("Double", "Int");
|
||||||
|
using data = std::tuple<double, int>;
|
||||||
|
std::vector<data> i;
|
||||||
|
|
||||||
|
CHECK(p.valid());
|
||||||
|
|
||||||
|
while (!p.eof()) {
|
||||||
|
try {
|
||||||
|
const auto& t = p.template get_next<data>();
|
||||||
|
if (p.valid()) {
|
||||||
|
i.push_back(t);
|
||||||
|
}
|
||||||
|
} catch (const ss::exception&) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<data> expected = {{2.34, 1}, {67.8, 3}, {9.10, 5}};
|
||||||
|
CHECK_EQ(i, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ss::parser<Ts...> p{f.name};
|
||||||
|
|
||||||
|
p.use_fields("String", "Double");
|
||||||
|
using data = std::tuple<std::string, double>;
|
||||||
|
std::vector<data> i;
|
||||||
|
|
||||||
|
CHECK(p.valid());
|
||||||
|
|
||||||
|
while (!p.eof()) {
|
||||||
|
try {
|
||||||
|
const auto& t = p.template get_next<data>();
|
||||||
|
if (p.valid()) {
|
||||||
|
i.push_back(t);
|
||||||
|
}
|
||||||
|
} catch (const ss::exception&) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<data> expected = {{"line1", 2.34},
|
||||||
|
{"line3", 67.8},
|
||||||
|
{"line5", 9.10},
|
||||||
|
{"line6", 10.11}};
|
||||||
|
CHECK_EQ(i, expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("parser test invalid rows with header") {
|
||||||
|
test_invalid_rows_with_header();
|
||||||
|
test_invalid_rows_with_header<ss::string_error>();
|
||||||
|
test_invalid_rows_with_header<ss::throw_on_error>();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
void test_ignore_empty_impl(const std::vector<X>& data) {
|
void test_ignore_empty_impl(const std::vector<X>& data) {
|
||||||
unique_file_name f{"test_parser"};
|
unique_file_name f{"test_parser"};
|
||||||
|
@ -775,6 +775,23 @@ TEST_CASE("splitter test resplit unterminated quote") {
|
|||||||
CHECK_EQ(words(vec), expected);
|
CHECK_EQ(words(vec), expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ss::converter<ss::quote<'"'>, ss::escape<'\\'>, ss::multiline> c;
|
||||||
|
auto& s = c.splitter;
|
||||||
|
auto vec = expect_unterminated_quote(s, R"("just\"some","ra)");
|
||||||
|
std::vector<std::string> expected{"just\"some"};
|
||||||
|
auto w = words(vec);
|
||||||
|
w.pop_back();
|
||||||
|
CHECK_EQ(w, expected);
|
||||||
|
REQUIRE(s.unterminated_quote());
|
||||||
|
{
|
||||||
|
auto new_line = buff.append(R"(n,dom",str\"ings)");
|
||||||
|
// invalid resplit size
|
||||||
|
vec = c.resplit(new_line, 4);
|
||||||
|
CHECK(!s.valid());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("splitter test resplit unterminated quote with exceptions") {
|
TEST_CASE("splitter test resplit unterminated quote with exceptions") {
|
||||||
@ -1040,47 +1057,57 @@ TEST_CASE("splitter test resplit unterminated quote with exceptions") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("splitter test invalid splits") {
|
template <typename... Ts>
|
||||||
ss::converter<ss::string_error, ss::quote<'"'>, ss::trim<' '>,
|
void test_invalid_splits() {
|
||||||
ss::escape<'\\'>>
|
ss::converter<ss::quote<'"'>, ss::trim<' '>, ss::escape<'\\'>, Ts...> c;
|
||||||
c;
|
|
||||||
auto& s = c.splitter;
|
auto& s = c.splitter;
|
||||||
|
|
||||||
|
auto check_error_msg = [&] {
|
||||||
|
if constexpr (ss::setup<Ts...>::string_error) {
|
||||||
|
CHECK_FALSE(s.error_msg().empty());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// empty delimiter
|
// empty delimiter
|
||||||
s.split(buff("some,random,strings"), "");
|
s.split(buff("some,random,strings"), "");
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
CHECK_FALSE(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// mismatched delimiter
|
// mismatched delimiter
|
||||||
s.split(buff(R"(some,"random,"strings")"));
|
s.split(buff(R"(some,"random,"strings")"));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
CHECK_FALSE(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// unterminated escape
|
// unterminated escape
|
||||||
s.split(buff(R"(some,random,strings\)"));
|
s.split(buff(R"(some,random,strings\)"));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
CHECK_FALSE(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// unterminated escape
|
// unterminated escape
|
||||||
s.split(buff(R"(some,random,"strings\)"));
|
s.split(buff(R"(some,random,"strings\)"));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
CHECK_FALSE(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// unterminated quote
|
// unterminated quote
|
||||||
s.split(buff("some,random,\"strings"));
|
s.split(buff("some,random,\"strings"));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK(s.unterminated_quote());
|
CHECK(s.unterminated_quote());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
|
||||||
// invalid resplit
|
// invalid resplit
|
||||||
char new_line[] = "some";
|
char new_line[] = "some";
|
||||||
c.resplit(new_line, strlen(new_line));
|
c.resplit(new_line, strlen(new_line));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
check_error_msg();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("splitter test invalid splits") {
|
||||||
|
test_invalid_splits();
|
||||||
|
test_invalid_splits<ss::string_error>();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("splitter test invalid splits with exceptions") {
|
TEST_CASE("splitter test invalid splits with exceptions") {
|
||||||
|
Loading…
Reference in New Issue
Block a user