summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/qi/real5.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/qi/real5.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/qi/real5.cpp')
-rw-r--r--src/boost/libs/spirit/test/qi/real5.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/boost/libs/spirit/test/qi/real5.cpp b/src/boost/libs/spirit/test/qi/real5.cpp
new file mode 100644
index 00000000..3749c4c6
--- /dev/null
+++ b/src/boost/libs/spirit/test/qi/real5.cpp
@@ -0,0 +1,137 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+ Copyright (c) 2011 Bryce Lelbach
+
+ 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;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // parameterized signed real number tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::qi::double_;
+ double d;
+
+ BOOST_TEST(test("+1234", double_(1234)));
+ BOOST_TEST(!test("+1234", double_(-1234)));
+ BOOST_TEST(test_attr("+1234", double_(1234), d));
+ BOOST_TEST(compare(d, 1234));
+ BOOST_TEST(!test_attr("+1234", double_(-1234), d));
+
+ BOOST_TEST(test("-1234", double_(-1234)));
+ BOOST_TEST(!test("-1234", double_(1234)));
+ BOOST_TEST(test_attr("-1234", double_(-1234), d));
+ BOOST_TEST(compare(d, -1234));
+ BOOST_TEST(!test_attr("-1234", double_(1234), d));
+
+ BOOST_TEST(test("+1.2e3", double_(1.2e3)));
+ BOOST_TEST(!test("+1.2e3", double_(-1.2e3)));
+ BOOST_TEST(test_attr("+1.2e3", double_(1.2e3), d));
+ BOOST_TEST(compare(d, 1.2e3));
+ BOOST_TEST(!test_attr("+1.2e3", double_(-1.2e3), d));
+
+ BOOST_TEST(test("-1.2e3", double_(-1.2e3)));
+ BOOST_TEST(!test("-1.2e3", double_(1.2e3)));
+ BOOST_TEST(test_attr("-1.2e3", double_(-1.2e3), d));
+ BOOST_TEST(compare(d, -1.2e3));
+ BOOST_TEST(!test_attr("-1.2e3", double_(1.2e3), d));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // parameterized unsigned real number tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::qi::real_parser;
+ using boost::spirit::qi::ureal_policies;
+ double d;
+
+ real_parser<double, ureal_policies<double> > udouble;
+
+ BOOST_TEST(test("1234", udouble(1234)));
+ BOOST_TEST(!test("1234", udouble(4321)));
+ BOOST_TEST(test_attr("1234", udouble(1234), d));
+ BOOST_TEST(compare(d, 1234));
+ BOOST_TEST(!test_attr("1234", udouble(4321), d));
+
+ BOOST_TEST(test("1.2e3", udouble(1.2e3)));
+ BOOST_TEST(!test("1.2e3", udouble(3.2e1)));
+ BOOST_TEST(test_attr("1.2e3", udouble(1.2e3), d));
+ BOOST_TEST(compare(d, 1.2e3));
+ BOOST_TEST(!test_attr("1.2e3", udouble(3.2e1), d));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // parameterized custom data type
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::math::concepts::real_concept;
+ using boost::spirit::qi::real_parser;
+ using boost::spirit::qi::real_policies;
+
+ real_parser<real_concept, real_policies<real_concept> > custom_real;
+ real_concept d;
+
+ BOOST_TEST(test("-1234", custom_real(-1234)));
+ BOOST_TEST(!test("-1234", custom_real(4321)));
+ BOOST_TEST(test_attr("-1234", custom_real(-1234), d));
+ BOOST_TEST(compare(d, -1234));
+ BOOST_TEST(!test_attr("-1234", custom_real(-4321), d));
+
+ BOOST_TEST(test("1.2e3", custom_real(1.2e3)));
+ BOOST_TEST(!test("1.2e3", custom_real(-1.2e3)));
+ BOOST_TEST(test_attr("1.2e3", custom_real(1.2e3), d));
+ BOOST_TEST(compare(d, 1.2e3));
+ BOOST_TEST(!test_attr("1.2e3", custom_real(-3.2e1), d));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // parameterized lazy tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::phoenix::ref;
+ using boost::spirit::qi::double_;
+ double n = 1.2e3, m = 3.2e1;
+
+ BOOST_TEST(test("1.2e3", double_(ref(n))));
+ BOOST_TEST(!test("1.2e3", double_(ref(m))));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // literal real number tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::qi::lit;
+
+ BOOST_TEST(test("+1.2e3", lit(1.2e3)));
+ BOOST_TEST(!test("+1.2e3", lit(-1.2e3)));
+ BOOST_TEST(test("-1.2e3", lit(-1.2e3)));
+ BOOST_TEST(!test("-1.2e3", lit(1.2e3)));
+ BOOST_TEST(test("1.2e3", lit(1.2e3)));
+ BOOST_TEST(!test("1.2e3", lit(3.2e1)));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // literal lazy tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::qi::lit;
+ using boost::phoenix::ref;
+ double n = 1.2e3, m = 3.2e1;
+
+ BOOST_TEST(test("1.2e3", lit(ref(n))));
+ BOOST_TEST(!test("1.2e3", lit(ref(m))));
+ }
+
+ return boost::report_errors();
+}