| 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 | #include "bool.hpp" |
| 9 | |
| 10 | int main() |
| 11 | { |
| 12 | using spirit_test::test_attr; |
| 13 | using spirit_test::test; |
| 14 | using boost::spirit::x3::bool_; |
| 15 | |
| 16 | { |
| 17 | BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(bool_); |
| 18 | |
| 19 | BOOST_TEST(test("true" , bool_)); |
| 20 | BOOST_TEST(test("false" , bool_)); |
| 21 | BOOST_TEST(!test("fasle" , bool_)); |
| 22 | } |
| 23 | |
| 24 | { |
| 25 | using boost::spirit::x3::true_; |
| 26 | using boost::spirit::x3::false_; |
| 27 | |
| 28 | BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(true_); |
| 29 | BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(false_); |
| 30 | |
| 31 | BOOST_TEST(test("true" , true_)); |
| 32 | BOOST_TEST(!test("true" , false_)); |
| 33 | BOOST_TEST(test("false" , false_)); |
| 34 | BOOST_TEST(!test("false" , true_)); |
| 35 | } |
| 36 | |
| 37 | { |
| 38 | using boost::spirit::x3::true_; |
| 39 | using boost::spirit::x3::false_; |
| 40 | using boost::spirit::x3::no_case; |
| 41 | |
| 42 | BOOST_TEST(test("True" , no_case[bool_])); |
| 43 | BOOST_TEST(test("False" , no_case[bool_])); |
| 44 | BOOST_TEST(test("True" , no_case[true_])); |
| 45 | BOOST_TEST(test("False" , no_case[false_])); |
| 46 | } |
| 47 | |
| 48 | { |
| 49 | bool b = false; |
| 50 | BOOST_TEST(test_attr("true" , bool_, b) && b); |
| 51 | BOOST_TEST(test_attr("false" , bool_, b) && !b); |
| 52 | BOOST_TEST(!test_attr("fasle" , bool_, b)); |
| 53 | } |
| 54 | |
| 55 | { |
| 56 | typedef boost::spirit::x3::bool_parser<bool, boost::spirit::char_encoding::standard, backwards_bool_policies> |
| 57 | backwards_bool_type; |
| 58 | constexpr backwards_bool_type backwards_bool{}; |
| 59 | |
| 60 | BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(backwards_bool); |
| 61 | |
| 62 | BOOST_TEST(test("true" , backwards_bool)); |
| 63 | BOOST_TEST(test("eurt" , backwards_bool)); |
| 64 | BOOST_TEST(!test("false" , backwards_bool)); |
| 65 | BOOST_TEST(!test("fasle" , backwards_bool)); |
| 66 | |
| 67 | bool b = false; |
| 68 | BOOST_TEST(test_attr("true" , backwards_bool, b) && b); |
| 69 | BOOST_TEST(test_attr("eurt" , backwards_bool, b) && !b); |
| 70 | BOOST_TEST(!test_attr("false" , backwards_bool, b)); |
| 71 | BOOST_TEST(!test_attr("fasle" , backwards_bool, b)); |
| 72 | } |
| 73 | |
| 74 | { |
| 75 | typedef boost::spirit::x3::bool_parser<test_bool_type, boost::spirit::char_encoding::standard> |
| 76 | bool_test_type; |
| 77 | constexpr bool_test_type test_bool{}; |
| 78 | |
| 79 | BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(test_bool); |
| 80 | |
| 81 | BOOST_TEST(test("true" , test_bool)); |
| 82 | BOOST_TEST(test("false" , test_bool)); |
| 83 | BOOST_TEST(!test("fasle" , test_bool)); |
| 84 | |
| 85 | test_bool_type b = false; |
| 86 | BOOST_TEST(test_attr("true" , test_bool, b) && b.b); |
| 87 | BOOST_TEST(test_attr("false" , test_bool, b) && !b.b); |
| 88 | BOOST_TEST(!test_attr("fasle" , test_bool, b)); |
| 89 | } |
| 90 | |
| 91 | return boost::report_errors(); |
| 92 | } |
| 93 | |