a  zez#@sxdZddlmZddlZddlmZddlmZmZddl m Z GdddZ Gd d d ej Z ed krtejd d dS)zTest hyperparser, coverage 98%.) HyperParserN)requires)TkText) EditorWindowc@s eZdZddZejZejZdS) DummyEditwincCs"||_d|_d|_d|_d|_dS)N>>>)2ii)textZ indentwidthZtabwidthprompt_last_lineZnum_context_lines)selfr rV/opt/bitninja-python-dojo/embedded/lib/python3.9/idlelib/idle_test/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|_|jt|j|_t|j|_dS)NZgui)rrrootZwithdrawrr reditwinclsrrr setUpClass%s   zHyperParserTest.setUpClasscCs|`|`|j|`dS)N)r rrZdestroyrrrr tearDownClass-s zHyperParserTest.tearDownClasscCs|jd|jdS)Ninsert)r rcoder rrrsetUp3szHyperParserTest.setUpcCs|jddd|j_dS)N1.0endr )r deleterr rrrrtearDown6szHyperParserTest.tearDowncCs t|j|S)z> Return a parser object with index at 'index' )rr)r indexrrr get_parser:szHyperParserTest.get_parsercCs|t*}|jddd|d}Wdn1s:0Y|dt|jd|j_ |d}| |j |j dd|j d|j ddd |d }dS) z6 test corner cases in the init method Zconsolerz1.endz1.5Nprecedesr z54.5) assertRaises ValueErrorr Ztag_addr$assertInstr exceptionrr assertEqualZrawtextgetr)r veprrr test_init@s ( zHyperParserTest.test_initcCs|j}|d}|||d}|||d}|||d}|||d}|||d}|||d}||dS)Nrz1.4z2.3z3.3z3.7z4.6z12.54)r$ assertFalseZ is_in_string assertTruer r.r0rrrtest_is_in_stringTsz!HyperParserTest.test_is_in_stringcCs|j}|d}|||d}|||d}|||d}|||d}|||d}||dS)Nrz1.1z2.5z3.4z3.6z4.14)r$r3Z is_in_coder2r4rrrtest_is_in_codefszHyperParserTest.test_is_in_codecCs|j}dd}dd}|d}|||||||d}|||d||||||d}|||d ||||||d }|||d ||||d }||||||dS) NcSs |jddS)NFZ mustcloseZget_surrounding_bracketsparserrrrwithout_mustcloseyszGHyperParserTest.test_get_surrounding_bracket..without_mustclosecSs |jddS)NTr7r8r9rrrwith_mustclose~szDHyperParserTest.test_get_surrounding_bracket..with_mustclosez3.2z5.6)z5.45.25z5.23)z5.21z5.24z6.15)z6.4z6.endz9.end)r$Z assertIsNoneZassertTupleEqual)r r.r;r<r0rrrtest_get_surrounding_bracketvs$z,HyperParserTest.test_get_surrounding_bracketcCs|j}|d}||d|d}|t}|Wdn1sN0Y|dt|j|d}||d|d}||d|d }||d |d }||d|d }||d |d}||d|d}|t}|Wdn1s,0Y|dt|j|d}||d |d}||d |d}||d |d}||d |d}||d|d}||ddS)Nz4.2zy z4.7zis inside a coder=z range(10)z6.7pyz6.8r&z7.9z8.endz x.__len__z9.13zr'asdf'z9.17z10.0z10.6z10.11z11.3z11.11Falsez12.6cliché)r$r-Zget_expressionr(r)r*r+r,)r r.r0r/rrrtest_get_expressionsF & (z#HyperParserTest.test_get_expressioncCsdd}||d||d||d||d||d||d||d ||d ||d ||d ||d ||d||d||d||d||d||d|tdddtd|tdddtd|tdddtd||d||d||d||d||d||d ||d!||d"dS)#NcSsJt|dt|}|t|kr"dS|dkr.dSd|t|}t|dS)NrTFz'Unexpected result: {} (expected 0 or {})r_eat_identifierlenformat Exception) candidateresulterr_msgrrr is_valid_ids z8HyperParserTest.test_eat_identifier..is_valid_idZ2notidZvalid_idZ _valid_idZ valid_id_Z _2valid_idTruer@NoneforimportreturnZclicherAua٢Z2au٢aua²z+ varrvarz+varr'z.var+ :?^\"z "a string")r2r3r-rrCrD)r rJrrrtest_eat_identifiers: z#HyperParserTest.test_eat_identifiercCs$tj}tddD] }||d|d||||d|d||||dd|dd||||dd|dd||||dd|dd||||d|ddd||||d|d|d||dd|dd|d||dd|dd|dqdS)Naré2rR)rrCranger-)r Zeat_idlengthrrr#test_eat_identifier_various_lengthss     z3HyperParserTest.test_eat_identifier_various_lengthsN)rrrr classmethodrrrr"r$r1r5r6r>rBrYrarrrrrs   !49r__main__) verbosity)__doc__Zidlelib.hyperparserrZunittestZ test.supportrtkinterrrZidlelib.editorrrZTestCaserrmainrrrrs