a 9êdgz#ã@sxdZddlmZddlZddlmZddlmZmZddl m Z Gdd„dƒZ Gd d „d ej ƒZ ed krtejd d dS)zTest hyperparser, coverage 98%.é)Ú HyperParserN)Úrequires)ÚTkÚText)Ú EditorWindowc@s eZdZdd„ZejZejZdS)Ú DummyEditwincCs"||_d|_d|_d|_d|_dS)Néú>>>)é2iôiè)ÚtextZ indentwidthZtabwidthÚprompt_last_lineZnum_context_lines)Úselfr ©rú>/usr/local/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@sxeZdZdZedd„ƒZedd„ƒZdd„Zdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS)Ú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é"cCs6tdƒtƒ|_|j ¡t|jƒ|_t|jƒ|_dS)NZgui)rrÚrootZwithdrawrr rÚeditwin©ÚclsrrrÚ setUpClass%s   zHyperParserTest.setUpClasscCs|`|`|j ¡|`dS)N)r rrZdestroyrrrrÚ tearDownClass-s zHyperParserTest.tearDownClasscCs|j d|j¡dS)NÚinsert)r rÚcode©r rrrÚsetUp3szHyperParserTest.setUpcCs|j dd¡d|j_dS)Nú1.0Úendr )r Údeleterr rrrrÚtearDown6szHyperParserTest.tearDowncCs t|j|ƒS)z> Return a parser object with index at 'index' )rr)r ÚindexrrrÚ get_parser:szHyperParserTest.get_parsercCsª| t¡*}|j ddd¡| d¡}Wdƒn1s:0Y| dt|jƒ¡d|j_ | d¡}|  |j |j  dd¡¡|j  d|j  dd¡d ¡| d ¡}dS) z6 test corner cases in the init method Zconsolerz1.endz1.5NÚprecedesÚr éz54.5)Ú assertRaisesÚ ValueErrorr Ztag_addr$ÚassertInÚstrÚ exceptionrr Ú assertEqualZrawtextÚgetr)r ÚveÚprrrÚ 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Ú assertTrue©r r.r0rrrÚtest_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_coder2r4rrrÚtest_is_in_codefszHyperParserTest.test_is_in_codecCsà|j}dd„}dd„}|dƒ}| ||ƒ¡| ||ƒ¡|dƒ}| ||ƒd¡| ||ƒ||ƒ¡|dƒ}| ||ƒd ¡| ||ƒ||ƒ¡|d ƒ}| ||ƒd ¡| ||ƒ¡|d ƒ}| ||ƒ¡| ||ƒ¡dS) NcSs |jddS)NF©Z mustclose©Zget_surrounding_brackets©ÚparserrrrÚwithout_mustcloseyszGHyperParserTest.test_get_surrounding_bracket..without_mustclosecSs |jddS)NTr7r8r9rrrÚwith_mustclose~szDHyperParserTest.test_get_surrounding_bracket..with_mustclosez3.2z5.6)z5.4ú5.25z5.23)z5.21z5.24z6.15)z6.4z6.endz9.end)r$Z assertIsNoneZassertTupleEqual)r r.r;r<r0rrrÚtest_get_surrounding_bracketvs$z,HyperParserTest.test_get_surrounding_bracketcCsÜ|j}|dƒ}| | ¡d¡|dƒ}| t¡}| ¡Wdƒn1sN0Y| dt|jƒ¡|dƒ}| | ¡d¡|dƒ}| | ¡d¡|d ƒ}| | ¡d ¡|d ƒ}| | ¡d¡|d ƒ}| | ¡d ¡|dƒ}| | ¡d¡|dƒ}| t¡}| ¡Wdƒn1s,0Y| dt|jƒ¡|dƒ}| | ¡d ¡|dƒ}| | ¡d ¡|dƒ}| | ¡d ¡|dƒ}| | ¡d ¡|dƒ}| | ¡d¡|dƒ}| | ¡d¡dS)Nz4.2zy z4.7zis inside a coder=z range(10)z6.7Úpyz6.8r&z7.9z8.endz x.__len__z9.13zr'asdf'z9.17z10.0z10.6z10.11z11.3z11.11ÚFalsez12.6õcliché)r$r-Zget_expressionr(r)r*r+r,)r r.r0r/rrrÚtest_get_expression—sF & (z#HyperParserTest.test_get_expressioncCs¸dd„}| |dƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| |d ƒ¡| |d ƒ¡| |d ƒ¡| |d ƒ¡| |d ƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| t ddd¡tdƒ¡| t ddd¡tdƒ¡| t ddd¡tdƒ¡| |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_identifierÚlenÚformatÚ Exception)Ú candidateÚresultÚerr_msgrrrÚ is_valid_idÌs ÿz8HyperParserTest.test_eat_identifier..is_valid_idZ2notidZvalid_idZ _valid_idZ valid_id_Z _2valid_idÚTruer@ÚNoneÚforÚimportÚreturnZclicherAuaÙ¢Z2auÙ¢aua²z+ varréÚvarz+varr'z.varú+ú ú:ú?ú^ú\ú"z "a string")r2r3r-rrCrD)r rJrrrÚtest_eat_identifierËs: z#HyperParserTest.test_eat_identifiercCs$tj}tddƒD] }| |d|d|ƒ|¡| |d|d|ƒ|¡| |dd|dd|ƒ|¡| |dd|dd|ƒ|¡| |dd|dd|ƒ|¡| |d|ddd|ƒ|¡| |d|d|ƒd¡| |dd|dd|ƒd¡| |dd|dd|ƒd¡qdS)NééÚarõéÚ2rR)rrCÚranger-)r Zeat_idÚlengthrrrÚ#test_eat_identifier_various_lengthss     z3HyperParserTest.test_eat_identifier_various_lengthsN)rrrrÚ classmethodrrrr"r$r1r5r6r>rBrYrarrrrrs ÿ  !49rÚ__main__é)Ú verbosity)Ú__doc__Zidlelib.hyperparserrZunittestZ test.supportrÚtkinterrrZidlelib.editorrrZTestCaserrÚmainrrrrÚs