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