| 1 | from pypy.module._cppyy import helper |
| 2 | |
| 3 | def test_remove_const(): |
| 4 | assert helper.remove_const("const int") == "int" |
| 5 | |
| 6 | assert helper.remove_const("const some_class*") == "some_class*" |
| 7 | assert helper.remove_const("const some_class const*") == "some_class*" |
| 8 | assert helper.remove_const("some_class const*const") == "some_class*" |
| 9 | |
| 10 | assert helper.remove_const("const some_class<const aap>*") == "some_class<const aap>*" |
| 11 | assert helper.remove_const("const some_class<const aap> const*") == "some_class<const aap>*" |
| 12 | assert helper.remove_const("some_class const<const aap*const>*const") == "some_class<const aap*const>*" |
| 13 | |
| 14 | def test_compound(): |
| 15 | assert helper.compound("int*") == "*" |
| 16 | assert helper.compound("int* const *&") == "**&" |
| 17 | assert helper.compound("std::vector<int>*") == "*" |
| 18 | assert helper.compound("unsigned long int[5]") == "[]" |
| 19 | assert helper.array_size("unsigned long int[5]") == 5 |
| 20 | |
| 21 | |
| 22 | def test_array_size(): |
| 23 | assert helper.array_size("int[5]") == 5 |
| 24 | |
| 25 | |
| 26 | def test_clean_type(): |
| 27 | assert helper.clean_type(" int***") == "int" |
| 28 | assert helper.clean_type("int* const *&") == "int" |
| 29 | assert helper.clean_type("std::vector<int>&") == "std::vector<int>" |
| 30 | assert helper.clean_type("const std::vector<int>&") == "std::vector<int>" |
| 31 | assert helper.clean_type("std::vector<std::vector<int> >" ) == "std::vector<std::vector<int> >" |
| 32 | assert helper.clean_type("unsigned short int[3]") == "unsigned short int" |
| 33 | |
| 34 | |
| 35 | def test_operator_mapping(): |
| 36 | assert helper.map_operator_name(None, "operator[]", 1, "const int&") == "__getitem__" |
| 37 | assert helper.map_operator_name(None, "operator[]", 1, "int&") == "__setitem__" |
| 38 | |
| 39 | assert helper.map_operator_name(None, "operator()", 1, "") == "__call__" |
| 40 | assert helper.map_operator_name(None, "operator%", 1, "") == "__mod__" |
| 41 | assert helper.map_operator_name(None, "operator**", 1, "") == "__pow__" |
| 42 | assert helper.map_operator_name(None, "operator<<", 1, "") == "__lshift__" |
| 43 | assert helper.map_operator_name(None, "operator|", 1, "") == "__or__" |
| 44 | |
| 45 | assert helper.map_operator_name(None, "operator*", 1, "") == "__mul__" |
| 46 | assert helper.map_operator_name(None, "operator*", 0, "") == "__deref__" |
| 47 | |
| 48 | assert helper.map_operator_name(None, "operator+", 1, "") == "__add__" |
| 49 | assert helper.map_operator_name(None, "operator+", 0, "") == "__pos__" |
| 50 | |
| 51 | assert helper.map_operator_name(None, "func", 0, "") == "func" |
| 52 | assert helper.map_operator_name(None, "some_method", 0, "") == "some_method" |
| 53 | |
| 54 | |
| 55 | def test_namespace_extraction(): |
| 56 | from pypy.module._cppyy import pythonify |
| 57 | |
| 58 | assert pythonify.extract_namespace("vector")[0] == "" |
| 59 | assert pythonify.extract_namespace("std::vector")[0] == "std" |
| 60 | assert pythonify.extract_namespace("std::vector<double>")[0] == "std" |
| 61 | assert pythonify.extract_namespace("std::vector<std::vector>")[0] == "std" |
| 62 | assert pythonify.extract_namespace("vector<double>")[0] == "" |
| 63 | assert pythonify.extract_namespace("vector<std::vector>")[0] == "" |
| 64 | assert pythonify.extract_namespace("aap::noot::mies::zus")[0] == "aap::noot::mies" |