3 2ax#@stddlmZddlZddlmZddlmZmZddlm Z GdddZ Gdd d ej Z e d krpejd d dS) ) HyperParserN)requires)TkText) EditorWindowc@s eZdZddZejZejZdS) DummyEditwincCs"||_d|_d|_d|_d|_dS)NT2)r r r )textZ indentwidthZtabwidthcontext_use_ps1Znum_context_lines)selfr r5/opt/alt/python36/lib64/python3.6/test_hyperparser.py__init__ s zDummyEditwin.__init__N)__name__ __module__ __qualname__rrZ_build_char_in_string_funcZis_char_in_stringrrrrr src@sxeZdZdZeddZeddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZdS)HyperParserTestu#"""This is a module docstring""" # this line is a comment x = "this is a string" y = 'this is also a string' l = [i for i in range(10)] m = [py*py for # comment py in l] x.__len__ z = ((r'asdf')+('a'))) [x for x in for = False cliché = "this is a string with unicode, what a cliché"cCs6tdt|_|jjt|j|_t|j|_dS)NZgui)rrrootZwithdrawrr reditwin)clsrrr setUpClass%s   zHyperParserTest.setUpClasscCs|`|`|jj|`dS)N)r rrZdestroy)rrrr tearDownClass-s zHyperParserTest.tearDownClasscCs|jjd|jdS)Ninsert)r rcode)rrrrsetUp3szHyperParserTest.setUpcCs|jjddd|j_dS)Nz1.0endT)r deleterr )rrrrtearDown6szHyperParserTest.tearDowncCs t|j|S)N)rr)rindexrrr get_parser:szHyperParserTest.get_parserc Cs|jt }|jjddd|jd}WdQRX|jdt|jd|j_ |jd}|j |j |jj dd|jj d|jj ddd|jd }dS) NZconsolez1.0z1.endz1.5precedesFrz54.5) assertRaises ValueErrorr Ztag_addr"assertInstr exceptionrr assertEqualZrawtextgetr)rveprrr test_init@s  zHyperParserTest.test_initcCs|j}|d}|j|j|d}|j|j|d}|j|j|d}|j|j|d}|j|j|d}|j|j|d}|j|jdS)Nz1.0z1.4z2.3z3.3z3.7z4.6z12.54)r" assertFalseZ is_in_string assertTrue)rr+r-rrrtest_is_in_stringTsz!HyperParserTest.test_is_in_stringcCs|j}|d}|j|j|d}|j|j|d}|j|j|d}|j|j|d}|j|j|d}|j|jdS)Nz1.0z1.1z2.5z3.4z3.6z4.14)r"r0Z is_in_coder/)rr+r-rrrtest_is_in_codefszHyperParserTest.test_is_in_codecCs|j}dd}dd}|d}|j|||j|||d}|j||d|j|||||d }|j||d|j|||||d }|j||d|j|||d}|j|||j||dS)NcSs |jddS)NF) mustclose)get_surrounding_brackets)parserrrrwithout_mustcloseyszGHyperParserTest.test_get_surrounding_bracket..without_mustclosecSs |jddS)NT)r3)r4)r5rrrwith_mustclose~szDHyperParserTest.test_get_surrounding_bracket..with_mustclosez3.2z5.65.45.25z5.235.215.24z6.156.46.endz9.end)r8r9)r:r;)r<r=)r"Z assertIsNoneZassertTupleEqual)rr+r6r7r-rrrtest_get_surrounding_bracketvs$z,HyperParserTest.test_get_surrounding_bracketcCs|j}|d}|j|jd|d}|jt}|jWdQRX|jdt|j|d}|j|jd|d}|j|jd|d }|j|jd |d }|j|jd|d }|j|jd |d}|j|jd|d}|jt}|jWdQRX|jdt|j|d}|j|jd |d}|j|jd |d}|j|jd |d}|j|jd |d}|j|jd|d}|j|jddS)Nz4.2zy z4.7zis inside a codez5.25z range(10)z6.7pyz6.8z7.9z8.endz x.__len__z9.13zr'asdf'z9.17z10.0z10.6z10.11z11.3z11.11Falsez12.6ucliché)r"r*Zget_expressionr%r&r'r(r))rr+r-r,rrrtest_get_expressionsF  z#HyperParserTest.test_get_expressioncCsdd}|j|d|j|d|j|d|j|d|j|d|j|d|j|d |j|d |j|d |j|d |j|d |j|d|j|d|j|d|j|d|j|d|j|d|jtjdddtd|jtjdddtd|jtjdddtd|j|d|j|d|j|d|j|d|j|d|j|d |j|d!|j|d"dS)#NcSsJtj|dt|}|t|kr"dS|dkr.dSdj|t|}t|dS)NrTFz'Unexpected result: {} (expected 0 or {})r_eat_identifierlenformat Exception) candidateresultZerr_msgrrr is_valid_ids  z8HyperParserTest.test_eat_identifier..is_valid_idZ2notidZvalid_idZ _valid_idZ valid_id_Z _2valid_idTruerANoneforimportreturnZclicheuclichéua٢Z2au٢aua²z+ varrvarz+varr$z.var+ :?^\"z "a string")r/r0r*rrCrD)rrIrrrtest_eat_identifiers: z#HyperParserTest.test_eat_identifiercCs*tj}xtddD] }|j|d|d|||j|d|d|||j|dd|dd|||j|dd|dd|||j|dd|dd|||j|d|ddd|||j|d|d|d|j|dd|dd|d|j|dd|dd|dqWdS)Naré2rQ)rrCranger*)rZeat_idZlengthrrr#test_eat_identifier_various_lengthss     z3HyperParserTest.test_eat_identifier_various_lengthsN)rrrr classmethodrrrr r"r.r1r2r>rBrXr_rrrrrs  !49r__main__) verbosity)Zidlelib.hyperparserrZunittestZ test.supportrZtkinterrrZidlelib.editorrrZTestCaserrmainrrrrs