a  ze:\@s<ddlmZddlZddlmZddlmZddlmZm Z ddl m Z ddl m ZGdd d ejZGd d d ejZGd d d ejZGdddejZGdddejZGdddZGdddZ GdddejZGdddZGdddejZGdddejZGdddejZed kr8ejd!d!d"dS)#)formatN)mock)requires)TkText) EditorWindow)Editorc@s8eZdZdZdZdZdZdZddZdd 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|td|td|t|jdS)Nz )Z assertTrueftZ is_all_whiteZ assertFalse test_commentselfrQ/opt/bitninja-python-dojo/embedded/lib/python3.9/idlelib/idle_test/test_format.pytest_is_all_whiteszIs_Get_Test.test_is_all_whitecCsR|j}|t|jd|t|jd|t|jd|t|jddS)Nr  ) assertEqualr Z get_indentr trailingws_commentleadingws_commentleadingws_nocommentrEqualrrrtest_get_indents zIs_Get_Test.test_get_indentcCsd|j}|t|jd|t|jd|t|jd|t|jd|t|jddS)N# #rr )rr Zget_comment_headerr rrrtest_nocommentrrrrtest_get_comment_header s z#Is_Get_Test.test_get_comment_headerN) __name__ __module__ __qualname__r rrrrrrrrrrrr sr c@s0eZdZeddZddZddZddZd S) FindTestcCsddlm}||_dS)Nr)r)Zidlelib.idle_test.mock_tkrtext)clsrrrr setUpClass5s zFindTest.setUpClassc Cs|j}|d|td|D]T}t|d|dd}d|d|fD]$}d||f}|t|||qJq| dddS) N1.0z%d.end.rz%d.%dend) r"insertrangeintindexsplitrr Zfind_paragraphdelete) rZ inserttextZstoplineexpectedr"lineZ linelengthcolZ tempindexrrrruncase:s  zFindTest.runcasec Csd}||dddd|ddfd}||d d d d|d d fd}||d d d d|d dfd}||dd dd|d dfd}||dd dd|d dfd}||dd dd|d dfd}||dd dd|d dfd}||dd dd|d dfdS)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.04.0r&FzS # Indented comment block with whitespace before and after # Comment line rRz # 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 1r3)rcommentrrrtest_find_commentGs0zFindTest.test_find_commentc Csd}||dddd|ddfd}||d d d d|d d fd}||d d d d|d dfd}||dd dd|d dfd}||dd dd|d dfdS)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. """ rUz """Single line string.""" r4r5z8 """Single line string with leading whitespace.""" 7rA)rZ teststringrrrtest_find_paragraph}szFindTest.test_find_paragraphN)rrr classmethodr$r3rCrIrrrrr!+s    6r!c@seZdZddZdS)ReformatFunctionTestcCs|j}tj}d}||ddd||ddd|||dd|||dd|||d d |||d d |||d dd }|||dd|||dd|||d d|||d d|||d d dS)Nz O hello world r&zHello worldz Hello worldz O hello worldz O hello world z O hello worldz O hello worldz O hello world)rr Zreformat_paragraph)rrZreformZhwrrrtest_reformat_paragraphs z,ReformatFunctionTest.test_reformat_paragraphN)rrr rRrrrrrKsrKc@seZdZddZdS)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_stringresultr0r rrrtest_reformat_comments z)ReformatCommentTest.test_reformat_commentN)rrr rVrrrrrSsrSc@seZdZddZdS)FormatClassTestcCs2td}||jd|||jddS)Neditor)r FormatParagraphrZeditwinclose)rinstancerrrtest_init_closes zFormatClassTest.test_init_closeN)rrr r\rrrrrWsrWc@s,eZdZddZddZddZddZd S) TextWrappercCst|d|_dS)N)master)rr")rr^rrr__init__szTextWrapper.__init__cCs t|j|SN)getattrr")rnamerrr __getattr__szTextWrapper.__getattr__cCsdSr`rr rrrundo_block_startzTextWrapper.undo_block_startcCsdSr`rr rrrundo_block_stoprezTextWrapper.undo_block_stopN)rrr r_rcrdrfrrrrr]sr]c@seZdZddZejZdS)rcCst||_dSr`)r]r")rrootrrrr_szEditor.__init__N)rrr r_rget_selection_indicesrrrrrsrc@sPeZdZdZdZdZeddZeddZdd Z d d Z d d Z ddZ 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.cCsBtdt|_|jt|jd}|jj|_t|j|_ dS)Ngui)rg) rrrgwithdrawrr"r rYZformat_paragraph_event formatter)r#rXrrrr$s    zFormatEventTest.setUpClasscCs$|`|`|j|j|`dSr`)r"rlrgupdate_idletasksdestroyr#rrr tearDownClasss  zFormatEventTest.tearDownClasscCs@|jdd|d||jddd|jdddS)Nr%z Short line ZDummyr*r))r"r*rlrgetr/r rrrtest_short_line s zFormatEventTest.test_short_linecCs|j}|d|j|dd|jddd|dd}d}||||dd|d|j|dd d |jddd|dd}d }||||dddS) 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_addrr"rUr0rrrtest_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/rxrrrtest_multiple_linesAs  z#FormatEventTest.test_multiple_linescCs|j}|d|j|jddd|dd}d}||||dd|d|j|dd d |jddd|dd}d }||||dddS) 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/rwrxrrrtest_comment_blockPs      z"FormatEventTest.test_comment_blockN) rrr rTrzr|rJr$rprrryr{r}rrrrris  ric@s eZdZddZejZejZdS) DummyEditwincCs(||_||_d|_d|_d|_d|_dS)Nr7FT)rgr" indentwidthZtabwidthusetabsZcontext_use_ps1)rrgr"rrrr_}s zDummyEditwin.__init__N)rrr r_rZ _make_blanksrhrrrrr~|sr~c@seZdZeddZeddZddZddZd Zd d Z d d Z ddZ ddZ ddZ ddZejejdddZejejdddZejedddZdS)FormatRegionTestcCs`tdt|_|jt|j|_t|j_t|j_ t |j|j|_ t |j |_dS)Nrj)rrrgrkrr"rMockrdrfr~rXr FormatRegionrlrorrrr$s    zFormatRegionTest.setUpClasscCs(|`|`|`|j|j|`dSr`)r"rlrXrgrmrnrorrrrps   zFormatRegionTest.tearDownClasscCs|jd|jdS)Nr%)r"r* code_sampler rrrsetUpszFormatRegionTest.setUpcCs|jdddS)Nr%r)r"r/r rrrtearDownszFormatRegionTest.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}|dddgd}||ddd||f|ddd||dd dd d gfdS) Nrv7.010.0)r z def compare(self):z if a > b:r  r%r)z15.0z16.0r )rl get_regionr"rrwjoin tag_remove)rrqr"eqZexpected_linesrrrtest_get_regionsz FormatRegionTest.test_get_regionc Cs&|jj}|j}|j}|j}t|_|jd}|jd}| 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 rrrz7.0-1cz12.0-1c)rl set_regionr"rZbellrrr splitlinesrwrZassert_called_oncerqrr.) rZset_r"rZ save_bellZline6Zline10headtailcharslinesZ newstringnewlinesrrrtest_set_regions.   z FormatRegionTest.test_set_regioncCs>|jj}|j}|j}|ddd|||ddddS)Nrvrrz2 def compare(self): if a > b: )rlZindent_region_eventr"rrwrq)rindentr"rrrrtest_indent_region_events z)FormatRegionTest.test_indent_region_eventcCs>|jj}|j}|j}|ddd|||ddddS)Nrvrrz" def compare(self): if a > b: )rlZdedent_region_eventr"rrwrq)rdedentr"rrrrtest_dedent_region_events z)FormatRegionTest.test_dedent_region_eventcCs>|jj}|j}|j}|ddd|||ddddS)Nrvrrz0## ## def compare(self): ## if a > b: )rlcomment_region_eventr"rrwrq)rrBr"rrrrtest_comment_region_events z*FormatRegionTest.test_comment_region_eventcCs|jj}|jj}|j}|j}|ddd||||ddd|ddd|ddd|||dd d |jddd d d g|||dd d dS)Nrvrrz* 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"rrrrtest_uncomment_region_eventsz,FormatRegionTest.test_uncomment_region_event _asktabwidthcCs\|jj}|j}|j}|dddd|_||d|_||||ddddS)Nrvrrr4z$ def compare(self): if a > b: ) rltabify_region_eventr"rrw return_value assertIsNoneassertIsNotNonerq)rrZtabifyr"rrrrtest_tabify_region_events  z)FormatRegionTest.test_tabify_region_eventcCsl|jj}|j}|j}|dddd|_||d|_|jd|_|||| ddddS)Nrvrrr(r4z0 def compare(self): if a > b: ) rlZuntabify_region_eventr"rrwrrrrrq)rrZuntabifyr"rrrrtest_untabify_region_event)s   z+FormatRegionTest.test_untabify_region_event askintegercCs |jj}d|_||ddS)N )rlrrr)rrZaskrrrtest_ask_tabwidth:sz"FormatRegionTest.test_ask_tabwidthN)rrr rJr$rprrrrrrrrrrpatchobjectr rrrrrrrrrs&  #      rc@s8eZdZejedddZejedddZdS) IndentsTestaskyesnocCsjtdd}t|}d|_|d||jd||jd|d||jd||jddS)NTF)r~r IndentsrZtoggle_tabs_eventrrr)rrrXindentsrrrtest_toggle_tabsCs    zIndentsTest.test_toggle_tabsrcCsxtdd}t|}d|_|d||jdd|_|d||jdd|_d|_|d||jddS)Nr7r4rDT)r~r rrZchange_indentwidth_eventrrr)rrrXrrrrtest_change_indentwidthQs     z#IndentsTest.test_change_indentwidthN) rrr rrrr rrrrrrrAs  rc@s<eZdZeddZeddZddZddZd d Zd S) RstripTestcCsHtdt|_|jt|j|_t|jd|_t |jj |_ dS)Nrj)r") rrrgrkrr" MockEditorrXr ZRstrip do_rstriprorrrr$fs   zRstripTest.setUpClasscCs(|`|`|`|j|j|`dSr`)r"rrXrgrmrnrorrrrpos   zRstripTest.tearDownClasscCs|jdddS)Nr%end-1crr rrrrvszRstripTest.tearDowncCs8d}d}|jd||||jdd|dS)NzLine 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*rrrq)rZoriginalstrippedrrrtest_rstrip_linesyszRstripTest.test_rstrip_linesc Cs|j}dD]X}|j|d8|d||||dddWdq 1sX0Yq dD]d}|j|dD|dd|d||||dddWdqh1s0YqhdS)N)r rz )coder%rr )a za za r)r"ZsubTestr*rrrqr/)rr"rrrrtest_rstrip_ends 4  zRstripTest.test_rstrip_endN) rrr rJr$rprrrrrrrrds  r__main__r() verbosityexit)Zidlelibrr ZunittestrZ test.supportrtkinterrrZidlelib.editorrZidlelib.idle_test.mock_idlerrZTestCaser r!rKrSrWr]rir~rrrrmainrrrrs,     w 9#7