From 0aacff5729f0d5dbb872921dc7b3f045a9664e6c Mon Sep 17 00:00:00 2001 From: ado Date: Mon, 28 Mar 2022 19:30:39 +0200 Subject: [PATCH] add a few more parser unit test, disable clang12 workflow --- .github/workflows/ubuntu-latest-clang.yml | 2 +- README.md | 2 +- include/ss/parser.hpp | 2 +- test/test_parser.cpp | 39 +++++++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ubuntu-latest-clang.yml b/.github/workflows/ubuntu-latest-clang.yml index b08c86f..a01c763 100644 --- a/.github/workflows/ubuntu-latest-clang.yml +++ b/.github/workflows/ubuntu-latest-clang.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: - version: [12, 11, 10, 9, 8, 7] + version: [11, 10, 9, 8, 7] runs-on: ubuntu-latest diff --git a/README.md b/README.md index d87a890..2328c40 100644 --- a/README.md +++ b/README.md @@ -226,7 +226,7 @@ Empty lines can be ignored by defining **ss::ignore_empty** within the setup par ```cpp ss::parser 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 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: diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index 0d112ec..d3c6e2a 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -103,7 +103,7 @@ public: } bool field_exists(const std::string& field) { - return header_index(field); + return header_index(field).has_value(); } template diff --git a/test/test_parser.cpp b/test/test_parser.cpp index 11dad95..22de334 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -879,6 +879,7 @@ void testFields(const std::string file_name, const std::vector& data, using CaseType = std::tuple; ss::parser p{file_name, ","}; + CHECK_FALSE(p.field_exists("Unknown")); p.use_fields(fields); std::vector i; @@ -958,6 +959,8 @@ TEST_CASE("parser test various cases with header") { { ss::parser p{f.name, ","}; + CHECK_FALSE(p.field_exists("Unknown")); + p.use_fields(Int, "Unknown"); CHECK_FALSE(p.valid()); } @@ -968,6 +971,42 @@ TEST_CASE("parser test various cases with header") { CHECK_FALSE(p.valid()); } + { + ss::parser p{f.name, ","}; + p.use_fields(Int, Dbl); + + { + auto [int_, double_] = p.get_next(); + CHECK_EQ(int_, data[0].i); + CHECK_EQ(double_, data[0].d); + } + + p.use_fields(Dbl, Int); + + { + auto [double_, int_] = p.get_next(); + CHECK_EQ(int_, data[1].i); + CHECK_EQ(double_, data[1].d); + } + + p.use_fields(Str); + + { + auto string_ = p.get_next(); + CHECK_EQ(string_, data[2].s); + } + + p.use_fields(Str, Int, Dbl); + + { + auto [string_, int_, double_] = + p.get_next(); + CHECK_EQ(double_, data[3].d); + CHECK_EQ(int_, data[3].i); + CHECK_EQ(string_, data[3].s); + } + } + /* python used to generate permutations import itertools