summaryrefslogtreecommitdiff
path: root/boost/spirit/home/x3/support/utility/testing.hpp
blob: fced46bef849ddbc7720b70418703a02a8dcc93b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*=============================================================================
    Copyright (c) 2014 Joel de Guzman

    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)
==============================================================================*/
#if !defined(BOOST_SPIRIT_X3_TESTING_JUNE_05_2014_00422PM)
#define BOOST_SPIRIT_X3_TESTING_JUNE_05_2014_00422PM

namespace boost { namespace spirit { namespace x3 { namespace testing
{
    ////////////////////////////////////////////////////////////////////////////
    //
    //  Test utility
    //
    //  The test function accepts a file loaded in memory. The 'test_file'
    //  range param points to the data contained in the file. This file
    //  contains two parts.
    //
    //      1) The source input for testing
    //      2) The expected result.
    //
    //  The first part of the file is sent to the generator function
    //  'gen' which returns a string. This generated string is then compared
    //  to the contents of the second (expected result) part.
    //
    //  The second part is demarcated by the string parameter 'demarcation'
    //  which defaults to "<**expected**>". The expected template may include
    //  embedded regular expressions marked-up within re_prefix and re_suffix
    //  parameter tags. For example, given the default RE markup ("<%" and
    //  "%>"), this template:
    //
    //      <%[0-9]+%>
    //
    //  will match any integer in the source input being tested. The function
    //  will return the first non-matching position. The flag full_match
    //  indicates a full match. It is possible for returned pos to be
    //  at the end of in (in.end()) while still returning full_match ==
    //  false. In that case, we have a partial match.
    //
    //  Here's an example of a test file:
    //
    //      Hello World, I am Joel. This is a test.
    //
    //      <**expected**>
    //      Hello World, I am <%[a-zA-Z]+%>. This is a test.
    //
    ////////////////////////////////////////////////////////////////////////////

    template <typename Iterator>
    struct test_result
    {
        Iterator pos;
        bool full_match;
    };

    template <typename Range, typename F>
    test_result<typename Range::const_iterator>
    test(
        Range test_file
      , F gen
      , char const* demarcation = "<**expected**>"
      , char const* re_prefix = "<%"
      , char const* re_suffix = "%>"
   );

}}}}

#endif