]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/x3/real3.cpp
update ceph source to reef 18.1.2
[ceph.git] / 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
4
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 =============================================================================*/
9
10 #include "real.hpp"
11
12 int
13 main()
14 {
15 using spirit_test::test;
16 using spirit_test::test_attr;
17
18 ///////////////////////////////////////////////////////////////////////////
19 // strict real number tests
20 ///////////////////////////////////////////////////////////////////////////
21 {
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;
26
27 constexpr real_parser<double, strict_ureal_policies<double> > strict_udouble;
28 constexpr real_parser<double, strict_real_policies<double> > strict_double;
29 double d;
30
31 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(strict_udouble);
32 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(strict_double);
33
34 BOOST_TEST(!test("1234", strict_udouble));
35 BOOST_TEST(!test_attr("1234", strict_udouble, d));
36
37 BOOST_TEST(test("1.2", strict_udouble));
38 BOOST_TEST(test_attr("1.2", strict_udouble, d) && compare(d, 1.2));
39
40 BOOST_TEST(!test("-1234", strict_double));
41 BOOST_TEST(!test_attr("-1234", strict_double, d));
42
43 BOOST_TEST(test("123.", strict_double));
44 BOOST_TEST(test_attr("123.", strict_double, d) && compare(d, 123));
45
46 BOOST_TEST(test("3.E6", strict_double));
47 BOOST_TEST(test_attr("3.E6", strict_double, d) && compare(d, 3e6));
48
49 constexpr real_parser<double, no_trailing_dot_policy<double> > notrdot_real;
50 constexpr real_parser<double, no_leading_dot_policy<double> > nolddot_real;
51
52 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(notrdot_real);
53 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(nolddot_real);
54
55 BOOST_TEST(!test("1234.", notrdot_real)); // Bad trailing dot
56 BOOST_TEST(!test(".1234", nolddot_real)); // Bad leading dot
57 }
58
59 ///////////////////////////////////////////////////////////////////////////
60 // Special thousands separated numbers
61 ///////////////////////////////////////////////////////////////////////////
62 {
63 using boost::spirit::x3::real_parser;
64 using boost::spirit::x3::parse;
65 constexpr real_parser<double, ts_real_policies<double> > ts_real;
66 double d;
67
68 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(ts_real);
69
70 BOOST_TEST(test("123.01", ts_real));
71 BOOST_TEST(test_attr("123.01", ts_real, d)
72 && compare(d, 123.01));
73
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));
77
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));
81
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));
85
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));
90 }
91
92 return boost::report_errors();
93 }