B RT¶ŽÏh·\ã @ s< d dl mZ d dlZd dlmZ d dlmZ d dlmZm Z d dl mZ d dlm Z G dd „ d ejƒZG d d„ dejƒZG dd „ d ejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dƒZG dd„ dƒZ G dd„ dejƒZG dd„ dƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZed kr8ejd!d!d" dS )#é )ÚformatN)Úmock)Úrequires)ÚTkÚText)ÚEditorWindow)ÚEditorc @ s8 e Zd ZdZdZdZdZdZdd„ Zdd „ Z d d„ Z dS ) ÚIs_Get_Testz# This is a commentzThis is not a commentz# This is a comment z # This is a commentz This is not a commentc C s6 | t d¡¡ | t d¡¡ | t | j¡¡ d S )NÚ z )Z assertTrueÚftZis_all_whiteZassertFalseÚtest_comment)Úself© r úB/opt/alt/python37/lib64/python3.7/idlelib/idle_test/test_format.pyÚtest_is_all_white s zIs_Get_Test.test_is_all_whitec C sR | j }|t | j¡dƒ |t | j¡dƒ |t | j¡dƒ |t | j¡dƒ d S )Nr z )ÚassertEqualr Z get_indentr Útrailingws_commentÚleadingws_commentÚleadingws_nocomment)r ÚEqualr r r Útest_get_indent s zIs_Get_Test.test_get_indentc C sd | j }|t | j¡dƒ |t | j¡dƒ |t | j¡dƒ |t | j¡dƒ |t | j¡dƒ d S )Nú#z #z r )r r Zget_comment_headerr r r r Útest_nocomment)r r r r r Útest_get_comment_header s z#Is_Get_Test.test_get_comment_headerN)Ú__name__Ú __module__Ú__qualname__r r r r r r r r r r r r r s r c @ s0 e Zd Zedd„ ƒZdd„ Zdd„ Zdd„ Zd S ) ÚFindTestc C s ddl m} |ƒ | _d S )Nr )r )Zidlelib.idle_test.mock_tkr Útext)Úclsr r r r Ú setUpClass5 s zFindTest.setUpClassc C sŠ | j }| d|¡ xftd|ƒD ]X}t| d| ¡ d¡d ƒ}x6d|d |fD ]$}d||f }| t ||¡|¡ qNW qW | dd¡ d S ) Nz1.0é z%d.endÚ.r é z%d.%dÚend) r ÚinsertÚrangeÚintÚindexÚsplitr r Zfind_paragraphÚdelete) r Z inserttextZstoplineÚexpectedr ÚlineZ linelengthÚcolZ tempindexr r r Úruncase: s zFindTest.runcasec C s d}| |dddd|dd… f¡ d}| |d d dd|dd … f¡ d}| |d d dd|dd… f¡ d}| |dd dd|dd… f¡ d}| |dd dd|dd… f¡ d}| |dd dd|dd… f¡ d}| |dd dd|dd… f¡ d}| |dd dd|dd… f¡ d S )Nz;# Comment block with no blank lines before # Comment line é z1.0z3.0r r é: zG # Comment block with whitespace line before and after # Comment line é z2.0z4.0r! éF zS # Indented comment block with whitespace before and after # Comment line z #éR z # Single line comment é z4 # Single line comment with leading whitespace é3 z0 # Comment immediately followed by code x = 42 é( z= # Indented comment immediately followed by code x = 42 é5 z= # Comment immediately followed by indented code x = 42 é1 )r. )r Úcommentr r r Útest_find_commentG s zFindTest.test_find_commentc C s® d}| |dddd|dd… f¡ d}| |d d dd|dd … f¡ d}| |d d dd|dd… f¡ d}| |dd dd|dd… f¡ d}| |dd dd|dd… f¡ d S )Nz6"""String with no blank lines before String line """ r1 z1.0z4.0r r r7 zC """String with whitespace line before and after String line. """ é z2.0z5.0r! éB zV """Indented string with whitespace before and after Comment string. """ z éU z """Single line string.""" r/ z3.0é z8 """Single line string with leading whitespace.""" é7 )r. )r Z teststringr r r Útest_find_paragraph} s zFindTest.test_find_paragraphN)r r r Úclassmethodr r. r: r@ r r r r r + s 6r c @ s e Zd Zdd„ ZdS )ÚReformatFunctionTestc C sØ | 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 ƒ d S )Nz O hello worldú r! zHello worldé zHello worldz O hello worldé é z O hello worldé é z O hello worldz O hello worldz O hello world)r r Zreformat_paragraph)r r ZreformZhwr r r Útest_reformat_paragraph¥ s z,ReformatFunctionTest.test_reformat_paragraphN)r r r rI r r r r rB ¢ s rB c @ s e Zd Zdd„ ZdS )ÚReformatCommentTestc C sJ | j }d}t |dd¡}d}|||ƒ d}t |dd¡}d}|||ƒ d S )Nzu """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""r2 z zy """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?r zo# this is a test of a reformat for a triple quoted string will it # reformat to less than 70 characters for me?)r r Zreformat_comment)r r Útest_stringÚresultr+ r r r r Útest_reformat_comment¿ s z)ReformatCommentTest.test_reformat_commentN)r r r rM r r r r rJ ¼ s rJ c @ s e Zd Zdd„ ZdS )ÚFormatClassTestc C s2 t d¡}| |jd¡ | ¡ | |jd ¡ d S )NÚeditor)r ÚFormatParagraphr ZeditwinÚclose)r Úinstancer r r Útest_init_close× s zFormatClassTest.test_init_closeN)r r r rS r r r r rN Ö s rN c @ s, e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd S ) ÚTextWrapperc C s t |d| _d S )N)Úmaster)r r )r rU r r r Ú__init__ê s zTextWrapper.__init__c C s t | j|ƒS )N)Úgetattrr )r Únamer r r Ú__getattr__ì s zTextWrapper.__getattr__c C s d S )Nr )r r r r Úundo_block_startî ó zTextWrapper.undo_block_startc C s d S )Nr )r r r r Úundo_block_stopï r[ zTextWrapper.undo_block_stopN)r r r rV rY rZ r\ r r r r rT é s rT c @ s e Zd Zdd„ ZejZdS )r c C s t |ƒ| _d S )N)rT r )r Úrootr r r rV ò s zEditor.__init__N)r r r rV r Úget_selection_indicesr r r r r ñ s r c @ sP e Zd ZdZdZdZedd„ ƒZedd„ ƒZdd „ Z d d„ Z dd „ Zdd„ ZdS )Ú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.c C sB t dƒ tƒ | _| j ¡ t| jd}|jj| _t |¡j| _ d S )NÚgui)r] ) r r r] Úwithdrawr r r rP Zformat_paragraph_eventÚ formatter)r rO r r r r s zFormatEventTest.setUpClassc C s$ | ` | `| j ¡ | j ¡ | `d S )N)r rb r] Úupdate_idletasksÚdestroy)r r r r Ú tearDownClass s zFormatEventTest.tearDownClassc C s@ | j dd¡ | d¡ | | j dd¡d¡ | j dd¡ d S )Nz1.0zShort line ZDummyr% r$ )r r% rb r Úgetr* )r r r r Útest_short_line s zFormatEventTest.test_short_linec C s¬ | j }| d| j¡ | dd¡ | jddd | dd¡}d}| ||¡ | dd¡ | d| j¡ | dd d ¡ | jddd | dd¡}d}| ||¡ | dd¡ d S )Nz1.0r% ÚParameterDoesNothingr2 )Ú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% rK Zmark_setrb rf r r* Útag_add)r r rL r+ r r r Útest_long_line& s zFormatEventTest.test_long_linec C s\ | j }| d| j¡ | ddd¡ | jddd | dd¡}d }| ||¡ | dd ¡ d S )Nz1.0rj z2.0z4.0rh r2 )ri r% 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_stringrk rb rf r r* )r r rL r+ r r r Útest_multiple_linesA s z#FormatEventTest.test_multiple_linesc C s | j }| d| j¡ | jddd | dd¡}d}| ||¡ | dd¡ | d| j¡ | dd d ¡ | jddd | dd¡}d}| ||¡ | dd¡ d S )Nz1.0rh r2 )ri r% 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$ rj z2.0z3.0z™# 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_commentrb rf r r* rk )r r rL r+ r r r Útest_comment_blockP s z"FormatEventTest.test_comment_blockN) r r r rK rm ro rA r re rg rl rn rp r r r r r_ ö s r_ c @ s e Zd Zdd„ ZejZejZdS )ÚDummyEditwinc C s( || _ || _d| _d| _d| _d| _d S )Nr1 FT)r] r ÚindentwidthZtabwidthÚusetabsZcontext_use_ps1)r r] r r r r rV } s zDummyEditwin.__init__N)r r r rV r Z_make_blanksr^ r r r r rq | s rq c @ s® e Zd Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zd Zd d„ Z dd „ Z dd„ Zdd„ Zdd„ Z dd„ Zej ejd¡dd„ ƒZej ejd¡dd„ ƒZej ed¡dd„ ƒZdS )ÚFormatRegionTestc C s` t dƒ tƒ | _| j ¡ t| jƒ| _t ¡ | j_t ¡ | j_ t | j| jƒ| _t | j¡| _d S )Nr` )r r r] ra r r r ÚMockrZ r\ rq rO r ÚFormatRegionrb )r r r r r ‹ s zFormatRegionTest.setUpClassc C s( | ` | `| `| j ¡ | j ¡ | `d S )N)r rb rO r] rc rd )r r r r re – s zFormatRegionTest.tearDownClassc C s | j d| j¡ d S )Nz1.0)r r% Úcode_sample)r r r r ÚsetUp s zFormatRegionTest.setUpc C s | j dd¡ d S )Nz1.0r$ )r r* )r r r r ÚtearDown s zFormatRegionTest.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 c C sr | j j}| j}| j}| ddd¡ ddddg}||ƒ ddd |¡|fƒ | ddd ¡ ||ƒ d ddddgfƒ d S )Nrj z7.0z10.0r z def compare(self):z if a > b:Ú z1.0r$ z15.0z16.0)rb Ú get_regionr r rk ÚjoinÚ tag_remove)r rf r ÚeqZexpected_linesr r r Útest_get_region´ s z FormatRegionTest.test_get_regionc C s& | j j}| j}| j}|j}t ¡ |_| j ¡ d }| j ¡ d }| ddd¡ | j ¡ \}}} } |||| | ƒ |j ¡ || dd¡| ƒ || dd¡| ƒ | ddd ¡ d }| d¡}|dd | |ƒ || dd¡|ƒ || dd¡|ƒ || dd¡|ƒ || dd¡|ƒ | ddd ¡ ||_d S )Nr; é rj z6.0z11.0z sel.firstzsel.lastz1.0r$ zadded line 1 rz z7.0z10.0z7.0-1cz12.0-1c)rb Ú set_regionr r Zbellr ru rw Ú splitlinesrk r{ Zassert_called_oncerf r} r) ) r Zset_r r~ Z save_bellZline6Zline10ÚheadÚtailÚcharsÚlinesZ newstringÚnewlinesr r r Útest_set_regionÅ s. z FormatRegionTest.test_set_regionc C s> | j j}| j}| j}| ddd¡ |ƒ || dd¡dƒ d S )Nrj z7.0z10.0z2 def compare(self): if a > b: )rb Zindent_region_eventr r rk rf )r Úindentr r~ r r r Útest_indent_region_eventè s z)FormatRegionTest.test_indent_region_eventc C s> | j j}| j}| j}| ddd¡ |ƒ || dd¡dƒ d S )Nrj z7.0z10.0z" def compare(self): if a > b: )rb Zdedent_region_eventr r rk rf )r Údedentr r~ r r r Útest_dedent_region_eventò s z)FormatRegionTest.test_dedent_region_eventc C s> | j j}| j}| j}| ddd¡ |ƒ || dd¡dƒ d S )Nrj z7.0z10.0z0## ## def compare(self): ## if a > b: )rb Úcomment_region_eventr r rk rf )r r9 r r~ r r r Útest_comment_region_eventü s z*FormatRegionTest.test_comment_region_eventc C s® | j j}| j j}| j}| j}| ddd¡ |ƒ |ƒ || dd¡dƒ | ddd¡ | ddd¡ |ƒ || dd ¡d ƒ | j dddddg¡ |ƒ || dd ¡d ƒ d S )Nrj z7.0z10.0z* def compare(self): if a > b: z1.0r$ z3.0z4.0z3.endz # Class comment.r z# Class comment.z Class comment.) rb r Zuncomment_region_eventr r rk rf r} r )r r9 Z uncommentr r~ r r r Útest_uncomment_region_event s z,FormatRegionTest.test_uncomment_region_eventÚ_asktabwidthc C s\ | j j}| j}| j}| ddd¡ d |_| |ƒ ¡ d|_| |ƒ ¡ || dd¡dƒ d S )Nrj z7.0z10.0r/ z$ def compare(self): if a > b: ) rb Útabify_region_eventr r rk Úreturn_valueÚassertIsNoneÚassertIsNotNonerf )r r Ztabifyr r~ r r r Útest_tabify_region_event s z)FormatRegionTest.test_tabify_region_eventc C sl | j j}| j}| j}| ddd¡ d |_| |ƒ ¡ d|_| j ¡ d|_| |ƒ ¡ || dd¡dƒ d S )Nrj z7.0z10.0r# r/ z0 def compare(self): if a > b: ) rb Zuntabify_region_eventr r rk r’ r“ r‘ r” rf )r r Zuntabifyr r~ r r r Útest_untabify_region_event) s z+FormatRegionTest.test_untabify_region_eventÚ askintegerc C s | j j}d|_| |ƒ d¡ d S )Né )rb r r’ r )r r— Zaskr r r Útest_ask_tabwidth: s z"FormatRegionTest.test_ask_tabwidthN)r r r rA r re rx ry rw r rˆ rŠ rŒ rŽ r r ÚpatchÚobjectr rv r• r– r™ r r r r rt ‰ s # rt c @ s8 e Zd Zej ed¡dd„ ƒZej ed¡dd„ ƒZdS )ÚIndentsTestÚaskyesnoc C sj t d d ƒ}t |¡}d|_| d ¡ | |jd¡ | |jd¡ | d ¡ | |jd¡ | |jd¡ d S )NTé F)rq r ÚIndentsr’ Ztoggle_tabs_eventr rs rr )r r rO Úindentsr r r Útest_toggle_tabsC s zIndentsTest.test_toggle_tabsr— c C sx t d d ƒ}t |¡}d |_| d ¡ | |jd¡ d|_| d ¡ | |jd¡ d|_d|_| d ¡ | |jd¡ d S )Nr1 r/ r; T)rq r rŸ r’ Zchange_indentwidth_eventr rr rs )r r— rO r r r r Útest_change_indentwidthQ s z#IndentsTest.test_change_indentwidthN) r r r r rš r› r r¡ r¢ r r r r rœ A s rœ c @ s<