File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed
graalpython/com.oracle.graal.python.test/src/tests/cpyext Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,11 @@ def _reference_setitem(args):
68
68
return listObj
69
69
70
70
71
+ def _reference_reverse (args ):
72
+ args [0 ].reverse ()
73
+ return args [0 ]
74
+
75
+
71
76
def _reference_SET_ITEM (args ):
72
77
listObj = args [0 ]
73
78
pos = args [1 ]
@@ -323,3 +328,25 @@ def compile_module(self, name):
323
328
arguments = ["PyObject* o" ],
324
329
cmpfunc = unhandled_error_compare
325
330
)
331
+
332
+ test_PyList_Reverse = CPyExtFunction (
333
+ _reference_reverse ,
334
+ lambda : (
335
+ ([],),
336
+ ([1 , 2 , 3 ],),
337
+ ([1 , "a" , 0.1 ],),
338
+ ),
339
+ code = '''PyObject* wrap_PyList_Reverse(PyObject* list) {
340
+ if (PyList_Reverse(list)) {
341
+ return NULL;
342
+ }
343
+ Py_INCREF(list);
344
+ return list;
345
+ }
346
+ ''' ,
347
+ resultspec = "O" ,
348
+ argspec = 'O' ,
349
+ arguments = ["PyObject* list" ],
350
+ callfunction = "wrap_PyList_Reverse" ,
351
+ cmpfunc = unhandled_error_compare
352
+ )
Original file line number Diff line number Diff line change @@ -57,6 +57,12 @@ def _reference_contains(args):
57
57
except TypeError :
58
58
return raise_Py6_SystemError ()
59
59
60
+
61
+ def _reference_clear (args ):
62
+ args [0 ].clear ()
63
+ return args [0 ]
64
+
65
+
60
66
class FrozenSetSubclass (frozenset ):
61
67
pass
62
68
@@ -202,3 +208,24 @@ def compile_module(self, name):
202
208
cmpfunc = unhandled_error_compare
203
209
)
204
210
211
+ test_PySet_Clear = CPyExtFunction (
212
+ _reference_clear ,
213
+ lambda : (
214
+ ({1 , 2 , 3 },),
215
+ ({1 , "a" , 0.1 },),
216
+ ),
217
+ code = '''PyObject* wrap_PySet_Clear(PyObject* set) {
218
+ if (PySet_Clear(set)) {
219
+ return NULL;
220
+ }
221
+ Py_INCREF(set);
222
+ return set;
223
+ }
224
+ ''' ,
225
+ resultspec = "O" ,
226
+ argspec = 'O' ,
227
+ arguments = ["PyObject* set" ],
228
+ callfunction = "wrap_PySet_Clear" ,
229
+ cmpfunc = unhandled_error_compare
230
+ )
231
+
Original file line number Diff line number Diff line change @@ -93,6 +93,12 @@ def _reference_readchar(args):
93
93
return ord (s [i ])
94
94
95
95
96
+ def _reference_contains (args ):
97
+ if not isinstance (args [0 ], str ) or not isinstance (args [1 ], str ):
98
+ raise TypeError
99
+ return args [1 ] in args [0 ]
100
+
101
+
96
102
class CustomString (str ):
97
103
pass
98
104
@@ -635,4 +641,16 @@ def compile_module(self, name):
635
641
cmpfunc = unhandled_error_compare
636
642
)
637
643
644
+ test_PyUnicode_Contains = CPyExtFunction (
645
+ _reference_contains ,
646
+ lambda : (
647
+ ("aaa" , "bbb" ),
648
+ ("aaa" , "a" ),
649
+ ),
650
+ resultspec = "i" ,
651
+ argspec = 'OO' ,
652
+ arguments = ["PyObject* haystack" , "PyObject* needle" ],
653
+ cmpfunc = unhandled_error_compare
654
+ )
655
+
638
656
You can’t perform that action at this time.
0 commit comments