From 5a1e5b38776a4fa466933f67a843aeeec0060632 Mon Sep 17 00:00:00 2001 From: ado Date: Sun, 27 Dec 2020 16:51:59 +0100 Subject: [PATCH] add tests for error mode --- test/test_converter.cpp | 13 +++++++++++++ test/test_parser.cpp | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/test/test_converter.cpp b/test/test_converter.cpp index 34cc0cf..6ded5f7 100644 --- a/test/test_converter.cpp +++ b/test/test_converter.cpp @@ -322,3 +322,16 @@ TEST_CASE("testing ss:ne restriction (not empty)") { CHECK(tup == extracted_vector); } } + +TEST_CASE("testing error mode") { + ss::converter c; + + c.convert("junk"); + CHECK(!c.valid()); + CHECK(!c.error_msg().empty()); + + c.set_error_mode(ss::error_mode::Bool); + c.convert("junk"); + CHECK(!c.valid()); + CHECK(c.error_msg().empty()); +} diff --git a/test/test_parser.cpp b/test/test_parser.cpp index ecb8bf3..c1eae76 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -438,3 +438,26 @@ TEST_CASE("testing the moving of parsed composite values") { .or_else>( [](auto&, auto&, auto&) {}); } + +TEST_CASE("testing error mode") { + unique_file_name f; + { + std::ofstream out{f.name}; + out << "junk" << std::endl; + out << "junk" << std::endl; + } + + ss::parser p(f.name, ","); + + REQUIRE(!p.eof()); + p.get_next(); + CHECK(!p.valid()); + CHECK(!p.error_msg().empty()); + + p.set_error_mode(ss::error_mode::Bool); + + REQUIRE(!p.eof()); + p.get_next(); + CHECK(!p.valid()); + CHECK(p.error_msg().empty()); +}