]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/real3.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2010 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::qi::real_parser
;
23 using boost::spirit::qi::parse
;
24 using boost::spirit::qi::strict_ureal_policies
;
25 using boost::spirit::qi::strict_real_policies
;
27 real_parser
<double, strict_ureal_policies
<double> > strict_udouble
;
28 real_parser
<double, strict_real_policies
<double> > strict_double
;
31 BOOST_TEST(!test("1234", strict_udouble
));
32 BOOST_TEST(!test_attr("1234", strict_udouble
, d
));
34 BOOST_TEST(test("1.2", strict_udouble
));
35 BOOST_TEST(test_attr("1.2", strict_udouble
, d
) && compare(d
, 1.2));
37 BOOST_TEST(!test("-1234", strict_double
));
38 BOOST_TEST(!test_attr("-1234", strict_double
, d
));
40 BOOST_TEST(test("123.", strict_double
));
41 BOOST_TEST(test_attr("123.", strict_double
, d
) && compare(d
, 123));
43 BOOST_TEST(test("3.E6", strict_double
));
44 BOOST_TEST(test_attr("3.E6", strict_double
, d
) && compare(d
, 3e6
));
46 real_parser
<double, no_trailing_dot_policy
<double> > notrdot_real
;
47 real_parser
<double, no_leading_dot_policy
<double> > nolddot_real
;
49 BOOST_TEST(!test("1234.", notrdot_real
)); // Bad trailing dot
50 BOOST_TEST(!test(".1234", nolddot_real
)); // Bad leading dot
53 ///////////////////////////////////////////////////////////////////////////
54 // Special thousands separated numbers
55 ///////////////////////////////////////////////////////////////////////////
57 using boost::spirit::qi::real_parser
;
58 using boost::spirit::qi::parse
;
59 real_parser
<double, ts_real_policies
<double> > ts_real
;
62 BOOST_TEST(test("123,456,789.01", ts_real
));
63 BOOST_TEST(test_attr("123,456,789.01", ts_real
, d
)
64 && compare(d
, 123456789.01));
66 BOOST_TEST(test("12,345,678.90", ts_real
));
67 BOOST_TEST(test_attr("12,345,678.90", ts_real
, d
)
68 && compare(d
, 12345678.90));
70 BOOST_TEST(test("1,234,567.89", ts_real
));
71 BOOST_TEST(test_attr("1,234,567.89", ts_real
, d
)
72 && compare(d
, 1234567.89));
74 BOOST_TEST(!test("1234,567,890", ts_real
));
75 BOOST_TEST(!test("1,234,5678,9", ts_real
));
76 BOOST_TEST(!test("1,234,567.89e6", ts_real
));
77 BOOST_TEST(!test("1,66", ts_real
));
80 return boost::report_errors();