]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/x3/real3.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2015 Joel de Guzman
3 Copyright (c) 2001-2010 Hartmut Kaiser
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
15 using spirit_test::test
;
16 using spirit_test::test_attr
;
18 ///////////////////////////////////////////////////////////////////////////
19 // strict real number tests
20 ///////////////////////////////////////////////////////////////////////////
22 using boost::spirit::x3::real_parser
;
23 using boost::spirit::x3::parse
;
24 using boost::spirit::x3::strict_ureal_policies
;
25 using boost::spirit::x3::strict_real_policies
;
27 constexpr real_parser
<double, strict_ureal_policies
<double> > strict_udouble
;
28 constexpr real_parser
<double, strict_real_policies
<double> > strict_double
;
31 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(strict_udouble
);
32 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(strict_double
);
34 BOOST_TEST(!test("1234", strict_udouble
));
35 BOOST_TEST(!test_attr("1234", strict_udouble
, d
));
37 BOOST_TEST(test("1.2", strict_udouble
));
38 BOOST_TEST(test_attr("1.2", strict_udouble
, d
) && compare(d
, 1.2));
40 BOOST_TEST(!test("-1234", strict_double
));
41 BOOST_TEST(!test_attr("-1234", strict_double
, d
));
43 BOOST_TEST(test("123.", strict_double
));
44 BOOST_TEST(test_attr("123.", strict_double
, d
) && compare(d
, 123));
46 BOOST_TEST(test("3.E6", strict_double
));
47 BOOST_TEST(test_attr("3.E6", strict_double
, d
) && compare(d
, 3e6
));
49 constexpr real_parser
<double, no_trailing_dot_policy
<double> > notrdot_real
;
50 constexpr real_parser
<double, no_leading_dot_policy
<double> > nolddot_real
;
52 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(notrdot_real
);
53 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(nolddot_real
);
55 BOOST_TEST(!test("1234.", notrdot_real
)); // Bad trailing dot
56 BOOST_TEST(!test(".1234", nolddot_real
)); // Bad leading dot
59 ///////////////////////////////////////////////////////////////////////////
60 // Special thousands separated numbers
61 ///////////////////////////////////////////////////////////////////////////
63 using boost::spirit::x3::real_parser
;
64 using boost::spirit::x3::parse
;
65 constexpr real_parser
<double, ts_real_policies
<double> > ts_real
;
68 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(ts_real
);
70 BOOST_TEST(test("123.01", ts_real
));
71 BOOST_TEST(test_attr("123.01", ts_real
, d
)
72 && compare(d
, 123.01));
74 BOOST_TEST(test("123,456,789.01", ts_real
));
75 BOOST_TEST(test_attr("123,456,789.01", ts_real
, d
)
76 && compare(d
, 123456789.01));
78 BOOST_TEST(test("12,345,678.90", ts_real
));
79 BOOST_TEST(test_attr("12,345,678.90", ts_real
, d
)
80 && compare(d
, 12345678.90));
82 BOOST_TEST(test("1,234,567.89", ts_real
));
83 BOOST_TEST(test_attr("1,234,567.89", ts_real
, d
)
84 && compare(d
, 1234567.89));
86 BOOST_TEST(!test("1234,567,890", ts_real
));
87 BOOST_TEST(!test("1,234,5678,9", ts_real
));
88 BOOST_TEST(!test("1,234,567.89e6", ts_real
));
89 BOOST_TEST(!test("1,66", ts_real
));
92 return boost::report_errors();