1 /*=============================================================================
2     Copyright (c) 2001-2011 Hartmut Kaiser
3     Copyright (c) 2011      Bryce Lelbach
4 
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 
9 #include "bool.hpp"
10 
main()11 int main()
12 {
13     using spirit_test::test_attr;
14     using spirit_test::test;
15     using boost::spirit::qi::bool_;
16     using boost::spirit::qi::lit;
17     using boost::spirit::qi::no_case;
18 
19     {
20         BOOST_TEST(test("true", bool_(true)));
21         BOOST_TEST(test("false", bool_(false)));
22         BOOST_TEST(!test("fasle", bool_(false)));
23         BOOST_TEST(!test("false", bool_(true)));
24         BOOST_TEST(!test("true", bool_(false)));
25     }
26 
27     {
28         BOOST_TEST(test("True", no_case[bool_(true)]));
29         BOOST_TEST(test("False", no_case[bool_(false)]));
30         BOOST_TEST(test("TRUE", no_case[bool_(true)]));
31         BOOST_TEST(test("FALSE", no_case[bool_(false)]));
32         BOOST_TEST(!test("True", no_case[bool_(false)]));
33         BOOST_TEST(!test("False", no_case[bool_(true)]));
34     }
35 
36     {
37         bool b = false;
38         BOOST_TEST(test_attr("true", bool_(true), b) && b);
39         BOOST_TEST(test_attr("false", bool_(false), b) && !b);
40         BOOST_TEST(!test_attr("fasle", bool_(false), b));
41     }
42 
43     {
44         typedef boost::spirit::qi::bool_parser<bool, backwards_bool_policies>
45             backwards_bool_type;
46         backwards_bool_type const backwards_bool = backwards_bool_type();
47 
48         BOOST_TEST(test("true", backwards_bool(true)));
49         BOOST_TEST(test("eurt", backwards_bool(false)));
50         BOOST_TEST(!test("true", backwards_bool(false)));
51         BOOST_TEST(!test("eurt", backwards_bool(true)));
52     }
53 
54     {
55         using boost::phoenix::ref;
56         bool n = true, m = false;
57 
58         BOOST_TEST(test("true", bool_(ref(n))));
59         BOOST_TEST(!test("true", bool_(ref(m))));
60     }
61 
62     {
63         BOOST_TEST(test("true", lit(true)));
64         BOOST_TEST(test("false", lit(false)));
65         BOOST_TEST(!test("fasle", lit(false)));
66         BOOST_TEST(!test("false", lit(true)));
67         BOOST_TEST(!test("true", lit(false)));
68     }
69 
70     {
71         BOOST_TEST(test("True", no_case[lit(true)]));
72         BOOST_TEST(test("False", no_case[lit(false)]));
73         BOOST_TEST(test("TRUE", no_case[lit(true)]));
74         BOOST_TEST(test("FALSE", no_case[lit(false)]));
75         BOOST_TEST(!test("True", no_case[lit(false)]));
76         BOOST_TEST(!test("False", no_case[lit(true)]));
77     }
78 
79     {
80         using boost::phoenix::ref;
81         bool n = true, m = false;
82 
83         BOOST_TEST(test("true", lit(ref(n))));
84         BOOST_TEST(!test("true", lit(ref(m))));
85     }
86 
87     return boost::report_errors();
88 }
89