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