a 9êdg:\ã@s<ddlmZddlZddlmZddlmZddlmZm Z ddl m Z ddl m ZGdd „d ejƒZGd d „d ejƒZGd d „d ejƒZGdd„dejƒZGdd„dejƒZGdd„dƒZGdd„dƒZ Gdd„dejƒZGdd„dƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZed kr8ejd!d!d"dS)#é)ÚformatN)Úmock)Úrequires)ÚTkÚText)Ú EditorWindow)ÚEditorc@s8eZdZdZdZdZdZdZdd„Zdd „Z d d „Z d S) Ú Is_Get_Testz# This is a commentzThis is not a commentz# This is a comment z # This is a commentz This is not a commentcCs6| t d¡¡| t d¡¡| t |j¡¡dS)NÚz )Z assertTrueÚftZ is_all_whiteZ assertFalseÚ test_comment©Úself©rú9/usr/local/lib/python3.9/idlelib/idle_test/test_format.pyÚtest_is_all_whiteszIs_Get_Test.test_is_all_whitecCsR|j}|t |j¡dƒ|t |j¡dƒ|t |j¡dƒ|t |j¡dƒdS)Nr ú )Ú assertEqualr Z get_indentr Útrailingws_commentÚleadingws_commentÚleadingws_nocomment©rÚEqualrrrÚtest_get_indents zIs_Get_Test.test_get_indentcCsd|j}|t |j¡dƒ|t |j¡dƒ|t |j¡dƒ|t |j¡dƒ|t |j¡dƒdS)Nú#ú #rr )rr Zget_comment_headerr rrrÚtest_nocommentrrrrÚtest_get_comment_header s z#Is_Get_Test.test_get_comment_headerN) Ú__name__Ú __module__Ú __qualname__r rrrrrrrrrrrr sr c@s0eZdZedd„ƒZdd„Zdd„Zdd„Zd S) ÚFindTestcCsddlm}|ƒ|_dS)Nr)r)Zidlelib.idle_test.mock_tkrÚtext)ÚclsrrrrÚ setUpClass5s zFindTest.setUpClassc Cs‚|j}| d|¡td|ƒD]T}t| d|¡ d¡dƒ}d|d|fD]$}d||f}| t ||¡|¡qJq|  dd¡dS) Nú1.0éz%d.endÚ.réz%d.%dÚend) r"ÚinsertÚrangeÚintÚindexÚsplitrr Zfind_paragraphÚdelete) rZ inserttextZstoplineÚexpectedr"ÚlineZ linelengthÚcolZ tempindexrrrÚruncase:s  zFindTest.runcasec Csd}| |dddd|dd…f¡d}| |d d d d|d d …f¡d}| |d d d d|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡dS)Nz;# Comment block with no blank lines before # Comment line ér%ú3.0rré:zG # Comment block with whitespace line before and after # Comment line éú2.0ú4.0r&éFzS # Indented comment block with whitespace before and after # Comment line réRz # Single line comment éz4 # Single line comment with leading whitespace é3z0 # Comment immediately followed by code x = 42 é(z= # Indented comment immediately followed by code x = 42 é5z= # Comment immediately followed by indented code x = 42 é1©r3)rÚcommentrrrÚtest_find_commentGs0ÿÿÿÿÿÿÿÿzFindTest.test_find_commentc Cs®d}| |dddd|dd…f¡d}| |d d d d|d d …f¡d}| |d d d d|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡dS)Nz6"""String with no blank lines before String line """ r7r%r9r rr?zC """String with whitespace line before and after String line. """ ér8z5.0r&éBzV """Indented string with whitespace before and after Comment string. """ réUz """Single line string.""" r4r5éz8 """Single line string with leading whitespace.""" é7rA)rZ teststringrrrÚtest_find_paragraph}sÿÿÿÿÿzFindTest.test_find_paragraphN)rrr Ú classmethodr$r3rCrIrrrrr!+s    6r!c@seZdZdd„ZdS)ÚReformatFunctionTestcCsØ|j}tj}d}||ddƒdƒ||ddƒdƒ|||dƒdƒ|||dƒdƒ|||d ƒd ƒ|||d ƒd ƒ|||d ƒdƒd }|||dƒdƒ|||dƒdƒ|||d ƒdƒ|||d ƒdƒ|||d ƒd ƒdS)Nz O hello worldú r&zHello worldéz Hello worldz O hello worldééz O hello worldé é z O hello worldz O hello worldz O hello world)rr Zreformat_paragraph)rrZreformZhwrrrÚtest_reformat_paragraph¥s z,ReformatFunctionTest.test_reformat_paragraphN)rrr rRrrrrrK¢srKc@seZdZdd„ZdS)ÚReformatCommentTestcCsJ|j}d}t |dd¡}d}|||ƒd}t |dd¡}d}|||ƒdS)Nzu """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""r:rzy """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""zm# this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?rzo# this is a test of a reformat for a triple quoted string will it # reformat to less than 70 characters for me?)rr Zreformat_comment)rrÚ test_stringÚresultr0r rrrÚtest_reformat_comment¿sÿÿ ÿÿz)ReformatCommentTest.test_reformat_commentN)rrr rVrrrrrS¼srSc@seZdZdd„ZdS)ÚFormatClassTestcCs2t d¡}| |jd¡| ¡| |jd¡dS)NÚeditor)r ÚFormatParagraphrZeditwinÚclose)rÚinstancerrrÚtest_init_close×s zFormatClassTest.test_init_closeN)rrr r\rrrrrWÖsrWc@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú TextWrappercCst|d|_dS)N)Úmaster)rr")rr^rrrÚ__init__êszTextWrapper.__init__cCs t|j|ƒS©N)Úgetattrr")rÚnamerrrÚ __getattr__ìszTextWrapper.__getattr__cCsdSr`rr rrrÚundo_block_startîózTextWrapper.undo_block_startcCsdSr`rr rrrÚundo_block_stopïrezTextWrapper.undo_block_stopN)rrr r_rcrdrfrrrrr]ésr]c@seZdZdd„ZejZdS)rcCst|ƒ|_dSr`)r]r")rÚrootrrrr_òszEditor.__init__N)rrr r_rÚget_selection_indicesrrrrrñsrc@sPeZdZdZdZdZedd„ƒZedd„ƒZdd „Z d d „Z d d „Z dd„Z dS)ÚFormatEventTestzv '''this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?''' a '''The first line is under the max width. The second line's length is way over the max width. It goes on and on until it is over 100 characters long. Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it. ''' a,# The first line is under the max width. # The second line's length is way over the max width. It goes on and on until it is over 100 characters long. # Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it. # The fourth line is short like the first line.cCsBtdƒtƒ|_|j ¡t|jd}|jj|_t |¡j|_ dS)NÚgui)rg) rrrgÚwithdrawrr"r rYZformat_paragraph_eventÚ formatter)r#rXrrrr$s    zFormatEventTest.setUpClasscCs$|`|`|j ¡|j ¡|`dSr`)r"rlrgÚupdate_idletasksÚdestroy©r#rrrÚ tearDownClasss  zFormatEventTest.tearDownClasscCs@|j dd¡| d¡| |j dd¡d¡|j dd¡dS)Nr%z Short line ZDummyr*r))r"r*rlrÚgetr/r rrrÚtest_short_line s zFormatEventTest.test_short_linecCs¬|j}| d|j¡| dd¡|jddd| dd¡}d}| ||¡| dd¡| d|j¡| dd d ¡|jddd| dd¡}d }| ||¡| dd¡dS) Nr%r*ÚParameterDoesNothingr:©Úlimitzz '''this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?''' r)Úselz1.11z1.endzv '''this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?''') r"r*rTZmark_setrlrqrr/Útag_add©rr"rUr0rrrÚtest_long_line&s"  ÿ   ÿ zFormatEventTest.test_long_linecCs\|j}| d|j¡| ddd¡|jddd| dd¡}d }| ||¡| dd ¡dS) Nr%rvr8r9rsr:rtr*zà The second line's length is way over the max width. It goes on and on until it is over 100 characters long. Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it. r))r"r*Úmultiline_test_stringrwrlrqrr/rxrrrÚtest_multiple_linesAs ÿ z#FormatEventTest.test_multiple_linescCs |j}| d|j¡|jddd| dd¡}d}| ||¡| dd¡| d|j¡| dd d ¡|jddd| dd¡}d }| ||¡| dd¡dS) Nr%rsr:rtr*a/# The first line is under the max width. The second line's length is # way over the max width. It goes on and on until it is over 100 # characters long. Same thing with the third line. It is also way over # the max width, but FormatParagraph will fix it. The fourth line is # short like the first line. r)rvr8r5z™# The first line is under the max width. # The second line's length is way over the max width. It goes on and # on until it is over 100 characters long. )r"r*Úmultiline_test_commentrlrqrr/rwrxrrrÚtest_comment_blockPs  ÿ   ÿ z"FormatEventTest.test_comment_blockN) rrr rTrzr|rJr$rprrryr{r}rrrrriösÿÿÿ  ric@s eZdZdd„ZejZejZdS)Ú DummyEditwincCs(||_||_d|_d|_d|_d|_dS)Nr7FT)rgr"Ú indentwidthZtabwidthÚusetabsZcontext_use_ps1)rrgr"rrrr_}s zDummyEditwin.__init__N)rrr r_rZ _make_blanksrhrrrrr~|sr~c@s®eZdZedd„ƒZedd„ƒZdd„Zdd„Zd Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zej ejd¡dd„ƒZej ejd¡dd„ƒZej ed¡dd„ƒZdS)ÚFormatRegionTestcCs`tdƒtƒ|_|j ¡t|jƒ|_t ¡|j_t ¡|j_ t |j|jƒ|_ t   |j ¡|_dS)Nrj)rrrgrkrr"rÚMockrdrfr~rXr Ú FormatRegionrlrorrrr$‹s    zFormatRegionTest.setUpClasscCs(|`|`|`|j ¡|j ¡|`dSr`)r"rlrXrgrmrnrorrrrp–s   zFormatRegionTest.tearDownClasscCs|j d|j¡dS)Nr%)r"r*Ú code_sampler rrrÚsetUpszFormatRegionTest.setUpcCs|j dd¡dS)Nr%r)©r"r/r rrrÚtearDown szFormatRegionTest.tearDowna # WS line needed for test. class C1: # Class comment. def __init__(self, a, b): self.a = a self.b = b def compare(self): if a > b: return a elif a < b: return b else: return None cCsn|jj}|j}|j}| ddd¡gd¢}||ƒddd |¡|fƒ| ddd¡||ƒdd dd d gfƒdS) Nrvú7.0ú10.0)r z def compare(self):z if a > b:r Ú r%r)z15.0z16.0r )rlÚ get_regionr"rrwÚjoinÚ tag_remove)rrqr"ÚeqZexpected_linesrrrÚtest_get_region´sz FormatRegionTest.test_get_regionc Cs&|jj}|j}|j}|j}t ¡|_|j ¡d}|j ¡d}|  ddd¡|j  ¡\}}} } |||| | ƒ|j  ¡||  dd¡| ƒ||  dd¡| ƒ|  ddd ¡d } |  d ¡} |d d | | ƒ||  dd¡| ƒ||  d d¡| ƒ||  dd¡|ƒ||  dd¡|ƒ|  ddd ¡||_dS)NrDé rvz6.0z11.0z sel.firstzsel.lastr%r)zadded line 1 rŠrˆr‰z7.0-1cz12.0-1c)rlÚ set_regionr"rZbellrr‚r„Ú splitlinesrwr‹Zassert_called_oncerqrr.) rZset_r"rŽZ save_bellZline6Zline10ÚheadÚtailÚcharsÚlinesZ newstringÚnewlinesrrrÚtest_set_regionÅs.   z FormatRegionTest.test_set_regioncCs>|jj}|j}|j}| ddd¡|ƒ|| dd¡dƒdS)Nrvrˆr‰z2 def compare(self): if a > b: )rlZindent_region_eventr"rrwrq)rÚindentr"rŽrrrÚtest_indent_region_eventès z)FormatRegionTest.test_indent_region_eventcCs>|jj}|j}|j}| ddd¡|ƒ|| dd¡dƒdS)Nrvrˆr‰z" def compare(self): if a > b: )rlZdedent_region_eventr"rrwrq)rÚdedentr"rŽrrrÚtest_dedent_region_eventòs z)FormatRegionTest.test_dedent_region_eventcCs>|jj}|j}|j}| ddd¡|ƒ|| dd¡dƒdS)Nrvrˆr‰z0## ## def compare(self): ## if a > b: )rlÚcomment_region_eventr"rrwrq)rrBr"rŽrrrÚtest_comment_region_eventüs z*FormatRegionTest.test_comment_region_eventcCs®|jj}|jj}|j}|j}| ddd¡|ƒ|ƒ|| dd¡dƒ| ddd¡| ddd¡|ƒ|| dd ¡d ƒ|j ddd d d g¡|ƒ|| dd ¡d ƒdS)Nrvrˆr‰z* def compare(self): if a > b: r%r)r5r9z3.endz # Class comment.r z# Class comment.z Class comment.) rlrZuncomment_region_eventr"rrwrqrr‘)rrBZ uncommentr"rŽrrrÚtest_uncomment_region_eventsz,FormatRegionTest.test_uncomment_region_eventÚ _asktabwidthcCs\|jj}|j}|j}| ddd¡d|_| |ƒ¡d|_| |ƒ¡|| dd¡dƒdS)Nrvrˆr‰r4z$ def compare(self): if a > b: ) rlÚtabify_region_eventr"rrwÚ return_valueÚ assertIsNoneÚassertIsNotNonerq)rr Ztabifyr"rŽrrrÚtest_tabify_region_events  z)FormatRegionTest.test_tabify_region_eventcCsl|jj}|j}|j}| ddd¡d|_| |ƒ¡d|_|j ¡d|_| |ƒ¡||  dd¡dƒdS)Nrvrˆr‰r(r4z0 def compare(self): if a > b: ) rlZuntabify_region_eventr"rrwr¢r£r¡r¤rq)rr Zuntabifyr"rŽrrrÚtest_untabify_region_event)s   z+FormatRegionTest.test_untabify_region_eventÚ askintegercCs |jj}d|_| |ƒd¡dS)Né )rlr r¢r)rr§ZaskrrrÚtest_ask_tabwidth:sz"FormatRegionTest.test_ask_tabwidthN)rrr rJr$rpr…r‡r„rr˜ršrœržrŸrÚpatchÚobjectr rƒr¥r¦r©rrrrr‰s&  #      rc@s8eZdZej ed¡dd„ƒZej ed¡dd„ƒZdS)Ú IndentsTestÚaskyesnocCsjtddƒ}t |¡}d|_| d¡| |jd¡| |jd¡| d¡| |jd¡| |jd¡dS)NTéF)r~r ÚIndentsr¢Ztoggle_tabs_eventrr€r)rr­rXÚindentsrrrÚtest_toggle_tabsCs    zIndentsTest.test_toggle_tabsr§cCsxtddƒ}t |¡}d|_| d¡| |jd¡d|_| d¡| |jd¡d|_d|_| d¡| |jd¡dS)Nr7r4rDT)r~r r¯r¢Zchange_indentwidth_eventrrr€)rr§rXr°rrrÚtest_change_indentwidthQs     z#IndentsTest.test_change_indentwidthN) rrr rrªr«r r±r²rrrrr¬As  r¬c@s<eZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Zd S) Ú RstripTestcCsHtdƒtƒ|_|j ¡t|jƒ|_t|jd|_t  |j¡j |_ dS)Nrj)r") rrrgrkrr"Ú MockEditorrXr ZRstripÚ do_rstriprorrrr$fs   zRstripTest.setUpClasscCs(|`|`|`|j ¡|j ¡|`dSr`)r"rµrXrgrmrnrorrrrpos   zRstripTest.tearDownClasscCs|j dd¡dS)Nr%úend-1cr†r rrrr‡vszRstripTest.tearDowncCs8d}d}|j d|¡| ¡| |j dd¡|¡dS)NzˆLine with an ending tab Line ending in 5 spaces Linewithnospaces indented line indented line with trailing space zyLine with an ending tab Line ending in 5 spaces Linewithnospaces indented line indented line with trailing space r%r*)r"r*rµrrq)rZoriginalÚstrippedrrrÚtest_rstrip_linesysÿÿzRstripTest.test_rstrip_linesc CsÒ|j}dD]X}|j|d8| d|¡| ¡| | dd¡d¡Wdƒq 1sX0Yq dD]d}|j|dD| dd¡| d|¡| ¡| | dd¡d¡Wdƒqh1sÂ0YqhdS)N)r rŠz )Úcoder%r¶r )úa za za rº)r"ZsubTestr*rµrrqr/)rr"r¹rrrÚtest_rstrip_endŒs 4  zRstripTest.test_rstrip_endN) rrr rJr$rpr‡r¸r»rrrrr³ds  r³Ú__main__r()Ú verbosityÚexit)Zidlelibrr ZunittestrZ test.supportrÚtkinterrrZidlelib.editorrZidlelib.idle_test.mock_idlerr´ZTestCaser r!rKrSrWr]rir~rr¬r³rÚmainrrrrÚs,     w 9#7