From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/boost/libs/python/test/list.cpp | 154 ++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 src/boost/libs/python/test/list.cpp (limited to 'src/boost/libs/python/test/list.cpp') diff --git a/src/boost/libs/python/test/list.cpp b/src/boost/libs/python/test/list.cpp new file mode 100644 index 000000000..3e9fcbe66 --- /dev/null +++ b/src/boost/libs/python/test/list.cpp @@ -0,0 +1,154 @@ +// Copyright David Abrahams 2002. +// 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 +#define BOOST_ENABLE_ASSERT_HANDLER +#include +#include "test_class.hpp" + +using namespace boost::python; + +object new_list() +{ + return list(); +} + +list listify(object x) +{ + return list(x); +} + +object listify_string(char const* s) +{ + return list(s); +} + +std::string x_rep(test_class<> const& x) +{ + return "X(" + boost::lexical_cast(x.value()) + ")"; +} + +object apply_object_list(object f, list x) +{ + return f(x); +} + +list apply_list_list(object f, list x) +{ + return call(f.ptr(), x); +} + +void append_object(list& x, object y) +{ + x.append(y); +} + +void append_list(list& x, list const& y) +{ + x.append(y); +} + +typedef test_class<> X; + +int notcmp(object const& x, object const& y) +{ + return y < x ? -1 : y > x ? 1 : 0; +} + +void exercise(list x, object y, object print) +{ + x.append(y); + x.append(5); + x.append(X(3)); + + print("after append:"); + print(x); + + print("number of", y, "instances:", x.count(y)); + + print("number of 5s:", x.count(5)); + + x.extend("xyz"); + print("after extend:"); + print(x); + print("index of", y, "is:", x.index(y)); + print("index of 'l' is:", x.index("l")); + + x.insert(4, 666); + print("after inserting 666:"); + print(x); + print("inserting with object as index:"); + x.insert(x[x.index(5)], "---"); + print(x); + + print("popping..."); + x.pop(); + print(x); + x.pop(x[x.index(5)]); + print(x); + x.pop(x.index(5)); + print(x); + + print("removing", y); + x.remove(y); + print(x); + print("removing", 666); + x.remove(666); + print(x); + + print("reversing..."); + x.reverse(); + print(x); + + print("sorted:"); + x.pop(2); // make sorting predictable + x.pop(2); // remove [1,2] so the list is sortable in py3k + x.sort(); + print(x); + + print("reverse sorted:"); +#if PY_VERSION_HEX >= 0x03000000 + x.sort(*tuple(), **dict(make_tuple(make_tuple("reverse", true)))); +#else + x.sort(¬cmp); +#endif + print(x); + + list w; + w.append(5); + w.append(6); + w += "hi"; + BOOST_ASSERT(w[0] == 5); + BOOST_ASSERT(w[1] == 6); + BOOST_ASSERT(w[2] == 'h'); + BOOST_ASSERT(w[3] == 'i'); +} + +BOOST_PYTHON_MODULE(list_ext) +{ + def("new_list", new_list); + def("listify", listify); + def("listify_string", listify_string); + def("apply_object_list", apply_object_list); + def("apply_list_list", apply_list_list); + + def("append_object", append_object); + def("append_list", append_list); + + def("exercise", exercise); + + class_("X", init()) + .def( "__repr__", x_rep) + ; +} + +#include "module_tail.cpp" -- cgit v1.2.3