diff --git a/include/tao/pegtl/contrib/input_with_depth.hpp b/include/tao/pegtl/contrib/input_with_depth.hpp index 0cd327ec..a2749f6e 100644 --- a/include/tao/pegtl/contrib/input_with_depth.hpp +++ b/include/tao/pegtl/contrib/input_with_depth.hpp @@ -33,8 +33,8 @@ namespace TAO_PEGTL_NAMESPACE --m_depth; } - depth_guard& operator=( depth_guard&& ) = delete; - depth_guard& operator=( const depth_guard& ) = delete; + void operator=( depth_guard&& ) = delete; + void operator=( const depth_guard& ) = delete; [[nodiscard]] std::size_t current_depth() const noexcept { @@ -54,14 +54,6 @@ namespace TAO_PEGTL_NAMESPACE public: using Input::Input; - void restart() noexcept - { - if constexpr( internal::has_restart< Input > ) { - Input::restart(); - } - m_depth = 0; - } - [[nodiscard]] internal::depth_guard make_depth_guard() noexcept { return internal::depth_guard( m_depth ); // NOLINT(google-readability-casting) diff --git a/include/tao/pegtl/contrib/input_with_offset.hpp b/include/tao/pegtl/contrib/input_with_offset.hpp index c418f97b..f151f20b 100644 --- a/include/tao/pegtl/contrib/input_with_offset.hpp +++ b/include/tao/pegtl/contrib/input_with_offset.hpp @@ -58,7 +58,7 @@ namespace TAO_PEGTL_NAMESPACE return m_offset; } - void direct_position() = delete; + void direct_position() const = delete; protected: offset_position_t m_offset; diff --git a/include/tao/pegtl/debug/analyze_traits_impl.hpp b/include/tao/pegtl/debug/analyze_traits_impl.hpp index 53631ce8..4acd2f07 100644 --- a/include/tao/pegtl/debug/analyze_traits_impl.hpp +++ b/include/tao/pegtl/debug/analyze_traits_impl.hpp @@ -66,8 +66,8 @@ namespace TAO_PEGTL_NAMESPACE : analyze_opt_traits<> {}; - template< typename Name, std::size_t Count, typename Reference > - struct analyze_traits< Name, internal::consume< Count, Reference > > + template< typename Name, std::size_t Count > + struct analyze_traits< Name, internal::consume< Count > > : std::conditional_t< ( Count > 0 ), analyze_any_traits<>, analyze_opt_traits<> > {}; @@ -150,7 +150,7 @@ namespace TAO_PEGTL_NAMESPACE template< typename Name, typename Head, typename... Rules > struct analyze_traits< Name, internal::rematch< Head, Rules... > > - : analyze_traits< Name, typename internal::sor< Head, internal::sor< internal::seq< Rules, internal::consume< 1, void > >... > >::rule_t > // TODO: Correct (enough)? + : analyze_traits< Name, typename internal::sor< Head, internal::sor< internal::seq< Rules, internal::consume< 1 > >... > >::rule_t > // TODO: Correct (enough)? {}; template< typename Name, std::size_t Cnt, typename... Rules > diff --git a/include/tao/pegtl/internal/consume.hpp b/include/tao/pegtl/internal/consume.hpp index 4060bce5..64f6e4b3 100644 --- a/include/tao/pegtl/internal/consume.hpp +++ b/include/tao/pegtl/internal/consume.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2024 Dr. Colin Hirsch and Daniel Frey // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) @@ -13,32 +13,12 @@ #include "../type_list.hpp" #include "enable_control.hpp" -#include "math_utility.hpp" #include "success.hpp" namespace TAO_PEGTL_NAMESPACE::internal { - template< std::size_t Count, typename Reference, typename = void > - struct consume - { - using rule_t = consume; - using subs_t = empty_list; - - template< typename ParseInput > - [[nodiscard]] static bool match( ParseInput& in ) noexcept - { - static_assert( is_divisible( sizeof( Reference ), sizeof( *in.current() ) ) ); - - if( in.size( Count ) >= Count ) { - in.template consume< eol_unknown_tag >( Count ); - return true; - } - return false; - } - }; - template< std::size_t Count > - struct consume< Count, void, std::enable_if_t< ( Count > 0 ) > > + struct consume { using rule_t = consume; using subs_t = empty_list; @@ -54,13 +34,13 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; - template< typename Reference > - struct consume< 0, Reference, void > + template<> + struct consume< 0 > : success {}; - template< std::size_t Count, typename Reference > - inline constexpr bool enable_control< consume< Count, Reference > > = false; + template< std::size_t Count > + inline constexpr bool enable_control< consume< Count > > = false; } // namespace TAO_PEGTL_NAMESPACE::internal diff --git a/include/tao/pegtl/internal/input_with_funcs.hpp b/include/tao/pegtl/internal/input_with_funcs.hpp index b50ee03a..4d17c075 100644 --- a/include/tao/pegtl/internal/input_with_funcs.hpp +++ b/include/tao/pegtl/internal/input_with_funcs.hpp @@ -32,7 +32,7 @@ namespace TAO_PEGTL_NAMESPACE::internal [[nodiscard]] T peek_as( const std::size_t offset = 0 ) const noexcept { static_assert( sizeof( data_t ) == sizeof( T ) ); - return static_cast< T >( *this->current( offset ) ); + return static_cast< T >( peek( offset ) ); } [[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept diff --git a/include/tao/pegtl/rules.hpp b/include/tao/pegtl/rules.hpp index 30ef1f89..8be8001c 100644 --- a/include/tao/pegtl/rules.hpp +++ b/include/tao/pegtl/rules.hpp @@ -30,7 +30,7 @@ namespace TAO_PEGTL_NAMESPACE struct bof : internal::bof {}; struct bol : internal::bol {}; template< typename Left, typename Right > struct combine : internal::combine_traits< typename Left::rule_t, typename Right::rule_t >::rule_t {}; - template< std::size_t Count > struct consume : internal::consume< Count, void > {}; + template< std::size_t Count > struct consume : internal::consume< Count > {}; template< template< typename... > class Control, typename... Rules > struct control : internal::control< Control, Rules... > {}; template< typename... Rules > struct disable : internal::disable< Rules... > {}; template< typename... Rules > struct enable : internal::enable< Rules... > {}; diff --git a/src/example/pegtl/coverage.cpp b/src/example/pegtl/coverage.cpp index 457438f1..c68f2d98 100644 --- a/src/example/pegtl/coverage.cpp +++ b/src/example/pegtl/coverage.cpp @@ -242,9 +242,9 @@ namespace coverage report( pair.first, pair.second ); } } - const double fraction = double( m_total_lines - m_problem_lines ) / double( m_total_lines ); - std::cout << "Summary for lines -- total " << m_total_lines << " problems " << m_problem_lines << " coverage " << fraction << std::endl; - std::cout << "Summary for files -- total " << m_total_files << " problems " << m_problem_files << std::endl; + const double fraction = 100.0 * double( m_total_lines - m_problem_lines ) / double( m_total_lines ); + std::cout << "Summary for lines -- total " << m_total_lines << " uncovered " << m_problem_lines << " coverage " << fraction << '%' << std::endl; + std::cout << "Summary for files -- total " << m_total_files << " problematic " << m_problem_files << std::endl; } void report( const std::string& name, const per_file_data& data ) diff --git a/src/test/pegtl/CMakeLists.txt b/src/test/pegtl/CMakeLists.txt index b6235fac..832ecffe 100644 --- a/src/test/pegtl/CMakeLists.txt +++ b/src/test/pegtl/CMakeLists.txt @@ -46,6 +46,7 @@ set(test_sources buffer_rule_is_buffer.cpp buffer_rule_require.cpp buffer_static_buffer.cpp + buffer_text_buffer_input.cpp contrib_alphabet.cpp contrib_check_count.cpp contrib_check_depth.cpp @@ -56,6 +57,7 @@ set(test_sources contrib_integer.cpp contrib_integer_convert.cpp contrib_integer_match.cpp + contrib_integer_maximum.cpp contrib_iri.cpp contrib_json.cpp contrib_limit_count.cpp diff --git a/src/test/pegtl/buffer_buffer_common.cpp b/src/test/pegtl/buffer_buffer_common.cpp index 143c1c5a..cdf7943c 100644 --- a/src/test/pegtl/buffer_buffer_common.cpp +++ b/src/test/pegtl/buffer_buffer_common.cpp @@ -69,6 +69,7 @@ namespace TAO_PEGTL_NAMESPACE #if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.require( 101 ) ); TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) ); + TAO_PEGTL_TEST_THROWS( (void)bc.size( 100, 101 ) ); #endif TAO_PEGTL_TEST_ASSERT( !bc.empty() ); diff --git a/src/test/pegtl/buffer_text_buffer_input.cpp b/src/test/pegtl/buffer_text_buffer_input.cpp new file mode 100644 index 00000000..b9f1057a --- /dev/null +++ b/src/test/pegtl/buffer_text_buffer_input.cpp @@ -0,0 +1,48 @@ +// Copyright (c) 2024 Dr. Colin Hirsch and Daniel Frey +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) + +#include "test.hpp" + +#include + +namespace TAO_PEGTL_NAMESPACE +{ + template< typename ParseInput > + void main_test( ParseInput& in ) + { + in.require( 10 ); + const auto m = in.rewind_position(); + TAO_PEGTL_TEST_ASSERT( in.previous( m ) == in.current() ); + in.consume< any >( 6 ); + TAO_PEGTL_TEST_ASSERT( in.previous( m ) + 6 == in.current() ); + in.rewind_to_position( m ); + TAO_PEGTL_TEST_ASSERT( in.previous( m ) == in.current() ); + TAO_PEGTL_TEST_ASSERT( &in.current_position() == &in.direct_position() ); + TAO_PEGTL_TEST_ASSERT( in.direct_count() == in.current_position().count ); + TAO_PEGTL_TEST_ASSERT( in.direct_line() == in.current_position().line ); + TAO_PEGTL_TEST_ASSERT( in.direct_column() == in.current_position().column ); + in.consume< alpha >( 5 ); + const auto n = in.rewind_position(); + in.consume< eol >( 1 ); + TAO_PEGTL_TEST_ASSERT( in.direct_count() == 6 ); + TAO_PEGTL_TEST_ASSERT( in.direct_line() == 2 ); + TAO_PEGTL_TEST_ASSERT( in.direct_column() == 1 ); + const auto p = in.previous_position( n ); + TAO_PEGTL_TEST_ASSERT( p.count == 5 ); + TAO_PEGTL_TEST_ASSERT( p.line == 1 ); + TAO_PEGTL_TEST_ASSERT( p.column == 6 ); + } + + void unit_test() + { + dynamic_text_cstring_input<> i1( 50, 10, "input\ndata" ); + main_test( i1 ); + dynamic_text_cstring_input< tao_buffer_eol, std::string > i2( "source", 50, 10, "input\ndata" ); + main_test( i2 ); + TAO_PEGTL_TEST_ASSERT( i2.direct_source() == "source" ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/test/pegtl/contrib_input_with_depth.cpp b/src/test/pegtl/contrib_input_with_depth.cpp new file mode 100644 index 00000000..045db910 --- /dev/null +++ b/src/test/pegtl/contrib_input_with_depth.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2024 Dr. Colin Hirsch and Daniel Frey +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) + +#include + +#include "test.hpp" +#include "test_utility.hpp" + +#include + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + using input_t = input_with_depth< text_view_input< scan::lf > >; + const std::string_view data = "test"; + input_t in( data ); + TAO_PEGTL_TEST_ASSERT( in.current() == data.data() ); + TAO_PEGTL_TEST_ASSERT( in.current_depth() == 0 ); + { + const auto dg = in.make_depth_guard(); + TAO_PEGTL_TEST_ASSERT( in.current_depth() == 1 ); + in.consume< alpha >( 2 ); + TAO_PEGTL_TEST_ASSERT( in.current() == data.data() + 2 ); + } + TAO_PEGTL_TEST_ASSERT( in.current() == data.data() + 2 ); + TAO_PEGTL_TEST_ASSERT( in.current_depth() == 0 ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/test/pegtl/contrib_input_with_offset.cpp b/src/test/pegtl/contrib_input_with_offset.cpp index d98993d5..8627ba5f 100644 --- a/src/test/pegtl/contrib_input_with_offset.cpp +++ b/src/test/pegtl/contrib_input_with_offset.cpp @@ -29,6 +29,7 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( b ); TAO_PEGTL_TEST_ASSERT( in.previous_position( r ).count == 46 ); TAO_PEGTL_TEST_ASSERT( in.current_position().count == 49 ); + TAO_PEGTL_TEST_ASSERT( in.direct_offset() == count_position( 42 ) ); } void test_count_offset_source() @@ -71,6 +72,7 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( in.current_position().count == 107 ); TAO_PEGTL_TEST_ASSERT( in.current_position().line == 201 ); TAO_PEGTL_TEST_ASSERT( in.current_position().column == 4 ); + TAO_PEGTL_TEST_ASSERT( in.direct_offset() == text_position( 200, 300, 100 ) ); } void test_text_offset_source() diff --git a/src/test/pegtl/contrib_integer.cpp b/src/test/pegtl/contrib_integer.cpp index 38e75aac..a1300485 100644 --- a/src/test/pegtl/contrib_integer.cpp +++ b/src/test/pegtl/contrib_integer.cpp @@ -53,6 +53,22 @@ namespace TAO_PEGTL_NAMESPACE parse< must< signed_rule_with_action, eof > >( in, st ); TAO_PEGTL_TEST_ASSERT( st == s ); } + { + text_view_input< scan::lf > in( i ); + parse< must< disable< signed_rule_with_action >, eof > >( in ); + } + { + S st = -123; + text_view_input< scan::lf > in( i ); + parse< must< disable< signed_rule_with_action >, eof > >( in, st ); + TAO_PEGTL_TEST_ASSERT( st == -123 ); + } + { + S st = -123; + text_view_input< scan::lf > in( i ); + parse< must< disable< signed_rule_with_action >, eof > >( in, st, in ); + TAO_PEGTL_TEST_ASSERT( st == -123 ); + } } template< typename S > @@ -64,7 +80,7 @@ namespace TAO_PEGTL_NAMESPACE } template< typename S > - std::string lexical_cast( const S s ) + [[nodiscard]] std::string lexical_cast( const S s ) { std::ostringstream oss; oss << s; @@ -90,6 +106,22 @@ namespace TAO_PEGTL_NAMESPACE parse< must< unsigned_rule, eof >, int_action >( in, st ); TAO_PEGTL_TEST_ASSERT( st == s ); } + { + text_view_input< scan::lf > in( i ); + parse< must< unsigned_rule_with_action, eof >, nothing, normal, apply_mode::nothing >( in ); + } + { + S st = 123; + text_view_input< scan::lf > in( i ); + parse< must< unsigned_rule_with_action, eof >, nothing, normal, apply_mode::nothing >( in, st ); + TAO_PEGTL_TEST_ASSERT( st == 123 ); + } + { + S st = 123; + text_view_input< scan::lf > in( i ); + parse< must< unsigned_rule_with_action, eof >, nothing, normal, apply_mode::nothing >( in, st, in ); + TAO_PEGTL_TEST_ASSERT( st == 123 ); + } { S st = 123; text_view_input< scan::lf > in( i ); @@ -116,9 +148,6 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( st == s ); } - template< auto M > - using max_seq_rule = seq< one< 'a' >, maximum_rule< std::uint64_t, M >, one< 'b' >, eof >; - void unit_test() { test_signed< signed char >( "" ); @@ -180,76 +209,6 @@ namespace TAO_PEGTL_NAMESPACE test_unsigned< unsigned long long >( "0", 0 ); test_unsigned< unsigned long long >( ( std::numeric_limits< unsigned long long >::max )() ); - verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "a0b", result_type::success ); - verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); - verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "a1b", result_type::local_failure ); - verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "a9b", result_type::local_failure ); - verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); - - verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a0b", result_type::success ); - verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a1b", result_type::success ); - verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); - verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a2b", result_type::local_failure ); - verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a9b", result_type::local_failure ); - verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); - - verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a0b", result_type::success ); - verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a1b", result_type::success ); - verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a2b", result_type::success ); - verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); - verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a3b", result_type::local_failure ); - verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a9b", result_type::local_failure ); - verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); - - verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "a0b", result_type::success ); - verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "a3b", result_type::success ); - verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); - verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "a4b", result_type::local_failure ); - verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); - - verify_rule< max_seq_rule< 4 > >( __LINE__, __FILE__, "a5b", result_type::local_failure ); - verify_rule< max_seq_rule< 4 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); - - verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "a0b", result_type::success ); - verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "a9b", result_type::success ); - verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); - verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "a10b", result_type::local_failure ); - verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); - - verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a0b", result_type::success ); - verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a9b", result_type::success ); - verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a10b", result_type::success ); - verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); - verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); - verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a19b", result_type::local_failure ); - - verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a0b", result_type::success ); - verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a9b", result_type::success ); - verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a10b", result_type::success ); - verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a11b", result_type::success ); - verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); - verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a12b", result_type::local_failure ); - verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a13b", result_type::local_failure ); - verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a111b", result_type::local_failure ); - - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a0b", result_type::success ); - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a1b", result_type::success ); - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a9b", result_type::success ); - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a10b", result_type::success ); - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a11b", result_type::success ); - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a12b", result_type::success ); - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a13b", result_type::local_failure ); - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a19b", result_type::local_failure ); - verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a111b", result_type::local_failure ); - - verify_rule< max_seq_rule< 18446744073709551614ULL > >( __LINE__, __FILE__, "a18446744073709551614b", result_type::success ); - verify_rule< max_seq_rule< 18446744073709551614ULL > >( __LINE__, __FILE__, "a18446744073709551615b", result_type::local_failure ); - - verify_rule< max_seq_rule< 18446744073709551615ULL > >( __LINE__, __FILE__, "a18446744073709551615b", result_type::success ); - verify_rule< max_seq_rule< 18446744073709551615ULL > >( __LINE__, __FILE__, "a18446744073709551616b", result_type::local_failure ); - verify_rule< max_seq_rule< 18446744073709551615ULL > >( __LINE__, __FILE__, "a98446744073709551614b", result_type::local_failure ); - verify_analyze< unsigned_rule >( __LINE__, __FILE__, true, false ); verify_analyze< unsigned_rule_with_action >( __LINE__, __FILE__, true, false ); diff --git a/src/test/pegtl/contrib_integer_maximum.cpp b/src/test/pegtl/contrib_integer_maximum.cpp new file mode 100644 index 00000000..4ac3e7bd --- /dev/null +++ b/src/test/pegtl/contrib_integer_maximum.cpp @@ -0,0 +1,183 @@ +// Copyright (c) 2018-2024 Dr. Colin Hirsch and Daniel Frey +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) + +#if !defined( __cpp_exceptions ) +#include +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + +#include +#include +#include + +#include "test.hpp" +#include "test_utility.hpp" +#include "verify_meta.hpp" +#include "verify_rule.hpp" + +#include + +namespace TAO_PEGTL_NAMESPACE +{ + template< typename Rule > + struct int_action + : nothing< Rule > + {}; + + template<> + struct int_action< unsigned_rule > + : maximum_action< unsigned, 42 > + {}; + + void test_overflow( const std::string& i ) + { + { + unsigned st = 123; + text_view_input< scan::lf > in( i ); + TAO_PEGTL_TEST_THROWS( parse< must< unsigned_rule, eof >, int_action >( in, st ) ); + } + { + text_view_input< scan::lf > in( i ); + TAO_PEGTL_TEST_THROWS( parse< must< maximum_rule_with_action< unsigned, 42 >, eof >, nothing, normal, apply_mode::nothing >( in ) ); + } + { + unsigned st = 123; + text_view_input< scan::lf > in( i ); + TAO_PEGTL_TEST_THROWS( parse< must< maximum_rule_with_action< unsigned, 42 >, eof >, nothing, normal, apply_mode::nothing >( in, st ) ); + } + { + unsigned st = 123; + text_view_input< scan::lf > in( i ); + TAO_PEGTL_TEST_THROWS( parse< must< maximum_rule_with_action< unsigned, 42 >, eof >, nothing, normal, apply_mode::nothing >( in, st, in ) ); + } + { + unsigned st = 123; + text_view_input< scan::lf > in( i ); + TAO_PEGTL_TEST_THROWS( parse< must< maximum_rule_with_action< unsigned, 42 >, eof > >( in, st ) ); + } + } + + void test_unsigned( const std::string& i, const unsigned s ) + { + { + unsigned st = 123; + text_view_input< scan::lf > in( i ); + parse< must< unsigned_rule, eof >, int_action >( in, st ); + TAO_PEGTL_TEST_ASSERT( st == s ); + } + { + text_view_input< scan::lf > in( i ); + parse< must< maximum_rule_with_action< unsigned, 42 >, eof >, nothing, normal, apply_mode::nothing >( in ); + } + { + unsigned st = 123; + text_view_input< scan::lf > in( i ); + parse< must< maximum_rule_with_action< unsigned, 42 >, eof >, nothing, normal, apply_mode::nothing >( in, st ); + TAO_PEGTL_TEST_ASSERT( st == 123 ); + } + { + unsigned st = 123; + text_view_input< scan::lf > in( i ); + parse< must< maximum_rule_with_action< unsigned, 42 >, eof >, nothing, normal, apply_mode::nothing >( in, st, in ); + TAO_PEGTL_TEST_ASSERT( st == 123 ); + } + { + unsigned st = 123; + text_view_input< scan::lf > in( i ); + parse< must< maximum_rule_with_action< unsigned, 42 >, eof > >( in, st ); + TAO_PEGTL_TEST_ASSERT( st == s ); + } + } + + template< auto M > + using max_seq_rule = seq< one< 'a' >, maximum_rule< std::uint64_t, M >, one< 'b' >, eof >; + + void unit_test() + { + test_overflow( "43" ); + test_overflow( "100" ); + + test_unsigned( "0", 0 ); + test_unsigned( "1", 1 ); + test_unsigned( "42", 42 ); + + verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "a0b", result_type::success ); + verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); + verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "a1b", result_type::local_failure ); + verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "a9b", result_type::local_failure ); + verify_rule< max_seq_rule< 0 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); + + verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a0b", result_type::success ); + verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a1b", result_type::success ); + verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); + verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a2b", result_type::local_failure ); + verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a9b", result_type::local_failure ); + verify_rule< max_seq_rule< 1 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); + + verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a0b", result_type::success ); + verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a1b", result_type::success ); + verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a2b", result_type::success ); + verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); + verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a3b", result_type::local_failure ); + verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a9b", result_type::local_failure ); + verify_rule< max_seq_rule< 2 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); + + verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "a0b", result_type::success ); + verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "a3b", result_type::success ); + verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); + verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "a4b", result_type::local_failure ); + verify_rule< max_seq_rule< 3 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); + + verify_rule< max_seq_rule< 4 > >( __LINE__, __FILE__, "a5b", result_type::local_failure ); + verify_rule< max_seq_rule< 4 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); + + verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "a0b", result_type::success ); + verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "a9b", result_type::success ); + verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); + verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "a10b", result_type::local_failure ); + verify_rule< max_seq_rule< 9 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); + + verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a0b", result_type::success ); + verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a9b", result_type::success ); + verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a10b", result_type::success ); + verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); + verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a11b", result_type::local_failure ); + verify_rule< max_seq_rule< 10 > >( __LINE__, __FILE__, "a19b", result_type::local_failure ); + + verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a0b", result_type::success ); + verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a9b", result_type::success ); + verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a10b", result_type::success ); + verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a11b", result_type::success ); + verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); + verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a12b", result_type::local_failure ); + verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a13b", result_type::local_failure ); + verify_rule< max_seq_rule< 11 > >( __LINE__, __FILE__, "a111b", result_type::local_failure ); + + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a0b", result_type::success ); + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a1b", result_type::success ); + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a9b", result_type::success ); + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a10b", result_type::success ); + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a11b", result_type::success ); + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a12b", result_type::success ); + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "ab", result_type::local_failure ); + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a13b", result_type::local_failure ); + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a19b", result_type::local_failure ); + verify_rule< max_seq_rule< 12 > >( __LINE__, __FILE__, "a111b", result_type::local_failure ); + + verify_rule< max_seq_rule< 18446744073709551614ULL > >( __LINE__, __FILE__, "a18446744073709551614b", result_type::success ); + verify_rule< max_seq_rule< 18446744073709551614ULL > >( __LINE__, __FILE__, "a18446744073709551615b", result_type::local_failure ); + + verify_rule< max_seq_rule< 18446744073709551615ULL > >( __LINE__, __FILE__, "a18446744073709551615b", result_type::success ); + verify_rule< max_seq_rule< 18446744073709551615ULL > >( __LINE__, __FILE__, "a18446744073709551616b", result_type::local_failure ); + verify_rule< max_seq_rule< 18446744073709551615ULL > >( __LINE__, __FILE__, "a98446744073709551614b", result_type::local_failure ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" + +#endif diff --git a/src/test/pegtl/contrib_record.cpp b/src/test/pegtl/contrib_record.cpp index 80812e47..d9008c4a 100644 --- a/src/test/pegtl/contrib_record.cpp +++ b/src/test/pegtl/contrib_record.cpp @@ -23,6 +23,7 @@ namespace TAO_PEGTL_NAMESPACE text_view_input<> in( "ac" ); const auto v = record< one_a, one_b, one_c >::parse< grammar >( in ); TAO_PEGTL_TEST_ASSERT( v.size() == 2 ); + std::cout << v << std::endl; } void test2() @@ -30,6 +31,7 @@ namespace TAO_PEGTL_NAMESPACE text_view_input<> in( "ac" ); const auto v = record< one_a, one_b, one_c, seq_ab >::parse< grammar >( in ); TAO_PEGTL_TEST_ASSERT( v.size() == 2 ); + std::cout << v << std::endl; } void test3() @@ -37,6 +39,7 @@ namespace TAO_PEGTL_NAMESPACE text_view_input<> in( "ad" ); const auto v = record< one_a, one_b, one_c, seq_ab >::parse< grammar >( in ); TAO_PEGTL_TEST_ASSERT( v.empty() ); + std::cout << v << std::endl; } void unit_test() diff --git a/src/test/pegtl/internal_constexpr.cpp b/src/test/pegtl/internal_constexpr.cpp index 6a8dd6c3..945066b2 100644 --- a/src/test/pegtl/internal_constexpr.cpp +++ b/src/test/pegtl/internal_constexpr.cpp @@ -2,8 +2,11 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) +#include + #include "test.hpp" +#include #include #include @@ -27,145 +30,308 @@ namespace TAO_PEGTL_NAMESPACE int bar; }; + // Some compilers simultaneously + // (a) optimise away every invocation of trivial constexpr functions even with -O0 -fno-inline, but + // (b) also emit the functions as code, even though they are impossible to call without contortions. + // For now using std::function bypasses the optimiser so that the functions are called at run-time. + + template< typename R > + void constexpr_to_runtime_hack( R ( &f )(), const std::decay_t< R > r ) // TODO: Use std::type_identity_t with C++20. + { + std::function< R() > u( f ); + TAO_PEGTL_TEST_ASSERT( u() == r ); + } + + template< typename R, typename T > + void constexpr_to_runtime_hack( R ( &f )( const T ), const std::decay_t< T > t, const std::decay_t< R > r ) // TODO: Use std::type_identity_t with C++20. + { + std::function< R( const T ) > u( f ); + TAO_PEGTL_TEST_ASSERT( u( t ) == r ); + } + void unit_test() { using in8 = internal::view_input< std::uint8_t >; using in16 = internal::view_input< std::uint16_t >; using in32 = internal::view_input< std::uint32_t >; using in64 = internal::view_input< std::uint64_t >; + using ins = internal::view_input< std::string >; + + static_assert( internal::peek_data::bulk< ins >() == true ); + static_assert( internal::peek_data::size< ins >() == 1 ); + + static_assert( internal::peek_char::bulk< in8 >() == true ); + static_assert( internal::peek_char::size< in8 >() == 1 ); + + static_assert( internal::peek_seven::bulk< in8 >() == false ); + static_assert( internal::peek_seven::size< in8 >() == 1 ); + + static_assert( internal::peek_utf8::bulk< in8 >() == false ); + static_assert( internal::peek_utf8::size< in8 >() == 0 ); + + static_assert( internal::peek_utf16_be::bulk< in8 >() == false ); + static_assert( internal::peek_utf16_be::size< in8 >() == 0 ); + + static_assert( internal::peek_utf16_le::bulk< in16 >() == false ); + static_assert( internal::peek_utf16_le::size< in16 >() == 0 ); + + static_assert( internal::peek_utf32_be::bulk< in8 >() == false ); + static_assert( internal::peek_utf32_be::size< in8 >() == 4 ); + + static_assert( internal::peek_utf32_le::bulk< in32 >() == false ); + static_assert( internal::peek_utf32_le::size< in32 >() == 1 ); + + static_assert( internal::peek_int8::bulk< in8 >() == true ); + static_assert( internal::peek_int8::size< in8 >() == 1 ); + + static_assert( internal::peek_int16_be::bulk< in8 >() == true ); + static_assert( internal::peek_int16_be::size< in8 >() == 2 ); + + static_assert( internal::peek_int16_le::bulk< in16 >() == true ); + static_assert( internal::peek_int16_le::size< in16 >() == 1 ); + + static_assert( internal::peek_int32_be::bulk< in8 >() == true ); + static_assert( internal::peek_int32_be::size< in8 >() == 4 ); + + static_assert( internal::peek_int32_le::bulk< in32 >() == true ); + static_assert( internal::peek_int32_le::size< in32 >() == 1 ); + + static_assert( internal::peek_int64_be::bulk< in8 >() == true ); + static_assert( internal::peek_int64_be::size< in8 >() == 8 ); + + static_assert( internal::peek_int64_le::bulk< in64 >() == true ); + static_assert( internal::peek_int64_le::size< in64 >() == 1 ); + + static_assert( internal::peek_uint8::bulk< in8 >() == true ); + static_assert( internal::peek_uint8::size< in8 >() == 1 ); + + static_assert( internal::peek_uint16_be::bulk< in8 >() == true ); + static_assert( internal::peek_uint16_be::size< in8 >() == 2 ); + + static_assert( internal::peek_uint16_le::bulk< in16 >() == true ); + static_assert( internal::peek_uint16_le::size< in16 >() == 1 ); + + static_assert( internal::peek_uint32_be::bulk< in8 >() == true ); + static_assert( internal::peek_uint32_be::size< in8 >() == 4 ); + + static_assert( internal::peek_uint32_le::bulk< in32 >() == true ); + static_assert( internal::peek_uint32_le::size< in32 >() == 1 ); + + static_assert( internal::peek_uint64_be::bulk< in8 >() == true ); + static_assert( internal::peek_uint64_be::size< in8 >() == 8 ); + + static_assert( internal::peek_uint64_le::bulk< in64 >() == true ); + static_assert( internal::peek_uint64_le::size< in64 >() == 1 ); + + static_assert( internal::peek_mask_int8< 42 >::bulk< in8 >() == true ); + static_assert( internal::peek_mask_int8< 43 >::size< in8 >() == 1 ); + + static_assert( internal::peek_mask_int16_be< 42 >::bulk< in8 >() == true ); + static_assert( internal::peek_mask_int16_be< 43 >::size< in8 >() == 2 ); + + static_assert( internal::peek_mask_int16_le< 42 >::bulk< in16 >() == true ); + static_assert( internal::peek_mask_int16_le< 43 >::size< in16 >() == 1 ); + + static_assert( internal::peek_mask_int32_be< 42 >::bulk< in8 >() == true ); + static_assert( internal::peek_mask_int32_be< 43 >::size< in8 >() == 4 ); + + static_assert( internal::peek_mask_int32_le< 42 >::bulk< in32 >() == true ); + static_assert( internal::peek_mask_int32_le< 43 >::size< in32 >() == 1 ); + + static_assert( internal::peek_mask_int64_be< 42 >::bulk< in8 >() == true ); + static_assert( internal::peek_mask_int64_be< 43 >::size< in8 >() == 8 ); + + static_assert( internal::peek_mask_int64_le< 42 >::bulk< in64 >() == true ); + static_assert( internal::peek_mask_int64_le< 43 >::size< in64 >() == 1 ); + + static_assert( internal::peek_mask_uint8< 42 >::bulk< in8 >() == true ); + static_assert( internal::peek_mask_uint8< 43 >::size< in8 >() == 1 ); + + static_assert( internal::peek_mask_uint16_be< 42 >::bulk< in8 >() == true ); + static_assert( internal::peek_mask_uint16_be< 43 >::size< in8 >() == 2 ); + + static_assert( internal::peek_mask_uint16_le< 42 >::bulk< in16 >() == true ); + static_assert( internal::peek_mask_uint16_le< 43 >::size< in16 >() == 1 ); + + static_assert( internal::peek_mask_uint32_be< 42 >::bulk< in8 >() == true ); + static_assert( internal::peek_mask_uint32_be< 43 >::size< in8 >() == 4 ); + + static_assert( internal::peek_mask_uint32_le< 42 >::bulk< in32 >() == true ); + static_assert( internal::peek_mask_uint32_le< 43 >::size< in32 >() == 1 ); + + static_assert( internal::peek_mask_uint64_be< 42 >::bulk< in8 >() == true ); + static_assert( internal::peek_mask_uint64_be< 43 >::size< in8 >() == 8 ); + + static_assert( internal::peek_mask_uint64_le< 42 >::bulk< in64 >() == true ); + static_assert( internal::peek_mask_uint64_le< 43 >::size< in64 >() == 1 ); + + static_assert( internal::peek_member< &foo::bar >::bulk< void >() == true ); + static_assert( internal::peek_member< &foo::bar >::size< void >() == 1 ); + + static_assert( internal::peek_unicode::bulk< ins >() == false ); + + static_assert( internal::has_utf8_length_1( 0x0000 ) == true ); + static_assert( internal::has_utf8_length_1( 0x007f ) == true ); + static_assert( internal::has_utf8_length_1( 0x0080 ) == false ); + static_assert( internal::has_utf8_length_1( 0xffff ) == false ); + + static_assert( internal::has_utf8_length_2( 0x007f ) == false ); + static_assert( internal::has_utf8_length_2( 0x0080 ) == true ); + static_assert( internal::has_utf8_length_2( 0x07ff ) == true ); + static_assert( internal::has_utf8_length_2( 0x0800 ) == false ); + + static_assert( internal::has_utf8_length_3( 0x007ff ) == false ); + static_assert( internal::has_utf8_length_3( 0x00800 ) == true ); + static_assert( internal::has_utf8_length_3( 0x0ffff ) == true ); + static_assert( internal::has_utf8_length_3( 0x10000 ) == false ); + + static_assert( internal::has_utf8_length_3( 0x0d7ff ) == true ); + static_assert( internal::has_utf8_length_3( 0x0d800 ) == false ); + static_assert( internal::has_utf8_length_3( 0x0dfff ) == false ); + static_assert( internal::has_utf8_length_3( 0x0e000 ) == true ); + + static_assert( internal::has_utf8_length_4( 0x00ffff ) == false ); + static_assert( internal::has_utf8_length_4( 0x010000 ) == true ); + static_assert( internal::has_utf8_length_4( 0x10ffff ) == true ); + static_assert( internal::has_utf8_length_4( 0x110000 ) == false ); + + constexpr_to_runtime_hack( internal::peek_data::bulk< ins >, true ); + constexpr_to_runtime_hack( internal::peek_data::size< ins >, 1 ); + + constexpr_to_runtime_hack( internal::peek_char::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_char::size< in8 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_char::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_char::size< in8 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_seven::bulk< in8 >, false ); + constexpr_to_runtime_hack( internal::peek_seven::size< in8 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_seven::bulk< in8 >() == false ); - TAO_PEGTL_TEST_ASSERT( internal::peek_seven::size< in8 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_utf8::bulk< in8 >, false ); + constexpr_to_runtime_hack( internal::peek_utf8::size< in8 >, 0 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf8::bulk< in8 >() == false ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf8::size< in8 >() == 0 ); + constexpr_to_runtime_hack( internal::peek_utf16_be::bulk< in8 >, false ); + constexpr_to_runtime_hack( internal::peek_utf16_be::size< in8 >, 0 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf16_be::bulk< in8 >() == false ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf16_be::size< in8 >() == 0 ); + constexpr_to_runtime_hack( internal::peek_utf16_le::bulk< in16 >, false ); + constexpr_to_runtime_hack( internal::peek_utf16_le::size< in16 >, 0 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf16_le::bulk< in16 >() == false ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf16_le::size< in16 >() == 0 ); + constexpr_to_runtime_hack( internal::peek_utf32_be::bulk< in8 >, false ); + constexpr_to_runtime_hack( internal::peek_utf32_be::size< in8 >, 4 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf32_be::bulk< in8 >() == false ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf32_be::size< in8 >() == 4 ); + constexpr_to_runtime_hack( internal::peek_utf32_le::bulk< in32 >, false ); + constexpr_to_runtime_hack( internal::peek_utf32_le::size< in32 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf32_le::bulk< in32 >() == false ); - TAO_PEGTL_TEST_ASSERT( internal::peek_utf32_le::size< in32 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_int8::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_int8::size< in8 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int8::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int8::size< in8 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_int16_be::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_int16_be::size< in8 >, 2 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int16_be::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int16_be::size< in8 >() == 2 ); + constexpr_to_runtime_hack( internal::peek_int16_le::bulk< in16 >, true ); + constexpr_to_runtime_hack( internal::peek_int16_le::size< in16 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int16_le::bulk< in16 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int16_le::size< in16 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_int32_be::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_int32_be::size< in8 >, 4 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int32_be::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int32_be::size< in8 >() == 4 ); + constexpr_to_runtime_hack( internal::peek_int32_le::bulk< in32 >, true ); + constexpr_to_runtime_hack( internal::peek_int32_le::size< in32 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int32_le::bulk< in32 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int32_le::size< in32 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_int64_be::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_int64_be::size< in8 >, 8 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int64_be::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int64_be::size< in8 >() == 8 ); + constexpr_to_runtime_hack( internal::peek_int64_le::bulk< in64 >, true ); + constexpr_to_runtime_hack( internal::peek_int64_le::size< in64 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int64_le::bulk< in64 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_int64_le::size< in64 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_uint8::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_uint8::size< in8 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint8::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint8::size< in8 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_uint16_be::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_uint16_be::size< in8 >, 2 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint16_be::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint16_be::size< in8 >() == 2 ); + constexpr_to_runtime_hack( internal::peek_uint16_le::bulk< in16 >, true ); + constexpr_to_runtime_hack( internal::peek_uint16_le::size< in16 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint16_le::bulk< in16 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint16_le::size< in16 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_uint32_be::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_uint32_be::size< in8 >, 4 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint32_be::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint32_be::size< in8 >() == 4 ); + constexpr_to_runtime_hack( internal::peek_uint32_le::bulk< in32 >, true ); + constexpr_to_runtime_hack( internal::peek_uint32_le::size< in32 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint32_le::bulk< in32 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint32_le::size< in32 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_uint64_be::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_uint64_be::size< in8 >, 8 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint64_be::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint64_be::size< in8 >() == 8 ); + constexpr_to_runtime_hack( internal::peek_uint64_le::bulk< in64 >, true ); + constexpr_to_runtime_hack( internal::peek_uint64_le::size< in64 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint64_le::bulk< in64 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_uint64_le::size< in64 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_mask_int8< 42 >::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_int8< 43 >::size< in8 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int8< 42 >::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int8< 43 >::size< in8 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_mask_int16_be< 42 >::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_int16_be< 43 >::size< in8 >, 2 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int16_be< 42 >::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int16_be< 43 >::size< in8 >() == 2 ); + constexpr_to_runtime_hack( internal::peek_mask_int16_le< 42 >::bulk< in16 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_int16_le< 43 >::size< in16 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int16_le< 42 >::bulk< in16 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int16_le< 43 >::size< in16 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_mask_int32_be< 42 >::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_int32_be< 43 >::size< in8 >, 4 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int32_be< 42 >::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int32_be< 43 >::size< in8 >() == 4 ); + constexpr_to_runtime_hack( internal::peek_mask_int32_le< 42 >::bulk< in32 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_int32_le< 43 >::size< in32 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int32_le< 42 >::bulk< in32 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int32_le< 43 >::size< in32 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_mask_int64_be< 42 >::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_int64_be< 43 >::size< in8 >, 8 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int64_be< 42 >::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int64_be< 43 >::size< in8 >() == 8 ); + constexpr_to_runtime_hack( internal::peek_mask_int64_le< 42 >::bulk< in64 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_int64_le< 43 >::size< in64 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int64_le< 42 >::bulk< in64 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_int64_le< 43 >::size< in64 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_mask_uint8< 42 >::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_uint8< 43 >::size< in8 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint8< 42 >::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint8< 43 >::size< in8 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_mask_uint16_be< 42 >::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_uint16_be< 43 >::size< in8 >, 2 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint16_be< 42 >::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint16_be< 43 >::size< in8 >() == 2 ); + constexpr_to_runtime_hack( internal::peek_mask_uint16_le< 42 >::bulk< in16 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_uint16_le< 43 >::size< in16 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint16_le< 42 >::bulk< in16 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint16_le< 43 >::size< in16 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_mask_uint32_be< 42 >::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_uint32_be< 43 >::size< in8 >, 4 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint32_be< 42 >::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint32_be< 43 >::size< in8 >() == 4 ); + constexpr_to_runtime_hack( internal::peek_mask_uint32_le< 42 >::bulk< in32 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_uint32_le< 43 >::size< in32 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint32_le< 42 >::bulk< in32 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint32_le< 43 >::size< in32 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_mask_uint64_be< 42 >::bulk< in8 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_uint64_be< 43 >::size< in8 >, 8 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint64_be< 42 >::bulk< in8 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint64_be< 43 >::size< in8 >() == 8 ); + constexpr_to_runtime_hack( internal::peek_mask_uint64_le< 42 >::bulk< in64 >, true ); + constexpr_to_runtime_hack( internal::peek_mask_uint64_le< 43 >::size< in64 >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint64_le< 42 >::bulk< in64 >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_mask_uint64_le< 43 >::size< in64 >() == 1 ); + constexpr_to_runtime_hack( internal::peek_member< &foo::bar >::bulk< void >, true ); + constexpr_to_runtime_hack( internal::peek_member< &foo::bar >::size< void >, 1 ); - TAO_PEGTL_TEST_ASSERT( internal::peek_member< &foo::bar >::bulk< void >() == true ); - TAO_PEGTL_TEST_ASSERT( internal::peek_member< &foo::bar >::size< void >() == 1 ); + constexpr_to_runtime_hack( internal::peek_unicode::bulk< ins >, false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_1( 0x0000 ) == true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_1( 0x007f ) == true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_1( 0x0080 ) == false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_1( 0xffff ) == false ); + constexpr_to_runtime_hack( internal::has_utf8_length_1, 0x0000, true ); + constexpr_to_runtime_hack( internal::has_utf8_length_1, 0x007f, true ); + constexpr_to_runtime_hack( internal::has_utf8_length_1, 0x0080, false ); + constexpr_to_runtime_hack( internal::has_utf8_length_1, 0xffff, false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_2( 0x007f ) == false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_2( 0x0080 ) == true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_2( 0x07ff ) == true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_2( 0x0800 ) == false ); + constexpr_to_runtime_hack( internal::has_utf8_length_2, 0x007f, false ); + constexpr_to_runtime_hack( internal::has_utf8_length_2, 0x0080, true ); + constexpr_to_runtime_hack( internal::has_utf8_length_2, 0x07ff, true ); + constexpr_to_runtime_hack( internal::has_utf8_length_2, 0x0800, false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_3( 0x007ff ) == false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_3( 0x00800 ) == true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_3( 0x0ffff ) == true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_3( 0x10000 ) == false ); + constexpr_to_runtime_hack( internal::has_utf8_length_3, 0x007ff, false ); + constexpr_to_runtime_hack( internal::has_utf8_length_3, 0x00800, true ); + constexpr_to_runtime_hack( internal::has_utf8_length_3, 0x0ffff, true ); + constexpr_to_runtime_hack( internal::has_utf8_length_3, 0x10000, false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_3( 0x0d7ff ) == true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_3( 0x0d800 ) == false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_3( 0x0dfff ) == false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_3( 0x0e000 ) == true ); + constexpr_to_runtime_hack( internal::has_utf8_length_3, 0x0d7ff, true ); + constexpr_to_runtime_hack( internal::has_utf8_length_3, 0x0d800, false ); + constexpr_to_runtime_hack( internal::has_utf8_length_3, 0x0dfff, false ); + constexpr_to_runtime_hack( internal::has_utf8_length_3, 0x0e000, true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_4( 0x00ffff ) == false ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_4( 0x010000 ) == true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_4( 0x10ffff ) == true ); - TAO_PEGTL_TEST_ASSERT( internal::has_utf8_length_4( 0x110000 ) == false ); + constexpr_to_runtime_hack( internal::has_utf8_length_4, 0x00ffff, false ); + constexpr_to_runtime_hack( internal::has_utf8_length_4, 0x010000, true ); + constexpr_to_runtime_hack( internal::has_utf8_length_4, 0x10ffff, true ); + constexpr_to_runtime_hack( internal::has_utf8_length_4, 0x110000, false ); } } // namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/rule_consume.cpp b/src/test/pegtl/rule_consume.cpp index d3853840..aeb560f8 100644 --- a/src/test/pegtl/rule_consume.cpp +++ b/src/test/pegtl/rule_consume.cpp @@ -11,8 +11,8 @@ namespace TAO_PEGTL_NAMESPACE void unit_test() { verify_meta< consume< 0 >, internal::success >(); - verify_meta< consume< 1 >, internal::consume< 1, void, void > >(); - verify_meta< consume< 42 >, internal::consume< 42, void, void > >(); + verify_meta< consume< 1 >, internal::consume< 1 > >(); + verify_meta< consume< 42 >, internal::consume< 42 > >(); verify_analyze< consume< 0 > >( __LINE__, __FILE__, false, false ); verify_analyze< consume< 1 > >( __LINE__, __FILE__, true, false );