1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 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 | #include "real.hpp" |
12 | |
13 | int |
14 | main() |
15 | { |
16 | using spirit_test::test; |
17 | using spirit_test::test_attr; |
18 | |
19 | /////////////////////////////////////////////////////////////////////////// |
20 | // Custom data type |
21 | /////////////////////////////////////////////////////////////////////////// |
22 | #ifndef BOOST_SPIRIT_NO_MATH_REAL_CONCEPT |
23 | { |
24 | using boost::math::concepts::real_concept; |
25 | using boost::spirit::qi::real_parser; |
26 | using boost::spirit::qi::real_policies; |
27 | using boost::spirit::qi::parse; |
28 | |
29 | real_parser<real_concept, real_policies<real_concept> > custom_real; |
30 | real_concept d; |
31 | |
32 | BOOST_TEST(test("-1234" , custom_real)); |
33 | BOOST_TEST(test_attr("-1234" , custom_real, d) && compare(d, -1234)); |
34 | |
35 | BOOST_TEST(test("-1.2e3" , custom_real)); |
36 | BOOST_TEST(test_attr("-1.2e3" , custom_real, d) && compare(d, -1.2e3)); |
37 | |
38 | BOOST_TEST(test("+1.2e3" , custom_real)); |
39 | BOOST_TEST(test_attr("+1.2e3" , custom_real, d) && compare(d, 1.2e3)); |
40 | |
41 | BOOST_TEST(test("-0.1" , custom_real)); |
42 | BOOST_TEST(test_attr("-0.1" , custom_real, d) && compare(d, -0.1)); |
43 | |
44 | BOOST_TEST(test("-1.2e-3" , custom_real)); |
45 | BOOST_TEST(test_attr("-1.2e-3" , custom_real, d) && compare(d, -1.2e-3)); |
46 | |
47 | BOOST_TEST(test("-1.e2" , custom_real)); |
48 | BOOST_TEST(test_attr("-1.e2" , custom_real, d) && compare(d, -1.e2)); |
49 | |
50 | BOOST_TEST(test("-.2e3" , custom_real)); |
51 | BOOST_TEST(test_attr("-.2e3" , custom_real, d) && compare(d, -.2e3)); |
52 | |
53 | BOOST_TEST(test("-2e3" , custom_real)); |
54 | BOOST_TEST(test_attr("-2e3" , custom_real, d) && compare(d, -2e3)); |
55 | |
56 | BOOST_TEST(!test("-e3" , custom_real)); |
57 | BOOST_TEST(!test_attr("-e3" , custom_real, d)); |
58 | |
59 | BOOST_TEST(!test("-1.2e" , custom_real)); |
60 | BOOST_TEST(!test_attr("-1.2e" , custom_real, d)); |
61 | } |
62 | #endif |
63 | |
64 | /////////////////////////////////////////////////////////////////////////// |
65 | // custom real tests |
66 | /////////////////////////////////////////////////////////////////////////// |
67 | { |
68 | using boost::spirit::qi::double_; |
69 | custom_real n; |
70 | |
71 | BOOST_TEST(test_attr("-123456e6" , double_, n)); |
72 | } |
73 | |
74 | return boost::report_errors(); |
75 | } |
76 | |