@@ -23,6 +23,17 @@ check_system_error(int failed, const char *message)
2323 return 0 ;
2424}
2525
26+ static int
27+ check_line_view (const _PyTok_SourceText * source , Py_ssize_t lineno ,
28+ const char * expected )
29+ {
30+ Py_ssize_t len ;
31+ const char * line = _PyTok_SourceLineView (source , lineno , & len );
32+ return check (len == (Py_ssize_t )strlen (expected ) &&
33+ memcmp (line , expected , len ) == 0 ,
34+ "wrong source line view" );
35+ }
36+
2637static int
2738same_cursor (const _PyTok_Cursor * left , const _PyTok_Cursor * right )
2839{
@@ -40,6 +51,10 @@ test_tokenizer_source(PyObject *Py_UNUSED(module),
4051 _PyTok_SourceText source ;
4152 _PyTok_SourceInit (& source );
4253
54+ if (check_line_view (& source , 1 , "" ) < 0 ) {
55+ goto error ;
56+ }
57+
4358 _PyTok_Loc loc ;
4459 _PyTok_Line line ;
4560 if (check (_PyTok_SourceLocation (
@@ -67,10 +82,20 @@ test_tokenizer_source(PyObject *Py_UNUSED(module),
6782 "wrong first source offset" ) < 0 ||
6883 check (_PyTok_SourceAppendLine (
6984 & source , "\xce\xb2\n" , 3 , 1 ) == 6 ,
70- "wrong second source offset" ) < 0 ||
71- check (_PyTok_SourceAppendLine (
72- & source , "nul\0x\n" , 6 , 0 ) == 9 ,
73- "wrong third source offset" ) < 0 ) {
85+ "wrong second source offset" ) < 0 ) {
86+ goto error ;
87+ }
88+
89+ if (check_line_view (& source , PY_SSIZE_T_MIN , "alpha" ) < 0 ||
90+ check_line_view (& source , 1 , "alpha" ) < 0 ||
91+ check_line_view (& source , 2 , "\xce\xb2" ) < 0 ||
92+ check_line_view (& source , 3 , "" ) < 0 ||
93+ check_line_view (& source , PY_SSIZE_T_MAX , "" ) < 0 ) {
94+ goto error ;
95+ }
96+
97+ if (check (_PyTok_SourceAppendLine (& source , "nul\0x\n" , 6 , 0 ) == 9 ,
98+ "wrong third source offset" ) < 0 ) {
7499 goto error ;
75100 }
76101
@@ -195,6 +220,11 @@ test_tokenizer_source(PyObject *Py_UNUSED(module),
195220 goto error ;
196221 }
197222
223+ if (check_line_view (& source , 1 , "tail" ) < 0 ||
224+ check_line_view (& source , PY_SSIZE_T_MAX , "tail" ) < 0 ) {
225+ goto error ;
226+ }
227+
198228 _PyTok_SourceDiscard (& source );
199229 if (check (_PyTok_SourceAppendLine (& source , "a\n" , 2 , 0 ) == 4 ,
200230 "wrong retained source offset" ) < 0 ||
0 commit comments