summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/qi/difference.cpp
blob: c9600a82d47d15c117e15e876af4fb857f7b4250 (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
70
71
72
73
74
75
76
77
78
/*=============================================================================
    Copyright (c) 2001-2010 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)
=============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/spirit/include/qi_operator.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_string.hpp>
#include <boost/spirit/include/qi_numeric.hpp>
#include <boost/spirit/include/qi_directive.hpp>
#include <boost/spirit/include/qi_action.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>

#include <string>
#include <iostream>
#include "test.hpp"

int
main()
{
    using namespace boost::spirit::ascii;
    using boost::spirit::lit;
    using spirit_test::test;

    {
        BOOST_TEST(test("b", char_ - 'a'));
        BOOST_TEST(!test("a", char_ - 'a'));
        BOOST_TEST(test("/* abcdefghijk */", "/*" >> *(char_ - "*/") >> "*/"));
    }

    {
        BOOST_TEST(test("b", char_ - no_case['a']));
        BOOST_TEST(!test("a", char_ - no_case['a']));
        BOOST_TEST(!test("A", char_ - no_case['a']));

        BOOST_TEST(test("b", no_case[lower - 'a']));
        BOOST_TEST(test("B", no_case[lower - 'a']));
        BOOST_TEST(!test("a", no_case[lower - 'a']));
        BOOST_TEST(!test("A", no_case[lower - 'a']));
    }

    {
        // $$$ See difference.hpp why these tests are not done anymore. $$$

        // BOOST_TEST(test("switcher", lit("switcher") - "switch"));
        // BOOST_TEST(test("    switcher    ", lit("switcher") - "switch", space));

        BOOST_TEST(!test("switch", lit("switch") - "switch"));
    }

    {
        using boost::spirit::_1;
        namespace phx = boost::phoenix;

        std::string s;

        BOOST_TEST(test(
            "/*abcdefghijk*/"
          , "/*" >> *(char_ - "*/")[phx::ref(s) += _1] >> "*/"
        ));
        BOOST_TEST(s == "abcdefghijk");
        s.clear();

        BOOST_TEST(test(
            "    /*abcdefghijk*/"
          , "/*" >> *(char_ - "*/")[phx::ref(s) += _1] >> "*/"
          , space
        ));
        BOOST_TEST(s == "abcdefghijk");
    }

    return boost::report_errors();
}