From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/spirit/test/karma/int3.cpp | 126 ++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 src/boost/libs/spirit/test/karma/int3.cpp (limited to 'src/boost/libs/spirit/test/karma/int3.cpp') diff --git a/src/boost/libs/spirit/test/karma/int3.cpp b/src/boost/libs/spirit/test/karma/int3.cpp new file mode 100644 index 00000000..47c5ad34 --- /dev/null +++ b/src/boost/libs/spirit/test/karma/int3.cpp @@ -0,0 +1,126 @@ +// Copyright (c) 2001-2011 Hartmut Kaiser +// +// Distributed under 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 +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include "test.hpp" + +using namespace spirit_test; + +/////////////////////////////////////////////////////////////////////////////// +struct test_minmax +{ + template + void operator()(T) const + { + using namespace boost::spirit; + using namespace boost::phoenix; + + T minval = (std::numeric_limits::min)(); + T maxval = (std::numeric_limits::max)(); + + std::string expected_minval = boost::lexical_cast(minval); + std::string expected_maxval = boost::lexical_cast(maxval); + + // create a correct generator type from the given integer type + typedef typename + boost::mpl::if_< + boost::mpl::bool_::is_signed>, + karma::int_generator, + karma::uint_generator + >::type + int_generator_type; + + int_generator_type const gen = int_generator_type(); + + BOOST_TEST(test(expected_maxval, gen, maxval)); + BOOST_TEST(test(expected_minval, gen, minval)); + BOOST_TEST(test(expected_maxval, gen(maxval))); + BOOST_TEST(test(expected_minval, gen(minval))); + BOOST_TEST(test(expected_maxval, gen(maxval), maxval)); + BOOST_TEST(test(expected_minval, gen(minval), minval)); + BOOST_TEST(!test("", gen(maxval), maxval-1)); + BOOST_TEST(!test("", gen(minval), minval+1)); + BOOST_TEST(test(expected_maxval, lit(maxval))); + BOOST_TEST(test(expected_minval, lit(minval))); + + BOOST_TEST(test_delimited(expected_maxval + " ", gen, maxval, char(' '))); + BOOST_TEST(test_delimited(expected_minval + " ", gen, minval, char(' '))); + BOOST_TEST(test_delimited(expected_maxval + " ", gen(maxval), char(' '))); + BOOST_TEST(test_delimited(expected_minval + " ", gen(minval), char(' '))); + BOOST_TEST(test_delimited(expected_maxval + " ", gen(maxval), maxval, char(' '))); + BOOST_TEST(test_delimited(expected_minval + " ", gen(minval), minval, char(' '))); + BOOST_TEST(!test_delimited("", gen(maxval), maxval-1, char(' '))); + BOOST_TEST(!test_delimited("", gen(minval), minval+1, char(' '))); + BOOST_TEST(test_delimited(expected_maxval + " ", lit(maxval), char(' '))); + BOOST_TEST(test_delimited(expected_minval + " ", lit(minval), char(' '))); + + // action tests + BOOST_TEST(test(expected_maxval, gen[_1 = val(maxval)])); + BOOST_TEST(test(expected_minval, gen[_1 = val(minval)])); + + // optional tests + boost::optional optmin, optmax(maxval); + + BOOST_TEST(!test("", gen, optmin)); + BOOST_TEST(!test("", gen(minval), optmin)); + + optmin = minval; + BOOST_TEST(test(expected_minval, gen, optmin)); + BOOST_TEST(test(expected_maxval, gen, optmax)); + BOOST_TEST(test(expected_minval, gen(minval), optmin)); + BOOST_TEST(test(expected_maxval, gen(maxval), optmax)); + +// we support Phoenix attributes only starting with V2.2 +#if SPIRIT_VERSION >= 0x2020 + // Phoenix expression tests (only supported while including + // karma_phoenix_attributes.hpp + namespace phoenix = boost::phoenix; + + BOOST_TEST(test("1", gen, phoenix::val(1))); + + T val = 1; + BOOST_TEST(test("1", gen, phoenix::ref(val))); + BOOST_TEST(test("2", gen, ++phoenix::ref(val))); +#endif + } +}; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + using namespace boost::spirit; + +// test boundary values + typedef boost::mpl::vector< +#ifdef BOOST_HAS_LONG_LONG + boost::long_long_type, boost::ulong_long_type, +#endif + short, unsigned short, + int, unsigned int, + long, unsigned long + > integer_types; + boost::mpl::for_each(test_minmax()); + + return boost::report_errors(); +} + -- cgit v1.2.3