File: test_helper.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (64 lines) | stat: -rw-r--r-- 3,161 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from pypy.module._cppyy import helper

def test_remove_const():
    assert helper.remove_const("const int") == "int"

    assert helper.remove_const("const some_class*") == "some_class*"
    assert helper.remove_const("const some_class const*") == "some_class*"
    assert helper.remove_const("some_class const*const") == "some_class*"

    assert helper.remove_const("const some_class<const aap>*") == "some_class<const aap>*"
    assert helper.remove_const("const some_class<const aap> const*") == "some_class<const aap>*"
    assert helper.remove_const("some_class const<const aap*const>*const") == "some_class<const aap*const>*"

def test_compound():
    assert helper.compound("int*") == "*"
    assert helper.compound("int* const *&") == "**&"
    assert helper.compound("std::vector<int>*") == "*"
    assert helper.compound("unsigned long int[5]") == "[]"
    assert helper.array_size("unsigned long int[5]") == 5


def test_array_size():
    assert helper.array_size("int[5]") == 5


def test_clean_type():
    assert helper.clean_type(" int***") == "int"
    assert helper.clean_type("int* const *&") == "int"
    assert helper.clean_type("std::vector<int>&") == "std::vector<int>"
    assert helper.clean_type("const std::vector<int>&") == "std::vector<int>"
    assert helper.clean_type("std::vector<std::vector<int> >" ) == "std::vector<std::vector<int> >"
    assert helper.clean_type("unsigned short int[3]") == "unsigned short int"


def test_operator_mapping():
    assert helper.map_operator_name(None, "operator[]", 1, "const int&")  == "__getitem__"
    assert helper.map_operator_name(None, "operator[]", 1, "int&")        == "__setitem__"

    assert helper.map_operator_name(None, "operator()", 1, "")  == "__call__"
    assert helper.map_operator_name(None, "operator%", 1, "")   == "__mod__"
    assert helper.map_operator_name(None, "operator**", 1, "")  == "__pow__"
    assert helper.map_operator_name(None, "operator<<", 1, "")  == "__lshift__"
    assert helper.map_operator_name(None, "operator|", 1, "")   == "__or__"

    assert helper.map_operator_name(None, "operator*", 1, "") == "__mul__"
    assert helper.map_operator_name(None, "operator*", 0, "") == "__deref__"

    assert helper.map_operator_name(None, "operator+", 1, "") == "__add__"
    assert helper.map_operator_name(None, "operator+", 0, "") == "__pos__"

    assert helper.map_operator_name(None, "func", 0, "")        == "func"
    assert helper.map_operator_name(None, "some_method", 0, "") == "some_method"


def test_namespace_extraction():
    from pypy.module._cppyy import pythonify

    assert pythonify.extract_namespace("vector")[0]                     == ""
    assert pythonify.extract_namespace("std::vector")[0]                == "std"
    assert pythonify.extract_namespace("std::vector<double>")[0]        == "std"
    assert pythonify.extract_namespace("std::vector<std::vector>")[0]   == "std"
    assert pythonify.extract_namespace("vector<double>")[0]             == ""
    assert pythonify.extract_namespace("vector<std::vector>")[0]        == ""
    assert pythonify.extract_namespace("aap::noot::mies::zus")[0]       == "aap::noot::mies"