1 // Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
2 // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3 
4 #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_RULE_HPP
5 #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_RULE_HPP
6 
7 #include <cstdlib>
8 #include <string>
9 
10 #include <tao/pegtl/eol.hpp>
11 #include <tao/pegtl/memory_input.hpp>
12 #include <tao/pegtl/tracking_mode.hpp>
13 #include <tao/pegtl/type_list.hpp>
14 
15 #include "result_type.hpp"
16 #include "verify_impl.hpp"
17 
verify_meta()18 namespace TAO_PEGTL_NAMESPACE
19 {
20    template< typename Rule >
21    struct verify_action_impl
22    {
23       template< typename ActionInput, typename... States >
24       static void apply( const ActionInput& /*unused*/, States&&... /*unused*/ )
25       {}
26    };
27 
28    template< typename Rule >
29    struct verify_action_impl0
30    {
31       template< typename... States >
32       static void apply0( States&&... /*unused*/ )
33       {}
34    };
35 
36    template< typename Rule, typename Eol = eol::lf_crlf >
37    void verify_rule( const std::size_t line, const char* file, const std::string& data, const result_type expected, int remain = -1 )
38    {
39       if( remain < 0 ) {
40          remain = ( expected == result_type::success ) ? 0 : int( data.size() );
41       }
42       {
43          memory_input< tracking_mode::eager, Eol > in( data.data(), data.data() + data.size(), file, 0, line, 1 );
44          verify_impl_one< Rule, nothing >( line, file, data, in, expected, remain );
45          memory_input< tracking_mode::lazy, Eol > i2( data.data(), data.data() + data.size(), file );
46          verify_impl_one< Rule, nothing >( line, file, data, i2, expected, remain );
47       }
48       {
49          memory_input< tracking_mode::eager, Eol > in( data.data(), data.data() + data.size(), file, 0, line, 1 );
50          verify_impl_one< Rule, verify_action_impl >( line, file, data, in, expected, remain );
51          memory_input< tracking_mode::lazy, Eol > i2( data.data(), data.data() + data.size(), file );
52          verify_impl_one< Rule, verify_action_impl >( line, file, data, i2, expected, remain );
53       }
54       {
55          memory_input< tracking_mode::eager, Eol > in( data.data(), data.data() + data.size(), file, 0, line, 1 );
56          verify_impl_one< Rule, verify_action_impl0 >( line, file, data, in, expected, remain );
57          memory_input< tracking_mode::lazy, Eol > i2( data.data(), data.data() + data.size(), file );
58          verify_impl_one< Rule, verify_action_impl0 >( line, file, data, i2, expected, remain );
59       }
60    }
61 
62    template< typename Rule, typename Eol = eol::lf_crlf >
63    void verify_only( const std::size_t line, const char* file, const std::string& data, const result_type expected, const std::size_t remain )
64    {
65       {
66          memory_input< tracking_mode::eager, Eol > in( data.data(), data.data() + data.size(), file, 0, line, 1 );
67          verify_impl_one< Rule, nothing >( line, file, data, in, expected, remain );
68       }
69       {
70          memory_input< tracking_mode::eager, Eol > in( data.data(), data.data() + data.size(), file, 0, line, 1 );
71          verify_impl_one< Rule, verify_action_impl >( line, file, data, in, expected, remain );
72       }
73       {
74          memory_input< tracking_mode::eager, Eol > in( data.data(), data.data() + data.size(), file, 0, line, 1 );
75          verify_impl_one< Rule, verify_action_impl0 >( line, file, data, in, expected, remain );
76       }
77    }
78 
79 }  // namespace TAO_PEGTL_NAMESPACE
80 
81 #endif
82