e fe#@sdZddlZddlmZddlmZmZddlmZddl m Z GdddZ Gd d d ej Z ed krejd d ndS)z Unittest for idlelib.HyperParserN)requires)TkText) EditorWindow) HyperParserc@s.eZdZddZejZejZdS) DummyEditwincCs1||_d|_d|_d|_d|_dS)NT2)r r r )textZ indentwidthZtabwidthcontext_use_ps1Znum_context_lines)selfr rG/opt/alt/python34/lib64/python3.4/idlelib/idle_test/test_hyperparser.py__init__ s     zDummyEditwin.__init__N)__name__ __module__ __qualname__rrZ_build_char_in_string_funcZis_char_in_stringrrrrrs   rc@seZdZdZeddZeddZddZdd 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é"cCs>tdt|_t|j|_t|j|_dS)NZgui)rrrootrr reditwin)clsrrr setUpClass$s  zHyperParserTest.setUpClasscCs#|`|`|jj|`dS)N)r rrZdestroy)rrrr tearDownClass+s  zHyperParserTest.tearDownClasscCs|jjd|jdS)Ninsert)r rcode)rrrrsetUp1szHyperParserTest.setUpcCs#|jjddd|j_dS)Nz1.0endT)r Zdeleterr )rrrrtearDown4szHyperParserTest.tearDowncCst|j|S)z> Return a parser object with index at 'index' )rr)rindexrrr get_parser8szHyperParserTest.get_parserc Cs|jt,}|jjddd|jd}WdQX|jdt|jd|j_ |jd}|j |j |jj dd|jj d|jj ddd |jd }dS) z6 test corner cases in the init method Zconsolez1.0z1.endz1.5NZprecedesFrz54.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_stringRs        z!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!r.Z is_in_coder-)rr)r+rrrtest_is_in_codeds       zHyperParserTest.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)N mustcloseF)get_surrounding_brackets)parserrrrwithout_mustclosewszGHyperParserTest.test_get_surrounding_bracket..without_mustclosecSs|jddS)Nr1T)r2)r3rrrwith_mustclose|szDHyperParserTest.test_get_surrounding_bracket..with_mustclosez3.2z5.65.45.25z5.235.215.24z6.156.46.endz9.end)r6r7)r8r9)r:r;)r!Z assertIsNoneZassertTupleEqual)rr)r4r5r+rrrtest_get_surrounding_bracketts$        z,HyperParserTest.test_get_surrounding_bracketcCsU|j}|d}|j|jd|d}|jt}|jWdQX|jdt|j|d}|j|jd|d}|j|jd|d }|j|jd |d }|j|jd|d }|j|jd |d}|j|jd|d}|jt}|jWdQX|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_expressioncCsZdd}|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)#NcSsitj|dt|}|t|kr1dS|dkrAdSdj|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_idTruer?NoneforimportreturnZclicheuclichéua٢Z2au٢aua²z+ varrvarz+varr"z.var+ :?^\"z "a string")r-r.r(rrArB)rrGrrrtest_eat_identifiers: %%%z#HyperParserTest.test_eat_identifiercCswtj}xgtddD]V}|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é2rO)rrAranger()rZeat_idZlengthrrr#test_eat_identifier_various_lengthss   (((( (z3HyperParserTest.test_eat_identifier_various_lengthsN)rrrr classmethodrrrrr!r,r/r0r<r@rVr]rrrrrs        ! 4 9r__main__ verbosity)__doc__ZunittestZ test.supportrZtkinterrrZidlelib.EditorWindowrZidlelib.HyperParserrrZTestCaserrmainrrrrs