| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2015 Joel de Guzman |
| 3 | Copyright (c) 2001-2011 Hartmut Kaiser |
| 4 | Copyright (c) 2011 Bryce Lelbach |
| 5 | |
| 6 | Use, modification and distribution is subject to the Boost Software |
| 7 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 8 | http://www.boost.org/LICENSE_1_0.txt) |
| 9 | =============================================================================*/ |
| 10 | |
| 11 | #if defined(_MSC_VER) && _MSC_VER < 1910 |
| 12 | int main() {} |
| 13 | #else |
| 14 | |
| 15 | #include "real.hpp" |
| 16 | |
| 17 | #include <boost/math/concepts/real_concept.hpp> |
| 18 | |
| 19 | int |
| 20 | main() |
| 21 | { |
| 22 | using spirit_test::test; |
| 23 | using spirit_test::test_attr; |
| 24 | |
| 25 | /////////////////////////////////////////////////////////////////////////// |
| 26 | // Custom data type |
| 27 | /////////////////////////////////////////////////////////////////////////// |
| 28 | { |
| 29 | using boost::math::concepts::real_concept; |
| 30 | using boost::spirit::x3::real_parser; |
| 31 | using boost::spirit::x3::real_policies; |
| 32 | using boost::spirit::x3::parse; |
| 33 | |
| 34 | constexpr real_parser<real_concept, real_policies<real_concept> > custom_real; |
| 35 | real_concept d; |
| 36 | |
| 37 | BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(custom_real); |
| 38 | |
| 39 | BOOST_TEST(test("-1234" , custom_real)); |
| 40 | BOOST_TEST(test_attr("-1234" , custom_real, d) && compare(d, -1234)); |
| 41 | |
| 42 | BOOST_TEST(test("-1.2e3" , custom_real)); |
| 43 | BOOST_TEST(test_attr("-1.2e3" , custom_real, d) && compare(d, -1.2e3)); |
| 44 | |
| 45 | BOOST_TEST(test("+1.2e3" , custom_real)); |
| 46 | BOOST_TEST(test_attr("+1.2e3" , custom_real, d) && compare(d, 1.2e3)); |
| 47 | |
| 48 | BOOST_TEST(test("-0.1" , custom_real)); |
| 49 | BOOST_TEST(test_attr("-0.1" , custom_real, d) && compare(d, -0.1)); |
| 50 | |
| 51 | BOOST_TEST(test("-1.2e-3" , custom_real)); |
| 52 | BOOST_TEST(test_attr("-1.2e-3" , custom_real, d) && compare(d, -1.2e-3)); |
| 53 | |
| 54 | BOOST_TEST(test("-1.e2" , custom_real)); |
| 55 | BOOST_TEST(test_attr("-1.e2" , custom_real, d) && compare(d, -1.e2)); |
| 56 | |
| 57 | BOOST_TEST(test("-.2e3" , custom_real)); |
| 58 | BOOST_TEST(test_attr("-.2e3" , custom_real, d) && compare(d, -.2e3)); |
| 59 | |
| 60 | BOOST_TEST(test("-2e3" , custom_real)); |
| 61 | BOOST_TEST(test_attr("-2e3" , custom_real, d) && compare(d, -2e3)); |
| 62 | |
| 63 | BOOST_TEST(!test("-e3" , custom_real)); |
| 64 | BOOST_TEST(!test_attr("-e3" , custom_real, d)); |
| 65 | |
| 66 | BOOST_TEST(!test("-1.2e" , custom_real)); |
| 67 | BOOST_TEST(!test_attr("-1.2e" , custom_real, d)); |
| 68 | } |
| 69 | |
| 70 | /////////////////////////////////////////////////////////////////////////// |
| 71 | // custom real tests |
| 72 | /////////////////////////////////////////////////////////////////////////// |
| 73 | { |
| 74 | using boost::spirit::x3::double_; |
| 75 | custom_real n; |
| 76 | |
| 77 | BOOST_TEST(test_attr("-123456e6" , double_, n)); |
| 78 | } |
| 79 | |
| 80 | return boost::report_errors(); |
| 81 | } |
| 82 | #endif |
| 83 | |