File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,10 @@ static PySequenceMethods cstring_as_sequence = {
141
141
.sq_contains = cstring_contains ,
142
142
};
143
143
144
+ static PyMappingMethods cstring_as_mapping = {
145
+ .mp_length = cstring_len ,
146
+ };
147
+
144
148
static PyTypeObject cstring_type = {
145
149
PyVarObject_HEAD_INIT (NULL , 0 )
146
150
.tp_name = "cstring" ,
@@ -154,6 +158,7 @@ static PyTypeObject cstring_type = {
154
158
.tp_str = cstring_str ,
155
159
.tp_hash = cstring_hash ,
156
160
.tp_as_sequence = & cstring_as_sequence ,
161
+ .tp_as_mapping = & cstring_as_mapping ,
157
162
};
158
163
159
164
static struct PyModuleDef module = {
Original file line number Diff line number Diff line change
1
+ from cstring import cstring
2
+
3
+
4
+ def test_len ():
5
+ result = cstring ('hello, world' )
6
+ assert len (result ) == 12
7
+
You can’t perform that action at this time.
0 commit comments