diff options
Diffstat (limited to 'src/boost/libs/spirit/classic/phoenix/test')
14 files changed, 1114 insertions, 0 deletions
diff --git a/src/boost/libs/spirit/classic/phoenix/test/Jamfile b/src/boost/libs/spirit/classic/phoenix/test/Jamfile new file mode 100644 index 00000000..cfc1b0cd --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/Jamfile @@ -0,0 +1,81 @@ +#============================================================================== +# Copyright (c) 2002 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) +#============================================================================== +# +# Phoenix examples boost-jam file +# Joel de Guzman [Sept 27, 2002] +# + +unit-test binary_tests + : binary_tests.cpp + : + ; + +unit-test binders_tests + : binders_tests.cpp + : + ; + +unit-test functors_tests + : functors_tests.cpp + : + ; + +unit-test iostream_tests + : iostream_tests.cpp + : + ; + + +unit-test mixed_binary_tests + : mixed_binary_tests.cpp + : + ; + + +unit-test more_expressions_tests + : more_expressions_tests.cpp + : + ; + + +unit-test primitives_tests + : primitives_tests.cpp + : + ; + + +unit-test statements_tests + : statements_tests.cpp + : + ; + + +unit-test stl_tests + : stl_tests.cpp + : + ; + + +unit-test tuples_tests + : tuples_tests.cpp + : + ; + + +unit-test unary_tests + : unary_tests.cpp + : + ; + + +unit-test new_tests + : new_test.cpp + : + ; + diff --git a/src/boost/libs/spirit/classic/phoenix/test/binary_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/binary_tests.cpp new file mode 100644 index 00000000..56725316 --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/binary_tests.cpp @@ -0,0 +1,98 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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) +==============================================================================*/ +#ifdef __GNUC__ // Darn these relops! +#ifndef __SGI_STL_INTERNAL_RELOPS +#define __SGI_STL_INTERNAL_RELOPS +#endif +#endif + +#include <iostream> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_operators.hpp> + +using namespace phoenix; +using namespace std; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + int i2 = 2, i3 = 3, i = 5; + const char* world = " world"; + +/////////////////////////////////////////////////////////////////////////////// +// +// Binary operators +// +/////////////////////////////////////////////////////////////////////////////// + BOOST_TEST((var(i) = var(i))() == 5); + BOOST_TEST((var(i) = 3)() == 3); + BOOST_TEST(i == 3); + i = 5; + int x, y, z; + (var(x) = var(y) = var(z) = 10)(); + BOOST_TEST(x == 10 && y == 10 && z == 10); + BOOST_TEST((val(world)[3])() == world[3]); + + BOOST_TEST((var(i) += 5)() == 10); + BOOST_TEST((var(i) -= 5)() == 5); + BOOST_TEST((var(i) *= 5)() == 25); + BOOST_TEST((var(i) /= 5)() == 5); + BOOST_TEST((var(i) %= 2)() == 1); + + BOOST_TEST((var(i) <<= 3)() == 8); + BOOST_TEST((var(i) >>= 1)() == 4); + BOOST_TEST((var(i) |= 0xFF)() == 0xFF); + BOOST_TEST((var(i) &= 0xF0)() == 0xF0); + BOOST_TEST((var(i) ^= 0xFFFFFFFF)() == int(0xFFFFFF0F)); + + BOOST_TEST((val(5) == val(5))()); + BOOST_TEST((val(5) == 5)()); + + BOOST_TEST((arg1 + arg2)(i2, i3) == i2 + i3); + BOOST_TEST((arg1 - arg2)(i2, i3) == i2 - i3); + BOOST_TEST((arg1 * arg2)(i2, i3) == i2 * i3); + BOOST_TEST((arg1 / arg2)(i2, i3) == i2 / i3); + BOOST_TEST((arg1 % arg2)(i2, i3) == i2 % i3); + BOOST_TEST((arg1 & arg2)(i2, i3) == (i2 & i3)); + BOOST_TEST((arg1 | arg2)(i2, i3) == (i2 | i3)); + BOOST_TEST((arg1 ^ arg2)(i2, i3) == (i2 ^ i3)); + BOOST_TEST((arg1 << arg2)(i2, i3) == i2 << i3); + BOOST_TEST((arg1 >> arg2)(i2, i3) == i2 >> i3); + + BOOST_TEST((val(5) != val(6))()); + BOOST_TEST((val(5) < val(6))()); + BOOST_TEST(!(val(5) > val(6))()); + BOOST_TEST((val(5) < val(6))()); + BOOST_TEST((val(5) <= val(6))()); + BOOST_TEST((val(5) <= val(5))()); + BOOST_TEST((val(7) >= val(6))()); + BOOST_TEST((val(7) >= val(7))()); + + BOOST_TEST((val(false) && val(false))() == false); + BOOST_TEST((val(true) && val(false))() == false); + BOOST_TEST((val(false) && val(true))() == false); + BOOST_TEST((val(true) && val(true))() == true); + + BOOST_TEST((val(false) || val(false))() == false); + BOOST_TEST((val(true) || val(false))() == true); + BOOST_TEST((val(false) || val(true))() == true); + BOOST_TEST((val(true) || val(true))() == true); + +/////////////////////////////////////////////////////////////////////////////// +// +// End asserts +// +/////////////////////////////////////////////////////////////////////////////// + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/binders_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/binders_tests.cpp new file mode 100644 index 00000000..c73ce5cc --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/binders_tests.cpp @@ -0,0 +1,123 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <functional> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_composite.hpp> +#include <boost/spirit/include/phoenix1_binders.hpp> + +using namespace phoenix; +using std::cout; +using std::endl; + + /////////////////////////////////////////////////////////////////////////////// + struct print_ { // a typical STL style monomorphic functor + + typedef void result_type; + void operator()() { cout << "got no args\n"; } + void operator()(int n0) { cout << "got 1 arg " << n0 << " \n"; } + void operator()(int n0, int n1) { cout << "got 2 args " << n0 << ", " << n1 << " \n"; } + + void foo0() const { cout << "print_::foo0\n"; } + void foo1(int n0) { cout << "print_::foo1 " << n0 << " \n"; } + void foo2(int n0, int n1) { cout << "print_::foo2 " << n0 << ", " << n1 << " \n"; } + + int x; + }; + + functor<print_> print = print_(); + member_function_ptr<void, print_, int> print_foo1 = &print_::foo1; + member_function_ptr<void, print_, int, int> print_foo2 = &print_::foo2; + member_var_ptr<int, print_> print_x = &print_::x; + print_ p; + bound_member<void, print_, int> bound_print_foo1(p,&print_::foo1); + bound_member<void, print_, int, int> bound_print_foo2(&p,&print_::foo2); + + /////////////////////////////////////////////////////////////////////////////// + void foo0() // a function w/ 0 args + { cout << "foo0\n"; } + + void foo1(int n0) // a function w/ 1 arg + { cout << "foo1 " << n0 << " \n"; } + + void foo2(int n0, int n1) // a function w/ 2 args + { cout << "foo2 " << n0 << ", " << n1 << " \n"; } + + void foo3_(int n0, int n1, int n2) // a function w/ 3 args + { cout << "foo3 " << n0 << ", " << n1 << ", " << n2 << " \n"; } + + function_ptr<void, int, int, int> foo3 = &foo3_; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + int i50 = 50, i20 = 20, i100 = 100; + +/////////////////////////////////////////////////////////////////////////////// +// +// Binders +// +/////////////////////////////////////////////////////////////////////////////// + +// Functor binders + + print()(); + print(111)(); + print(111, arg1)(i100); + print(111, 222)(); + cout << bind(std::negate<int>())(arg1)(i20) << endl; + cout << bind(std::plus<int>())(arg1, arg2)(i20, i50) << endl; + +// Function binders + + bind(&foo0)()(); + bind(&foo1)(111)(); + bind(&foo2)(111, arg1)(i100); + bind(&foo2)(111, 222)(); + + foo3(111, 222, 333)(); + foo3(arg1, arg2, arg3)(i20, i50, i100); + foo3(111, arg1, arg2)(i50, i100); + +// Member function binders + + print_ printer; + bind(&print_::foo0)(arg1)(printer); + + bind(&print_::foo1)(arg1, 111)(printer); + print_foo1(arg1, 111)(printer); + print_foo1(var(printer), 111)(); + print_foo2(var(printer), 111, 222)(); + print_foo2(var(printer), 111, arg1)(i100); + +// Member var binders + + printer.x = 3; + BOOST_TEST(bind(&print_::x)(arg1)(printer) == 3); + BOOST_TEST(print_x(arg1)(printer) == 3); + BOOST_TEST(print_x(printer)() == 3); + BOOST_TEST(0 != (print_x(var(printer))() = 4)); + BOOST_TEST(printer.x == 4); + +// Bound member functions + + bind(&printer,&print_::foo0)()(); + + bind(printer,&print_::foo1)(111)(); + bound_print_foo1(111)(); + bound_print_foo1(111)(); + bound_print_foo2(111, 222)(); + bound_print_foo2(111, arg1)(i100); + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/functors_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/functors_tests.cpp new file mode 100644 index 00000000..e0b84672 --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/functors_tests.cpp @@ -0,0 +1,95 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <cmath> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_composite.hpp> +#include <boost/spirit/include/phoenix1_functions.hpp> +#include <boost/spirit/include/phoenix1_operators.hpp> + +using namespace phoenix; +using namespace std; + + /////////////////////////////////////////////////////////////////////////////// + struct test_ { + + typedef void result_type; + void operator()() const { cout << "TEST LAZY FUNCTION\n"; } + }; + + function<test_> test; + + /////////////////////////////////////////////////////////////////////////////// + struct sqr_ { + + template <typename ArgT> + struct result { typedef ArgT type; }; + + template <typename ArgT> + ArgT operator()(ArgT n) const { return n * n; } + }; + + function<sqr_> sqr; + + /////////////////////////////////////////////////////////////////////////////// + struct fact_ { + + template <typename ArgT> + struct result { typedef ArgT type; }; + + template <typename ArgT> + ArgT operator()(ArgT n) const + { return (n <= 0) ? 1 : n * this->operator()(n-1); } + }; + + function<fact_> fact; + + /////////////////////////////////////////////////////////////////////////////// + struct pow_ { + + template <typename Arg1T, typename Arg2T> + struct result { typedef Arg1T type; }; + + template <typename Arg1T, typename Arg2T> + Arg1T operator()(Arg1T a, Arg2T b) const { return pow(a, b); } + }; + + function<pow_> power; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + int i5 = 5; + double d5 = 5, d3 = 3; + +/////////////////////////////////////////////////////////////////////////////// +// +// Lazy functors +// +/////////////////////////////////////////////////////////////////////////////// + + test()(); + BOOST_TEST(sqr(arg1)(i5) == (i5*i5)); + BOOST_TEST(fact(4)() == 24); + BOOST_TEST(fact(arg1)(i5) == 120); + BOOST_TEST((int)power(arg1, arg2)(d5, d3) == (int)pow(d5, d3)); + BOOST_TEST((sqr(arg1) + 5)(i5) == ((i5*i5)+5)); + +/////////////////////////////////////////////////////////////////////////////// +// +// End asserts +// +/////////////////////////////////////////////////////////////////////////////// + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/iostream_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/iostream_tests.cpp new file mode 100644 index 00000000..1677938b --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/iostream_tests.cpp @@ -0,0 +1,86 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <vector> +#include <algorithm> +#include <string> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/config.hpp> +#ifdef BOOST_NO_STRINGSTREAM +#include <strstream> +#define SSTREAM strstream +std::string GETSTRING(std::strstream& ss) +{ + ss << ends; + std::string rval = ss.str(); + ss.freeze(false); + return rval; +} +#else +#include <sstream> +#define GETSTRING(ss) ss.str() +#define SSTREAM stringstream +#endif + +//#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_composite.hpp> +#include <boost/spirit/include/phoenix1_operators.hpp> +#include <boost/spirit/include/phoenix1_special_ops.hpp> + +using namespace phoenix; +using namespace std; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + int i100 = 100; + string hello = "hello"; + const char* world = " world"; + +/////////////////////////////////////////////////////////////////////////////// +// +// IO streams +// +/////////////////////////////////////////////////////////////////////////////// + vector<int> v; + v.push_back(1); + v.push_back(2); + v.push_back(3); + v.push_back(4); + v.push_back(5); + + char const* msg = "cout assert\n"; + (cout << arg1)(msg); + (cout << val(hello) << world << ", you da man!\n")(); + for_each(v.begin(), v.end(), cout << arg1 << ','); + cout << endl; + +#ifdef __BORLANDC__ // *** See special_ops.hpp why *** + (cout << arg1 << "this is it, shukz:" << hex_ << arg2 << endl_ << endl_)(msg, i100); +#else + (cout << arg1 << "this is it, shukz:" << hex << arg2 << endl << endl)(msg, i100); +#endif + int in; + int out = 12345; + SSTREAM sstr; + (sstr << arg1)(out); + (sstr >> arg1)(in); + BOOST_TEST(in == out); + +/////////////////////////////////////////////////////////////////////////////// +// +// End asserts +// +/////////////////////////////////////////////////////////////////////////////// + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/mixed_binary_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/mixed_binary_tests.cpp new file mode 100644 index 00000000..9f60a368 --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/mixed_binary_tests.cpp @@ -0,0 +1,50 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <string> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_operators.hpp> + +using namespace phoenix; +using namespace std; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + int i1 = 1, i2 = 2, i50 = 50, i100 = 100; + double d2_5 = 2.5; + string hello = "hello"; + const char* world = " world"; + +/////////////////////////////////////////////////////////////////////////////// +// +// Mixed type operators +// +/////////////////////////////////////////////////////////////////////////////// + BOOST_TEST((arg1 + arg2)(i100, i50) == (i100 + i50)); + BOOST_TEST((arg1 + 3)(i100) == (3 + i100)); + BOOST_TEST((arg1 + arg2)(hello, world) == "hello world"); + BOOST_TEST((arg1 + arg2)(i1, d2_5) == (i1 + d2_5)); + + BOOST_TEST((*(arg1 + arg2))(world, i2) == *(world + i2)); + BOOST_TEST((*(arg1 + arg2))(i2, world) == *(i2 + world)); + BOOST_TEST((*(val(world+i2) - arg1))(i2) == *world); + +/////////////////////////////////////////////////////////////////////////////// +// +// End asserts +// +/////////////////////////////////////////////////////////////////////////////// + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/more_expressions_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/more_expressions_tests.cpp new file mode 100644 index 00000000..51837416 --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/more_expressions_tests.cpp @@ -0,0 +1,104 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_composite.hpp> +#include <boost/spirit/include/phoenix1_functions.hpp> +#include <boost/spirit/include/phoenix1_operators.hpp> + +using namespace phoenix; +using namespace std; + + /////////////////////////////////////////////////////////////////////////////// + struct sqr_ { + + template <typename ArgT> + struct result { typedef ArgT type; }; + + template <typename ArgT> + ArgT operator()(ArgT n) const { return n * n; } + }; + + function<sqr_> sqr; + + /////////////////////////////////////////////////////////////////////////////// + struct adder_ { + + template <typename Arg1T, typename Arg2T, typename ArgT3> + struct result { typedef Arg1T type; }; + + template <typename Arg1T, typename Arg2T, typename ArgT3> + Arg1T operator()(Arg1T a, Arg2T b, ArgT3 c) const { return a + b + c; } + }; + + function<adder_> adder; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + int i2 = 2, i = 4, i50 = 50, i10 = 10, i20 = 20, i100 = 100; + double d5 = 5, d10 = 10; + string hello = "hello"; + +/////////////////////////////////////////////////////////////////////////////// +// +// More complex expressions +// +/////////////////////////////////////////////////////////////////////////////// + BOOST_TEST((10 - arg1)(i100) == (10 - i100)); + BOOST_TEST((20 - arg1)(i100) == (20 - i100)); + BOOST_TEST((arg1 - 10)(i100) == (i100 - 10)); + BOOST_TEST((arg1 - 20)(i100) == (i100 - 20)); + BOOST_TEST((arg1 - arg2)(i100, i50) == (i100 - i50)); + BOOST_TEST((arg1 - var(i))(i10) == (i10 - i)); + BOOST_TEST((arg1 + arg2 - arg3)(i100, i50, i20) == (i100 + i50 - i20)); + BOOST_TEST((sqr(arg1) + arg2 - arg3)(i100, i50, i20) == ((i100*i100) + i50 - i20)); + + int ii = i; + BOOST_TEST((var(i) += arg1)(i2) == (ii += i2)); + BOOST_TEST((sqr(sqr(arg1)))(i100) == (i100*i100*i100*i100)); + + +#if 0 /*** SHOULD NOT COMPILE ***/ + (val(3) += arg1)(i100); + (val(3) = 3)(); +#endif + + BOOST_TEST(((adder(arg1, arg2, arg3) + arg2 - arg3)(i100, i50, i20)) == (i100 + i50 + i20) + i50 - i20); + BOOST_TEST((adder(arg1, arg2, arg3)(i100, i50, i20)) == (i100 + i50 + i20)); + BOOST_TEST((sqr(sqr(sqr(sqr(arg1)))))(d10) == 1e16); + BOOST_TEST((sqr(sqr(arg1)) / arg1 / arg1)(d5) == 25); + + for (int j = 0; j < 20; ++j) + { + cout << (10 < arg1)(j); + BOOST_TEST((10 < arg1)(j) == (10 < j)); + } + cout << endl; + + for (int k = 0; k < 20; ++k) + { + bool r = ((arg1 % 2 == 0) && (arg1 < 15))(k); + cout << r; + BOOST_TEST(r == ((k % 2 == 0) && (k < 15))); + } + cout << endl; + +/////////////////////////////////////////////////////////////////////////////// +// +// End asserts +// +/////////////////////////////////////////////////////////////////////////////// + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/new_test.cpp b/src/boost/libs/spirit/classic/phoenix/test/new_test.cpp new file mode 100644 index 00000000..22c3b181 --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/new_test.cpp @@ -0,0 +1,46 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + Copyright (c) 2003 Vaclav Vesely + + 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 <iostream> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_new.hpp> + +using namespace phoenix; +using namespace std; + +class X +{ +public: + X(int i_ = 1) + : i(i_) + {} + + int i; +}; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + int i2 = 2; + X x3(3); + + BOOST_TEST(new_<int>()() != NULL); + BOOST_TEST(*new_<int>(arg1)(i2) == 2); + + BOOST_TEST(new_<X>()() != NULL); + BOOST_TEST(new_<X>()()->i == 1); + BOOST_TEST(new_<X>(arg1)(i2)->i == 2); + BOOST_TEST(new_<X>(arg1)(x3)->i == 3); + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/primitives_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/primitives_tests.cpp new file mode 100644 index 00000000..ada53334 --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/primitives_tests.cpp @@ -0,0 +1,42 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> + +using namespace phoenix; +using namespace std; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + char c1 = '1'; + int i1 = 1, i2 = 2, i = 4; + const char* s2 = "2"; + +/////////////////////////////////////////////////////////////////////////////// +// +// Values, variables and arguments +// +/////////////////////////////////////////////////////////////////////////////// + cout << val("Hello")() << val(' ')() << val("World")() << endl; + + BOOST_TEST(arg1(c1) == c1); + BOOST_TEST(arg1(i1, i2) == i1); + BOOST_TEST(arg2(i1, s2) == s2); + + BOOST_TEST(val(3)() == 3); + BOOST_TEST(var(i)() == 4); + BOOST_TEST(var(++i)() == 5); + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/runtest.sh b/src/boost/libs/spirit/classic/phoenix/test/runtest.sh new file mode 100644 index 00000000..09b804ea --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/runtest.sh @@ -0,0 +1,25 @@ +#============================================================================== +# Copyright (c) 2002 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) +#============================================================================== +#!/bin/sh +#./test1 << EOS || exit 1 +#123321 +#EOS +./binary_tests || exit 1 +./binders_tests || exit 1 +./functors_tests || exit 1 +./iostream_tests << EOS || exit 1 +123321 +EOS +./mixed_binary_tests || exit 1 +./more_expressions_tests || exit 1 +./primitives_tests || exit 1 +./statements_tests || exit 1 +./stl_tests || exit 1 +./tuples_tests || exit 1 +./unary_tests || exit 1 diff --git a/src/boost/libs/spirit/classic/phoenix/test/statements_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/statements_tests.cpp new file mode 100644 index 00000000..83db0acf --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/statements_tests.cpp @@ -0,0 +1,165 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <vector> +#include <algorithm> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_functions.hpp> +#include <boost/spirit/include/phoenix1_operators.hpp> +#include <boost/spirit/include/phoenix1_special_ops.hpp> +#include <boost/spirit/include/phoenix1_statements.hpp> + +using namespace phoenix; +using namespace std; + + /////////////////////////////////////////////////////////////////////////////// + struct poly_print_ { + + template <typename ArgT> + struct result { typedef void type; }; + + template <typename ArgT> + void operator()(ArgT v) const + { cout << v; } + }; + + function<poly_print_> poly_print; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + char c1 = '1'; + int i1 = 1; + double d2_5 = 2.5; + string hello = "hello"; + const char* world = " world"; + +/////////////////////////////////////////////////////////////////////////////// +// +// Block statements +// +/////////////////////////////////////////////////////////////////////////////// + ( + poly_print(arg1), + poly_print(arg2), + poly_print(arg3), + poly_print(arg4), + poly_print(arg5), + poly_print("\n\n") + ) + (hello, c1, world, i1, d2_5); + +/////////////////////////////////////////////////////////////////////////////// +// +// If-else, while, do-while, for tatements +// +/////////////////////////////////////////////////////////////////////////////// + + vector<int> v; + v.push_back(1); + v.push_back(2); + v.push_back(3); + v.push_back(4); + v.push_back(5); + v.push_back(6); + v.push_back(7); + v.push_back(8); + v.push_back(9); + v.push_back(10); + + cout << dec; + + ////////////////////////////////// + for_each(v.begin(), v.end(), + if_(arg1 > 3 && arg1 <= 8) + [ + cout << arg1 << ", " + ] + ); + + cout << endl; + + ////////////////////////////////// + for_each(v.begin(), v.end(), + if_(arg1 > 5) + [ + cout << arg1 << " > 5\n" + ] + .else_ + [ + if_(arg1 == 5) + [ + cout << arg1 << " == 5\n" + ] + .else_ + [ + cout << arg1 << " < 5\n" + ] + ] + ); + + cout << endl; + + vector<int> t = v; + ////////////////////////////////// + for_each(v.begin(), v.end(), + ( + while_(arg1--) + [ + cout << arg1 << ", " + ], + cout << val("\n") + ) + ); + + v = t; + cout << endl; + + ////////////////////////////////// + for_each(v.begin(), v.end(), + ( + do_ + [ + cout << arg1 << ", " + ] + .while_(arg1--), + cout << val("\n") + ) + ); + + v = t; + cout << endl; + + ////////////////////////////////// + int iii; + for_each(v.begin(), v.end(), + ( + for_(var(iii) = 0, var(iii) < arg1, ++var(iii)) + [ + cout << arg1 << ", " + ], + cout << val("\n") + ) + ); + + v = t; + cout << endl; + +/////////////////////////////////////////////////////////////////////////////// +// +// End asserts +// +/////////////////////////////////////////////////////////////////////////////// + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/stl_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/stl_tests.cpp new file mode 100644 index 00000000..2fe461f0 --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/stl_tests.cpp @@ -0,0 +1,95 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <vector> +#include <list> +#include <algorithm> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_composite.hpp> +#include <boost/spirit/include/phoenix1_functions.hpp> +#include <boost/spirit/include/phoenix1_operators.hpp> +#include <boost/spirit/include/phoenix1_binders.hpp> +#include <boost/spirit/include/phoenix1_special_ops.hpp> + +using namespace phoenix; +using namespace std; + + /////////////////////////////////////////////////////////////////////////////// + struct print_ { // a typical STL style monomorphic functor + + typedef void result_type; + void operator()(int n0) { cout << "got 1 arg " << n0 << " \n"; } + }; + + functor<print_> print = print_(); + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + +/////////////////////////////////////////////////////////////////////////////// +// +// STL algorithms +// +/////////////////////////////////////////////////////////////////////////////// + vector<int> v; + v.push_back(1); + v.push_back(2); + v.push_back(3); + v.push_back(4); + v.push_back(5); + + for_each(v.begin(), v.end(), arg1 *= 2); + for (int m = 0; m < 5; ++m, (cout << ',')) + { + cout << v[m]; + BOOST_TEST(v[m] == (m+1)*2); + } + cout << endl; + + for_each(v.begin(), v.end(), print(arg1)); + + vector<int>::iterator it = find_if(v.begin(), v.end(), arg1 > 5); + if (it != v.end()) + cout << *it << endl; + +/////////////////////////////////////////////////////////////////////////////// +// +// STL iterators and containers +// +/////////////////////////////////////////////////////////////////////////////// + + BOOST_TEST((arg1[0])(v) == v[0]); + BOOST_TEST((arg1[1])(v) == v[1]); + + list<int> l; + l.push_back(1); + l.push_back(2); + l.push_back(3); + l.push_back(4); + l.push_back(5); + + list<int>::iterator first = l.begin(); + list<int>::iterator last = l.end(); + + BOOST_TEST((*(++arg1))(first) == 2); + BOOST_TEST((*(----arg1))(last) == 4); + +/////////////////////////////////////////////////////////////////////////////// +// +// End asserts +// +/////////////////////////////////////////////////////////////////////////////// + + return boost::report_errors(); +} diff --git a/src/boost/libs/spirit/classic/phoenix/test/tuples_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/tuples_tests.cpp new file mode 100644 index 00000000..43b53fdd --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/tuples_tests.cpp @@ -0,0 +1,57 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <string> +#include <boost/detail/lightweight_test.hpp> +#include <boost/spirit/include/phoenix1_tuples.hpp> + +using namespace phoenix; +using namespace phoenix::tuple_index_names; +using std::cout; +using std::endl; +using std::string; + +int +main() +{ + { + typedef tuple<int, char> tuple_t; + tuple_t ttt(3, 'c'); + + tuple_element<0, tuple_t>::type& e0 = ttt[_1]; + tuple_element<1, tuple_t>::type& e1 = ttt[_2]; + + BOOST_TEST(e0 == 3); + BOOST_TEST(e1 == 'c'); + + cout << e0 << endl; + cout << e1 << endl; + } + + { + typedef tuple<int, char, char const*> tuple_t; + tuple_t ttt(3, 'c', "hello world"); + cout << ttt.length << endl; + + tuple_element<0, tuple_t>::type& e0 = ttt[_1]; + tuple_element<1, tuple_t>::type& e1 = ttt[_2]; + tuple_element<2, tuple_t>::type& e2 = ttt[_3]; + + BOOST_TEST(e0 == 3); + BOOST_TEST(e1 == 'c'); + BOOST_TEST(string(e2) == "hello world"); + + cout << e0 << endl; + cout << e1 << endl; + cout << e2 << endl; + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/spirit/classic/phoenix/test/unary_tests.cpp b/src/boost/libs/spirit/classic/phoenix/test/unary_tests.cpp new file mode 100644 index 00000000..6ac72cb6 --- /dev/null +++ b/src/boost/libs/spirit/classic/phoenix/test/unary_tests.cpp @@ -0,0 +1,47 @@ +/*============================================================================= + Phoenix V1.2.1 + Copyright (c) 2001-2003 Joel de Guzman + + 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 <iostream> +#include <boost/detail/lightweight_test.hpp> + +#define PHOENIX_LIMIT 15 +#include <boost/spirit/include/phoenix1_primitives.hpp> +#include <boost/spirit/include/phoenix1_operators.hpp> + +using namespace phoenix; +using namespace std; + +/////////////////////////////////////////////////////////////////////////////// +int +main() +{ + int i1 = 1, i = 5; + +/////////////////////////////////////////////////////////////////////////////// +// +// Unary operators +// +/////////////////////////////////////////////////////////////////////////////// + BOOST_TEST((!val(true))() == false); + BOOST_TEST((-val(1))() == -1); + BOOST_TEST((+val(1))() == +1); + BOOST_TEST((~val(1))() == ~1); + BOOST_TEST(*(&arg1)(i1) == *(&i1)); + BOOST_TEST((&arg1)(i1) == &i1); + + BOOST_TEST((*val(&i1))() == *(&i1)); + BOOST_TEST((*&arg1)(i1) == *(&i1)); + BOOST_TEST((++var(i))() == 6); + BOOST_TEST((--var(i))() == 5); + BOOST_TEST((var(i)++)() == 5); + BOOST_TEST(i == 6); + BOOST_TEST((var(i)--)() == 6); + BOOST_TEST(i == 5); + + return boost::report_errors(); +} |