a zeZ@sddlZddlmZmZmZmZmZmZGdddejZ Gddde Z Gddde Z Gd d d e Z Gd d d e Z Gd ddejZGdddejZGddde ZedkredS)N) TextWrapperwrapfilldedentindentshortenc@s0eZdZdZddZddZddZdd Zd S) BaseTestCasez5Parent class with utility methods for textwrap tests.cCsdt|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____doc__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_whitespacer4r*rrrtest_empty_stringDszWrapTestCase.test_empty_stringcCs*|jddgdd|jddgddddS)Nr7r8++initial_indentF)r>r:r4r*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.r3z 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.rEzThis is a shortz paragraph.(zThis is a short paragraph.r4r5rrrtest_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=r4r5rrrtest_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'lyrGzthis-is-a-useful-feature-for-z%reformatting-posts-from-tim-peters'ly)r2z*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.rI)zPython 1.0.0 was released onz1994-01-26. Python 1.0.1 waszreleased on 1994-02-15.rGz(Python 1.0.0 was released on 1994-01-26.z(Python 1.0.1 was released on 1994-02-15.rMFrNzI do all my shopping at 7-11.zI do all my shopping atz7-11.)r rPr5rrrtest_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.rSzEm-dashes should bezwritten -- thus.rUzEm-dashes should be writtenz-- thus.zEm-dashes should be written --zthus.rI#$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 evenrYz You can also do--this or even---r\ z7Here's an -- em-dash and--here's another---and another!)zHere's Zanra--razem-Zdashraandrbzhere'sraZanotherz---rcrazanother!zand then--bam!--he was gone) rcraZthenrbzbam!rbheraZwasraZgoner r#rQrrr test_em_dashsT zWrapTestCase.test_em_dashcCsd}||dgd||dgdddg}||d|||d |||d |||d |d d g}||d|||d|ddg}||d|d}gd}|||dS)Nzr4r*rrr6test_drop_whitespace_false_whitespace_only_with_indentsszCWrapTestCase.test_drop_whitespace_false_whitespace_only_with_indentcCs|ddgdS)Nrr8r4r*rrr$test_drop_whitespace_whitespace_onlyysz1WrapTestCase.test_drop_whitespace_whitespace_onlycCs*d}||ddg||dddgdS)Nz, This is a sentence with leading whitespace.2rIz This is a sentence withzleading whitespace.r4r5rrr'test_drop_whitespace_leading_whitespace}sz4WrapTestCase.test_drop_whitespace_leading_whitespacecCs0d}|j|dgddd||dddgdS)Nz abcd efghr8)abcdr{efghFr9rrr4r5rrr$test_drop_whitespace_whitespace_lines z1WrapTestCase.test_drop_whitespace_whitespace_linecCs|jddgdddS)Nrr8r<r=r4r*rrr0test_drop_whitespace_whitespace_only_with_indentsz=WrapTestCase.test_drop_whitespace_whitespace_only_with_indentcCs|jddddgddddS)Nz abcd efghr8z abcdz efghrr>subsequent_indentr4r*rrr&test_drop_whitespace_whitespace_indentsz3WrapTestCase.test_drop_whitespace_whitespace_indentcCs$d}|j|}||gddS)Nz0Hello there -- you goof-ball, use the -b option!)HelloraZthererarbraZyourazgoof-zball,raZuserarlraz-brazoption!)r!r"r)rrrrrr test_splits  zWrapTestCase.test_splitcCs4d}|j|dddgdd|j|dddgd ddS) Nz yaba daba-doorzz yaba daba-ZdooTZbreak_on_hyphensZyabazdaba-dooFr4r5rrrtest_break_on_hyphenssz"WrapTestCase.test_break_on_hyphenscCs(d}|tt|d|tt|ddS)NzWhatever, it doesn't matter.r) assertRaises ValueErrorrr5rrrtest_bad_widthszWrapTestCase.test_bad_widthcCsd}||dgddS)NuDie Empfänger-Auswahl )ZDieu Empfänger-ZAuswahlr4r5rrrtest_no_split_at_umlautsz$WrapTestCase.test_no_split_at_umlautcCsd}||dddgdS)Nu aa ää-ääuaa ää-uäär4r5rrrtest_umlaut_followed_by_dashsz)WrapTestCase.test_umlaut_followed_by_dashcCs4d}|j|dgddd|j|dgddddS)Nu,This is a sentence with non-breaking space.rE)This is a sentence with non-ubreaking space.Tr)rwithunon-breaking space.Fr4r5rrrtest_non_breaking_spacesz$WrapTestCase.test_non_breaking_spacecCs4d}|j|dgddd|j|dgddddS)Nu-This is a sentence with non-breaking space.rE)rrubreaking space.Tr)rrunon-breaking space.Fr4r5rrrtest_narrow_non_breaking_spacesz+WrapTestCase.test_narrow_non_breaking_spaceN)!r$r%r&r+r6r;r?rCrFrHrJrRrVrfrorvrxryr|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_linesrMr/z how [...]rz how are [...]r3r.r8r rr*rrrr6s2     zMaxLinesTestCase.test_simplecCsP|j|jdgddd|j|jdddgdd|j|jd dgd dddS) Nr-)r/r0r1z day? [...]rArr8r[...]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...rMz...r placeholderr/z how are...rr[r{z [truncated]...)r>rr)rrrz Hello there,z [truncated]...r)rr>rrr3a........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................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*****rr4r5rrrtest_placeholder_backtrack2s z+MaxLinesTestCase.test_placeholder_backtrackN)r$r%r&rr6rrrrrrrrs  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) NrI)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----------hellorz)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)NrrI)z Did you sayz%"supercalifragilisticexpialidocious?"zHow *do* you spell that oddzword, anyways?)rrO)r!rOrrrrrrrrrrtest_nobreak_longjs z"LongWordTestCase.test_nobreak_longcCs|j|jdgddddS)Nr-)rrrrrArrr*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).rGrrrrrrr 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).rGrr=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).rGz * r{rrrrrrtest_subsequent_indents z&IndentTestCases.test_subsequent_indentN)r$r%r&r+rrrrrrrrs rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)DedentTestCasecCs||t|dS)z,assert that dedent() has no effect on 'text'Nrrr5rrrassertUnchangedszDedentTestCase.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! )rr5rrrtest_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. rrQrrrtest_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 rrQrrrtest_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 rrQrrrtest_dedent_decliningsz$DedentTestCase.test_dedent_decliningcCs,d}d}||t|||t|dS)Nz hello there how are you?zhello there how are you?rrQrrr"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)rrrrQrrr 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|qdSNr7CASESrrr5rrrtest_indent_nomargin_defaultDs z+IndentTestCase.test_indent_nomargin_defaultcCs$|jD]}|t|dd|qdSrrr5rrr%test_indent_nomargin_explicit_defaultIs z4IndentTestCase.test_indent_nomargin_explicit_defaultcCs,dd}|jD]}|t|d||qdS)NcSsdSNTrlinerrrRz?IndentTestCase.test_indent_nomargin_all_lines..r7rr predicaterrrrtest_indent_nomargin_all_linesOs z-IndentTestCase.test_indent_nomargin_all_linescCs,dd}|jD]}|t|d||qdS)NcSsdS)NFrrrrrrXrz5IndentTestCase.test_indent_no_lines..r{rrrrrtest_indent_no_linesVs z#IndentTestCase.test_indent_no_linescCs&|jD]}|tt|d|qdS)Nr{ROUNDTRIP_CASESrrrr5rrrtest_roundtrip_spaces\s z$IndentTestCase.test_roundtrip_spacescCs&|jD]}|tt|d|qdS)Nz rr5rrrtest_roundtrip_tabsas z"IndentTestCase.test_roundtrip_tabscCs&|jD]}|tt|d|qdS)Nz rr5rrrtest_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 [...]rzrrr5rrrrCszShortenTestCase.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&rr6rr;rCrrrrrrrs  r__main__)ZunittesttextwraprrrrrrZTestCaserr(rrrrrrr$mainrrrr s 4_E3z9