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/classic/test/match_tests.cpp | 175 +++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 src/boost/libs/spirit/classic/test/match_tests.cpp (limited to 'src/boost/libs/spirit/classic/test/match_tests.cpp') diff --git a/src/boost/libs/spirit/classic/test/match_tests.cpp b/src/boost/libs/spirit/classic/test/match_tests.cpp new file mode 100644 index 00000000..bc919bbe --- /dev/null +++ b/src/boost/libs/spirit/classic/test/match_tests.cpp @@ -0,0 +1,175 @@ +/*============================================================================= + Copyright (c) 1998-2003 Joel de Guzman + http://spirit.sourceforge.net/ + + 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 +#include +#include + +using namespace std; + +#include +using namespace BOOST_SPIRIT_CLASSIC_NS; + +/////////////////////////////////////////////////////////////////////////////// +// +// Match tests +// +/////////////////////////////////////////////////////////////////////////////// +struct X {}; +struct Y { Y(int) {} }; // not default constructible +struct Z { Z(double n):n(n){} double n; }; // implicitly convertible from double + +void +match_tests() +{ + match<> m0; + BOOST_TEST(!m0.has_valid_attribute()); + + match m1(m0); + m1.value(123); + BOOST_TEST(m1.has_valid_attribute()); + BOOST_TEST(m1.value() == 123); + + match m2(m1); + BOOST_TEST(m2.has_valid_attribute()); + BOOST_TEST(m1.value() == int(m2.value())); + m2.value(456); + + *&m0 = m0; // match = match + m0 = m1; // match = match + m0 = m2; // match = match + m1 = m0; // match = match + BOOST_TEST(!m1); + BOOST_TEST(!m1.has_valid_attribute()); + + *&m1 = m1; // match = match + m1.value(int(m2.value())); + BOOST_TEST(m1.has_valid_attribute()); + BOOST_TEST(m1.value() == int(m2.value())); + + m2.value(123.456); + match mz(m2); // copy from match + mz = m2; // assign from match + BOOST_TEST(mz.value().n == 123.456); + + m1.value(123); + m2 = m0; + BOOST_TEST(!m2); + BOOST_TEST(!m2.has_valid_attribute()); + + m2 = m1; // match = match + BOOST_TEST(m2.has_valid_attribute()); + BOOST_TEST(m1.value() == int(m2.value())); + *&m2 = m2; // match = match + + cout << "sizeof(int) == " << sizeof(int) << '\n'; + cout << "sizeof(match<>) == " << sizeof(m0) << '\n'; + cout << "sizeof(match) == " << sizeof(m1) << '\n'; + cout << "sizeof(match) == " << sizeof(m2) << '\n'; + + match mr; + BOOST_TEST(!mr.has_valid_attribute()); + + match mrr(4); + BOOST_TEST(!mrr.has_valid_attribute()); + + int ri = 3; + match mr2(4, ri); + BOOST_TEST(mr2.has_valid_attribute()); + mr = mr2; + BOOST_TEST(mr.has_valid_attribute()); + + match mr3(mrr); + BOOST_TEST(!mr3.has_valid_attribute()); + mr2 = mr3; + BOOST_TEST(!mr2.has_valid_attribute()); + + match mx; + m1 = mx; + m0 = mx; + BOOST_TEST(!mx.has_valid_attribute()); + BOOST_TEST(!m0.has_valid_attribute()); + BOOST_TEST(!m1.has_valid_attribute()); + + match my; + BOOST_TEST(!my.has_valid_attribute()); + + match ms; + BOOST_TEST(!ms.has_valid_attribute()); + ms.value("Kimpo Ponchwayla"); + BOOST_TEST(ms.has_valid_attribute()); + BOOST_TEST(ms.value() == "Kimpo Ponchwayla"); + ms = match<>(); + BOOST_TEST(!ms.has_valid_attribute()); + + // let's try a match with a reference: + int i; + match mr4(4, i); + BOOST_TEST(mr4.has_valid_attribute()); + mr4.value(3); + BOOST_TEST(mr4.value() == 3); + BOOST_TEST(i == 3); + (void)i; + + int x = 456; + match mref(1, x); + BOOST_TEST(mref.value() == 456); + mref.value(123); + BOOST_TEST(mref.value() == 123); + x = mref.value(); + BOOST_TEST(x == 123); + mref.value() = 986; + BOOST_TEST(x == 986); + + std::string s("hello"); + match mint(1, x); + BOOST_TEST(mint.value() == x); + match mstr(1, s); + BOOST_TEST(mstr.value() == "hello"); + mstr = mint; + mint = mstr; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Match Policy tests +// +/////////////////////////////////////////////////////////////////////////////// +void +match_policy_tests() +{ + match<> m0; + match m1; + match m2; + match_policy mp; + + m0 = mp.no_match(); BOOST_TEST(!m0); + m1 = mp.no_match(); BOOST_TEST(!m1); + m0 = mp.empty_match(); BOOST_TEST(!!m0); + m2 = mp.empty_match(); BOOST_TEST(!!m2); + + m1 = mp.create_match(5, 100, 0, 0); + m2 = mp.create_match(5, 10.5, 0, 0); + + mp.concat_match(m1, m2); + BOOST_TEST(m1.length() == 10); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Main +// +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + match_tests(); + match_policy_tests(); + return boost::report_errors(); +} + -- cgit v1.2.3