a zeZ@sddlZddlmZmZmZmZmZmZGdddejZ Gddde Z Gddde Z Gd d d e Z Gd d d e Z Gd ddejZGdddejZGddde ZedkredS)N) TextWrapperwrapfilldedentindentshortenc@s,eZdZddZddZddZddZd S) BaseTestCasecCsdt|trJg}tt|D]}|d|||fq|rDd|nd}nt|tr`dt|}|S)Nz %d: %r z no linesz %s ) isinstancelistrangelenappendjoinstrrepr)selfZtextinresultirF/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_textwrap.pyshows   zBaseTestCase.showc Cs&|||d||||fdS)Nzexpected: %s but got: %s) assertEqualr)rrexpectrrrchecks zBaseTestCase.checkcKs"t||fi|}|||dSN)rrrtextwidthrkwargsrrrr check_wrap#szBaseTestCase.check_wrapcCs&|j|}|||d||fdS)Nz expected %r but got %r)wrapper_splitr)rrrrrrr check_split's  zBaseTestCase.check_splitN)__name__ __module__ __qualname__rrr r#rrrrrs rc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=S)> WrapTestCasecCstdd|_dS)N-)r)rr!rrrrsetUp0szWrapTestCase.setUpcCs<d}||dgd||dddg||d|gdS)N=Hello there, how are you this fine day? I'm glad to hear it!  Hello there, how are you this finez day? I'mz glad to hearzit!*z'Hello there, how are you this fine day?zI'm glad to hear it!Pr rrrrr test_simple3szWrapTestCase.test_simplecCs$|ddg|jddgdddS)NFdrop_whitespacer3r)rrrtest_empty_stringDszWrapTestCase.test_empty_stringcCs*|jddgdd|jddgddddS)Nr6r7++initial_indentF)r=r9r3r)rrr%test_empty_string_with_initial_indentIsz2WrapTestCase.test_empty_string_with_initial_indentcCsd}gd}tddd}||}|||||}||d|d}dg}||d |d }d g}|j|d |d d dS)NzThis is a paragraph that already has line breaks. But some of its lines are much longer than the others, so it needs to be wrapped. Some lines are tabbed too. What a mess! )z)This is a paragraph that already has linez'breaks. But some of its lines are muchz)longer than the others, so it needs to bez-wrapped. Some lines are tabbed too. What azmess!r(TZfix_sentence_endingsr z Test default tabsize.z( Test default tabsize.r2z Test custom tabsize.z Test custom tabsize.)tabsize)rrrrrr )rrrr!rrrrtest_whitespaceNs    zWrapTestCase.test_whitespacecCstddd}d}dg}||||d}dg}||||d}||||d }d g}||||d |_gd }||||d }gd}||||d|_dg}||||d}dg}||||dS)N<Tr?z$A short line. Note the single space.z%A short line. Note the single space.z Well, Doctor? What do you think?z!Well, Doctor? What do you think?z Well, Doctor? What do you think?z)I say, chaps! Anyone for "tennis?" Hmmph!z+I say, chaps! Anyone for "tennis?" Hmmph!)z I say, chaps!zAnyone for "tennis?"zHmmph!z1And she said, "Go to hell!" Can you believe that?)zAnd she said, "Go tozhell!" Can youz believe that?z2And she said, "Go to hell!" Can you believe that?zFile stdio.h is nice.)rrrr)rr!rrrrrtest_fix_sentence_endingsns0 z&WrapTestCase.test_fix_sentence_endingscCs*d}||dddg||ddgdS)NzThis is a short paragraph.rDzThis is a shortz paragraph.(zThis is a short paragraph.r3r4rrrtest_wrap_shorts  zWrapTestCase.test_wrap_shortcCs,d}||ddg|j|ddgdddS)NzThis is a short line.z(1) This is a short line.z(1) r<r3r4rrrtest_wrap_short_1lines  z"WrapTestCase.test_wrap_short_1linecCsd}||dddg||dddg||dddgd d }|j|d |d d ||||ddg|ddg|ddd dS)NzBthis-is-a-useful-feature-for-reformatting-posts-from-tim-peters'lyrFzthis-is-a-useful-feature-for-z%reformatting-posts-from-tim-peters'ly)r1z*this-is-a-useful-feature-for-reformatting-zposts-from-tim-peters'lyzLthis-|is-|a-|useful-|feature-|for-|reformatting-|posts-|from-|tim-|peters'ly|Fbreak_long_wordsze-mailzJelly-Oz half-a-crownzhalf-|a-|crown)r splitr#rrrrrrtest_hyphenateds0 zWrapTestCase.test_hyphenatedcCsd}||dgd||dddg|j|d|dd d }||d d d g||dd d g||dd g|j|d|dd dS)NzRPython 1.0.0 was released on 1994-01-26. Python 1.0.1 was released on 1994-02-15.rH)zPython 1.0.0 was released onz1994-01-26. Python 1.0.1 waszreleased on 1994-02-15.rFz(Python 1.0.0 was released on 1994-01-26.z(Python 1.0.1 was released on 1994-02-15.rLFrMzI do all my shopping at 7-11.zI do all my shopping atz7-11.)r rOr4rrrtest_hyphenated_numberss   z$WrapTestCase.test_hyphenated_numberscCs$d}||dddg||dddgdd g}||d |||d |||d dgd }gd}||d|||d|gd}||d|||d|ddg}||d|||d|ddg}||d|||d |d}gd}|||d}gd}|||dS)Nz$Em-dashes should be written -- thus.rRzEm-dashes should bezwritten -- thus.rTzEm-dashes should be writtenz-- thus.zEm-dashes should be written --zthus.rH#$z%You can also do--this or even---this.)zYou can also doz--this or even---this.)zYou can also do--zthis or even---this.zYou can also do--this or evenrXz You can also do--this or even---r[ z7Here's an -- em-dash and--here's another---and another!)zHere's Zanr`--r`zem-Zdashr`andrazhere'sr`Zanotherz---rbr`zanother!zand then--bam!--he was gone) rbr`Zthenrazbam!raher`Zwasr`Zgoner r#rPrrr test_em_dashsT zWrapTestCase.test_em_dashcCsd}||dgd||dgdddg}||d|||d |||d |||d |d d g}||d|||d|ddg}||d|d}gd}|||dS)NzrBrErGrIrQrUrernrurwrxr{r}rrrrrrrrrrrrrrrrrr'.s< *  7"     r'c@s0eZdZdZddZddZddZdd Zd S) MaxLinesTestCaser+cCs|j|jddgdd|j|jddgdd|j|jdddgdd|j|jd dd gdd|j|jd |jgdd|j|jdgd d ddS)Nr,z Hello [...]r max_linesrLr.z how [...]rz how are [...]r2r-r7r rr)rrrr5s2     zMaxLinesTestCase.test_simplecCsP|j|jdgddd|j|jdddgdd|j|jd dgd dddS) Nr,)r.r/r0z day? [...]r@rr7r[...]rz r-rr)rrr test_spacess  zMaxLinesTestCase.test_spacesc Cs|j|jddgddd|j|jdddgddd|t$t|jd d dd d Wdn1sf0Y|t$t|jd d dd d Wdn1s0Y|j|jd ddgdd dd d|j|jd dgddd d d|j|jd|jgdddS)Nr,zHello...rLz...r placeholderr.z how are...rrZrzz [truncated]...)r=rr)rrrz Hello there,z [truncated]...r)rr=rrr2a........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................r)r rrrrr)rrrtest_placeholdersJ    $  $  z!MaxLinesTestCase.test_placeholdercCs d}|j|dddgddddS)Nz1Good grief Python features are advancing quickly!r,z Good griefz Python*****z*****rr3r4rrrtest_placeholder_backtrack2s z+MaxLinesTestCase.test_placeholder_backtrackN)r$r%r&rr5rrrrrrrrs  rc@s,eZdZddZddZddZddZd S) LongWordTestCasecCst|_d|_dS)Nz]Did you say "supercalifragilisticexpialidocious?" How *do* you spell that odd word, anyways? )rr!rr)rrrr*?szLongWordTestCase.setUpcCsV||jdgd||jdddg|jddgdd d ||jd gd dS) NrH)zDid you say "supercalifragiliszticexpialidocious?" How *do*zyou spell that odd word,anyways?rz1Did you say "supercalifragilisticexpialidocious?"z*How *do* you spell that odd word, anyways?z----------hellory)z ----------z hz e lrz oz )rr,) Did you say "supercalifr agilisticexpz ialidocious?z " How *do*z you spellzthat oddzword,rrr)rrrtest_break_longFs   z LongWordTestCase.test_break_longcCsRd|j_d|j_gd}|j|j}|||t|jddd}|||dS)NrrH)z Did you sayz%"supercalifragilisticexpialidocious?"zHow *do* you spell that oddzword, anyways?)rrN)r!rNrrrrrrrrrrtest_nobreak_longjs z"LongWordTestCase.test_nobreak_longcCs|j|jdgddddS)Nr,)rrrrr@rrr)rrrtest_max_lines_longzs z$LongWordTestCase.test_max_lines_longN)r$r%r&r*rrrrrrrr>s$rc@s,eZdZddZddZddZddZd S) IndentTestCasescCs d|_dS)NznThis paragraph will be filled, first without any indentation, and then with some (including a hanging indent).)rr)rrrr*szIndentTestCases.setUpcCs d}t|jd}|||dS)NznThis paragraph will be filled, first without any indentation, and then with some (including a hanging indent).rFrrrrrrr test_fills zIndentTestCases.test_fillcCsNgd}t|jddd}|||d|}t|jddd}|||dS)N)z# This paragraph will be filled,z'first without any indentation, and thenz'with some (including a hanging indent).rFr~r<r )rrrrrrrrrtest_initial_indents   z#IndentTestCases.test_initial_indentcCs&d}t|jdddd}|||dS)Nz~ * This paragraph will be filled, first without any indentation, and then with some (including a hanging indent).rFz * rzrrrrrrtest_subsequent_indents z&IndentTestCases.test_subsequent_indentN)r$r%r&r*rrrrrrrrs rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)DedentTestCasecCs||t|dSrrrr4rrrassertUnchangedszDedentTestCase.assertUnchangedcCs<d}||d}||d}||d}||dS)Nz,Hello there. How are you? Oh good, I'm glad.zHello there. Boo!z Hello there. This is indented.zHello there. Boo! )rr4rrrtest_dedent_nomargins   z#DedentTestCase.test_dedent_nomargincCsLd}d}||t|d}d}||t|d}d}||t|dS)Nz' Hello there. How are ya? Oh good.z!Hello there. How are ya? Oh good.z) Hello there. How are ya? Oh good. z#Hello there. How are ya? Oh good. z+ Hello there. How are ya? Oh good. rrPrrrtest_dedent_evenszDedentTestCase.test_dedent_evencCsLd}d}||t|d}d}||t|d}d}||t|dS)NzK def foo(): while 1: return foo z+def foo(): while 1: return foo z Foo Bar Baz zFoo Bar Baz z Foo Bar Baz rrPrrrtest_dedent_unevensz!DedentTestCase.test_dedent_unevencCsLd}d}||t|d}d}||t|d}d}||t|dS)Nz Foo Bar z Foo Bar z Foo Bar z Foo Bar z Foo Bar rrPrrrtest_dedent_decliningsz$DedentTestCase.test_dedent_decliningcCs,d}d}||t|||t|dS)Nz hello there how are you?zhello there how are you?rrPrrr"test_dedent_preserve_internal_tabssz1DedentTestCase.test_dedent_preserve_internal_tabscCsd}||d}||d}d}||t|d}||t|d}||t|d}d}||t|d }d }||t|dS) Nz hello there how are you?z! hello there how are you?z hello there how are you?zhello there how are you?z hello there how are you?z" hello there how are you?z hello there how are you?zhello there how are you?z2 hello there how are you? I'm fine, thanksz/ hello there how are you? I'm fine, thanks)rrrrPrrr test_dedent_preserve_margin_tabss"  z/DedentTestCase.test_dedent_preserve_margin_tabsN) r$r%r&rrrrrrrrrrrrs rc@speZdZdZedZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZdS)IndentTestCase)Hi. This is a test. Testing.zHi. This is a test. Testing.z Hi. This is a test. Testing. ) Hi. This is a test. Testing. z# Hi. This is a test. Testing. cCs"|jD]}|t|d|qdSNr6CASESrrr4rrrtest_indent_nomargin_defaultDs z+IndentTestCase.test_indent_nomargin_defaultcCs$|jD]}|t|dd|qdSrrr4rrr%test_indent_nomargin_explicit_defaultIs z4IndentTestCase.test_indent_nomargin_explicit_defaultcCs,dd}|jD]}|t|d||qdS)NcSsdSNTrlinerrrRz?IndentTestCase.test_indent_nomargin_all_lines..r6rr predicaterrrrtest_indent_nomargin_all_linesOs z-IndentTestCase.test_indent_nomargin_all_linescCs,dd}|jD]}|t|d||qdS)NcSsdS)NFrrrrrrXrz5IndentTestCase.test_indent_no_lines..rzrrrrrtest_indent_no_linesVs z#IndentTestCase.test_indent_no_linescCs&|jD]}|tt|d|qdS)NrzROUNDTRIP_CASESrrrr4rrrtest_roundtrip_spaces\s z$IndentTestCase.test_roundtrip_spacescCs&|jD]}|tt|d|qdS)Nz rr4rrrtest_roundtrip_tabsas z"IndentTestCase.test_roundtrip_tabscCs&|jD]}|tt|d|qdS)Nz rr4rrrtest_roundtrip_mixedfs z#IndentTestCase.test_roundtrip_mixedcCs4d}d}t|j|D]\}}|t|||qdSNr)" Hi. This is a test. Testing.z# Hi. This is a test. Testing.z$ Hi. This is a test. Testing. & Hi. This is a test. Testing. z) Hi. This is a test. Testing. ziprrrrprefixexpectedrrrrrtest_indent_defaultks z"IndentTestCase.test_indent_defaultcCs6d}d}t|j|D]\}}|t||d|qdSrrrrrrtest_indent_explicit_default}s z+IndentTestCase.test_indent_explicit_defaultcCs>d}d}dd}t|j|D]\}}|t||||qdS)Nr)rz% Hi. This is a test. Testing.z& Hi. This is a test. Testing. rz/ Hi. This is a test. Testing. cSsdSrrrrrrrrz6IndentTestCase.test_indent_all_lines..rrrrrrrrrrtest_indent_all_liness  z$IndentTestCase.test_indent_all_linescCs>d}d}dd}t|j|D]\}}|t||||qdS)Nr)rzHi. This is a test. Testing.z Hi. This is a test. Testing. rz) Hi. This is a test. Testing. cSs | Sr)striprrrrrrz8IndentTestCase.test_indent_empty_lines..rrrrrtest_indent_empty_liness  z&IndentTestCase.test_indent_empty_linesN)r$r%r&rrrrrrrrrrrrrrrrrr0src@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)ShortenTestCasecKs"t||fi|}|||dSr)rrrrrr check_shortenszShortenTestCase.check_shortencCs>d}||dd||t||||t|dddS)Nz>This is a paragraph that already has line breaks and tabs too.=z:This is a paragraph that already has line breaks and [...]zhello world! r,z hello world! z hello [...]ryrrr4rrrrBszShortenTestCase.test_whitespacecCsJtdddd|ttddddWdn1s<0YdS)NZxxxxxxxxxxxxxxxxxxxxz(......))rrz (.......))rrrr)rrr$test_width_too_small_for_placeholders z4ShortenTestCase.test_width_too_small_for_placeholdercCs|ddddS)NZHelloorrr)rrr-test_first_word_too_long_but_placeholder_fitssz=ShortenTestCase.test_first_word_too_long_but_placeholder_fitsN) r$r%r&rr5rr:rBrrrrrrrs  r__main__)ZunittesttextwraprrrrrrZTestCaserr'rrrrrrr$mainrrrr s 4_E3z9