From aa1c185bb1910210e4cc758235271352f82d3cfd Mon Sep 17 00:00:00 2001 From: Denis Mikhaylov Date: Tue, 4 Oct 2022 12:06:10 +0600 Subject: [PATCH 1/2] Cover position_cache with test --- test/x3/Jamfile | 2 ++ test/x3/position_cache.cpp | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) mode change 100644 => 100755 test/x3/Jamfile create mode 100755 test/x3/position_cache.cpp diff --git a/test/x3/Jamfile b/test/x3/Jamfile old mode 100644 new mode 100755 index f2671e6ba1..212751044e --- a/test/x3/Jamfile +++ b/test/x3/Jamfile @@ -132,3 +132,5 @@ run rule_separate_tu.cpp rule_separate_tu_grammar ; obj grammar_linker : grammar.cpp ; run grammar_linker.cpp grammar_linker ; + +run position_cache.cpp ; diff --git a/test/x3/position_cache.cpp b/test/x3/position_cache.cpp new file mode 100755 index 0000000000..88d632e7ec --- /dev/null +++ b/test/x3/position_cache.cpp @@ -0,0 +1,55 @@ +/*============================================================================= + Copyright (c) 2022 Denis Mikhailov + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#include +#include + +#include +#include +#include + +#include +#include + +struct employee +{ + int age; + double salary; +}; + +struct employee_with_position_tagged : boost::spirit::x3::position_tagged +{ + int age; + double salary; +}; + +using iterator_type = std::string::const_iterator; +using position_cache = boost::spirit::x3::position_cache>; + +std::string input = "Hello world!!"; + +int +main() +{ + position_cache positions{input.begin(), input.end()}; + + { + employee ast; + positions.annotate(ast, input.begin() + 6, input.begin() + 11); + const auto r = positions.position_of(ast); + BOOST_TEST(r.empty()); + } + + { + employee_with_position_tagged ast; + positions.annotate(ast, input.begin() + 6, input.begin() + 11); + const auto r = positions.position_of(ast); + const auto str = std::string{r.begin(), r.end()}; + BOOST_TEST(!r.empty()); + BOOST_TEST(str == "world"); + } + + return boost::report_errors(); +} \ No newline at end of file From 919fd34ea3671857e8356ef983674a7867f2470c Mon Sep 17 00:00:00 2001 From: Denis Mikhaylov Date: Wed, 12 Oct 2022 16:33:57 +0600 Subject: [PATCH 2/2] increase level --- test/x3/Jamfile | 3 +- test/x3/error_handler_positions.cpp | 71 +++++++++++++++++++++++++++++ test/x3/position_cache.cpp | 55 ---------------------- 3 files changed, 72 insertions(+), 57 deletions(-) create mode 100755 test/x3/error_handler_positions.cpp delete mode 100755 test/x3/position_cache.cpp diff --git a/test/x3/Jamfile b/test/x3/Jamfile index 212751044e..eb8f110b3b 100755 --- a/test/x3/Jamfile +++ b/test/x3/Jamfile @@ -123,6 +123,7 @@ run attribute_type_check.cpp ; run fusion_map.cpp ; run x3_variant.cpp ; run error_handler.cpp ; +run error_handler_positions.cpp ; run iterator_check.cpp ; run to_utf8.cpp ; @@ -132,5 +133,3 @@ run rule_separate_tu.cpp rule_separate_tu_grammar ; obj grammar_linker : grammar.cpp ; run grammar_linker.cpp grammar_linker ; - -run position_cache.cpp ; diff --git a/test/x3/error_handler_positions.cpp b/test/x3/error_handler_positions.cpp new file mode 100755 index 0000000000..632bdbf43c --- /dev/null +++ b/test/x3/error_handler_positions.cpp @@ -0,0 +1,71 @@ +/*============================================================================= + Copyright (c) 2022 Denis Mikhailov + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#include +#include + +#include +#include + +#include +#include +#include + +struct employee +{ + int age; + double salary; +}; + +struct employee_with_position_tagged : boost::spirit::x3::position_tagged +{ + int age; + double salary; +}; + +using iterator_type = std::string::const_iterator; +using error_handler_type = boost::spirit::x3::error_handler; + +std::string input = "Hello world!!"; + +void test() { + { + error_handler_type error_handler{input.begin(), input.end(), std::cerr}; + employee ast; + error_handler.tag(ast, input.begin() + 6, input.begin() + 11); + // const auto r = error_handler.position_of(ast); + // BOOST_TEST(r.empty()); + BOOST_TEST(error_handler.get_position_cache().get_positions().empty()); + } +} + +void test_with_position_tagged() { + { + error_handler_type error_handler{input.begin(), input.end(), std::cerr}; + employee_with_position_tagged ast; + error_handler.tag(ast, input.begin() + 6, input.begin() + 11); + const auto r = error_handler.position_of(ast); + const auto str = std::string{r.begin(), r.end()}; + BOOST_TEST(!r.empty()); + BOOST_TEST(str == "world"); + } + { + std::stringstream stream; + error_handler_type error_handler{input.begin(), input.end(), stream}; + employee_with_position_tagged ast; + error_handler.tag(ast, input.begin() + 6, input.begin() + 11); + error_handler(ast, "You were wrong"); + BOOST_TEST_EQ(stream.str(), "In line 1:\nYou were wrong\nHello world!!\n ~~~~~ <<-- Here\n"); + } +} + +int +main() +{ + test(); + test_with_position_tagged(); + return boost::report_errors(); +} + diff --git a/test/x3/position_cache.cpp b/test/x3/position_cache.cpp deleted file mode 100755 index 88d632e7ec..0000000000 --- a/test/x3/position_cache.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/*============================================================================= - Copyright (c) 2022 Denis Mikhailov - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ -#include -#include - -#include -#include -#include - -#include -#include - -struct employee -{ - int age; - double salary; -}; - -struct employee_with_position_tagged : boost::spirit::x3::position_tagged -{ - int age; - double salary; -}; - -using iterator_type = std::string::const_iterator; -using position_cache = boost::spirit::x3::position_cache>; - -std::string input = "Hello world!!"; - -int -main() -{ - position_cache positions{input.begin(), input.end()}; - - { - employee ast; - positions.annotate(ast, input.begin() + 6, input.begin() + 11); - const auto r = positions.position_of(ast); - BOOST_TEST(r.empty()); - } - - { - employee_with_position_tagged ast; - positions.annotate(ast, input.begin() + 6, input.begin() + 11); - const auto r = positions.position_of(ast); - const auto str = std::string{r.begin(), r.end()}; - BOOST_TEST(!r.empty()); - BOOST_TEST(str == "world"); - } - - return boost::report_errors(); -} \ No newline at end of file