@@ -374,6 +374,39 @@ test_unicodewriter_recover_error(PyObject *self, PyObject *Py_UNUSED(args))
374374}
375375
376376
377+ static PyObject *
378+ test_unicodewriter_decode_utf8 (PyObject * self , PyObject * Py_UNUSED (args ))
379+ {
380+ // test PyUnicodeWriter_DecodeUTF8Stateful()
381+ PyUnicodeWriter * writer = PyUnicodeWriter_Create (0 );
382+ if (writer == NULL ) {
383+ return NULL ;
384+ }
385+ if (PyUnicodeWriter_DecodeUTF8Stateful (writer , "ign\xFFore" , -1 , "ignore" , NULL ) < 0 ) {
386+ goto error ;
387+ }
388+ if (PyUnicodeWriter_WriteChar (writer , '-' ) < 0 ) {
389+ goto error ;
390+ }
391+ if (PyUnicodeWriter_DecodeUTF8Stateful (writer , "replace\xFF" , -1 , "replace" , NULL ) < 0 ) {
392+ goto error ;
393+ }
394+
395+ PyObject * result = PyUnicodeWriter_Finish (writer );
396+ if (result == NULL ) {
397+ return NULL ;
398+ }
399+ assert (PyUnicode_EqualToUTF8 (result , "ignore-replace\xef\xbf\xbd" ));
400+ Py_DECREF (result );
401+
402+ Py_RETURN_NONE ;
403+
404+ error :
405+ PyUnicodeWriter_Discard (writer );
406+ return NULL ;
407+ }
408+
409+
377410static PyObject *
378411test_unicodewriter_format (PyObject * self , PyObject * Py_UNUSED (args ))
379412{
@@ -484,6 +517,7 @@ static PyMethodDef TestMethods[] = {
484517 {"test_unicodewriter_utf8" , test_unicodewriter_utf8 , METH_NOARGS },
485518 {"test_unicodewriter_invalid_utf8" , test_unicodewriter_invalid_utf8 , METH_NOARGS },
486519 {"test_unicodewriter_recover_error" , test_unicodewriter_recover_error , METH_NOARGS },
520+ {"test_unicodewriter_decode_utf8" , test_unicodewriter_decode_utf8 , METH_NOARGS },
487521 {"test_unicodewriter_format" , test_unicodewriter_format , METH_NOARGS },
488522 {"test_unicodewriter_format_recover_error" , test_unicodewriter_format_recover_error , METH_NOARGS },
489523 {"test_unicodewriter_widechar" , test_unicodewriter_widechar , METH_NOARGS },
0 commit comments