add a few more parser unit test, disable clang12 workflow

This commit is contained in:
ado 2022-03-28 19:30:39 +02:00
parent 6d6caf7414
commit 0aacff5729
4 changed files with 42 additions and 3 deletions

View File

@ -23,7 +23,7 @@ jobs:
strategy: strategy:
matrix: matrix:
version: [12, 11, 10, 9, 8, 7] version: [11, 10, 9, 8, 7]
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -226,7 +226,7 @@ Empty lines can be ignored by defining **ss::ignore_empty** within the setup par
```cpp ```cpp
ss::parser<ss::ignore_empty> p{file_name}; ss::parser<ss::ignore_empty> p{file_name};
``` ```
If this setup option is not set then reading an empty line will result in an error (unless only one column is present within the parser). If this setup option is not set then reading an empty line will result in an error (unless only one column is present within the csv).
### Quoting ### Quoting
Quoting can be enabled by defining **ss::quote** within the setup parameters. A single character can be defined as the quoting character, for example to use **"** as a quoting character: Quoting can be enabled by defining **ss::quote** within the setup parameters. A single character can be defined as the quoting character, for example to use **"** as a quoting character:

View File

@ -103,7 +103,7 @@ public:
} }
bool field_exists(const std::string& field) { bool field_exists(const std::string& field) {
return header_index(field); return header_index(field).has_value();
} }
template <typename... Ts> template <typename... Ts>

View File

@ -879,6 +879,7 @@ void testFields(const std::string file_name, const std::vector<X>& data,
using CaseType = std::tuple<Ts...>; using CaseType = std::tuple<Ts...>;
ss::parser p{file_name, ","}; ss::parser p{file_name, ","};
CHECK_FALSE(p.field_exists("Unknown"));
p.use_fields(fields); p.use_fields(fields);
std::vector<CaseType> i; std::vector<CaseType> i;
@ -958,6 +959,8 @@ TEST_CASE("parser test various cases with header") {
{ {
ss::parser<ss::ignore_header, ss::string_error> p{f.name, ","}; ss::parser<ss::ignore_header, ss::string_error> p{f.name, ","};
CHECK_FALSE(p.field_exists("Unknown"));
p.use_fields(Int, "Unknown"); p.use_fields(Int, "Unknown");
CHECK_FALSE(p.valid()); CHECK_FALSE(p.valid());
} }
@ -968,6 +971,42 @@ TEST_CASE("parser test various cases with header") {
CHECK_FALSE(p.valid()); CHECK_FALSE(p.valid());
} }
{
ss::parser<ss::string_error> p{f.name, ","};
p.use_fields(Int, Dbl);
{
auto [int_, double_] = p.get_next<int, double>();
CHECK_EQ(int_, data[0].i);
CHECK_EQ(double_, data[0].d);
}
p.use_fields(Dbl, Int);
{
auto [double_, int_] = p.get_next<double, int>();
CHECK_EQ(int_, data[1].i);
CHECK_EQ(double_, data[1].d);
}
p.use_fields(Str);
{
auto string_ = p.get_next<std::string>();
CHECK_EQ(string_, data[2].s);
}
p.use_fields(Str, Int, Dbl);
{
auto [string_, int_, double_] =
p.get_next<std::string, int, double>();
CHECK_EQ(double_, data[3].d);
CHECK_EQ(int_, data[3].i);
CHECK_EQ(string_, data[3].s);
}
}
/* python used to generate permutations /* python used to generate permutations
import itertools import itertools