summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/x3/real3.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/spirit/test/x3/real3.cpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/spirit/test/x3/real3.cpp')
-rw-r--r--src/boost/libs/spirit/test/x3/real3.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/boost/libs/spirit/test/x3/real3.cpp b/src/boost/libs/spirit/test/x3/real3.cpp
new file mode 100644
index 00000000..09e11ad9
--- /dev/null
+++ b/src/boost/libs/spirit/test/x3/real3.cpp
@@ -0,0 +1,85 @@
+/*=============================================================================
+ Copyright (c) 2001-2015 Joel de Guzman
+ Copyright (c) 2001-2010 Hartmut Kaiser
+
+ Use, modification and distribution is subject to the Boost Software
+ License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+
+#include "real.hpp"
+
+int
+main()
+{
+ using spirit_test::test;
+ using spirit_test::test_attr;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // strict real number tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::x3::real_parser;
+ using boost::spirit::x3::parse;
+ using boost::spirit::x3::strict_ureal_policies;
+ using boost::spirit::x3::strict_real_policies;
+
+ real_parser<double, strict_ureal_policies<double> > strict_udouble;
+ real_parser<double, strict_real_policies<double> > strict_double;
+ double d;
+
+ BOOST_TEST(!test("1234", strict_udouble));
+ BOOST_TEST(!test_attr("1234", strict_udouble, d));
+
+ BOOST_TEST(test("1.2", strict_udouble));
+ BOOST_TEST(test_attr("1.2", strict_udouble, d) && compare(d, 1.2));
+
+ BOOST_TEST(!test("-1234", strict_double));
+ BOOST_TEST(!test_attr("-1234", strict_double, d));
+
+ BOOST_TEST(test("123.", strict_double));
+ BOOST_TEST(test_attr("123.", strict_double, d) && compare(d, 123));
+
+ BOOST_TEST(test("3.E6", strict_double));
+ BOOST_TEST(test_attr("3.E6", strict_double, d) && compare(d, 3e6));
+
+ real_parser<double, no_trailing_dot_policy<double> > notrdot_real;
+ real_parser<double, no_leading_dot_policy<double> > nolddot_real;
+
+ BOOST_TEST(!test("1234.", notrdot_real)); // Bad trailing dot
+ BOOST_TEST(!test(".1234", nolddot_real)); // Bad leading dot
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Special thousands separated numbers
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::x3::real_parser;
+ using boost::spirit::x3::parse;
+ real_parser<double, ts_real_policies<double> > ts_real;
+ double d;
+
+ BOOST_TEST(test("123.01", ts_real));
+ BOOST_TEST(test_attr("123.01", ts_real, d)
+ && compare(d, 123.01));
+
+ BOOST_TEST(test("123,456,789.01", ts_real));
+ BOOST_TEST(test_attr("123,456,789.01", ts_real, d)
+ && compare(d, 123456789.01));
+
+ BOOST_TEST(test("12,345,678.90", ts_real));
+ BOOST_TEST(test_attr("12,345,678.90", ts_real, d)
+ && compare(d, 12345678.90));
+
+ BOOST_TEST(test("1,234,567.89", ts_real));
+ BOOST_TEST(test_attr("1,234,567.89", ts_real, d)
+ && compare(d, 1234567.89));
+
+ BOOST_TEST(!test("1234,567,890", ts_real));
+ BOOST_TEST(!test("1,234,5678,9", ts_real));
+ BOOST_TEST(!test("1,234,567.89e6", ts_real));
+ BOOST_TEST(!test("1,66", ts_real));
+ }
+
+ return boost::report_errors();
+}