TextFormatterTests.cs 207 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223
  1. using System.Text;
  2. using UICatalog;
  3. using Xunit.Abstractions;
  4. // Alias Console to MockConsole so we don't accidentally use Console
  5. namespace Terminal.Gui.TextTests;
  6. public class TextFormatterTests
  7. {
  8. public TextFormatterTests (ITestOutputHelper output) { _output = output; }
  9. private readonly ITestOutputHelper _output;
  10. [Theory]
  11. [InlineData ("")]
  12. [InlineData (null)]
  13. [InlineData ("test")]
  14. public void ClipAndJustify_Invalid_Returns_Original (string text)
  15. {
  16. string expected = string.IsNullOrEmpty (text) ? text : "";
  17. Assert.Equal (expected, TextFormatter.ClipAndJustify (text, 0, Alignment.Start));
  18. Assert.Equal (expected, TextFormatter.ClipAndJustify (text, 0, Alignment.Start));
  19. Assert.Throws<ArgumentOutOfRangeException> (
  20. () =>
  21. TextFormatter.ClipAndJustify (text, -1, Alignment.Start)
  22. );
  23. }
  24. [Theory]
  25. [InlineData ("test", "", 0)]
  26. [InlineData ("test", "te", 2)]
  27. [InlineData ("test", "test", int.MaxValue)]
  28. [InlineData ("A sentence has words.", "A sentence has words.", 22)] // should fit
  29. [InlineData ("A sentence has words.", "A sentence has words.", 21)] // should fit
  30. [InlineData ("A sentence has words.", "A sentence has words.", int.MaxValue)] // should fit
  31. [InlineData ("A sentence has words.", "A sentence has words", 20)] // Should not fit
  32. [InlineData ("A sentence has words.", "A sentence", 10)] // Should not fit
  33. [InlineData ("A\tsentence\thas\twords.", "A sentence has words.", int.MaxValue)]
  34. [InlineData ("A\tsentence\thas\twords.", "A sentence", 10)]
  35. [InlineData ("line1\nline2\nline3long!", "line1\nline2\nline3long!", int.MaxValue)]
  36. [InlineData ("line1\nline2\nline3long!", "line1\nline", 10)]
  37. [InlineData (" ~  s  gui.cs   master ↑10", " ~  s  ", 10)] // Unicode
  38. [InlineData ("Ð ÑÐ", "Ð ÑÐ", 5)] // should fit
  39. [InlineData ("Ð ÑÐ", "Ð ÑÐ", 4)] // should fit
  40. [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit
  41. public void ClipAndJustify_Valid_Centered (string text, string justifiedText, int maxWidth)
  42. {
  43. var alignment = Alignment.Center;
  44. var textDirection = TextDirection.LeftRight_TopBottom;
  45. var tabWidth = 1;
  46. Assert.Equal (
  47. justifiedText,
  48. TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
  49. );
  50. int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth);
  51. Assert.Equal (
  52. justifiedText,
  53. TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
  54. );
  55. Assert.True (justifiedText.GetRuneCount () <= maxWidth);
  56. Assert.True (justifiedText.GetColumns () <= maxWidth);
  57. Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ());
  58. Assert.Equal (
  59. expectedClippedWidth,
  60. justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))
  61. );
  62. Assert.True (expectedClippedWidth <= maxWidth);
  63. Assert.Equal (
  64. StringExtensions.ToString (justifiedText.ToRunes () [..expectedClippedWidth]),
  65. justifiedText
  66. );
  67. }
  68. [Theory]
  69. [InlineData ("test", "", 0)]
  70. [InlineData ("test", "te", 2)]
  71. [InlineData ("test", "test", int.MaxValue)] // This doesn't throw because it only create a word with length 1
  72. [InlineData ("A sentence has words.", "A sentence has words.", 22)] // should fit
  73. [InlineData ("A sentence has words.", "A sentence has words.", 21)] // should fit
  74. [InlineData (
  75. "A sentence has words.",
  76. "A sentence has words.",
  77. 500
  78. )] // should fit
  79. [InlineData ("A sentence has words.", "A sentence has words", 20)] // Should not fit
  80. [InlineData ("A sentence has words.", "A sentence", 10)] // Should not fit
  81. // Now throw System.OutOfMemoryException. See https://stackoverflow.com/questions/20672920/maxcapacity-of-stringbuilder
  82. //[InlineData ("A\tsentence\thas\twords.", "A sentence has words.", int.MaxValue)]
  83. [InlineData ("A\tsentence\thas\twords.", "A sentence", 10)]
  84. [InlineData (
  85. "line1\nline2\nline3long!",
  86. "line1\nline2\nline3long!",
  87. int.MaxValue
  88. )] // This doesn't throw because it only create a line with length 1
  89. [InlineData ("line1\nline2\nline3long!", "line1\nline", 10)]
  90. [InlineData (" ~  s  gui.cs   master ↑10", " ~  s  ", 10)] // Unicode
  91. [InlineData ("Ð ÑÐ", "Ð ÑÐ", 5)] // should fit
  92. [InlineData ("Ð ÑÐ", "Ð ÑÐ", 4)] // should fit
  93. [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit
  94. public void ClipAndJustify_Valid_Justified (string text, string justifiedText, int maxWidth)
  95. {
  96. var alignment = Alignment.Fill;
  97. var textDirection = TextDirection.LeftRight_TopBottom;
  98. var tabWidth = 1;
  99. Assert.Equal (
  100. justifiedText,
  101. TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
  102. );
  103. int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth);
  104. Assert.Equal (
  105. justifiedText,
  106. TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
  107. );
  108. Assert.True (justifiedText.GetRuneCount () <= maxWidth);
  109. Assert.True (justifiedText.GetColumns () <= maxWidth);
  110. Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ());
  111. Assert.Equal (
  112. expectedClippedWidth,
  113. justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))
  114. );
  115. Assert.True (expectedClippedWidth <= maxWidth);
  116. Assert.Equal (
  117. StringExtensions.ToString (justifiedText.ToRunes () [..expectedClippedWidth]),
  118. justifiedText
  119. );
  120. // see Justify_ tests below
  121. }
  122. [Theory]
  123. [InlineData ("test", "", 0)]
  124. [InlineData ("test", "te", 2)]
  125. [InlineData ("test", "test", int.MaxValue)]
  126. [InlineData ("A sentence has words.", "A sentence has words.", 22)] // should fit
  127. [InlineData ("A sentence has words.", "A sentence has words.", 21)] // should fit
  128. [InlineData ("A sentence has words.", "A sentence has words.", int.MaxValue)] // should fit
  129. [InlineData ("A sentence has words.", "A sentence has words", 20)] // Should not fit
  130. [InlineData ("A sentence has words.", "A sentence", 10)] // Should not fit
  131. [InlineData ("A\tsentence\thas\twords.", "A sentence has words.", int.MaxValue)]
  132. [InlineData ("A\tsentence\thas\twords.", "A sentence", 10)]
  133. [InlineData ("line1\nline2\nline3long!", "line1\nline2\nline3long!", int.MaxValue)]
  134. [InlineData ("line1\nline2\nline3long!", "line1\nline", 10)]
  135. [InlineData (" ~  s  gui.cs   master ↑10", " ~  s  ", 10)] // Unicode
  136. [InlineData ("Ð ÑÐ", "Ð ÑÐ", 5)] // should fit
  137. [InlineData ("Ð ÑÐ", "Ð ÑÐ", 4)] // should fit
  138. [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit
  139. public void ClipAndJustify_Valid_Left (string text, string justifiedText, int maxWidth)
  140. {
  141. var alignment = Alignment.Start;
  142. var textDirection = TextDirection.LeftRight_BottomTop;
  143. var tabWidth = 1;
  144. Assert.Equal (
  145. justifiedText,
  146. TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
  147. );
  148. int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth);
  149. Assert.Equal (
  150. justifiedText,
  151. TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
  152. );
  153. Assert.True (justifiedText.GetRuneCount () <= maxWidth);
  154. Assert.True (justifiedText.GetColumns () <= maxWidth);
  155. Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ());
  156. Assert.Equal (
  157. expectedClippedWidth,
  158. justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))
  159. );
  160. Assert.True (expectedClippedWidth <= maxWidth);
  161. Assert.Equal (
  162. StringExtensions.ToString (justifiedText.ToRunes () [..expectedClippedWidth]),
  163. justifiedText
  164. );
  165. }
  166. [Theory]
  167. [InlineData ("test", "", 0)]
  168. [InlineData ("test", "te", 2)]
  169. [InlineData ("test", "test", int.MaxValue)]
  170. [InlineData ("A sentence has words.", "A sentence has words.", 22)] // should fit
  171. [InlineData ("A sentence has words.", "A sentence has words.", 21)] // should fit
  172. [InlineData ("A sentence has words.", "A sentence has words.", int.MaxValue)] // should fit
  173. [InlineData ("A sentence has words.", "A sentence has words", 20)] // Should not fit
  174. [InlineData ("A sentence has words.", "A sentence", 10)] // Should not fit
  175. [InlineData ("A\tsentence\thas\twords.", "A sentence has words.", int.MaxValue)]
  176. [InlineData ("A\tsentence\thas\twords.", "A sentence", 10)]
  177. [InlineData ("line1\nline2\nline3long!", "line1\nline2\nline3long!", int.MaxValue)]
  178. [InlineData ("line1\nline2\nline3long!", "line1\nline", 10)]
  179. [InlineData (" ~  s  gui.cs   master ↑10", " ~  s  ", 10)] // Unicode
  180. [InlineData ("Ð ÑÐ", "Ð ÑÐ", 5)] // should fit
  181. [InlineData ("Ð ÑÐ", "Ð ÑÐ", 4)] // should fit
  182. [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit
  183. public void ClipAndJustify_Valid_Right (string text, string justifiedText, int maxWidth)
  184. {
  185. var alignment = Alignment.End;
  186. var textDirection = TextDirection.LeftRight_BottomTop;
  187. var tabWidth = 1;
  188. Assert.Equal (
  189. justifiedText,
  190. TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
  191. );
  192. int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth);
  193. Assert.Equal (
  194. justifiedText,
  195. TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
  196. );
  197. Assert.True (justifiedText.GetRuneCount () <= maxWidth);
  198. Assert.True (justifiedText.GetColumns () <= maxWidth);
  199. Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ());
  200. Assert.Equal (
  201. expectedClippedWidth,
  202. justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))
  203. );
  204. Assert.True (expectedClippedWidth <= maxWidth);
  205. Assert.Equal (
  206. StringExtensions.ToString (justifiedText.ToRunes () [..expectedClippedWidth]),
  207. justifiedText
  208. );
  209. }
  210. public static IEnumerable<object []> CMGlyphs =>
  211. new List<object []> { new object [] { $"{CM.Glyphs.LeftBracket} Say Hello 你 {CM.Glyphs.RightBracket}", 16, 15 } };
  212. [SetupFakeDriver]
  213. [Theory]
  214. [InlineData ("A", 0, "")]
  215. [InlineData ("A", 1, "A")]
  216. [InlineData ("A", 2, "A")]
  217. [InlineData ("A", 3, " A")]
  218. [InlineData ("AB", 1, "A")]
  219. [InlineData ("AB", 2, "AB")]
  220. [InlineData ("ABC", 3, "ABC")]
  221. [InlineData ("ABC", 4, "ABC")]
  222. [InlineData ("ABC", 5, " ABC")]
  223. [InlineData ("ABC", 6, " ABC")]
  224. [InlineData ("ABC", 9, " ABC")]
  225. public void Draw_Horizontal_Centered (string text, int width, string expectedText)
  226. {
  227. TextFormatter tf = new ()
  228. {
  229. Text = text,
  230. Alignment = Alignment.Center
  231. };
  232. tf.ConstrainToWidth = width;
  233. tf.ConstrainToHeight = 1;
  234. tf.Draw (new (0, 0, width, 1), Attribute.Default, Attribute.Default);
  235. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  236. }
  237. [SetupFakeDriver]
  238. [Theory]
  239. [InlineData ("A", 0, "")]
  240. [InlineData ("A", 1, "A")]
  241. [InlineData ("A", 2, "A")]
  242. [InlineData ("A B", 3, "A B")]
  243. [InlineData ("A B", 1, "A")]
  244. [InlineData ("A B", 2, "A")]
  245. [InlineData ("A B", 4, "A B")]
  246. [InlineData ("A B", 5, "A B")]
  247. [InlineData ("A B", 6, "A B")]
  248. [InlineData ("A B", 10, "A B")]
  249. [InlineData ("ABC ABC", 10, "ABC ABC")]
  250. public void Draw_Horizontal_Justified (string text, int width, string expectedText)
  251. {
  252. TextFormatter tf = new ()
  253. {
  254. Text = text,
  255. Alignment = Alignment.Fill
  256. };
  257. tf.ConstrainToWidth = width;
  258. tf.ConstrainToHeight = 1;
  259. tf.Draw (new (0, 0, width, 1), Attribute.Default, Attribute.Default);
  260. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  261. }
  262. [SetupFakeDriver]
  263. [Theory]
  264. [InlineData ("A", 0, "")]
  265. [InlineData ("A", 1, "A")]
  266. [InlineData ("A", 2, "A")]
  267. [InlineData ("AB", 1, "A")]
  268. [InlineData ("AB", 2, "AB")]
  269. [InlineData ("ABC", 3, "ABC")]
  270. [InlineData ("ABC", 4, "ABC")]
  271. [InlineData ("ABC", 6, "ABC")]
  272. public void Draw_Horizontal_Left (string text, int width, string expectedText)
  273. {
  274. TextFormatter tf = new ()
  275. {
  276. Text = text,
  277. Alignment = Alignment.Start
  278. };
  279. tf.ConstrainToWidth = width;
  280. tf.ConstrainToHeight = 1;
  281. tf.Draw (new (0, 0, width, 1), Attribute.Default, Attribute.Default);
  282. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  283. }
  284. [SetupFakeDriver]
  285. [Theory]
  286. [InlineData ("A", 0, "")]
  287. [InlineData ("A", 1, "A")]
  288. [InlineData ("A", 2, " A")]
  289. [InlineData ("AB", 1, "B")]
  290. [InlineData ("AB", 2, "AB")]
  291. [InlineData ("ABC", 3, "ABC")]
  292. [InlineData ("ABC", 4, " ABC")]
  293. [InlineData ("ABC", 6, " ABC")]
  294. public void Draw_Horizontal_Right (string text, int width, string expectedText)
  295. {
  296. TextFormatter tf = new ()
  297. {
  298. Text = text,
  299. Alignment = Alignment.End
  300. };
  301. tf.ConstrainToWidth = width;
  302. tf.ConstrainToHeight = 1;
  303. tf.Draw (new (Point.Empty, new (width, 1)), Attribute.Default, Attribute.Default);
  304. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  305. }
  306. [SetupFakeDriver]
  307. [Theory]
  308. [InlineData ("A", 1, 0, "")]
  309. [InlineData ("A", 0, 1, "")]
  310. [InlineData ("AB1 2", 2, 1, "2")]
  311. [InlineData ("AB12", 5, 1, "21BA")]
  312. [InlineData ("AB\n12", 5, 2, "21\nBA")]
  313. [InlineData ("ABC 123 456", 7, 2, "CBA \n654 321")]
  314. [InlineData ("こんにちは", 1, 1, "")]
  315. [InlineData ("こんにちは", 2, 1, "は")]
  316. [InlineData ("こんにちは", 5, 1, "はち")]
  317. [InlineData ("こんにちは", 10, 1, "はちにんこ")]
  318. [InlineData ("こんにちは\nAB\n12", 10, 3, "21 \nBA \nはちにんこ")]
  319. public void Draw_Horizontal_RightLeft_BottomTop (string text, int width, int height, string expectedText)
  320. {
  321. TextFormatter tf = new ()
  322. {
  323. Text = text,
  324. Direction = TextDirection.RightLeft_BottomTop
  325. };
  326. tf.ConstrainToWidth = width;
  327. tf.ConstrainToHeight = height;
  328. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  329. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  330. }
  331. [SetupFakeDriver]
  332. [Theory]
  333. [InlineData ("A", 1, 0, "")]
  334. [InlineData ("A", 0, 1, "")]
  335. [InlineData ("AB1 2", 2, 1, "2")]
  336. [InlineData ("AB12", 5, 1, "21BA")]
  337. [InlineData ("AB\n12", 5, 2, "BA\n21")]
  338. [InlineData ("ABC 123 456", 7, 2, "654 321\nCBA ")]
  339. [InlineData ("こんにちは", 1, 1, "")]
  340. [InlineData ("こんにちは", 2, 1, "は")]
  341. [InlineData ("こんにちは", 5, 1, "はち")]
  342. [InlineData ("こんにちは", 10, 1, "はちにんこ")]
  343. [InlineData ("こんにちは\nAB\n12", 10, 3, "はちにんこ\nBA \n21 ")]
  344. public void Draw_Horizontal_RightLeft_TopBottom (string text, int width, int height, string expectedText)
  345. {
  346. TextFormatter tf = new ()
  347. {
  348. Text = text,
  349. Direction = TextDirection.RightLeft_TopBottom
  350. };
  351. tf.ConstrainToWidth = width;
  352. tf.ConstrainToHeight = height;
  353. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  354. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  355. }
  356. [SetupFakeDriver]
  357. [Theory]
  358. // Horizontal with Alignment.Start
  359. // LeftRight_TopBottom
  360. [InlineData (
  361. "0 2 4",
  362. Alignment.Start,
  363. Alignment.Start,
  364. TextDirection.LeftRight_TopBottom,
  365. @"
  366. 0 2 4**
  367. *******
  368. *******
  369. *******
  370. *******
  371. *******
  372. *******")]
  373. [InlineData (
  374. "0 2 4",
  375. Alignment.End,
  376. Alignment.Start,
  377. TextDirection.LeftRight_TopBottom,
  378. @"
  379. **0 2 4
  380. *******
  381. *******
  382. *******
  383. *******
  384. *******
  385. *******")]
  386. [InlineData (
  387. "0 2 4",
  388. Alignment.Center,
  389. Alignment.Start,
  390. TextDirection.LeftRight_TopBottom,
  391. @"
  392. *0 2 4*
  393. *******
  394. *******
  395. *******
  396. *******
  397. *******
  398. *******")]
  399. [InlineData (
  400. "0 2 4",
  401. Alignment.Fill,
  402. Alignment.Start,
  403. TextDirection.LeftRight_TopBottom,
  404. @"
  405. 0 2 4
  406. *******
  407. *******
  408. *******
  409. *******
  410. *******
  411. *******")]
  412. [InlineData (
  413. "0 你 4",
  414. Alignment.Start,
  415. Alignment.Start,
  416. TextDirection.LeftRight_TopBottom,
  417. @"
  418. 0 你 4*
  419. *******
  420. *******
  421. *******
  422. *******
  423. *******
  424. *******")]
  425. [InlineData (
  426. "0 你 4",
  427. Alignment.End,
  428. Alignment.Start,
  429. TextDirection.LeftRight_TopBottom,
  430. @"
  431. *0 你 4
  432. *******
  433. *******
  434. *******
  435. *******
  436. *******
  437. *******")]
  438. [InlineData (
  439. "0 你 4",
  440. Alignment.Center,
  441. Alignment.Start,
  442. TextDirection.LeftRight_TopBottom,
  443. @"
  444. 0 你 4*
  445. *******
  446. *******
  447. *******
  448. *******
  449. *******
  450. *******")]
  451. [InlineData (
  452. "0 你 4",
  453. Alignment.Fill,
  454. Alignment.Start,
  455. TextDirection.LeftRight_TopBottom,
  456. @"
  457. 0 你 4
  458. *******
  459. *******
  460. *******
  461. *******
  462. *******
  463. *******")]
  464. // LeftRight_BottomTop
  465. [InlineData (
  466. "0 2 4",
  467. Alignment.Start,
  468. Alignment.Start,
  469. TextDirection.LeftRight_BottomTop,
  470. @"
  471. 0 2 4**
  472. *******
  473. *******
  474. *******
  475. *******
  476. *******
  477. *******")]
  478. [InlineData (
  479. "0 2 4",
  480. Alignment.End,
  481. Alignment.Start,
  482. TextDirection.LeftRight_BottomTop,
  483. @"
  484. **0 2 4
  485. *******
  486. *******
  487. *******
  488. *******
  489. *******
  490. *******")]
  491. [InlineData (
  492. "0 2 4",
  493. Alignment.Center,
  494. Alignment.Start,
  495. TextDirection.LeftRight_BottomTop,
  496. @"
  497. *0 2 4*
  498. *******
  499. *******
  500. *******
  501. *******
  502. *******
  503. *******")]
  504. [InlineData (
  505. "0 2 4",
  506. Alignment.Fill,
  507. Alignment.Start,
  508. TextDirection.LeftRight_BottomTop,
  509. @"
  510. 0 2 4
  511. *******
  512. *******
  513. *******
  514. *******
  515. *******
  516. *******")]
  517. [InlineData (
  518. "0 你 4",
  519. Alignment.Start,
  520. Alignment.Start,
  521. TextDirection.LeftRight_BottomTop,
  522. @"
  523. 0 你 4*
  524. *******
  525. *******
  526. *******
  527. *******
  528. *******
  529. *******")]
  530. [InlineData (
  531. "0 你 4",
  532. Alignment.End,
  533. Alignment.Start,
  534. TextDirection.LeftRight_BottomTop,
  535. @"
  536. *0 你 4
  537. *******
  538. *******
  539. *******
  540. *******
  541. *******
  542. *******")]
  543. [InlineData (
  544. "0 你 4",
  545. Alignment.Center,
  546. Alignment.Start,
  547. TextDirection.LeftRight_BottomTop,
  548. @"
  549. 0 你 4*
  550. *******
  551. *******
  552. *******
  553. *******
  554. *******
  555. *******")]
  556. [InlineData (
  557. "0 你 4",
  558. Alignment.Fill,
  559. Alignment.Start,
  560. TextDirection.LeftRight_BottomTop,
  561. @"
  562. 0 你 4
  563. *******
  564. *******
  565. *******
  566. *******
  567. *******
  568. *******")]
  569. // RightLeft_TopBottom
  570. [InlineData (
  571. "0 2 4",
  572. Alignment.Start,
  573. Alignment.Start,
  574. TextDirection.RightLeft_TopBottom,
  575. @"
  576. 4 2 0**
  577. *******
  578. *******
  579. *******
  580. *******
  581. *******
  582. *******")]
  583. [InlineData (
  584. "0 2 4",
  585. Alignment.End,
  586. Alignment.Start,
  587. TextDirection.RightLeft_TopBottom,
  588. @"
  589. **4 2 0
  590. *******
  591. *******
  592. *******
  593. *******
  594. *******
  595. *******")]
  596. [InlineData (
  597. "0 2 4",
  598. Alignment.Center,
  599. Alignment.Start,
  600. TextDirection.RightLeft_TopBottom,
  601. @"
  602. *4 2 0*
  603. *******
  604. *******
  605. *******
  606. *******
  607. *******
  608. *******")]
  609. [InlineData (
  610. "0 2 4",
  611. Alignment.Fill,
  612. Alignment.Start,
  613. TextDirection.RightLeft_TopBottom,
  614. @"
  615. 4 2 0
  616. *******
  617. *******
  618. *******
  619. *******
  620. *******
  621. *******")]
  622. [InlineData (
  623. "0 你 4",
  624. Alignment.Start,
  625. Alignment.Start,
  626. TextDirection.RightLeft_TopBottom,
  627. @"
  628. 4 你 0*
  629. *******
  630. *******
  631. *******
  632. *******
  633. *******
  634. *******")]
  635. [InlineData (
  636. "0 你 4",
  637. Alignment.End,
  638. Alignment.Start,
  639. TextDirection.RightLeft_TopBottom,
  640. @"
  641. *4 你 0
  642. *******
  643. *******
  644. *******
  645. *******
  646. *******
  647. *******")]
  648. [InlineData (
  649. "0 你 4",
  650. Alignment.Center,
  651. Alignment.Start,
  652. TextDirection.RightLeft_TopBottom,
  653. @"
  654. 4 你 0*
  655. *******
  656. *******
  657. *******
  658. *******
  659. *******
  660. *******")]
  661. [InlineData (
  662. "0 你 4",
  663. Alignment.Fill,
  664. Alignment.Start,
  665. TextDirection.RightLeft_TopBottom,
  666. @"
  667. 4 你 0
  668. *******
  669. *******
  670. *******
  671. *******
  672. *******
  673. *******")]
  674. // RightLeft_BottomTop
  675. [InlineData (
  676. "0 2 4",
  677. Alignment.Start,
  678. Alignment.Start,
  679. TextDirection.RightLeft_BottomTop,
  680. @"
  681. 4 2 0**
  682. *******
  683. *******
  684. *******
  685. *******
  686. *******
  687. *******")]
  688. [InlineData (
  689. "0 2 4",
  690. Alignment.End,
  691. Alignment.Start,
  692. TextDirection.RightLeft_BottomTop,
  693. @"
  694. **4 2 0
  695. *******
  696. *******
  697. *******
  698. *******
  699. *******
  700. *******")]
  701. [InlineData (
  702. "0 2 4",
  703. Alignment.Center,
  704. Alignment.Start,
  705. TextDirection.RightLeft_BottomTop,
  706. @"
  707. *4 2 0*
  708. *******
  709. *******
  710. *******
  711. *******
  712. *******
  713. *******")]
  714. [InlineData (
  715. "0 2 4",
  716. Alignment.Fill,
  717. Alignment.Start,
  718. TextDirection.RightLeft_BottomTop,
  719. @"
  720. 4 2 0
  721. *******
  722. *******
  723. *******
  724. *******
  725. *******
  726. *******")]
  727. [InlineData (
  728. "0 你 4",
  729. Alignment.Start,
  730. Alignment.Start,
  731. TextDirection.RightLeft_BottomTop,
  732. @"
  733. 4 你 0*
  734. *******
  735. *******
  736. *******
  737. *******
  738. *******
  739. *******")]
  740. [InlineData (
  741. "0 你 4",
  742. Alignment.End,
  743. Alignment.Start,
  744. TextDirection.RightLeft_BottomTop,
  745. @"
  746. *4 你 0
  747. *******
  748. *******
  749. *******
  750. *******
  751. *******
  752. *******")]
  753. [InlineData (
  754. "0 你 4",
  755. Alignment.Center,
  756. Alignment.Start,
  757. TextDirection.RightLeft_BottomTop,
  758. @"
  759. 4 你 0*
  760. *******
  761. *******
  762. *******
  763. *******
  764. *******
  765. *******")]
  766. [InlineData (
  767. "0 你 4",
  768. Alignment.Fill,
  769. Alignment.Start,
  770. TextDirection.RightLeft_BottomTop,
  771. @"
  772. 4 你 0
  773. *******
  774. *******
  775. *******
  776. *******
  777. *******
  778. *******")]
  779. // Horizontal with Alignment.End
  780. // LeftRight_TopBottom
  781. [InlineData (
  782. "0 2 4",
  783. Alignment.Start,
  784. Alignment.End,
  785. TextDirection.LeftRight_TopBottom,
  786. @"
  787. *******
  788. *******
  789. *******
  790. *******
  791. *******
  792. *******
  793. 0 2 4**")]
  794. [InlineData (
  795. "0 2 4",
  796. Alignment.End,
  797. Alignment.End,
  798. TextDirection.LeftRight_TopBottom,
  799. @"
  800. *******
  801. *******
  802. *******
  803. *******
  804. *******
  805. *******
  806. **0 2 4")]
  807. [InlineData (
  808. "0 2 4",
  809. Alignment.Center,
  810. Alignment.End,
  811. TextDirection.LeftRight_TopBottom,
  812. @"
  813. *******
  814. *******
  815. *******
  816. *******
  817. *******
  818. *******
  819. *0 2 4*")]
  820. [InlineData (
  821. "0 2 4",
  822. Alignment.Fill,
  823. Alignment.End,
  824. TextDirection.LeftRight_TopBottom,
  825. @"
  826. *******
  827. *******
  828. *******
  829. *******
  830. *******
  831. *******
  832. 0 2 4")]
  833. [InlineData (
  834. "0 你 4",
  835. Alignment.Start,
  836. Alignment.End,
  837. TextDirection.LeftRight_TopBottom,
  838. @"
  839. *******
  840. *******
  841. *******
  842. *******
  843. *******
  844. *******
  845. 0 你 4*")]
  846. [InlineData (
  847. "0 你 4",
  848. Alignment.End,
  849. Alignment.End,
  850. TextDirection.LeftRight_TopBottom,
  851. @"
  852. *******
  853. *******
  854. *******
  855. *******
  856. *******
  857. *******
  858. *0 你 4")]
  859. [InlineData (
  860. "0 你 4",
  861. Alignment.Center,
  862. Alignment.End,
  863. TextDirection.LeftRight_TopBottom,
  864. @"
  865. *******
  866. *******
  867. *******
  868. *******
  869. *******
  870. *******
  871. 0 你 4*")]
  872. [InlineData (
  873. "0 你 4",
  874. Alignment.Fill,
  875. Alignment.End,
  876. TextDirection.LeftRight_TopBottom,
  877. @"
  878. *******
  879. *******
  880. *******
  881. *******
  882. *******
  883. *******
  884. 0 你 4")]
  885. // LeftRight_BottomTop
  886. [InlineData (
  887. "0 2 4",
  888. Alignment.Start,
  889. Alignment.End,
  890. TextDirection.LeftRight_BottomTop,
  891. @"
  892. *******
  893. *******
  894. *******
  895. *******
  896. *******
  897. *******
  898. 0 2 4**")]
  899. [InlineData (
  900. "0 2 4",
  901. Alignment.End,
  902. Alignment.End,
  903. TextDirection.LeftRight_BottomTop,
  904. @"
  905. *******
  906. *******
  907. *******
  908. *******
  909. *******
  910. *******
  911. **0 2 4")]
  912. [InlineData (
  913. "0 2 4",
  914. Alignment.Center,
  915. Alignment.End,
  916. TextDirection.LeftRight_BottomTop,
  917. @"
  918. *******
  919. *******
  920. *******
  921. *******
  922. *******
  923. *******
  924. *0 2 4*")]
  925. [InlineData (
  926. "0 2 4",
  927. Alignment.Fill,
  928. Alignment.End,
  929. TextDirection.LeftRight_BottomTop,
  930. @"
  931. *******
  932. *******
  933. *******
  934. *******
  935. *******
  936. *******
  937. 0 2 4")]
  938. [InlineData (
  939. "0 你 4",
  940. Alignment.Start,
  941. Alignment.End,
  942. TextDirection.LeftRight_BottomTop,
  943. @"
  944. *******
  945. *******
  946. *******
  947. *******
  948. *******
  949. *******
  950. 0 你 4*")]
  951. [InlineData (
  952. "0 你 4",
  953. Alignment.End,
  954. Alignment.End,
  955. TextDirection.LeftRight_BottomTop,
  956. @"
  957. *******
  958. *******
  959. *******
  960. *******
  961. *******
  962. *******
  963. *0 你 4")]
  964. [InlineData (
  965. "0 你 4",
  966. Alignment.Center,
  967. Alignment.End,
  968. TextDirection.LeftRight_BottomTop,
  969. @"
  970. *******
  971. *******
  972. *******
  973. *******
  974. *******
  975. *******
  976. 0 你 4*")]
  977. [InlineData (
  978. "0 你 4",
  979. Alignment.Fill,
  980. Alignment.End,
  981. TextDirection.LeftRight_BottomTop,
  982. @"
  983. *******
  984. *******
  985. *******
  986. *******
  987. *******
  988. *******
  989. 0 你 4")]
  990. // RightLeft_TopBottom
  991. [InlineData (
  992. "0 2 4",
  993. Alignment.Start,
  994. Alignment.End,
  995. TextDirection.RightLeft_TopBottom,
  996. @"
  997. *******
  998. *******
  999. *******
  1000. *******
  1001. *******
  1002. *******
  1003. 4 2 0**")]
  1004. [InlineData (
  1005. "0 2 4",
  1006. Alignment.End,
  1007. Alignment.End,
  1008. TextDirection.RightLeft_TopBottom,
  1009. @"
  1010. *******
  1011. *******
  1012. *******
  1013. *******
  1014. *******
  1015. *******
  1016. **4 2 0")]
  1017. [InlineData (
  1018. "0 2 4",
  1019. Alignment.Center,
  1020. Alignment.End,
  1021. TextDirection.RightLeft_TopBottom,
  1022. @"
  1023. *******
  1024. *******
  1025. *******
  1026. *******
  1027. *******
  1028. *******
  1029. *4 2 0*")]
  1030. [InlineData (
  1031. "0 2 4",
  1032. Alignment.Fill,
  1033. Alignment.End,
  1034. TextDirection.RightLeft_TopBottom,
  1035. @"
  1036. *******
  1037. *******
  1038. *******
  1039. *******
  1040. *******
  1041. *******
  1042. 4 2 0")]
  1043. [InlineData (
  1044. "0 你 4",
  1045. Alignment.Start,
  1046. Alignment.End,
  1047. TextDirection.RightLeft_TopBottom,
  1048. @"
  1049. *******
  1050. *******
  1051. *******
  1052. *******
  1053. *******
  1054. *******
  1055. 4 你 0*")]
  1056. [InlineData (
  1057. "0 你 4",
  1058. Alignment.End,
  1059. Alignment.End,
  1060. TextDirection.RightLeft_TopBottom,
  1061. @"
  1062. *******
  1063. *******
  1064. *******
  1065. *******
  1066. *******
  1067. *******
  1068. *4 你 0")]
  1069. [InlineData (
  1070. "0 你 4",
  1071. Alignment.Center,
  1072. Alignment.End,
  1073. TextDirection.RightLeft_TopBottom,
  1074. @"
  1075. *******
  1076. *******
  1077. *******
  1078. *******
  1079. *******
  1080. *******
  1081. 4 你 0*")]
  1082. [InlineData (
  1083. "0 你 4",
  1084. Alignment.Fill,
  1085. Alignment.End,
  1086. TextDirection.RightLeft_TopBottom,
  1087. @"
  1088. *******
  1089. *******
  1090. *******
  1091. *******
  1092. *******
  1093. *******
  1094. 4 你 0")]
  1095. // RightLeft_BottomTop
  1096. [InlineData (
  1097. "0 2 4",
  1098. Alignment.Start,
  1099. Alignment.End,
  1100. TextDirection.RightLeft_BottomTop,
  1101. @"
  1102. *******
  1103. *******
  1104. *******
  1105. *******
  1106. *******
  1107. *******
  1108. 4 2 0**")]
  1109. [InlineData (
  1110. "0 2 4",
  1111. Alignment.End,
  1112. Alignment.End,
  1113. TextDirection.RightLeft_BottomTop,
  1114. @"
  1115. *******
  1116. *******
  1117. *******
  1118. *******
  1119. *******
  1120. *******
  1121. **4 2 0")]
  1122. [InlineData (
  1123. "0 2 4",
  1124. Alignment.Center,
  1125. Alignment.End,
  1126. TextDirection.RightLeft_BottomTop,
  1127. @"
  1128. *******
  1129. *******
  1130. *******
  1131. *******
  1132. *******
  1133. *******
  1134. *4 2 0*")]
  1135. [InlineData (
  1136. "0 2 4",
  1137. Alignment.Fill,
  1138. Alignment.End,
  1139. TextDirection.RightLeft_BottomTop,
  1140. @"
  1141. *******
  1142. *******
  1143. *******
  1144. *******
  1145. *******
  1146. *******
  1147. 4 2 0")]
  1148. [InlineData (
  1149. "0 你 4",
  1150. Alignment.Start,
  1151. Alignment.End,
  1152. TextDirection.RightLeft_BottomTop,
  1153. @"
  1154. *******
  1155. *******
  1156. *******
  1157. *******
  1158. *******
  1159. *******
  1160. 4 你 0*")]
  1161. [InlineData (
  1162. "0 你 4",
  1163. Alignment.End,
  1164. Alignment.End,
  1165. TextDirection.RightLeft_BottomTop,
  1166. @"
  1167. *******
  1168. *******
  1169. *******
  1170. *******
  1171. *******
  1172. *******
  1173. *4 你 0")]
  1174. [InlineData (
  1175. "0 你 4",
  1176. Alignment.Center,
  1177. Alignment.End,
  1178. TextDirection.RightLeft_BottomTop,
  1179. @"
  1180. *******
  1181. *******
  1182. *******
  1183. *******
  1184. *******
  1185. *******
  1186. 4 你 0*")]
  1187. [InlineData (
  1188. "0 你 4",
  1189. Alignment.Fill,
  1190. Alignment.End,
  1191. TextDirection.RightLeft_BottomTop,
  1192. @"
  1193. *******
  1194. *******
  1195. *******
  1196. *******
  1197. *******
  1198. *******
  1199. 4 你 0")]
  1200. // Horizontal with alignment.Centered
  1201. // LeftRight_TopBottom
  1202. [InlineData (
  1203. "0 2 4",
  1204. Alignment.Start,
  1205. Alignment.Center,
  1206. TextDirection.LeftRight_TopBottom,
  1207. @"
  1208. *******
  1209. *******
  1210. *******
  1211. 0 2 4**
  1212. *******
  1213. *******
  1214. *******")]
  1215. [InlineData (
  1216. "0 2 4",
  1217. Alignment.End,
  1218. Alignment.Center,
  1219. TextDirection.LeftRight_TopBottom,
  1220. @"
  1221. *******
  1222. *******
  1223. *******
  1224. **0 2 4
  1225. *******
  1226. *******
  1227. *******")]
  1228. [InlineData (
  1229. "0 2 4",
  1230. Alignment.Center,
  1231. Alignment.Center,
  1232. TextDirection.LeftRight_TopBottom,
  1233. @"
  1234. *******
  1235. *******
  1236. *******
  1237. *0 2 4*
  1238. *******
  1239. *******
  1240. *******")]
  1241. [InlineData (
  1242. "0 2 4",
  1243. Alignment.Fill,
  1244. Alignment.Center,
  1245. TextDirection.LeftRight_TopBottom,
  1246. @"
  1247. *******
  1248. *******
  1249. *******
  1250. 0 2 4
  1251. *******
  1252. *******
  1253. *******")]
  1254. [InlineData (
  1255. "0 你 4",
  1256. Alignment.Start,
  1257. Alignment.Center,
  1258. TextDirection.LeftRight_TopBottom,
  1259. @"
  1260. *******
  1261. *******
  1262. *******
  1263. 0 你 4*
  1264. *******
  1265. *******
  1266. *******")]
  1267. [InlineData (
  1268. "0 你 4",
  1269. Alignment.End,
  1270. Alignment.Center,
  1271. TextDirection.LeftRight_TopBottom,
  1272. @"
  1273. *******
  1274. *******
  1275. *******
  1276. *0 你 4
  1277. *******
  1278. *******
  1279. *******")]
  1280. [InlineData (
  1281. "0 你 4",
  1282. Alignment.Center,
  1283. Alignment.Center,
  1284. TextDirection.LeftRight_TopBottom,
  1285. @"
  1286. *******
  1287. *******
  1288. *******
  1289. 0 你 4*
  1290. *******
  1291. *******
  1292. *******")]
  1293. [InlineData (
  1294. "0 你 4",
  1295. Alignment.Fill,
  1296. Alignment.Center,
  1297. TextDirection.LeftRight_TopBottom,
  1298. @"
  1299. *******
  1300. *******
  1301. *******
  1302. 0 你 4
  1303. *******
  1304. *******
  1305. *******")]
  1306. // LeftRight_BottomTop
  1307. [InlineData (
  1308. "0 2 4",
  1309. Alignment.Start,
  1310. Alignment.Center,
  1311. TextDirection.LeftRight_BottomTop,
  1312. @"
  1313. *******
  1314. *******
  1315. *******
  1316. 0 2 4**
  1317. *******
  1318. *******
  1319. *******")]
  1320. [InlineData (
  1321. "0 2 4",
  1322. Alignment.End,
  1323. Alignment.Center,
  1324. TextDirection.LeftRight_BottomTop,
  1325. @"
  1326. *******
  1327. *******
  1328. *******
  1329. **0 2 4
  1330. *******
  1331. *******
  1332. *******")]
  1333. [InlineData (
  1334. "0 2 4",
  1335. Alignment.Center,
  1336. Alignment.Center,
  1337. TextDirection.LeftRight_BottomTop,
  1338. @"
  1339. *******
  1340. *******
  1341. *******
  1342. *0 2 4*
  1343. *******
  1344. *******
  1345. *******")]
  1346. [InlineData (
  1347. "0 2 4",
  1348. Alignment.Fill,
  1349. Alignment.Center,
  1350. TextDirection.LeftRight_BottomTop,
  1351. @"
  1352. *******
  1353. *******
  1354. *******
  1355. 0 2 4
  1356. *******
  1357. *******
  1358. *******")]
  1359. [InlineData (
  1360. "0 你 4",
  1361. Alignment.Start,
  1362. Alignment.Center,
  1363. TextDirection.LeftRight_BottomTop,
  1364. @"
  1365. *******
  1366. *******
  1367. *******
  1368. 0 你 4*
  1369. *******
  1370. *******
  1371. *******")]
  1372. [InlineData (
  1373. "0 你 4",
  1374. Alignment.End,
  1375. Alignment.Center,
  1376. TextDirection.LeftRight_BottomTop,
  1377. @"
  1378. *******
  1379. *******
  1380. *******
  1381. *0 你 4
  1382. *******
  1383. *******
  1384. *******")]
  1385. [InlineData (
  1386. "0 你 4",
  1387. Alignment.Center,
  1388. Alignment.Center,
  1389. TextDirection.LeftRight_BottomTop,
  1390. @"
  1391. *******
  1392. *******
  1393. *******
  1394. 0 你 4*
  1395. *******
  1396. *******
  1397. *******")]
  1398. [InlineData (
  1399. "0 你 4",
  1400. Alignment.Fill,
  1401. Alignment.Center,
  1402. TextDirection.LeftRight_BottomTop,
  1403. @"
  1404. *******
  1405. *******
  1406. *******
  1407. 0 你 4
  1408. *******
  1409. *******
  1410. *******")]
  1411. // RightLeft_TopBottom
  1412. [InlineData (
  1413. "0 2 4",
  1414. Alignment.Start,
  1415. Alignment.Center,
  1416. TextDirection.RightLeft_TopBottom,
  1417. @"
  1418. *******
  1419. *******
  1420. *******
  1421. 4 2 0**
  1422. *******
  1423. *******
  1424. *******")]
  1425. [InlineData (
  1426. "0 2 4",
  1427. Alignment.End,
  1428. Alignment.Center,
  1429. TextDirection.RightLeft_TopBottom,
  1430. @"
  1431. *******
  1432. *******
  1433. *******
  1434. **4 2 0
  1435. *******
  1436. *******
  1437. *******")]
  1438. [InlineData (
  1439. "0 2 4",
  1440. Alignment.Center,
  1441. Alignment.Center,
  1442. TextDirection.RightLeft_TopBottom,
  1443. @"
  1444. *******
  1445. *******
  1446. *******
  1447. *4 2 0*
  1448. *******
  1449. *******
  1450. *******")]
  1451. [InlineData (
  1452. "0 2 4",
  1453. Alignment.Fill,
  1454. Alignment.Center,
  1455. TextDirection.RightLeft_TopBottom,
  1456. @"
  1457. *******
  1458. *******
  1459. *******
  1460. 4 2 0
  1461. *******
  1462. *******
  1463. *******")]
  1464. [InlineData (
  1465. "0 你 4",
  1466. Alignment.Start,
  1467. Alignment.Center,
  1468. TextDirection.RightLeft_TopBottom,
  1469. @"
  1470. *******
  1471. *******
  1472. *******
  1473. 4 你 0*
  1474. *******
  1475. *******
  1476. *******")]
  1477. [InlineData (
  1478. "0 你 4",
  1479. Alignment.End,
  1480. Alignment.Center,
  1481. TextDirection.RightLeft_TopBottom,
  1482. @"
  1483. *******
  1484. *******
  1485. *******
  1486. *4 你 0
  1487. *******
  1488. *******
  1489. *******")]
  1490. [InlineData (
  1491. "0 你 4",
  1492. Alignment.Center,
  1493. Alignment.Center,
  1494. TextDirection.RightLeft_TopBottom,
  1495. @"
  1496. *******
  1497. *******
  1498. *******
  1499. 4 你 0*
  1500. *******
  1501. *******
  1502. *******")]
  1503. [InlineData (
  1504. "0 你 4",
  1505. Alignment.Fill,
  1506. Alignment.Center,
  1507. TextDirection.RightLeft_TopBottom,
  1508. @"
  1509. *******
  1510. *******
  1511. *******
  1512. 4 你 0
  1513. *******
  1514. *******
  1515. *******")]
  1516. // RightLeft_BottomTop
  1517. [InlineData (
  1518. "0 2 4",
  1519. Alignment.Start,
  1520. Alignment.Center,
  1521. TextDirection.RightLeft_BottomTop,
  1522. @"
  1523. *******
  1524. *******
  1525. *******
  1526. 4 2 0**
  1527. *******
  1528. *******
  1529. *******")]
  1530. [InlineData (
  1531. "0 2 4",
  1532. Alignment.End,
  1533. Alignment.Center,
  1534. TextDirection.RightLeft_BottomTop,
  1535. @"
  1536. *******
  1537. *******
  1538. *******
  1539. **4 2 0
  1540. *******
  1541. *******
  1542. *******")]
  1543. [InlineData (
  1544. "0 2 4",
  1545. Alignment.Center,
  1546. Alignment.Center,
  1547. TextDirection.RightLeft_BottomTop,
  1548. @"
  1549. *******
  1550. *******
  1551. *******
  1552. *4 2 0*
  1553. *******
  1554. *******
  1555. *******")]
  1556. [InlineData (
  1557. "0 2 4",
  1558. Alignment.Fill,
  1559. Alignment.Center,
  1560. TextDirection.RightLeft_BottomTop,
  1561. @"
  1562. *******
  1563. *******
  1564. *******
  1565. 4 2 0
  1566. *******
  1567. *******
  1568. *******")]
  1569. [InlineData (
  1570. "0 你 4",
  1571. Alignment.Start,
  1572. Alignment.Center,
  1573. TextDirection.RightLeft_BottomTop,
  1574. @"
  1575. *******
  1576. *******
  1577. *******
  1578. 4 你 0*
  1579. *******
  1580. *******
  1581. *******")]
  1582. [InlineData (
  1583. "0 你 4",
  1584. Alignment.End,
  1585. Alignment.Center,
  1586. TextDirection.RightLeft_BottomTop,
  1587. @"
  1588. *******
  1589. *******
  1590. *******
  1591. *4 你 0
  1592. *******
  1593. *******
  1594. *******")]
  1595. [InlineData (
  1596. "0 你 4",
  1597. Alignment.Center,
  1598. Alignment.Center,
  1599. TextDirection.RightLeft_BottomTop,
  1600. @"
  1601. *******
  1602. *******
  1603. *******
  1604. 4 你 0*
  1605. *******
  1606. *******
  1607. *******")]
  1608. [InlineData (
  1609. "0 你 4",
  1610. Alignment.Fill,
  1611. Alignment.Center,
  1612. TextDirection.RightLeft_BottomTop,
  1613. @"
  1614. *******
  1615. *******
  1616. *******
  1617. 4 你 0
  1618. *******
  1619. *******
  1620. *******")]
  1621. // Horizontal with alignment.Justified
  1622. // LeftRight_TopBottom
  1623. [InlineData (
  1624. "0 2 4",
  1625. Alignment.Start,
  1626. Alignment.Fill,
  1627. TextDirection.LeftRight_TopBottom,
  1628. @"
  1629. 0 2 4**
  1630. *******
  1631. *******
  1632. *******
  1633. *******
  1634. *******
  1635. *******")]
  1636. [InlineData (
  1637. "0 2 4",
  1638. Alignment.End,
  1639. Alignment.Fill,
  1640. TextDirection.LeftRight_TopBottom,
  1641. @"
  1642. **0 2 4
  1643. *******
  1644. *******
  1645. *******
  1646. *******
  1647. *******
  1648. *******")]
  1649. [InlineData (
  1650. "0 2 4",
  1651. Alignment.Center,
  1652. Alignment.Fill,
  1653. TextDirection.LeftRight_TopBottom,
  1654. @"
  1655. *0 2 4*
  1656. *******
  1657. *******
  1658. *******
  1659. *******
  1660. *******
  1661. *******")]
  1662. [InlineData (
  1663. "0 2 4",
  1664. Alignment.Fill,
  1665. Alignment.Fill,
  1666. TextDirection.LeftRight_TopBottom,
  1667. @"
  1668. 0 2 4
  1669. *******
  1670. *******
  1671. *******
  1672. *******
  1673. *******
  1674. *******")]
  1675. [InlineData (
  1676. "0 你 4",
  1677. Alignment.Start,
  1678. Alignment.Fill,
  1679. TextDirection.LeftRight_TopBottom,
  1680. @"
  1681. 0 你 4*
  1682. *******
  1683. *******
  1684. *******
  1685. *******
  1686. *******
  1687. *******")]
  1688. [InlineData (
  1689. "0 你 4",
  1690. Alignment.End,
  1691. Alignment.Fill,
  1692. TextDirection.LeftRight_TopBottom,
  1693. @"
  1694. *0 你 4
  1695. *******
  1696. *******
  1697. *******
  1698. *******
  1699. *******
  1700. *******")]
  1701. [InlineData (
  1702. "0 你 4",
  1703. Alignment.Center,
  1704. Alignment.Fill,
  1705. TextDirection.LeftRight_TopBottom,
  1706. @"
  1707. 0 你 4*
  1708. *******
  1709. *******
  1710. *******
  1711. *******
  1712. *******
  1713. *******")]
  1714. [InlineData (
  1715. "0 你 4",
  1716. Alignment.Fill,
  1717. Alignment.Fill,
  1718. TextDirection.LeftRight_TopBottom,
  1719. @"
  1720. 0 你 4
  1721. *******
  1722. *******
  1723. *******
  1724. *******
  1725. *******
  1726. *******")]
  1727. // LeftRight_BottomTop
  1728. [InlineData (
  1729. "0 2 4",
  1730. Alignment.Start,
  1731. Alignment.Fill,
  1732. TextDirection.LeftRight_BottomTop,
  1733. @"
  1734. 0 2 4**
  1735. *******
  1736. *******
  1737. *******
  1738. *******
  1739. *******
  1740. *******")]
  1741. [InlineData (
  1742. "0 2 4",
  1743. Alignment.End,
  1744. Alignment.Fill,
  1745. TextDirection.LeftRight_BottomTop,
  1746. @"
  1747. **0 2 4
  1748. *******
  1749. *******
  1750. *******
  1751. *******
  1752. *******
  1753. *******")]
  1754. [InlineData (
  1755. "0 2 4",
  1756. Alignment.Center,
  1757. Alignment.Fill,
  1758. TextDirection.LeftRight_BottomTop,
  1759. @"
  1760. *0 2 4*
  1761. *******
  1762. *******
  1763. *******
  1764. *******
  1765. *******
  1766. *******")]
  1767. [InlineData (
  1768. "0 2 4",
  1769. Alignment.Fill,
  1770. Alignment.Fill,
  1771. TextDirection.LeftRight_BottomTop,
  1772. @"
  1773. 0 2 4
  1774. *******
  1775. *******
  1776. *******
  1777. *******
  1778. *******
  1779. *******")]
  1780. [InlineData (
  1781. "0 你 4",
  1782. Alignment.Start,
  1783. Alignment.Fill,
  1784. TextDirection.LeftRight_BottomTop,
  1785. @"
  1786. 0 你 4*
  1787. *******
  1788. *******
  1789. *******
  1790. *******
  1791. *******
  1792. *******")]
  1793. [InlineData (
  1794. "0 你 4",
  1795. Alignment.End,
  1796. Alignment.Fill,
  1797. TextDirection.LeftRight_BottomTop,
  1798. @"
  1799. *0 你 4
  1800. *******
  1801. *******
  1802. *******
  1803. *******
  1804. *******
  1805. *******")]
  1806. [InlineData (
  1807. "0 你 4",
  1808. Alignment.Center,
  1809. Alignment.Fill,
  1810. TextDirection.LeftRight_BottomTop,
  1811. @"
  1812. 0 你 4*
  1813. *******
  1814. *******
  1815. *******
  1816. *******
  1817. *******
  1818. *******")]
  1819. [InlineData (
  1820. "0 你 4",
  1821. Alignment.Fill,
  1822. Alignment.Fill,
  1823. TextDirection.LeftRight_BottomTop,
  1824. @"
  1825. 0 你 4
  1826. *******
  1827. *******
  1828. *******
  1829. *******
  1830. *******
  1831. *******")]
  1832. // RightLeft_TopBottom
  1833. [InlineData (
  1834. "0 2 4",
  1835. Alignment.Start,
  1836. Alignment.Fill,
  1837. TextDirection.RightLeft_TopBottom,
  1838. @"
  1839. 4 2 0**
  1840. *******
  1841. *******
  1842. *******
  1843. *******
  1844. *******
  1845. *******")]
  1846. [InlineData (
  1847. "0 2 4",
  1848. Alignment.End,
  1849. Alignment.Fill,
  1850. TextDirection.RightLeft_TopBottom,
  1851. @"
  1852. **4 2 0
  1853. *******
  1854. *******
  1855. *******
  1856. *******
  1857. *******
  1858. *******")]
  1859. [InlineData (
  1860. "0 2 4",
  1861. Alignment.Center,
  1862. Alignment.Fill,
  1863. TextDirection.RightLeft_TopBottom,
  1864. @"
  1865. *4 2 0*
  1866. *******
  1867. *******
  1868. *******
  1869. *******
  1870. *******
  1871. *******")]
  1872. [InlineData (
  1873. "0 2 4",
  1874. Alignment.Fill,
  1875. Alignment.Fill,
  1876. TextDirection.RightLeft_TopBottom,
  1877. @"
  1878. 4 2 0
  1879. *******
  1880. *******
  1881. *******
  1882. *******
  1883. *******
  1884. *******")]
  1885. [InlineData (
  1886. "0 你 4",
  1887. Alignment.Start,
  1888. Alignment.Fill,
  1889. TextDirection.RightLeft_TopBottom,
  1890. @"
  1891. 4 你 0*
  1892. *******
  1893. *******
  1894. *******
  1895. *******
  1896. *******
  1897. *******")]
  1898. [InlineData (
  1899. "0 你 4",
  1900. Alignment.End,
  1901. Alignment.Fill,
  1902. TextDirection.RightLeft_TopBottom,
  1903. @"
  1904. *4 你 0
  1905. *******
  1906. *******
  1907. *******
  1908. *******
  1909. *******
  1910. *******")]
  1911. [InlineData (
  1912. "0 你 4",
  1913. Alignment.Center,
  1914. Alignment.Fill,
  1915. TextDirection.RightLeft_TopBottom,
  1916. @"
  1917. 4 你 0*
  1918. *******
  1919. *******
  1920. *******
  1921. *******
  1922. *******
  1923. *******")]
  1924. [InlineData (
  1925. "0 你 4",
  1926. Alignment.Fill,
  1927. Alignment.Fill,
  1928. TextDirection.RightLeft_TopBottom,
  1929. @"
  1930. 4 你 0
  1931. *******
  1932. *******
  1933. *******
  1934. *******
  1935. *******
  1936. *******")]
  1937. // RightLeft_BottomTop
  1938. [InlineData (
  1939. "0 2 4",
  1940. Alignment.Start,
  1941. Alignment.Fill,
  1942. TextDirection.RightLeft_BottomTop,
  1943. @"
  1944. 4 2 0**
  1945. *******
  1946. *******
  1947. *******
  1948. *******
  1949. *******
  1950. *******")]
  1951. [InlineData (
  1952. "0 2 4",
  1953. Alignment.End,
  1954. Alignment.Fill,
  1955. TextDirection.RightLeft_BottomTop,
  1956. @"
  1957. **4 2 0
  1958. *******
  1959. *******
  1960. *******
  1961. *******
  1962. *******
  1963. *******")]
  1964. [InlineData (
  1965. "0 2 4",
  1966. Alignment.Center,
  1967. Alignment.Fill,
  1968. TextDirection.RightLeft_BottomTop,
  1969. @"
  1970. *4 2 0*
  1971. *******
  1972. *******
  1973. *******
  1974. *******
  1975. *******
  1976. *******")]
  1977. [InlineData (
  1978. "0 2 4",
  1979. Alignment.Fill,
  1980. Alignment.Fill,
  1981. TextDirection.RightLeft_BottomTop,
  1982. @"
  1983. 4 2 0
  1984. *******
  1985. *******
  1986. *******
  1987. *******
  1988. *******
  1989. *******")]
  1990. [InlineData (
  1991. "0 你 4",
  1992. Alignment.Start,
  1993. Alignment.Fill,
  1994. TextDirection.RightLeft_BottomTop,
  1995. @"
  1996. 4 你 0*
  1997. *******
  1998. *******
  1999. *******
  2000. *******
  2001. *******
  2002. *******")]
  2003. [InlineData (
  2004. "0 你 4",
  2005. Alignment.End,
  2006. Alignment.Fill,
  2007. TextDirection.RightLeft_BottomTop,
  2008. @"
  2009. *4 你 0
  2010. *******
  2011. *******
  2012. *******
  2013. *******
  2014. *******
  2015. *******")]
  2016. [InlineData (
  2017. "0 你 4",
  2018. Alignment.Center,
  2019. Alignment.Fill,
  2020. TextDirection.RightLeft_BottomTop,
  2021. @"
  2022. 4 你 0*
  2023. *******
  2024. *******
  2025. *******
  2026. *******
  2027. *******
  2028. *******")]
  2029. [InlineData (
  2030. "0 你 4",
  2031. Alignment.Fill,
  2032. Alignment.Fill,
  2033. TextDirection.RightLeft_BottomTop,
  2034. @"
  2035. 4 你 0
  2036. *******
  2037. *******
  2038. *******
  2039. *******
  2040. *******
  2041. *******")]
  2042. // Vertical with alignment.Left
  2043. // TopBottom_LeftRight
  2044. [InlineData (
  2045. "0 2 4",
  2046. Alignment.Start,
  2047. Alignment.Start,
  2048. TextDirection.TopBottom_LeftRight,
  2049. @"
  2050. 0******
  2051. ******
  2052. 2******
  2053. ******
  2054. 4******
  2055. *******
  2056. *******")]
  2057. [InlineData (
  2058. "0 2 4",
  2059. Alignment.Start,
  2060. Alignment.End,
  2061. TextDirection.TopBottom_LeftRight,
  2062. @"
  2063. *******
  2064. *******
  2065. 0******
  2066. ******
  2067. 2******
  2068. ******
  2069. 4******")]
  2070. [InlineData (
  2071. "0 2 4",
  2072. Alignment.Start,
  2073. Alignment.Center,
  2074. TextDirection.TopBottom_LeftRight,
  2075. @"
  2076. *******
  2077. 0******
  2078. ******
  2079. 2******
  2080. ******
  2081. 4******
  2082. *******")]
  2083. [InlineData (
  2084. "0 2 4",
  2085. Alignment.Start,
  2086. Alignment.Fill,
  2087. TextDirection.TopBottom_LeftRight,
  2088. @"
  2089. 0******
  2090. ******
  2091. ******
  2092. 2******
  2093. ******
  2094. ******
  2095. 4******")]
  2096. [InlineData (
  2097. "0 你 4",
  2098. Alignment.Start,
  2099. Alignment.Start,
  2100. TextDirection.TopBottom_LeftRight,
  2101. @"
  2102. 0******
  2103. ******
  2104. 你*****
  2105. ******
  2106. 4******
  2107. *******
  2108. *******")]
  2109. [InlineData (
  2110. "0 你 4",
  2111. Alignment.Start,
  2112. Alignment.End,
  2113. TextDirection.TopBottom_LeftRight,
  2114. @"
  2115. *******
  2116. *******
  2117. 0******
  2118. ******
  2119. 你*****
  2120. ******
  2121. 4******")]
  2122. [InlineData (
  2123. "0 你 4",
  2124. Alignment.Start,
  2125. Alignment.Center,
  2126. TextDirection.TopBottom_LeftRight,
  2127. @"
  2128. *******
  2129. 0******
  2130. ******
  2131. 你*****
  2132. ******
  2133. 4******
  2134. *******")]
  2135. [InlineData (
  2136. "0 你 4",
  2137. Alignment.Start,
  2138. Alignment.Fill,
  2139. TextDirection.TopBottom_LeftRight,
  2140. @"
  2141. 0******
  2142. ******
  2143. ******
  2144. 你*****
  2145. ******
  2146. ******
  2147. 4******")]
  2148. // TopBottom_RightLeft
  2149. [InlineData (
  2150. "0 2 4",
  2151. Alignment.Start,
  2152. Alignment.Start,
  2153. TextDirection.TopBottom_RightLeft,
  2154. @"
  2155. 0******
  2156. ******
  2157. 2******
  2158. ******
  2159. 4******
  2160. *******
  2161. *******")]
  2162. [InlineData (
  2163. "0 2 4",
  2164. Alignment.Start,
  2165. Alignment.End,
  2166. TextDirection.TopBottom_RightLeft,
  2167. @"
  2168. *******
  2169. *******
  2170. 0******
  2171. ******
  2172. 2******
  2173. ******
  2174. 4******")]
  2175. [InlineData (
  2176. "0 2 4",
  2177. Alignment.Start,
  2178. Alignment.Center,
  2179. TextDirection.TopBottom_RightLeft,
  2180. @"
  2181. *******
  2182. 0******
  2183. ******
  2184. 2******
  2185. ******
  2186. 4******
  2187. *******")]
  2188. [InlineData (
  2189. "0 2 4",
  2190. Alignment.Start,
  2191. Alignment.Fill,
  2192. TextDirection.TopBottom_RightLeft,
  2193. @"
  2194. 0******
  2195. ******
  2196. ******
  2197. 2******
  2198. ******
  2199. ******
  2200. 4******")]
  2201. [InlineData (
  2202. "0 你 4",
  2203. Alignment.Start,
  2204. Alignment.Start,
  2205. TextDirection.TopBottom_RightLeft,
  2206. @"
  2207. 0******
  2208. ******
  2209. 你*****
  2210. ******
  2211. 4******
  2212. *******
  2213. *******")]
  2214. [InlineData (
  2215. "0 你 4",
  2216. Alignment.Start,
  2217. Alignment.End,
  2218. TextDirection.TopBottom_RightLeft,
  2219. @"
  2220. *******
  2221. *******
  2222. 0******
  2223. ******
  2224. 你*****
  2225. ******
  2226. 4******")]
  2227. [InlineData (
  2228. "0 你 4",
  2229. Alignment.Start,
  2230. Alignment.Center,
  2231. TextDirection.TopBottom_RightLeft,
  2232. @"
  2233. *******
  2234. 0******
  2235. ******
  2236. 你*****
  2237. ******
  2238. 4******
  2239. *******")]
  2240. [InlineData (
  2241. "0 你 4",
  2242. Alignment.Start,
  2243. Alignment.Fill,
  2244. TextDirection.TopBottom_RightLeft,
  2245. @"
  2246. 0******
  2247. ******
  2248. ******
  2249. 你*****
  2250. ******
  2251. ******
  2252. 4******")]
  2253. // BottomTop_LeftRight
  2254. [InlineData (
  2255. "0 2 4",
  2256. Alignment.Start,
  2257. Alignment.Start,
  2258. TextDirection.BottomTop_LeftRight,
  2259. @"
  2260. 4******
  2261. ******
  2262. 2******
  2263. ******
  2264. 0******
  2265. *******
  2266. *******")]
  2267. [InlineData (
  2268. "0 2 4",
  2269. Alignment.Start,
  2270. Alignment.End,
  2271. TextDirection.BottomTop_LeftRight,
  2272. @"
  2273. *******
  2274. *******
  2275. 4******
  2276. ******
  2277. 2******
  2278. ******
  2279. 0******")]
  2280. [InlineData (
  2281. "0 2 4",
  2282. Alignment.Start,
  2283. Alignment.Center,
  2284. TextDirection.BottomTop_LeftRight,
  2285. @"
  2286. *******
  2287. 4******
  2288. ******
  2289. 2******
  2290. ******
  2291. 0******
  2292. *******")]
  2293. [InlineData (
  2294. "0 2 4",
  2295. Alignment.Start,
  2296. Alignment.Fill,
  2297. TextDirection.BottomTop_LeftRight,
  2298. @"
  2299. 4******
  2300. ******
  2301. ******
  2302. 2******
  2303. ******
  2304. ******
  2305. 0******")]
  2306. [InlineData (
  2307. "0 你 4",
  2308. Alignment.Start,
  2309. Alignment.Start,
  2310. TextDirection.BottomTop_LeftRight,
  2311. @"
  2312. 4******
  2313. ******
  2314. 你*****
  2315. ******
  2316. 0******
  2317. *******
  2318. *******")]
  2319. [InlineData (
  2320. "0 你 4",
  2321. Alignment.Start,
  2322. Alignment.End,
  2323. TextDirection.BottomTop_LeftRight,
  2324. @"
  2325. *******
  2326. *******
  2327. 4******
  2328. ******
  2329. 你*****
  2330. ******
  2331. 0******")]
  2332. [InlineData (
  2333. "0 你 4",
  2334. Alignment.Start,
  2335. Alignment.Center,
  2336. TextDirection.BottomTop_LeftRight,
  2337. @"
  2338. *******
  2339. 4******
  2340. ******
  2341. 你*****
  2342. ******
  2343. 0******
  2344. *******")]
  2345. [InlineData (
  2346. "0 你 4",
  2347. Alignment.Start,
  2348. Alignment.Fill,
  2349. TextDirection.BottomTop_LeftRight,
  2350. @"
  2351. 4******
  2352. ******
  2353. ******
  2354. 你*****
  2355. ******
  2356. ******
  2357. 0******")]
  2358. // BottomTop_RightLeft
  2359. [InlineData (
  2360. "0 2 4",
  2361. Alignment.Start,
  2362. Alignment.Start,
  2363. TextDirection.BottomTop_RightLeft,
  2364. @"
  2365. 4******
  2366. ******
  2367. 2******
  2368. ******
  2369. 0******
  2370. *******
  2371. *******")]
  2372. [InlineData (
  2373. "0 2 4",
  2374. Alignment.Start,
  2375. Alignment.End,
  2376. TextDirection.BottomTop_RightLeft,
  2377. @"
  2378. *******
  2379. *******
  2380. 4******
  2381. ******
  2382. 2******
  2383. ******
  2384. 0******")]
  2385. [InlineData (
  2386. "0 2 4",
  2387. Alignment.Start,
  2388. Alignment.Center,
  2389. TextDirection.BottomTop_RightLeft,
  2390. @"
  2391. *******
  2392. 4******
  2393. ******
  2394. 2******
  2395. ******
  2396. 0******
  2397. *******")]
  2398. [InlineData (
  2399. "0 2 4",
  2400. Alignment.Start,
  2401. Alignment.Fill,
  2402. TextDirection.BottomTop_RightLeft,
  2403. @"
  2404. 4******
  2405. ******
  2406. ******
  2407. 2******
  2408. ******
  2409. ******
  2410. 0******")]
  2411. [InlineData (
  2412. "0 你 4",
  2413. Alignment.Start,
  2414. Alignment.Start,
  2415. TextDirection.BottomTop_RightLeft,
  2416. @"
  2417. 4******
  2418. ******
  2419. 你*****
  2420. ******
  2421. 0******
  2422. *******
  2423. *******")]
  2424. [InlineData (
  2425. "0 你 4",
  2426. Alignment.Start,
  2427. Alignment.End,
  2428. TextDirection.BottomTop_RightLeft,
  2429. @"
  2430. *******
  2431. *******
  2432. 4******
  2433. ******
  2434. 你*****
  2435. ******
  2436. 0******")]
  2437. [InlineData (
  2438. "0 你 4",
  2439. Alignment.Start,
  2440. Alignment.Center,
  2441. TextDirection.BottomTop_RightLeft,
  2442. @"
  2443. *******
  2444. 4******
  2445. ******
  2446. 你*****
  2447. ******
  2448. 0******
  2449. *******")]
  2450. [InlineData (
  2451. "0 你 4",
  2452. Alignment.Start,
  2453. Alignment.Fill,
  2454. TextDirection.BottomTop_RightLeft,
  2455. @"
  2456. 4******
  2457. ******
  2458. ******
  2459. 你*****
  2460. ******
  2461. ******
  2462. 0******")]
  2463. // Vertical with alignment.Right
  2464. // TopBottom_LeftRight
  2465. [InlineData (
  2466. "0 2 4",
  2467. Alignment.End,
  2468. Alignment.Start,
  2469. TextDirection.TopBottom_LeftRight,
  2470. @"
  2471. ******0
  2472. ******
  2473. ******2
  2474. ******
  2475. ******4
  2476. *******
  2477. *******")]
  2478. [InlineData (
  2479. "0 2 4",
  2480. Alignment.End,
  2481. Alignment.End,
  2482. TextDirection.TopBottom_LeftRight,
  2483. @"
  2484. *******
  2485. *******
  2486. ******0
  2487. ******
  2488. ******2
  2489. ******
  2490. ******4")]
  2491. [InlineData (
  2492. "0 2 4",
  2493. Alignment.End,
  2494. Alignment.Center,
  2495. TextDirection.TopBottom_LeftRight,
  2496. @"
  2497. *******
  2498. ******0
  2499. ******
  2500. ******2
  2501. ******
  2502. ******4
  2503. *******")]
  2504. [InlineData (
  2505. "0 2 4",
  2506. Alignment.End,
  2507. Alignment.Fill,
  2508. TextDirection.TopBottom_LeftRight,
  2509. @"
  2510. ******0
  2511. ******
  2512. ******
  2513. ******2
  2514. ******
  2515. ******
  2516. ******4")]
  2517. [InlineData (
  2518. "0 你 4",
  2519. Alignment.End,
  2520. Alignment.Start,
  2521. TextDirection.TopBottom_LeftRight,
  2522. @"
  2523. *****0*
  2524. ***** *
  2525. *****你
  2526. ***** *
  2527. *****4*
  2528. *******
  2529. *******")]
  2530. [InlineData (
  2531. "0 你 4",
  2532. Alignment.End,
  2533. Alignment.End,
  2534. TextDirection.TopBottom_LeftRight,
  2535. @"
  2536. *******
  2537. *******
  2538. *****0*
  2539. ***** *
  2540. *****你
  2541. ***** *
  2542. *****4*")]
  2543. [InlineData (
  2544. "0 你 4",
  2545. Alignment.End,
  2546. Alignment.Center,
  2547. TextDirection.TopBottom_LeftRight,
  2548. @"
  2549. *******
  2550. *****0*
  2551. ***** *
  2552. *****你
  2553. ***** *
  2554. *****4*
  2555. *******")]
  2556. [InlineData (
  2557. "0 你 4",
  2558. Alignment.End,
  2559. Alignment.Fill,
  2560. TextDirection.TopBottom_LeftRight,
  2561. @"
  2562. *****0*
  2563. ***** *
  2564. ***** *
  2565. *****你
  2566. ***** *
  2567. ***** *
  2568. *****4*")]
  2569. // TopBottom_RightLeft
  2570. [InlineData (
  2571. "0 2 4",
  2572. Alignment.End,
  2573. Alignment.Start,
  2574. TextDirection.TopBottom_RightLeft,
  2575. @"
  2576. ******0
  2577. ******
  2578. ******2
  2579. ******
  2580. ******4
  2581. *******
  2582. *******")]
  2583. [InlineData (
  2584. "0 2 4",
  2585. Alignment.End,
  2586. Alignment.End,
  2587. TextDirection.TopBottom_RightLeft,
  2588. @"
  2589. *******
  2590. *******
  2591. ******0
  2592. ******
  2593. ******2
  2594. ******
  2595. ******4")]
  2596. [InlineData (
  2597. "0 2 4",
  2598. Alignment.End,
  2599. Alignment.Center,
  2600. TextDirection.TopBottom_RightLeft,
  2601. @"
  2602. *******
  2603. ******0
  2604. ******
  2605. ******2
  2606. ******
  2607. ******4
  2608. *******")]
  2609. [InlineData (
  2610. "0 2 4",
  2611. Alignment.End,
  2612. Alignment.Fill,
  2613. TextDirection.TopBottom_RightLeft,
  2614. @"
  2615. ******0
  2616. ******
  2617. ******
  2618. ******2
  2619. ******
  2620. ******
  2621. ******4")]
  2622. [InlineData (
  2623. "0 你 4",
  2624. Alignment.End,
  2625. Alignment.Start,
  2626. TextDirection.TopBottom_RightLeft,
  2627. @"
  2628. *****0*
  2629. ***** *
  2630. *****你
  2631. ***** *
  2632. *****4*
  2633. *******
  2634. *******")]
  2635. [InlineData (
  2636. "0 你 4",
  2637. Alignment.End,
  2638. Alignment.End,
  2639. TextDirection.TopBottom_RightLeft,
  2640. @"
  2641. *******
  2642. *******
  2643. *****0*
  2644. ***** *
  2645. *****你
  2646. ***** *
  2647. *****4*")]
  2648. [InlineData (
  2649. "0 你 4",
  2650. Alignment.End,
  2651. Alignment.Center,
  2652. TextDirection.TopBottom_RightLeft,
  2653. @"
  2654. *******
  2655. *****0*
  2656. ***** *
  2657. *****你
  2658. ***** *
  2659. *****4*
  2660. *******")]
  2661. [InlineData (
  2662. "0 你 4",
  2663. Alignment.End,
  2664. Alignment.Fill,
  2665. TextDirection.TopBottom_RightLeft,
  2666. @"
  2667. *****0*
  2668. ***** *
  2669. ***** *
  2670. *****你
  2671. ***** *
  2672. ***** *
  2673. *****4*")]
  2674. // BottomTop_LeftRight
  2675. [InlineData (
  2676. "0 2 4",
  2677. Alignment.End,
  2678. Alignment.Start,
  2679. TextDirection.BottomTop_LeftRight,
  2680. @"
  2681. ******4
  2682. ******
  2683. ******2
  2684. ******
  2685. ******0
  2686. *******
  2687. *******")]
  2688. [InlineData (
  2689. "0 2 4",
  2690. Alignment.End,
  2691. Alignment.End,
  2692. TextDirection.BottomTop_LeftRight,
  2693. @"
  2694. *******
  2695. *******
  2696. ******4
  2697. ******
  2698. ******2
  2699. ******
  2700. ******0")]
  2701. [InlineData (
  2702. "0 2 4",
  2703. Alignment.End,
  2704. Alignment.Center,
  2705. TextDirection.BottomTop_LeftRight,
  2706. @"
  2707. *******
  2708. ******4
  2709. ******
  2710. ******2
  2711. ******
  2712. ******0
  2713. *******")]
  2714. [InlineData (
  2715. "0 2 4",
  2716. Alignment.End,
  2717. Alignment.Fill,
  2718. TextDirection.BottomTop_LeftRight,
  2719. @"
  2720. ******4
  2721. ******
  2722. ******
  2723. ******2
  2724. ******
  2725. ******
  2726. ******0")]
  2727. [InlineData (
  2728. "0 你 4",
  2729. Alignment.End,
  2730. Alignment.Start,
  2731. TextDirection.BottomTop_LeftRight,
  2732. @"
  2733. *****4*
  2734. ***** *
  2735. *****你
  2736. ***** *
  2737. *****0*
  2738. *******
  2739. *******")]
  2740. [InlineData (
  2741. "0 你 4",
  2742. Alignment.End,
  2743. Alignment.End,
  2744. TextDirection.BottomTop_LeftRight,
  2745. @"
  2746. *******
  2747. *******
  2748. *****4*
  2749. ***** *
  2750. *****你
  2751. ***** *
  2752. *****0*")]
  2753. [InlineData (
  2754. "0 你 4",
  2755. Alignment.End,
  2756. Alignment.Center,
  2757. TextDirection.BottomTop_LeftRight,
  2758. @"
  2759. *******
  2760. *****4*
  2761. ***** *
  2762. *****你
  2763. ***** *
  2764. *****0*
  2765. *******")]
  2766. [InlineData (
  2767. "0 你 4",
  2768. Alignment.End,
  2769. Alignment.Fill,
  2770. TextDirection.BottomTop_LeftRight,
  2771. @"
  2772. *****4*
  2773. ***** *
  2774. ***** *
  2775. *****你
  2776. ***** *
  2777. ***** *
  2778. *****0*")]
  2779. // BottomTop_RightLeft
  2780. [InlineData (
  2781. "0 2 4",
  2782. Alignment.End,
  2783. Alignment.Start,
  2784. TextDirection.BottomTop_RightLeft,
  2785. @"
  2786. ******4
  2787. ******
  2788. ******2
  2789. ******
  2790. ******0
  2791. *******
  2792. *******")]
  2793. [InlineData (
  2794. "0 2 4",
  2795. Alignment.End,
  2796. Alignment.End,
  2797. TextDirection.BottomTop_RightLeft,
  2798. @"
  2799. *******
  2800. *******
  2801. ******4
  2802. ******
  2803. ******2
  2804. ******
  2805. ******0")]
  2806. [InlineData (
  2807. "0 2 4",
  2808. Alignment.End,
  2809. Alignment.Center,
  2810. TextDirection.BottomTop_RightLeft,
  2811. @"
  2812. *******
  2813. ******4
  2814. ******
  2815. ******2
  2816. ******
  2817. ******0
  2818. *******")]
  2819. [InlineData (
  2820. "0 2 4",
  2821. Alignment.End,
  2822. Alignment.Fill,
  2823. TextDirection.BottomTop_RightLeft,
  2824. @"
  2825. ******4
  2826. ******
  2827. ******
  2828. ******2
  2829. ******
  2830. ******
  2831. ******0")]
  2832. [InlineData (
  2833. "0 你 4",
  2834. Alignment.End,
  2835. Alignment.Start,
  2836. TextDirection.BottomTop_RightLeft,
  2837. @"
  2838. *****4*
  2839. ***** *
  2840. *****你
  2841. ***** *
  2842. *****0*
  2843. *******
  2844. *******")]
  2845. [InlineData (
  2846. "0 你 4",
  2847. Alignment.End,
  2848. Alignment.End,
  2849. TextDirection.BottomTop_RightLeft,
  2850. @"
  2851. *******
  2852. *******
  2853. *****4*
  2854. ***** *
  2855. *****你
  2856. ***** *
  2857. *****0*")]
  2858. [InlineData (
  2859. "0 你 4",
  2860. Alignment.End,
  2861. Alignment.Center,
  2862. TextDirection.BottomTop_RightLeft,
  2863. @"
  2864. *******
  2865. *****4*
  2866. ***** *
  2867. *****你
  2868. ***** *
  2869. *****0*
  2870. *******")]
  2871. [InlineData (
  2872. "0 你 4",
  2873. Alignment.End,
  2874. Alignment.Fill,
  2875. TextDirection.BottomTop_RightLeft,
  2876. @"
  2877. *****4*
  2878. ***** *
  2879. ***** *
  2880. *****你
  2881. ***** *
  2882. ***** *
  2883. *****0*")]
  2884. // Vertical with alignment.Centered
  2885. // TopBottom_LeftRight
  2886. [InlineData (
  2887. "0 2 4",
  2888. Alignment.Center,
  2889. Alignment.Start,
  2890. TextDirection.TopBottom_LeftRight,
  2891. @"
  2892. ***0***
  2893. *** ***
  2894. ***2***
  2895. *** ***
  2896. ***4***
  2897. *******
  2898. *******")]
  2899. [InlineData (
  2900. "0 2 4",
  2901. Alignment.Center,
  2902. Alignment.End,
  2903. TextDirection.TopBottom_LeftRight,
  2904. @"
  2905. *******
  2906. *******
  2907. ***0***
  2908. *** ***
  2909. ***2***
  2910. *** ***
  2911. ***4***")]
  2912. [InlineData (
  2913. "0 2 4",
  2914. Alignment.Center,
  2915. Alignment.Center,
  2916. TextDirection.TopBottom_LeftRight,
  2917. @"
  2918. *******
  2919. ***0***
  2920. *** ***
  2921. ***2***
  2922. *** ***
  2923. ***4***
  2924. *******")]
  2925. [InlineData (
  2926. "0 2 4",
  2927. Alignment.Center,
  2928. Alignment.Fill,
  2929. TextDirection.TopBottom_LeftRight,
  2930. @"
  2931. ***0***
  2932. *** ***
  2933. *** ***
  2934. ***2***
  2935. *** ***
  2936. *** ***
  2937. ***4***")]
  2938. [InlineData (
  2939. "0 你 4",
  2940. Alignment.Center,
  2941. Alignment.Start,
  2942. TextDirection.TopBottom_LeftRight,
  2943. @"
  2944. **0****
  2945. ** ****
  2946. **你***
  2947. ** ****
  2948. **4****
  2949. *******
  2950. *******")]
  2951. [InlineData (
  2952. "0 你 4",
  2953. Alignment.Center,
  2954. Alignment.End,
  2955. TextDirection.TopBottom_LeftRight,
  2956. @"
  2957. *******
  2958. *******
  2959. **0****
  2960. ** ****
  2961. **你***
  2962. ** ****
  2963. **4****")]
  2964. [InlineData (
  2965. "0 你 4",
  2966. Alignment.Center,
  2967. Alignment.Center,
  2968. TextDirection.TopBottom_LeftRight,
  2969. @"
  2970. *******
  2971. **0****
  2972. ** ****
  2973. **你***
  2974. ** ****
  2975. **4****
  2976. *******")]
  2977. [InlineData (
  2978. "0 你 4",
  2979. Alignment.Center,
  2980. Alignment.Fill,
  2981. TextDirection.TopBottom_LeftRight,
  2982. @"
  2983. **0****
  2984. ** ****
  2985. ** ****
  2986. **你***
  2987. ** ****
  2988. ** ****
  2989. **4****")]
  2990. // TopBottom_RightLeft
  2991. [InlineData (
  2992. "0 2 4",
  2993. Alignment.Center,
  2994. Alignment.Start,
  2995. TextDirection.TopBottom_RightLeft,
  2996. @"
  2997. ***0***
  2998. *** ***
  2999. ***2***
  3000. *** ***
  3001. ***4***
  3002. *******
  3003. *******")]
  3004. [InlineData (
  3005. "0 2 4",
  3006. Alignment.Center,
  3007. Alignment.End,
  3008. TextDirection.TopBottom_RightLeft,
  3009. @"
  3010. *******
  3011. *******
  3012. ***0***
  3013. *** ***
  3014. ***2***
  3015. *** ***
  3016. ***4***")]
  3017. [InlineData (
  3018. "0 2 4",
  3019. Alignment.Center,
  3020. Alignment.Center,
  3021. TextDirection.TopBottom_RightLeft,
  3022. @"
  3023. *******
  3024. ***0***
  3025. *** ***
  3026. ***2***
  3027. *** ***
  3028. ***4***
  3029. *******")]
  3030. [InlineData (
  3031. "0 2 4",
  3032. Alignment.Center,
  3033. Alignment.Fill,
  3034. TextDirection.TopBottom_RightLeft,
  3035. @"
  3036. ***0***
  3037. *** ***
  3038. *** ***
  3039. ***2***
  3040. *** ***
  3041. *** ***
  3042. ***4***")]
  3043. [InlineData (
  3044. "0 你 4",
  3045. Alignment.Center,
  3046. Alignment.Start,
  3047. TextDirection.TopBottom_RightLeft,
  3048. @"
  3049. **0****
  3050. ** ****
  3051. **你***
  3052. ** ****
  3053. **4****
  3054. *******
  3055. *******")]
  3056. [InlineData (
  3057. "0 你 4",
  3058. Alignment.Center,
  3059. Alignment.End,
  3060. TextDirection.TopBottom_RightLeft,
  3061. @"
  3062. *******
  3063. *******
  3064. **0****
  3065. ** ****
  3066. **你***
  3067. ** ****
  3068. **4****")]
  3069. [InlineData (
  3070. "0 你 4",
  3071. Alignment.Center,
  3072. Alignment.Center,
  3073. TextDirection.TopBottom_RightLeft,
  3074. @"
  3075. *******
  3076. **0****
  3077. ** ****
  3078. **你***
  3079. ** ****
  3080. **4****
  3081. *******")]
  3082. [InlineData (
  3083. "0 你 4",
  3084. Alignment.Center,
  3085. Alignment.Fill,
  3086. TextDirection.TopBottom_RightLeft,
  3087. @"
  3088. **0****
  3089. ** ****
  3090. ** ****
  3091. **你***
  3092. ** ****
  3093. ** ****
  3094. **4****")]
  3095. // BottomTop_LeftRight
  3096. [InlineData (
  3097. "0 2 4",
  3098. Alignment.Center,
  3099. Alignment.Start,
  3100. TextDirection.BottomTop_LeftRight,
  3101. @"
  3102. ***4***
  3103. *** ***
  3104. ***2***
  3105. *** ***
  3106. ***0***
  3107. *******
  3108. *******")]
  3109. [InlineData (
  3110. "0 2 4",
  3111. Alignment.Center,
  3112. Alignment.End,
  3113. TextDirection.BottomTop_LeftRight,
  3114. @"
  3115. *******
  3116. *******
  3117. ***4***
  3118. *** ***
  3119. ***2***
  3120. *** ***
  3121. ***0***")]
  3122. [InlineData (
  3123. "0 2 4",
  3124. Alignment.Center,
  3125. Alignment.Center,
  3126. TextDirection.BottomTop_LeftRight,
  3127. @"
  3128. *******
  3129. ***4***
  3130. *** ***
  3131. ***2***
  3132. *** ***
  3133. ***0***
  3134. *******")]
  3135. [InlineData (
  3136. "0 2 4",
  3137. Alignment.Center,
  3138. Alignment.Fill,
  3139. TextDirection.BottomTop_LeftRight,
  3140. @"
  3141. ***4***
  3142. *** ***
  3143. *** ***
  3144. ***2***
  3145. *** ***
  3146. *** ***
  3147. ***0***")]
  3148. [InlineData (
  3149. "0 你 4",
  3150. Alignment.Center,
  3151. Alignment.Start,
  3152. TextDirection.BottomTop_LeftRight,
  3153. @"
  3154. **4****
  3155. ** ****
  3156. **你***
  3157. ** ****
  3158. **0****
  3159. *******
  3160. *******")]
  3161. [InlineData (
  3162. "0 你 4",
  3163. Alignment.Center,
  3164. Alignment.End,
  3165. TextDirection.BottomTop_LeftRight,
  3166. @"
  3167. *******
  3168. *******
  3169. **4****
  3170. ** ****
  3171. **你***
  3172. ** ****
  3173. **0****")]
  3174. [InlineData (
  3175. "0 你 4",
  3176. Alignment.Center,
  3177. Alignment.Center,
  3178. TextDirection.BottomTop_LeftRight,
  3179. @"
  3180. *******
  3181. **4****
  3182. ** ****
  3183. **你***
  3184. ** ****
  3185. **0****
  3186. *******")]
  3187. [InlineData (
  3188. "0 你 4",
  3189. Alignment.Center,
  3190. Alignment.Fill,
  3191. TextDirection.BottomTop_LeftRight,
  3192. @"
  3193. **4****
  3194. ** ****
  3195. ** ****
  3196. **你***
  3197. ** ****
  3198. ** ****
  3199. **0****")]
  3200. // BottomTop_RightLeft
  3201. [InlineData (
  3202. "0 2 4",
  3203. Alignment.Center,
  3204. Alignment.Start,
  3205. TextDirection.BottomTop_RightLeft,
  3206. @"
  3207. ***4***
  3208. *** ***
  3209. ***2***
  3210. *** ***
  3211. ***0***
  3212. *******
  3213. *******")]
  3214. [InlineData (
  3215. "0 2 4",
  3216. Alignment.Center,
  3217. Alignment.End,
  3218. TextDirection.BottomTop_RightLeft,
  3219. @"
  3220. *******
  3221. *******
  3222. ***4***
  3223. *** ***
  3224. ***2***
  3225. *** ***
  3226. ***0***")]
  3227. [InlineData (
  3228. "0 2 4",
  3229. Alignment.Center,
  3230. Alignment.Center,
  3231. TextDirection.BottomTop_RightLeft,
  3232. @"
  3233. *******
  3234. ***4***
  3235. *** ***
  3236. ***2***
  3237. *** ***
  3238. ***0***
  3239. *******")]
  3240. [InlineData (
  3241. "0 2 4",
  3242. Alignment.Center,
  3243. Alignment.Fill,
  3244. TextDirection.BottomTop_RightLeft,
  3245. @"
  3246. ***4***
  3247. *** ***
  3248. *** ***
  3249. ***2***
  3250. *** ***
  3251. *** ***
  3252. ***0***")]
  3253. [InlineData (
  3254. "0 你 4",
  3255. Alignment.Center,
  3256. Alignment.Start,
  3257. TextDirection.BottomTop_RightLeft,
  3258. @"
  3259. **4****
  3260. ** ****
  3261. **你***
  3262. ** ****
  3263. **0****
  3264. *******
  3265. *******")]
  3266. [InlineData (
  3267. "0 你 4",
  3268. Alignment.Center,
  3269. Alignment.End,
  3270. TextDirection.BottomTop_RightLeft,
  3271. @"
  3272. *******
  3273. *******
  3274. **4****
  3275. ** ****
  3276. **你***
  3277. ** ****
  3278. **0****")]
  3279. [InlineData (
  3280. "0 你 4",
  3281. Alignment.Center,
  3282. Alignment.Center,
  3283. TextDirection.BottomTop_RightLeft,
  3284. @"
  3285. *******
  3286. **4****
  3287. ** ****
  3288. **你***
  3289. ** ****
  3290. **0****
  3291. *******")]
  3292. [InlineData (
  3293. "0 你 4",
  3294. Alignment.Center,
  3295. Alignment.Fill,
  3296. TextDirection.BottomTop_RightLeft,
  3297. @"
  3298. **4****
  3299. ** ****
  3300. ** ****
  3301. **你***
  3302. ** ****
  3303. ** ****
  3304. **0****")]
  3305. // Vertical with alignment.Justified
  3306. // TopBottom_LeftRight
  3307. [InlineData (
  3308. "0 2 4",
  3309. Alignment.Fill,
  3310. Alignment.Start,
  3311. TextDirection.TopBottom_LeftRight,
  3312. @"
  3313. 0******
  3314. ******
  3315. 2******
  3316. ******
  3317. 4******
  3318. *******
  3319. *******")]
  3320. [InlineData (
  3321. "0 2 4",
  3322. Alignment.Fill,
  3323. Alignment.End,
  3324. TextDirection.TopBottom_LeftRight,
  3325. @"
  3326. *******
  3327. *******
  3328. 0******
  3329. ******
  3330. 2******
  3331. ******
  3332. 4******")]
  3333. [InlineData (
  3334. "0 2 4",
  3335. Alignment.Fill,
  3336. Alignment.Center,
  3337. TextDirection.TopBottom_LeftRight,
  3338. @"
  3339. *******
  3340. 0******
  3341. ******
  3342. 2******
  3343. ******
  3344. 4******
  3345. *******")]
  3346. [InlineData (
  3347. "0 2 4",
  3348. Alignment.Fill,
  3349. Alignment.Fill,
  3350. TextDirection.TopBottom_LeftRight,
  3351. @"
  3352. 0******
  3353. ******
  3354. ******
  3355. 2******
  3356. ******
  3357. ******
  3358. 4******")]
  3359. [InlineData (
  3360. "0 你 4",
  3361. Alignment.Fill,
  3362. Alignment.Start,
  3363. TextDirection.TopBottom_LeftRight,
  3364. @"
  3365. 0******
  3366. ******
  3367. 你*****
  3368. ******
  3369. 4******
  3370. *******
  3371. *******")]
  3372. [InlineData (
  3373. "0 你 4",
  3374. Alignment.Fill,
  3375. Alignment.End,
  3376. TextDirection.TopBottom_LeftRight,
  3377. @"
  3378. *******
  3379. *******
  3380. 0******
  3381. ******
  3382. 你*****
  3383. ******
  3384. 4******")]
  3385. [InlineData (
  3386. "0 你 4",
  3387. Alignment.Fill,
  3388. Alignment.Center,
  3389. TextDirection.TopBottom_LeftRight,
  3390. @"
  3391. *******
  3392. 0******
  3393. ******
  3394. 你*****
  3395. ******
  3396. 4******
  3397. *******")]
  3398. [InlineData (
  3399. "0 你 4",
  3400. Alignment.Fill,
  3401. Alignment.Fill,
  3402. TextDirection.TopBottom_LeftRight,
  3403. @"
  3404. 0******
  3405. ******
  3406. ******
  3407. 你*****
  3408. ******
  3409. ******
  3410. 4******")]
  3411. // TopBottom_RightLeft
  3412. [InlineData (
  3413. "0 2 4",
  3414. Alignment.Fill,
  3415. Alignment.Start,
  3416. TextDirection.TopBottom_RightLeft,
  3417. @"
  3418. 0******
  3419. ******
  3420. 2******
  3421. ******
  3422. 4******
  3423. *******
  3424. *******")]
  3425. [InlineData (
  3426. "0 2 4",
  3427. Alignment.Fill,
  3428. Alignment.End,
  3429. TextDirection.TopBottom_RightLeft,
  3430. @"
  3431. *******
  3432. *******
  3433. 0******
  3434. ******
  3435. 2******
  3436. ******
  3437. 4******")]
  3438. [InlineData (
  3439. "0 2 4",
  3440. Alignment.Fill,
  3441. Alignment.Center,
  3442. TextDirection.TopBottom_RightLeft,
  3443. @"
  3444. *******
  3445. 0******
  3446. ******
  3447. 2******
  3448. ******
  3449. 4******
  3450. *******")]
  3451. [InlineData (
  3452. "0 2 4",
  3453. Alignment.Fill,
  3454. Alignment.Fill,
  3455. TextDirection.TopBottom_RightLeft,
  3456. @"
  3457. 0******
  3458. ******
  3459. ******
  3460. 2******
  3461. ******
  3462. ******
  3463. 4******")]
  3464. [InlineData (
  3465. "0 你 4",
  3466. Alignment.Fill,
  3467. Alignment.Start,
  3468. TextDirection.TopBottom_RightLeft,
  3469. @"
  3470. 0******
  3471. ******
  3472. 你*****
  3473. ******
  3474. 4******
  3475. *******
  3476. *******")]
  3477. [InlineData (
  3478. "0 你 4",
  3479. Alignment.Fill,
  3480. Alignment.End,
  3481. TextDirection.TopBottom_RightLeft,
  3482. @"
  3483. *******
  3484. *******
  3485. 0******
  3486. ******
  3487. 你*****
  3488. ******
  3489. 4******")]
  3490. [InlineData (
  3491. "0 你 4",
  3492. Alignment.Fill,
  3493. Alignment.Center,
  3494. TextDirection.TopBottom_RightLeft,
  3495. @"
  3496. *******
  3497. 0******
  3498. ******
  3499. 你*****
  3500. ******
  3501. 4******
  3502. *******")]
  3503. [InlineData (
  3504. "0 你 4",
  3505. Alignment.Fill,
  3506. Alignment.Fill,
  3507. TextDirection.TopBottom_RightLeft,
  3508. @"
  3509. 0******
  3510. ******
  3511. ******
  3512. 你*****
  3513. ******
  3514. ******
  3515. 4******")]
  3516. // BottomTop_LeftRight
  3517. [InlineData (
  3518. "0 2 4",
  3519. Alignment.Fill,
  3520. Alignment.Start,
  3521. TextDirection.BottomTop_LeftRight,
  3522. @"
  3523. 4******
  3524. ******
  3525. 2******
  3526. ******
  3527. 0******
  3528. *******
  3529. *******")]
  3530. [InlineData (
  3531. "0 2 4",
  3532. Alignment.Fill,
  3533. Alignment.End,
  3534. TextDirection.BottomTop_LeftRight,
  3535. @"
  3536. *******
  3537. *******
  3538. 4******
  3539. ******
  3540. 2******
  3541. ******
  3542. 0******")]
  3543. [InlineData (
  3544. "0 2 4",
  3545. Alignment.Fill,
  3546. Alignment.Center,
  3547. TextDirection.BottomTop_LeftRight,
  3548. @"
  3549. *******
  3550. 4******
  3551. ******
  3552. 2******
  3553. ******
  3554. 0******
  3555. *******")]
  3556. [InlineData (
  3557. "0 2 4",
  3558. Alignment.Fill,
  3559. Alignment.Fill,
  3560. TextDirection.BottomTop_LeftRight,
  3561. @"
  3562. 4******
  3563. ******
  3564. ******
  3565. 2******
  3566. ******
  3567. ******
  3568. 0******")]
  3569. [InlineData (
  3570. "0 你 4",
  3571. Alignment.Fill,
  3572. Alignment.Start,
  3573. TextDirection.BottomTop_LeftRight,
  3574. @"
  3575. 4******
  3576. ******
  3577. 你*****
  3578. ******
  3579. 0******
  3580. *******
  3581. *******")]
  3582. [InlineData (
  3583. "0 你 4",
  3584. Alignment.Fill,
  3585. Alignment.End,
  3586. TextDirection.BottomTop_LeftRight,
  3587. @"
  3588. *******
  3589. *******
  3590. 4******
  3591. ******
  3592. 你*****
  3593. ******
  3594. 0******")]
  3595. [InlineData (
  3596. "0 你 4",
  3597. Alignment.Fill,
  3598. Alignment.Center,
  3599. TextDirection.BottomTop_LeftRight,
  3600. @"
  3601. *******
  3602. 4******
  3603. ******
  3604. 你*****
  3605. ******
  3606. 0******
  3607. *******")]
  3608. [InlineData (
  3609. "0 你 4",
  3610. Alignment.Fill,
  3611. Alignment.Fill,
  3612. TextDirection.BottomTop_LeftRight,
  3613. @"
  3614. 4******
  3615. ******
  3616. ******
  3617. 你*****
  3618. ******
  3619. ******
  3620. 0******")]
  3621. // BottomTop_RightLeft
  3622. [InlineData (
  3623. "0 2 4",
  3624. Alignment.Fill,
  3625. Alignment.Start,
  3626. TextDirection.BottomTop_RightLeft,
  3627. @"
  3628. 4******
  3629. ******
  3630. 2******
  3631. ******
  3632. 0******
  3633. *******
  3634. *******")]
  3635. [InlineData (
  3636. "0 2 4",
  3637. Alignment.Fill,
  3638. Alignment.End,
  3639. TextDirection.BottomTop_RightLeft,
  3640. @"
  3641. *******
  3642. *******
  3643. 4******
  3644. ******
  3645. 2******
  3646. ******
  3647. 0******")]
  3648. [InlineData (
  3649. "0 2 4",
  3650. Alignment.Fill,
  3651. Alignment.Center,
  3652. TextDirection.BottomTop_RightLeft,
  3653. @"
  3654. *******
  3655. 4******
  3656. ******
  3657. 2******
  3658. ******
  3659. 0******
  3660. *******")]
  3661. [InlineData (
  3662. "0 2 4",
  3663. Alignment.Fill,
  3664. Alignment.Fill,
  3665. TextDirection.BottomTop_RightLeft,
  3666. @"
  3667. 4******
  3668. ******
  3669. ******
  3670. 2******
  3671. ******
  3672. ******
  3673. 0******")]
  3674. [InlineData (
  3675. "0 你 4",
  3676. Alignment.Fill,
  3677. Alignment.Start,
  3678. TextDirection.BottomTop_RightLeft,
  3679. @"
  3680. 4******
  3681. ******
  3682. 你*****
  3683. ******
  3684. 0******
  3685. *******
  3686. *******")]
  3687. [InlineData (
  3688. "0 你 4",
  3689. Alignment.Fill,
  3690. Alignment.End,
  3691. TextDirection.BottomTop_RightLeft,
  3692. @"
  3693. *******
  3694. *******
  3695. 4******
  3696. ******
  3697. 你*****
  3698. ******
  3699. 0******")]
  3700. [InlineData (
  3701. "0 你 4",
  3702. Alignment.Fill,
  3703. Alignment.Center,
  3704. TextDirection.BottomTop_RightLeft,
  3705. @"
  3706. *******
  3707. 4******
  3708. ******
  3709. 你*****
  3710. ******
  3711. 0******
  3712. *******")]
  3713. [InlineData (
  3714. "0 你 4",
  3715. Alignment.Fill,
  3716. Alignment.Fill,
  3717. TextDirection.BottomTop_RightLeft,
  3718. @"
  3719. 4******
  3720. ******
  3721. ******
  3722. 你*****
  3723. ******
  3724. ******
  3725. 0******")]
  3726. public void Draw_Text_Justification (string text, Alignment horizontalTextAlignment, Alignment alignment, TextDirection textDirection, string expectedText)
  3727. {
  3728. TextFormatter tf = new ()
  3729. {
  3730. Alignment = horizontalTextAlignment,
  3731. VerticalAlignment = alignment,
  3732. Direction = textDirection,
  3733. ConstrainToSize = new (7, 7),
  3734. Text = text
  3735. };
  3736. Application.Driver?.FillRect (new (0, 0, 7, 7), (Rune)'*');
  3737. tf.Draw (new (0, 0, 7, 7), Attribute.Default, Attribute.Default);
  3738. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3739. }
  3740. [SetupFakeDriver]
  3741. [Theory]
  3742. [InlineData ("A", 0, 1, "", 0)]
  3743. [InlineData ("A", 1, 1, "A", 0)]
  3744. [InlineData ("A", 2, 2, " A", 1)]
  3745. [InlineData ("AB", 1, 1, "B", 0)]
  3746. [InlineData ("AB", 2, 2, " A\n B", 0)]
  3747. [InlineData ("ABC", 3, 2, " B\n C", 0)]
  3748. [InlineData ("ABC", 4, 2, " B\n C", 0)]
  3749. [InlineData ("ABC", 6, 2, " B\n C", 0)]
  3750. [InlineData ("こんにちは", 0, 1, "", 0)]
  3751. [InlineData ("こんにちは", 1, 0, "", 0)]
  3752. [InlineData ("こんにちは", 1, 1, "", 0)]
  3753. [InlineData ("こんにちは", 2, 1, "は", 0)]
  3754. [InlineData ("こんにちは", 2, 2, "ち\nは", 0)]
  3755. [InlineData ("こんにちは", 2, 3, "に\nち\nは", 0)]
  3756. [InlineData ("こんにちは", 2, 4, "ん\nに\nち\nは", 0)]
  3757. [InlineData ("こんにちは", 2, 5, "こ\nん\nに\nち\nは", 0)]
  3758. [InlineData ("こんにちは", 2, 6, "こ\nん\nに\nち\nは", 1)]
  3759. [InlineData ("ABCD\nこんにちは", 4, 7, " こ\n Aん\n Bに\n Cち\n Dは", 2)]
  3760. [InlineData ("こんにちは\nABCD", 3, 7, "こ \nんA\nにB\nちC\nはD", 2)]
  3761. public void Draw_Vertical_Bottom_Horizontal_Right (string text, int width, int height, string expectedText, int expectedY)
  3762. {
  3763. TextFormatter tf = new ()
  3764. {
  3765. Text = text,
  3766. Alignment = Alignment.End,
  3767. Direction = TextDirection.TopBottom_LeftRight,
  3768. VerticalAlignment = Alignment.End
  3769. };
  3770. tf.ConstrainToWidth = width;
  3771. tf.ConstrainToHeight = height;
  3772. tf.Draw (new (Point.Empty, new (width, height)), Attribute.Default, Attribute.Default);
  3773. Rectangle rect = TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3774. Assert.Equal (expectedY, rect.Y);
  3775. }
  3776. [SetupFakeDriver]
  3777. [Theory]
  3778. [InlineData ("A", 1, 0, "")]
  3779. [InlineData ("A", 0, 1, "")]
  3780. [InlineData ("AB1 2", 1, 2, "2")]
  3781. [InlineData ("AB12", 1, 5, "2\n1\nB\nA")]
  3782. [InlineData ("AB\n12", 2, 5, "B2\nA1")]
  3783. [InlineData ("ABC 123 456", 2, 7, "6C\n5B\n4A\n \n3 \n2 \n1 ")]
  3784. [InlineData ("こんにちは", 1, 1, "")]
  3785. [InlineData ("こんにちは", 2, 1, "は")]
  3786. [InlineData ("こんにちは", 2, 5, "は\nち\nに\nん\nこ")]
  3787. [InlineData ("こんにちは", 2, 10, "は\nち\nに\nん\nこ")]
  3788. [InlineData ("こんにちは\nAB\n12", 4, 10, "はB2\nちA1\nに \nん \nこ ")]
  3789. public void Draw_Vertical_BottomTop_LeftRight (string text, int width, int height, string expectedText)
  3790. {
  3791. TextFormatter tf = new ()
  3792. {
  3793. Text = text,
  3794. Direction = TextDirection.BottomTop_LeftRight
  3795. };
  3796. tf.ConstrainToWidth = width;
  3797. tf.ConstrainToHeight = height;
  3798. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  3799. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3800. }
  3801. [SetupFakeDriver]
  3802. [Theory]
  3803. [InlineData ("A", 1, 0, "")]
  3804. [InlineData ("A", 0, 1, "")]
  3805. [InlineData ("AB1 2", 1, 2, "2")]
  3806. [InlineData ("AB12", 1, 5, "2\n1\nB\nA")]
  3807. [InlineData ("AB\n12", 2, 5, "2B\n1A")]
  3808. [InlineData ("ABC 123 456", 2, 7, "C6\nB5\nA4\n \n 3\n 2\n 1")]
  3809. [InlineData ("こんにちは", 1, 1, "")]
  3810. [InlineData ("こんにちは", 2, 1, "は")]
  3811. [InlineData ("こんにちは", 2, 5, "は\nち\nに\nん\nこ")]
  3812. [InlineData ("こんにちは", 2, 10, "は\nち\nに\nん\nこ")]
  3813. [InlineData ("こんにちは\nAB\n12", 4, 10, "2Bは\n1Aち\n に\n ん\n こ")]
  3814. public void Draw_Vertical_BottomTop_RightLeft (string text, int width, int height, string expectedText)
  3815. {
  3816. TextFormatter tf = new ()
  3817. {
  3818. Text = text,
  3819. Direction = TextDirection.BottomTop_RightLeft
  3820. };
  3821. tf.ConstrainToWidth = width;
  3822. tf.ConstrainToHeight = height;
  3823. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  3824. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3825. }
  3826. // Draw tests - Note that these depend on View
  3827. [Fact]
  3828. [TestRespondersDisposed]
  3829. public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  3830. {
  3831. Application.Init (new FakeDriver ());
  3832. Dialog.DefaultShadow = ShadowStyle.None;
  3833. Button.DefaultShadow = ShadowStyle.None;
  3834. Toplevel top = new ();
  3835. var view = new View { Y = -2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight, Text = "view" };
  3836. top.Add (view);
  3837. Application.Iteration += (s, a) =>
  3838. {
  3839. Assert.Equal (-2, view.Y);
  3840. Application.RequestStop ();
  3841. };
  3842. try
  3843. {
  3844. Application.Run (top);
  3845. }
  3846. catch (IndexOutOfRangeException ex)
  3847. {
  3848. // After the fix this exception will not be caught.
  3849. Assert.IsType<IndexOutOfRangeException> (ex);
  3850. }
  3851. top.Dispose ();
  3852. // Shutdown must be called to safely clean up Application if Init has been called
  3853. Application.Shutdown ();
  3854. }
  3855. [SetupFakeDriver]
  3856. [Theory]
  3857. [InlineData ("A", 5, 5, "A")]
  3858. [InlineData (
  3859. "AB12",
  3860. 5,
  3861. 5,
  3862. @"
  3863. A
  3864. B
  3865. 1
  3866. 2")]
  3867. [InlineData (
  3868. "AB\n12",
  3869. 5,
  3870. 5,
  3871. @"
  3872. A1
  3873. B2")]
  3874. [InlineData ("", 5, 1, "")]
  3875. [InlineData (
  3876. "Hello Worlds",
  3877. 1,
  3878. 12,
  3879. @"
  3880. H
  3881. e
  3882. l
  3883. l
  3884. o
  3885. W
  3886. o
  3887. r
  3888. l
  3889. d
  3890. s")]
  3891. [InlineData ("Hello Worlds", 12, 1, @"HelloWorlds")]
  3892. public void Draw_Vertical_TopBottom_LeftRight (string text, int width, int height, string expectedText)
  3893. {
  3894. TextFormatter tf = new ()
  3895. {
  3896. Text = text,
  3897. Direction = TextDirection.TopBottom_LeftRight
  3898. };
  3899. tf.ConstrainToWidth = width;
  3900. tf.ConstrainToHeight = height;
  3901. tf.Draw (new (0, 0, 20, 20), Attribute.Default, Attribute.Default);
  3902. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3903. }
  3904. [SetupFakeDriver]
  3905. [Theory]
  3906. // The expectedY param is to probe that the expectedText param start at that Y coordinate
  3907. [InlineData ("A", 0, "", 0)]
  3908. [InlineData ("A", 1, "A", 0)]
  3909. [InlineData ("A", 2, "A", 0)]
  3910. [InlineData ("A", 3, "A", 1)]
  3911. [InlineData ("AB", 1, "A", 0)]
  3912. [InlineData ("AB", 2, "A\nB", 0)]
  3913. [InlineData ("ABC", 2, "A\nB", 0)]
  3914. [InlineData ("ABC", 3, "A\nB\nC", 0)]
  3915. [InlineData ("ABC", 4, "A\nB\nC", 0)]
  3916. [InlineData ("ABC", 5, "A\nB\nC", 1)]
  3917. [InlineData ("ABC", 6, "A\nB\nC", 1)]
  3918. [InlineData ("ABC", 9, "A\nB\nC", 3)]
  3919. [InlineData ("ABCD", 2, "B\nC", 0)]
  3920. [InlineData ("こんにちは", 0, "", 0)]
  3921. [InlineData ("こんにちは", 1, "に", 0)]
  3922. [InlineData ("こんにちは", 2, "ん\nに", 0)]
  3923. [InlineData ("こんにちは", 3, "ん\nに\nち", 0)]
  3924. [InlineData ("こんにちは", 4, "こ\nん\nに\nち", 0)]
  3925. [InlineData ("こんにちは", 5, "こ\nん\nに\nち\nは", 0)]
  3926. [InlineData ("こんにちは", 6, "こ\nん\nに\nち\nは", 0)]
  3927. [InlineData ("ABCD\nこんにちは", 7, "Aこ\nBん\nCに\nDち\n は", 1)]
  3928. [InlineData ("こんにちは\nABCD", 7, "こA\nんB\nにC\nちD\nは ", 1)]
  3929. public void Draw_Vertical_TopBottom_LeftRight_Middle (string text, int height, string expectedText, int expectedY)
  3930. {
  3931. TextFormatter tf = new ()
  3932. {
  3933. Text = text,
  3934. Direction = TextDirection.TopBottom_LeftRight,
  3935. VerticalAlignment = Alignment.Center
  3936. };
  3937. int width = text.ToRunes ().Max (r => r.GetColumns ());
  3938. if (text.Contains ("\n"))
  3939. {
  3940. width++;
  3941. }
  3942. tf.ConstrainToWidth = width;
  3943. tf.ConstrainToHeight = height;
  3944. tf.Draw (new (0, 0, 5, height), Attribute.Default, Attribute.Default);
  3945. Rectangle rect = TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3946. Assert.Equal (expectedY, rect.Y);
  3947. }
  3948. [SetupFakeDriver]
  3949. [Theory]
  3950. [InlineData ("A", 5, "A")]
  3951. [InlineData (
  3952. "AB12",
  3953. 5,
  3954. @"
  3955. A
  3956. B
  3957. 1
  3958. 2")]
  3959. [InlineData (
  3960. "AB\n12",
  3961. 5,
  3962. @"
  3963. A1
  3964. B2")]
  3965. [InlineData ("", 1, "")]
  3966. [InlineData (
  3967. "AB1 2",
  3968. 2,
  3969. @"
  3970. A12
  3971. B ")]
  3972. [InlineData (
  3973. "こんにちは",
  3974. 1,
  3975. @"
  3976. こん")]
  3977. [InlineData (
  3978. "こんにちは",
  3979. 2,
  3980. @"
  3981. こに
  3982. んち")]
  3983. [InlineData (
  3984. "こんにちは",
  3985. 5,
  3986. @"
  3987. は")]
  3988. public void Draw_Vertical_TopBottom_LeftRight_Top (string text, int height, string expectedText)
  3989. {
  3990. TextFormatter tf = new ()
  3991. {
  3992. Text = text,
  3993. Direction = TextDirection.TopBottom_LeftRight
  3994. };
  3995. tf.ConstrainToWidth = 5;
  3996. tf.ConstrainToHeight = height;
  3997. tf.Draw (new (0, 0, 5, height), Attribute.Default, Attribute.Default);
  3998. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3999. }
  4000. [Theory]
  4001. [InlineData (14, 1, TextDirection.LeftRight_TopBottom, "Les Misęrables")]
  4002. [InlineData (1, 14, TextDirection.TopBottom_LeftRight, "L\ne\ns\n \nM\ni\ns\nę\nr\na\nb\nl\ne\ns")]
  4003. [InlineData (
  4004. 4,
  4005. 4,
  4006. TextDirection.TopBottom_LeftRight,
  4007. @"
  4008. LMre
  4009. eias
  4010. ssb
  4011. ęl "
  4012. )]
  4013. public void Draw_With_Combining_Runes (int width, int height, TextDirection textDirection, string expected)
  4014. {
  4015. var driver = new FakeDriver ();
  4016. driver.Init ();
  4017. var text = "Les Mise\u0328\u0301rables";
  4018. var tf = new TextFormatter ();
  4019. tf.Direction = textDirection;
  4020. tf.Text = text;
  4021. Assert.True (tf.WordWrap);
  4022. tf.ConstrainToSize = new (width, height);
  4023. tf.Draw (
  4024. new (0, 0, width, height),
  4025. new (ColorName16.White, ColorName16.Black),
  4026. new (ColorName16.Blue, ColorName16.Black),
  4027. default (Rectangle),
  4028. driver
  4029. );
  4030. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
  4031. driver.End ();
  4032. }
  4033. [Fact]
  4034. [SetupFakeDriver]
  4035. public void FillRemaining_True_False ()
  4036. {
  4037. ((FakeDriver)Application.Driver!).SetBufferSize (22, 5);
  4038. Attribute [] attrs =
  4039. {
  4040. Attribute.Default, new (ColorName16.Green, ColorName16.BrightMagenta),
  4041. new (ColorName16.Blue, ColorName16.Cyan)
  4042. };
  4043. var tf = new TextFormatter { ConstrainToSize = new (14, 3), Text = "Test\nTest long\nTest long long\n", MultiLine = true };
  4044. tf.Draw (
  4045. new (1, 1, 19, 3),
  4046. attrs [1],
  4047. attrs [2]);
  4048. Assert.False (tf.FillRemaining);
  4049. TestHelpers.AssertDriverContentsWithFrameAre (
  4050. @"
  4051. Test
  4052. Test long
  4053. Test long long",
  4054. _output);
  4055. TestHelpers.AssertDriverAttributesAre (
  4056. @"
  4057. 000000000000000000000
  4058. 011110000000000000000
  4059. 011111111100000000000
  4060. 011111111111111000000
  4061. 000000000000000000000",
  4062. null,
  4063. attrs);
  4064. tf.FillRemaining = true;
  4065. tf.Draw (
  4066. new (1, 1, 19, 3),
  4067. attrs [1],
  4068. attrs [2]);
  4069. TestHelpers.AssertDriverAttributesAre (
  4070. @"
  4071. 000000000000000000000
  4072. 011111111111111111110
  4073. 011111111111111111110
  4074. 011111111111111111110
  4075. 000000000000000000000",
  4076. null,
  4077. attrs);
  4078. }
  4079. [Theory]
  4080. [InlineData ("_k Before", true, 0, (KeyCode)'K')] // lower case should return uppercase Hotkey
  4081. [InlineData ("a_k Second", true, 1, (KeyCode)'K')]
  4082. [InlineData ("Last _k", true, 5, (KeyCode)'K')]
  4083. [InlineData ("After k_", false, -1, KeyCode.Null)]
  4084. [InlineData ("Multiple _k and _R", true, 9, (KeyCode)'K')]
  4085. [InlineData ("Non-english: _кдать", true, 13, (KeyCode)'к')] // Lower case Cryllic K (к)
  4086. [InlineData ("_k Before", true, 0, (KeyCode)'K', true)] // Turn on FirstUpperCase and verify same results
  4087. [InlineData ("a_k Second", true, 1, (KeyCode)'K', true)]
  4088. [InlineData ("Last _k", true, 5, (KeyCode)'K', true)]
  4089. [InlineData ("After k_", false, -1, KeyCode.Null, true)]
  4090. [InlineData ("Multiple _k and _r", true, 9, (KeyCode)'K', true)]
  4091. [InlineData ("Non-english: _кдать", true, 13, (KeyCode)'к', true)] // Cryllic K (К)
  4092. public void FindHotKey_AlphaLowerCase_Succeeds (
  4093. string text,
  4094. bool expectedResult,
  4095. int expectedHotPos,
  4096. KeyCode expectedKey,
  4097. bool supportFirstUpperCase = false
  4098. )
  4099. {
  4100. var hotKeySpecifier = (Rune)'_';
  4101. bool result = TextFormatter.FindHotKey (
  4102. text,
  4103. hotKeySpecifier,
  4104. out int hotPos,
  4105. out Key hotKey,
  4106. supportFirstUpperCase
  4107. );
  4108. if (expectedResult)
  4109. {
  4110. Assert.True (result);
  4111. }
  4112. else
  4113. {
  4114. Assert.False (result);
  4115. }
  4116. Assert.Equal (expectedResult, result);
  4117. Assert.Equal (expectedHotPos, hotPos);
  4118. Assert.Equal (expectedKey, hotKey);
  4119. }
  4120. [Theory]
  4121. [InlineData ("_K Before", true, 0, (KeyCode)'K')]
  4122. [InlineData ("a_K Second", true, 1, (KeyCode)'K')]
  4123. [InlineData ("Last _K", true, 5, (KeyCode)'K')]
  4124. [InlineData ("After K_", false, -1, KeyCode.Null)]
  4125. [InlineData ("Multiple _K and _R", true, 9, (KeyCode)'K')]
  4126. [InlineData ("Non-english: _Кдать", true, 13, (KeyCode)'К')] // Cryllic K (К)
  4127. [InlineData ("_K Before", true, 0, (KeyCode)'K', true)] // Turn on FirstUpperCase and verify same results
  4128. [InlineData ("a_K Second", true, 1, (KeyCode)'K', true)]
  4129. [InlineData ("Last _K", true, 5, (KeyCode)'K', true)]
  4130. [InlineData ("After K_", false, -1, KeyCode.Null, true)]
  4131. [InlineData ("Multiple _K and _R", true, 9, (KeyCode)'K', true)]
  4132. [InlineData ("Non-english: _Кдать", true, 13, (KeyCode)'К', true)] // Cryllic K (К)
  4133. public void FindHotKey_AlphaUpperCase_Succeeds (
  4134. string text,
  4135. bool expectedResult,
  4136. int expectedHotPos,
  4137. KeyCode expectedKey,
  4138. bool supportFirstUpperCase = false
  4139. )
  4140. {
  4141. var hotKeySpecifier = (Rune)'_';
  4142. bool result = TextFormatter.FindHotKey (
  4143. text,
  4144. hotKeySpecifier,
  4145. out int hotPos,
  4146. out Key hotKey,
  4147. supportFirstUpperCase
  4148. );
  4149. if (expectedResult)
  4150. {
  4151. Assert.True (result);
  4152. }
  4153. else
  4154. {
  4155. Assert.False (result);
  4156. }
  4157. Assert.Equal (expectedResult, result);
  4158. Assert.Equal (expectedHotPos, hotPos);
  4159. Assert.Equal (expectedKey, hotKey);
  4160. }
  4161. [Theory]
  4162. [InlineData (null)]
  4163. [InlineData ("")]
  4164. [InlineData ("no hotkey")]
  4165. [InlineData ("No hotkey, Upper Case")]
  4166. [InlineData ("Non-english: Сохранить")]
  4167. public void FindHotKey_Invalid_ReturnsFalse (string text)
  4168. {
  4169. var hotKeySpecifier = (Rune)'_';
  4170. var supportFirstUpperCase = false;
  4171. var hotPos = 0;
  4172. Key hotKey = KeyCode.Null;
  4173. var result = false;
  4174. result = TextFormatter.FindHotKey (
  4175. text,
  4176. hotKeySpecifier,
  4177. out hotPos,
  4178. out hotKey,
  4179. supportFirstUpperCase
  4180. );
  4181. Assert.False (result);
  4182. Assert.Equal (-1, hotPos);
  4183. Assert.Equal (KeyCode.Null, hotKey);
  4184. }
  4185. [Theory]
  4186. [InlineData ("\"k before")]
  4187. [InlineData ("ak second")]
  4188. [InlineData ("last k")]
  4189. [InlineData ("multiple k and r")]
  4190. [InlineData ("12345")]
  4191. [InlineData ("`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?")] // punctuation
  4192. [InlineData (" ~  s  gui.cs   master ↑10")] // ~IsLetterOrDigit + Unicode
  4193. [InlineData ("non-english: кдать")] // Lower case Cryllic K (к)
  4194. public void FindHotKey_Legacy_FirstUpperCase_NotFound_Returns_False (string text)
  4195. {
  4196. var supportFirstUpperCase = true;
  4197. var hotKeySpecifier = (Rune)0;
  4198. bool result = TextFormatter.FindHotKey (
  4199. text,
  4200. hotKeySpecifier,
  4201. out int hotPos,
  4202. out Key hotKey,
  4203. supportFirstUpperCase
  4204. );
  4205. Assert.False (result);
  4206. Assert.Equal (-1, hotPos);
  4207. Assert.Equal (KeyCode.Null, hotKey);
  4208. }
  4209. [Theory]
  4210. [InlineData ("K Before", true, 0, (KeyCode)'K')]
  4211. [InlineData ("aK Second", true, 1, (KeyCode)'K')]
  4212. [InlineData ("last K", true, 5, (KeyCode)'K')]
  4213. [InlineData ("multiple K and R", true, 9, (KeyCode)'K')]
  4214. [InlineData ("non-english: Кдать", true, 13, (KeyCode)'К')] // Cryllic K (К)
  4215. public void FindHotKey_Legacy_FirstUpperCase_Succeeds (
  4216. string text,
  4217. bool expectedResult,
  4218. int expectedHotPos,
  4219. KeyCode expectedKey
  4220. )
  4221. {
  4222. var supportFirstUpperCase = true;
  4223. var hotKeySpecifier = (Rune)0;
  4224. bool result = TextFormatter.FindHotKey (
  4225. text,
  4226. hotKeySpecifier,
  4227. out int hotPos,
  4228. out Key hotKey,
  4229. supportFirstUpperCase
  4230. );
  4231. if (expectedResult)
  4232. {
  4233. Assert.True (result);
  4234. }
  4235. else
  4236. {
  4237. Assert.False (result);
  4238. }
  4239. Assert.Equal (expectedResult, result);
  4240. Assert.Equal (expectedHotPos, hotPos);
  4241. Assert.Equal (expectedKey, hotKey);
  4242. }
  4243. [Theory]
  4244. [InlineData ("_1 Before", true, 0, (KeyCode)'1')] // Digits
  4245. [InlineData ("a_1 Second", true, 1, (KeyCode)'1')]
  4246. [InlineData ("Last _1", true, 5, (KeyCode)'1')]
  4247. [InlineData ("After 1_", false, -1, KeyCode.Null)]
  4248. [InlineData ("Multiple _1 and _2", true, 9, (KeyCode)'1')]
  4249. [InlineData ("_1 Before", true, 0, (KeyCode)'1', true)] // Turn on FirstUpperCase and verify same results
  4250. [InlineData ("a_1 Second", true, 1, (KeyCode)'1', true)]
  4251. [InlineData ("Last _1", true, 5, (KeyCode)'1', true)]
  4252. [InlineData ("After 1_", false, -1, KeyCode.Null, true)]
  4253. [InlineData ("Multiple _1 and _2", true, 9, (KeyCode)'1', true)]
  4254. public void FindHotKey_Numeric_Succeeds (
  4255. string text,
  4256. bool expectedResult,
  4257. int expectedHotPos,
  4258. KeyCode expectedKey,
  4259. bool supportFirstUpperCase = false
  4260. )
  4261. {
  4262. var hotKeySpecifier = (Rune)'_';
  4263. bool result = TextFormatter.FindHotKey (
  4264. text,
  4265. hotKeySpecifier,
  4266. out int hotPos,
  4267. out Key hotKey,
  4268. supportFirstUpperCase
  4269. );
  4270. if (expectedResult)
  4271. {
  4272. Assert.True (result);
  4273. }
  4274. else
  4275. {
  4276. Assert.False (result);
  4277. }
  4278. Assert.Equal (expectedResult, result);
  4279. Assert.Equal (expectedHotPos, hotPos);
  4280. Assert.Equal (expectedKey, hotKey);
  4281. }
  4282. [Theory]
  4283. [InlineData ("_\"k before", true, (KeyCode)'"')] // BUGBUG: Not sure why this fails. " is a normal char
  4284. [InlineData ("\"_k before", true, KeyCode.K)]
  4285. [InlineData ("_`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?", true, (KeyCode)'`')]
  4286. [InlineData ("`_~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?", true, (KeyCode)'~')]
  4287. [InlineData (
  4288. "`~!@#$%^&*()-__=+[{]}\\|;:'\",<.>/?",
  4289. true,
  4290. (KeyCode)'='
  4291. )] // BUGBUG: Not sure why this fails. Ignore the first and consider the second
  4292. [InlineData ("_ ~  s  gui.cs   master ↑10", true, (KeyCode)'')] // ~IsLetterOrDigit + Unicode
  4293. [InlineData (" ~  s  gui.cs  _ master ↑10", true, (KeyCode)'')] // ~IsLetterOrDigit + Unicode
  4294. [InlineData ("non-english: _кдать", true, (KeyCode)'к')] // Lower case Cryllic K (к)
  4295. public void FindHotKey_Symbols_Returns_Symbol (string text, bool found, KeyCode expected)
  4296. {
  4297. var hotKeySpecifier = (Rune)'_';
  4298. bool result = TextFormatter.FindHotKey (text, hotKeySpecifier, out int _, out Key hotKey);
  4299. Assert.Equal (found, result);
  4300. Assert.Equal (expected, hotKey);
  4301. }
  4302. [Fact]
  4303. public void Format_Dont_Throw_ArgumentException_With_WordWrap_As_False_And_Keep_End_Spaces_As_True ()
  4304. {
  4305. Exception exception = Record.Exception (
  4306. () =>
  4307. TextFormatter.Format (
  4308. "Some text",
  4309. 4,
  4310. Alignment.Start,
  4311. false,
  4312. true
  4313. )
  4314. );
  4315. Assert.Null (exception);
  4316. }
  4317. [Theory]
  4318. [InlineData (
  4319. "Hello world, how are you today? Pretty neat!",
  4320. 44,
  4321. 80,
  4322. "Hello world, how are you today? Pretty neat!"
  4323. )]
  4324. public void Format_Justified_Always_Returns_Text_Width_Equal_To_Passed_Width_Horizontal (
  4325. string text,
  4326. int runeCount,
  4327. int maxWidth,
  4328. string justifiedText
  4329. )
  4330. {
  4331. Assert.Equal (runeCount, text.GetRuneCount ());
  4332. var fmtText = string.Empty;
  4333. for (int i = text.GetRuneCount (); i < maxWidth; i++)
  4334. {
  4335. fmtText = TextFormatter.Format (text, i, Alignment.Fill, true) [0];
  4336. Assert.Equal (i, fmtText.GetRuneCount ());
  4337. char c = fmtText [^1];
  4338. Assert.True (text.EndsWith (c));
  4339. }
  4340. Assert.Equal (justifiedText, fmtText);
  4341. }
  4342. [Theory]
  4343. [InlineData (
  4344. "Hello world, how are you today? Pretty neat!",
  4345. 44,
  4346. 80,
  4347. "Hello world, how are you today? Pretty neat!"
  4348. )]
  4349. public void Format_Justified_Always_Returns_Text_Width_Equal_To_Passed_Width_Vertical (
  4350. string text,
  4351. int runeCount,
  4352. int maxWidth,
  4353. string justifiedText
  4354. )
  4355. {
  4356. Assert.Equal (runeCount, text.GetRuneCount ());
  4357. var fmtText = string.Empty;
  4358. for (int i = text.GetRuneCount (); i < maxWidth; i++)
  4359. {
  4360. fmtText = TextFormatter.Format (
  4361. text,
  4362. i,
  4363. Alignment.Fill,
  4364. false,
  4365. true,
  4366. 0,
  4367. TextDirection.TopBottom_LeftRight
  4368. ) [0];
  4369. Assert.Equal (i, fmtText.GetRuneCount ());
  4370. char c = fmtText [^1];
  4371. Assert.True (text.EndsWith (c));
  4372. }
  4373. Assert.Equal (justifiedText, fmtText);
  4374. }
  4375. [Theory]
  4376. [InlineData ("Truncate", 3, "Tru")]
  4377. [InlineData ("デモエムポンズ", 3, "デ")]
  4378. public void Format_Truncate_Simple_And_Wide_Runes (string text, int width, string expected)
  4379. {
  4380. List<string> list = TextFormatter.Format (text, width, false, false);
  4381. Assert.Equal (expected, list [^1]);
  4382. }
  4383. [Theory]
  4384. [MemberData (nameof (FormatEnvironmentNewLine))]
  4385. public void Format_With_PreserveTrailingSpaces_And_Without_PreserveTrailingSpaces (
  4386. string text,
  4387. int width,
  4388. IEnumerable<string> expected
  4389. )
  4390. {
  4391. var preserveTrailingSpaces = false;
  4392. List<string> formated = TextFormatter.Format (text, width, false, true, preserveTrailingSpaces);
  4393. Assert.Equal (expected, formated);
  4394. preserveTrailingSpaces = true;
  4395. formated = TextFormatter.Format (text, width, false, true, preserveTrailingSpaces);
  4396. Assert.Equal (expected, formated);
  4397. }
  4398. [Theory]
  4399. [InlineData (
  4400. " A sentence has words. \n This is the second Line - 2. ",
  4401. 4,
  4402. -50,
  4403. Alignment.Start,
  4404. true,
  4405. false,
  4406. new [] { " A", "sent", "ence", "has", "word", "s. ", " Thi", "s is", "the", "seco", "nd", "Line", "- 2." },
  4407. " Asentencehaswords. This isthesecondLine- 2."
  4408. )]
  4409. [InlineData (
  4410. " A sentence has words. \n This is the second Line - 2. ",
  4411. 4,
  4412. -50,
  4413. Alignment.Start,
  4414. true,
  4415. true,
  4416. new []
  4417. {
  4418. " A ",
  4419. "sent",
  4420. "ence",
  4421. " ",
  4422. "has ",
  4423. "word",
  4424. "s. ",
  4425. " ",
  4426. "This",
  4427. " is ",
  4428. "the ",
  4429. "seco",
  4430. "nd ",
  4431. "Line",
  4432. " - ",
  4433. "2. "
  4434. },
  4435. " A sentence has words. This is the second Line - 2. "
  4436. )]
  4437. public void Format_WordWrap_PreserveTrailingSpaces (
  4438. string text,
  4439. int maxWidth,
  4440. int widthOffset,
  4441. Alignment alignment,
  4442. bool wrap,
  4443. bool preserveTrailingSpaces,
  4444. IEnumerable<string> resultLines,
  4445. string expectedWrappedText
  4446. )
  4447. {
  4448. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  4449. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
  4450. Assert.Equal (list.Count, resultLines.Count ());
  4451. Assert.Equal (resultLines, list);
  4452. var wrappedText = string.Empty;
  4453. foreach (string txt in list)
  4454. {
  4455. wrappedText += txt;
  4456. }
  4457. Assert.Equal (expectedWrappedText, wrappedText);
  4458. }
  4459. public static IEnumerable<object []> FormatEnvironmentNewLine =>
  4460. new List<object []>
  4461. {
  4462. new object []
  4463. {
  4464. $"Line1{Environment.NewLine}Line2{Environment.NewLine}Line3{Environment.NewLine}",
  4465. 60,
  4466. new [] { "Line1", "Line2", "Line3" }
  4467. }
  4468. };
  4469. [Theory]
  4470. [InlineData ("Hello World", 11)]
  4471. [InlineData ("こんにちは世界", 14)]
  4472. public void GetColumns_Simple_And_Wide_Runes (string text, int width) { Assert.Equal (width, text.GetColumns ()); }
  4473. [Theory]
  4474. [InlineData (new [] { "0123456789" }, 1)]
  4475. [InlineData (new [] { "Hello World" }, 1)]
  4476. [InlineData (new [] { "Hello", "World" }, 2)]
  4477. [InlineData (new [] { "こんにちは", "世界" }, 4)]
  4478. public void GetColumnsRequiredForVerticalText_List_GetsWidth (IEnumerable<string> text, int expectedWidth)
  4479. {
  4480. Assert.Equal (expectedWidth, TextFormatter.GetColumnsRequiredForVerticalText (text.ToList ()));
  4481. }
  4482. [Theory]
  4483. [InlineData (new [] { "Hello World" }, 1, 0, 1, 1)]
  4484. [InlineData (new [] { "Hello", "World" }, 2, 1, 1, 1)]
  4485. [InlineData (new [] { "こんにちは", "世界" }, 4, 1, 1, 2)]
  4486. public void GetColumnsRequiredForVerticalText_List_Simple_And_Wide_Runes (
  4487. IEnumerable<string> text,
  4488. int expectedWidth,
  4489. int index,
  4490. int length,
  4491. int expectedIndexWidth
  4492. )
  4493. {
  4494. Assert.Equal (expectedWidth, TextFormatter.GetColumnsRequiredForVerticalText (text.ToList ()));
  4495. Assert.Equal (expectedIndexWidth, TextFormatter.GetColumnsRequiredForVerticalText (text.ToList (), index, length));
  4496. }
  4497. [Fact]
  4498. public void GetColumnsRequiredForVerticalText_List_With_Combining_Runes ()
  4499. {
  4500. List<string> text = new () { "Les Mis", "e\u0328\u0301", "rables" };
  4501. Assert.Equal (1, TextFormatter.GetColumnsRequiredForVerticalText (text, 1, 1));
  4502. }
  4503. [Theory]
  4504. [InlineData ("Hello World", 6, 6)]
  4505. [InlineData ("こんにちは 世界", 6, 3)]
  4506. [MemberData (nameof (CMGlyphs))]
  4507. public void GetLengthThatFits_List_Simple_And_Wide_Runes (string text, int columns, int expectedLength)
  4508. {
  4509. List<Rune> runes = text.ToRuneList ();
  4510. Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (runes, columns));
  4511. }
  4512. [Theory]
  4513. [InlineData ("test", 3, 3)]
  4514. [InlineData ("test", 4, 4)]
  4515. [InlineData ("test", 10, 4)]
  4516. public void GetLengthThatFits_Runelist (string text, int columns, int expectedLength)
  4517. {
  4518. List<Rune> runes = text.ToRuneList ();
  4519. Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (runes, columns));
  4520. }
  4521. [Theory]
  4522. [InlineData ("Hello World", 6, 6)]
  4523. [InlineData ("こんにちは 世界", 6, 3)]
  4524. public void GetLengthThatFits_Simple_And_Wide_Runes (string text, int columns, int expectedLength)
  4525. {
  4526. Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (text, columns));
  4527. }
  4528. [Theory]
  4529. [InlineData ("test", 3, 3)]
  4530. [InlineData ("test", 4, 4)]
  4531. [InlineData ("test", 10, 4)]
  4532. [InlineData ("test", 1, 1)]
  4533. [InlineData ("test", 0, 0)]
  4534. [InlineData ("test", -1, 0)]
  4535. [InlineData (null, -1, 0)]
  4536. [InlineData ("", -1, 0)]
  4537. public void GetLengthThatFits_String (string text, int columns, int expectedLength)
  4538. {
  4539. Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (text, columns));
  4540. }
  4541. [Fact]
  4542. public void GetLengthThatFits_With_Combining_Runes ()
  4543. {
  4544. var text = "Les Mise\u0328\u0301rables";
  4545. Assert.Equal (16, TextFormatter.GetLengthThatFits (text, 14));
  4546. }
  4547. [Fact]
  4548. public void GetMaxColsForWidth_With_Combining_Runes ()
  4549. {
  4550. List<string> text = new () { "Les Mis", "e\u0328\u0301", "rables" };
  4551. Assert.Equal (1, TextFormatter.GetMaxColsForWidth (text, 1));
  4552. }
  4553. //[Fact]
  4554. //public void GetWidestLineLength_With_Combining_Runes ()
  4555. //{
  4556. // var text = "Les Mise\u0328\u0301rables";
  4557. // Assert.Equal (1, TextFormatter.GetWidestLineLength (text, 1, 1));
  4558. //}
  4559. [Fact]
  4560. public void Internal_Tests ()
  4561. {
  4562. var tf = new TextFormatter ();
  4563. Assert.Equal (KeyCode.Null, tf.HotKey);
  4564. tf.HotKey = KeyCode.CtrlMask | KeyCode.Q;
  4565. Assert.Equal (KeyCode.CtrlMask | KeyCode.Q, tf.HotKey);
  4566. }
  4567. [SetupFakeDriver]
  4568. [Theory]
  4569. [InlineData ("Hello World", 15, 1, "Hello World")]
  4570. [InlineData (
  4571. "Well Done\nNice Work",
  4572. 15,
  4573. 2,
  4574. @"
  4575. Well Done
  4576. Nice Work")]
  4577. [InlineData ("你好 世界", 15, 1, "你好 世界")]
  4578. [InlineData (
  4579. "做 得好\n幹 得好",
  4580. 15,
  4581. 2,
  4582. @"
  4583. 做 得好
  4584. 幹 得好")]
  4585. public void Justify_Horizontal (string text, int width, int height, string expectedText)
  4586. {
  4587. TextFormatter tf = new ()
  4588. {
  4589. Text = text,
  4590. Alignment = Alignment.Fill,
  4591. ConstrainToSize = new Size (width, height),
  4592. MultiLine = true
  4593. };
  4594. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  4595. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  4596. }
  4597. [Theory]
  4598. [InlineData ("")]
  4599. [InlineData (null)]
  4600. [InlineData ("test")]
  4601. public void Justify_Invalid (string text)
  4602. {
  4603. Assert.Equal (text, TextFormatter.Justify (text, 0));
  4604. Assert.Equal (text, TextFormatter.Justify (text, 0));
  4605. Assert.Throws<ArgumentOutOfRangeException> (() => TextFormatter.Justify (text, -1));
  4606. }
  4607. [Theory]
  4608. // Even # of spaces
  4609. // 0123456789
  4610. [InlineData ("012 456 89", "012 456 89", 10, 0, "+", true)]
  4611. [InlineData ("012 456 89", "012++456+89", 11, 1)]
  4612. [InlineData ("012 456 89", "012 456 89", 12, 2, "++", true)]
  4613. [InlineData ("012 456 89", "012+++456++89", 13, 3)]
  4614. [InlineData ("012 456 89", "012 456 89", 14, 4, "+++", true)]
  4615. [InlineData ("012 456 89", "012++++456+++89", 15, 5)]
  4616. [InlineData ("012 456 89", "012 456 89", 16, 6, "++++", true)]
  4617. [InlineData ("012 456 89", "012 456 89", 30, 20, "+++++++++++", true)]
  4618. [InlineData ("012 456 89", "012+++++++++++++456++++++++++++89", 33, 23)]
  4619. // Odd # of spaces
  4620. // 01234567890123
  4621. [InlineData ("012 456 89 end", "012 456 89 end", 14, 0, "+", true)]
  4622. [InlineData ("012 456 89 end", "012++456+89+end", 15, 1)]
  4623. [InlineData ("012 456 89 end", "012++456++89+end", 16, 2)]
  4624. [InlineData ("012 456 89 end", "012 456 89 end", 17, 3, "++", true)]
  4625. [InlineData ("012 456 89 end", "012+++456++89++end", 18, 4)]
  4626. [InlineData ("012 456 89 end", "012+++456+++89++end", 19, 5)]
  4627. [InlineData ("012 456 89 end", "012 456 89 end", 20, 6, "+++", true)]
  4628. [InlineData ("012 456 89 end", "012++++++++456++++++++89+++++++end", 34, 20)]
  4629. [InlineData ("012 456 89 end", "012+++++++++456+++++++++89++++++++end", 37, 23)]
  4630. // Unicode
  4631. // Even # of chars
  4632. // 0123456789
  4633. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 10, 0, "+", true)]
  4634. [InlineData ("пÑРвРÑ", "пÑÐ++вÐ+Ñ", 11, 1)]
  4635. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 12, 2, "++", true)]
  4636. [InlineData ("пÑРвРÑ", "пÑÐ+++вÐ++Ñ", 13, 3)]
  4637. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 14, 4, "+++", true)]
  4638. [InlineData ("пÑРвРÑ", "пÑÐ++++вÐ+++Ñ", 15, 5)]
  4639. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 16, 6, "++++", true)]
  4640. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 30, 20, "+++++++++++", true)]
  4641. [InlineData ("пÑРвРÑ", "пÑÐ+++++++++++++вÐ++++++++++++Ñ", 33, 23)]
  4642. // Unicode
  4643. // Odd # of chars
  4644. // 0123456789
  4645. [InlineData ("Ð ÑРвРÑ", "Ð ÑРвРÑ", 10, 0, "+", true)]
  4646. [InlineData ("Ð ÑРвРÑ", "Ð++ÑÐ+вÐ+Ñ", 11, 1)]
  4647. [InlineData ("Ð ÑРвРÑ", "Ð++ÑÐ++вÐ+Ñ", 12, 2)]
  4648. [InlineData ("Ð ÑРвРÑ", "Ð ÑРвРÑ", 13, 3, "++", true)]
  4649. [InlineData ("Ð ÑРвРÑ", "Ð+++ÑÐ++вÐ++Ñ", 14, 4)]
  4650. [InlineData ("Ð ÑРвРÑ", "Ð+++ÑÐ+++вÐ++Ñ", 15, 5)]
  4651. [InlineData ("Ð ÑРвРÑ", "Ð ÑРвРÑ", 16, 6, "+++", true)]
  4652. [InlineData ("Ð ÑРвРÑ", "Ð++++++++ÑÐ++++++++вÐ+++++++Ñ", 30, 20)]
  4653. [InlineData ("Ð ÑРвРÑ", "Ð+++++++++ÑÐ+++++++++вÐ++++++++Ñ", 33, 23)]
  4654. public void Justify_Sentence (
  4655. string text,
  4656. string justifiedText,
  4657. int forceToWidth,
  4658. int widthOffset,
  4659. string replaceWith = null,
  4660. bool replace = false
  4661. )
  4662. {
  4663. var fillChar = '+';
  4664. Assert.Equal (forceToWidth, text.GetRuneCount () + widthOffset);
  4665. if (replace)
  4666. {
  4667. justifiedText = text.Replace (" ", replaceWith);
  4668. }
  4669. Assert.Equal (justifiedText, TextFormatter.Justify (text, forceToWidth, fillChar));
  4670. Assert.True (Math.Abs (forceToWidth - justifiedText.GetRuneCount ()) < text.Count (s => s == ' '));
  4671. Assert.True (Math.Abs (forceToWidth - justifiedText.GetColumns ()) < text.Count (s => s == ' '));
  4672. }
  4673. [Theory]
  4674. [InlineData ("word")] // Even # of chars
  4675. [InlineData ("word.")] // Odd # of chars
  4676. [InlineData ("пÑивеÑ")] // Unicode (even #)
  4677. [InlineData ("пÑивеÑ.")] // Unicode (odd # of chars)
  4678. public void Justify_SingleWord (string text)
  4679. {
  4680. string justifiedText = text;
  4681. var fillChar = '+';
  4682. int width = text.GetRuneCount ();
  4683. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4684. width = text.GetRuneCount () + 1;
  4685. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4686. width = text.GetRuneCount () + 2;
  4687. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4688. width = text.GetRuneCount () + 10;
  4689. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4690. width = text.GetRuneCount () + 11;
  4691. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4692. }
  4693. [SetupFakeDriver]
  4694. [Theory]
  4695. [InlineData ("Hello World", 1, 15, "H\ne\nl\nl\no\n \n \n \n \n \nW\no\nr\nl\nd")]
  4696. [InlineData (
  4697. "Well Done\nNice Work",
  4698. 2,
  4699. 15,
  4700. @"
  4701. WN
  4702. ei
  4703. lc
  4704. le
  4705. DW
  4706. oo
  4707. nr
  4708. ek")]
  4709. [InlineData ("你好 世界", 2, 15, "你\n好\n \n \n \n \n \n \n \n \n \n \n \n世\n界")]
  4710. [InlineData (
  4711. "做 得好\n幹 得好",
  4712. 4,
  4713. 15,
  4714. @"
  4715. 做幹
  4716. 得得
  4717. 好好")]
  4718. public void Justify_Vertical (string text, int width, int height, string expectedText)
  4719. {
  4720. TextFormatter tf = new ()
  4721. {
  4722. Text = text,
  4723. Direction = TextDirection.TopBottom_LeftRight,
  4724. VerticalAlignment = Alignment.Fill,
  4725. ConstrainToSize = new Size (width, height),
  4726. MultiLine = true
  4727. };
  4728. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  4729. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  4730. }
  4731. [Theory]
  4732. [InlineData ("Single Line 界", 14)]
  4733. [InlineData ("First Line 界\nSecond Line 界\nThird Line 界\n", 14)]
  4734. public void MaxWidthLine_With_And_Without_Newlines (string text, int expected) { Assert.Equal (expected, TextFormatter.GetWidestLineLength (text)); }
  4735. [Theory]
  4736. [InlineData (
  4737. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4738. 0,
  4739. 0,
  4740. false,
  4741. new [] { "" }
  4742. )]
  4743. [InlineData (
  4744. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4745. 0,
  4746. 1,
  4747. false,
  4748. new [] { "" }
  4749. )]
  4750. [InlineData (
  4751. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4752. 1,
  4753. 0,
  4754. false,
  4755. new [] { "" }
  4756. )]
  4757. [InlineData (
  4758. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4759. 0,
  4760. 0,
  4761. true,
  4762. new [] { "" }
  4763. )]
  4764. [InlineData (
  4765. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4766. 0,
  4767. 1,
  4768. true,
  4769. new [] { "" }
  4770. )]
  4771. [InlineData (
  4772. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4773. 1,
  4774. 0,
  4775. true,
  4776. new [] { "" }
  4777. )]
  4778. [InlineData (
  4779. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4780. 6,
  4781. 5,
  4782. false,
  4783. new [] { "First " }
  4784. )]
  4785. [InlineData ("1\n2\n3\n4\n5\n6", 6, 5, false, new [] { "1 2 3 " })]
  4786. [InlineData (
  4787. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4788. 6,
  4789. 5,
  4790. true,
  4791. new [] { "First ", "Second", "Third ", "Forty ", "Fiftee" }
  4792. )]
  4793. [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, false, new [] { "第一" })]
  4794. [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, true, new [] { "第一", "第二", "第三", "四十", "第十" })]
  4795. public void MultiLine_WordWrap_False_Horizontal_Direction (
  4796. string text,
  4797. int maxWidth,
  4798. int maxHeight,
  4799. bool multiLine,
  4800. IEnumerable<string> resultLines
  4801. )
  4802. {
  4803. var tf = new TextFormatter
  4804. {
  4805. Text = text, ConstrainToSize = new (maxWidth, maxHeight), WordWrap = false, MultiLine = multiLine
  4806. };
  4807. Assert.False (tf.WordWrap);
  4808. Assert.True (tf.MultiLine == multiLine);
  4809. Assert.Equal (TextDirection.LeftRight_TopBottom, tf.Direction);
  4810. List<string> splitLines = tf.GetLines ();
  4811. Assert.Equal (splitLines.Count, resultLines.Count ());
  4812. Assert.Equal (splitLines, resultLines);
  4813. }
  4814. [Theory]
  4815. [InlineData (
  4816. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4817. 0,
  4818. 0,
  4819. false,
  4820. new [] { "" }
  4821. )]
  4822. [InlineData (
  4823. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4824. 0,
  4825. 1,
  4826. false,
  4827. new [] { "" }
  4828. )]
  4829. [InlineData (
  4830. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4831. 1,
  4832. 0,
  4833. false,
  4834. new [] { "" }
  4835. )]
  4836. [InlineData (
  4837. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4838. 0,
  4839. 0,
  4840. true,
  4841. new [] { "" }
  4842. )]
  4843. [InlineData (
  4844. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4845. 0,
  4846. 1,
  4847. true,
  4848. new [] { "" }
  4849. )]
  4850. [InlineData (
  4851. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4852. 1,
  4853. 0,
  4854. true,
  4855. new [] { "" }
  4856. )]
  4857. [InlineData (
  4858. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4859. 6,
  4860. 5,
  4861. false,
  4862. new [] { "First" }
  4863. )]
  4864. [InlineData ("1\n2\n3\n4\n5\n6", 6, 5, false, new [] { "1 2 3" })]
  4865. [InlineData (
  4866. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4867. 6,
  4868. 5,
  4869. true,
  4870. new [] { "First", "Secon", "Third", "Forty", "Fifte", "Seven" }
  4871. )]
  4872. [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, false, new [] { "第一行 第" })]
  4873. [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, true, new [] { "第一行", "第二行" })]
  4874. public void MultiLine_WordWrap_False_Vertical_Direction (
  4875. string text,
  4876. int maxWidth,
  4877. int maxHeight,
  4878. bool multiLine,
  4879. IEnumerable<string> resultLines
  4880. )
  4881. {
  4882. var tf = new TextFormatter
  4883. {
  4884. Text = text,
  4885. ConstrainToSize = new (maxWidth, maxHeight),
  4886. WordWrap = false,
  4887. MultiLine = multiLine,
  4888. Direction = TextDirection.TopBottom_LeftRight
  4889. };
  4890. Assert.False (tf.WordWrap);
  4891. Assert.True (tf.MultiLine == multiLine);
  4892. Assert.Equal (TextDirection.TopBottom_LeftRight, tf.Direction);
  4893. List<string> splitLines = tf.GetLines ();
  4894. Assert.Equal (splitLines.Count, resultLines.Count ());
  4895. Assert.Equal (splitLines, resultLines);
  4896. }
  4897. [Fact]
  4898. public void NeedsFormat_Sets ()
  4899. {
  4900. var testText = "test";
  4901. var testBounds = new Rectangle (0, 0, 100, 1);
  4902. var tf = new TextFormatter ();
  4903. tf.Text = "test";
  4904. Assert.True (tf.NeedsFormat); // get_Lines causes a Format
  4905. Assert.NotEmpty (tf.GetLines ());
  4906. Assert.False (tf.NeedsFormat); // get_Lines causes a Format
  4907. Assert.Equal (testText, tf.Text);
  4908. tf.Draw (testBounds, new (), new ());
  4909. Assert.False (tf.NeedsFormat);
  4910. tf.ConstrainToSize = new (1, 1);
  4911. Assert.True (tf.NeedsFormat);
  4912. Assert.NotEmpty (tf.GetLines ());
  4913. Assert.False (tf.NeedsFormat); // get_Lines causes a Format
  4914. tf.Alignment = Alignment.Center;
  4915. Assert.True (tf.NeedsFormat);
  4916. Assert.NotEmpty (tf.GetLines ());
  4917. Assert.False (tf.NeedsFormat); // get_Lines causes a Format
  4918. }
  4919. // Test that changing TextFormatter does not impact View dimensions if Dim.Auto is not in play
  4920. [Fact]
  4921. public void Not_Used_TextFormatter_Does_Not_Change_View_Size ()
  4922. {
  4923. View view = new ()
  4924. {
  4925. Text = "_1234"
  4926. };
  4927. Assert.Equal (Size.Empty, view.Frame.Size);
  4928. view.TextFormatter.Text = "ABC";
  4929. Assert.Equal (Size.Empty, view.Frame.Size);
  4930. view.TextFormatter.Alignment = Alignment.Fill;
  4931. Assert.Equal (Size.Empty, view.Frame.Size);
  4932. view.TextFormatter.VerticalAlignment = Alignment.Center;
  4933. Assert.Equal (Size.Empty, view.Frame.Size);
  4934. view.TextFormatter.HotKeySpecifier = (Rune)'*';
  4935. Assert.Equal (Size.Empty, view.Frame.Size);
  4936. view.TextFormatter.Text = "*ABC";
  4937. Assert.Equal (Size.Empty, view.Frame.Size);
  4938. }
  4939. [Fact]
  4940. public void Not_Used_TextSettings_Do_Not_Change_View_Size ()
  4941. {
  4942. View view = new ()
  4943. {
  4944. Text = "_1234"
  4945. };
  4946. Assert.Equal (Size.Empty, view.Frame.Size);
  4947. view.TextAlignment = Alignment.Fill;
  4948. Assert.Equal (Size.Empty, view.Frame.Size);
  4949. view.VerticalTextAlignment = Alignment.Center;
  4950. Assert.Equal (Size.Empty, view.Frame.Size);
  4951. view.HotKeySpecifier = (Rune)'*';
  4952. Assert.Equal (Size.Empty, view.Frame.Size);
  4953. view.Text = "*ABC";
  4954. Assert.Equal (Size.Empty, view.Frame.Size);
  4955. }
  4956. [Theory]
  4957. [InlineData ("", -1, Alignment.Start, false, 0)]
  4958. [InlineData (null, 0, Alignment.Start, false, 1)]
  4959. [InlineData (null, 0, Alignment.Start, true, 1)]
  4960. [InlineData ("", 0, Alignment.Start, false, 1)]
  4961. [InlineData ("", 0, Alignment.Start, true, 1)]
  4962. public void Reformat_Invalid (string text, int maxWidth, Alignment alignment, bool wrap, int linesCount)
  4963. {
  4964. if (maxWidth < 0)
  4965. {
  4966. Assert.Throws<ArgumentOutOfRangeException> (
  4967. () =>
  4968. TextFormatter.Format (text, maxWidth, alignment, wrap)
  4969. );
  4970. }
  4971. else
  4972. {
  4973. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap);
  4974. Assert.NotEmpty (list);
  4975. Assert.True (list.Count == linesCount);
  4976. Assert.Equal (string.Empty, list [0]);
  4977. }
  4978. }
  4979. [Theory]
  4980. [InlineData ("A sentence has words.\nLine 2.", 0, -29, Alignment.Start, false, 1, true)]
  4981. [InlineData ("A sentence has words.\nLine 2.", 1, -28, Alignment.Start, false, 1, false)]
  4982. [InlineData ("A sentence has words.\nLine 2.", 5, -24, Alignment.Start, false, 1, false)]
  4983. [InlineData ("A sentence has words.\nLine 2.", 28, -1, Alignment.Start, false, 1, false)]
  4984. // no clip
  4985. [InlineData ("A sentence has words.\nLine 2.", 29, 0, Alignment.Start, false, 1, false)]
  4986. [InlineData ("A sentence has words.\nLine 2.", 30, 1, Alignment.Start, false, 1, false)]
  4987. [InlineData ("A sentence has words.\r\nLine 2.", 0, -30, Alignment.Start, false, 1, true)]
  4988. [InlineData ("A sentence has words.\r\nLine 2.", 1, -29, Alignment.Start, false, 1, false)]
  4989. [InlineData ("A sentence has words.\r\nLine 2.", 5, -25, Alignment.Start, false, 1, false)]
  4990. [InlineData ("A sentence has words.\r\nLine 2.", 29, -1, Alignment.Start, false, 1, false, 1)]
  4991. [InlineData ("A sentence has words.\r\nLine 2.", 30, 0, Alignment.Start, false, 1, false)]
  4992. [InlineData ("A sentence has words.\r\nLine 2.", 31, 1, Alignment.Start, false, 1, false)]
  4993. public void Reformat_NoWordrap_NewLines_MultiLine_False (
  4994. string text,
  4995. int maxWidth,
  4996. int widthOffset,
  4997. Alignment alignment,
  4998. bool wrap,
  4999. int linesCount,
  5000. bool stringEmpty,
  5001. int clipWidthOffset = 0
  5002. )
  5003. {
  5004. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5005. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth) + clipWidthOffset;
  5006. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap);
  5007. Assert.NotEmpty (list);
  5008. Assert.True (list.Count == linesCount);
  5009. if (stringEmpty)
  5010. {
  5011. Assert.Equal (string.Empty, list [0]);
  5012. }
  5013. else
  5014. {
  5015. Assert.NotEqual (string.Empty, list [0]);
  5016. }
  5017. if (text.Contains ("\r\n") && maxWidth > 0)
  5018. {
  5019. Assert.Equal (
  5020. StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth])
  5021. .Replace ("\r\n", " "),
  5022. list [0]
  5023. );
  5024. }
  5025. else if (text.Contains ('\n') && maxWidth > 0)
  5026. {
  5027. Assert.Equal (
  5028. StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth])
  5029. .Replace ("\n", " "),
  5030. list [0]
  5031. );
  5032. }
  5033. else
  5034. {
  5035. Assert.Equal (StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth]), list [0]);
  5036. }
  5037. }
  5038. [Theory]
  5039. [InlineData ("A sentence has words.\nLine 2.", 0, -29, Alignment.Start, false, 1, true, new [] { "" })]
  5040. [InlineData (
  5041. "A sentence has words.\nLine 2.",
  5042. 1,
  5043. -28,
  5044. Alignment.Start,
  5045. false,
  5046. 2,
  5047. false,
  5048. new [] { "A", "L" }
  5049. )]
  5050. [InlineData (
  5051. "A sentence has words.\nLine 2.",
  5052. 5,
  5053. -24,
  5054. Alignment.Start,
  5055. false,
  5056. 2,
  5057. false,
  5058. new [] { "A sen", "Line " }
  5059. )]
  5060. [InlineData (
  5061. "A sentence has words.\nLine 2.",
  5062. 28,
  5063. -1,
  5064. Alignment.Start,
  5065. false,
  5066. 2,
  5067. false,
  5068. new [] { "A sentence has words.", "Line 2." }
  5069. )]
  5070. //// no clip
  5071. [InlineData (
  5072. "A sentence has words.\nLine 2.",
  5073. 29,
  5074. 0,
  5075. Alignment.Start,
  5076. false,
  5077. 2,
  5078. false,
  5079. new [] { "A sentence has words.", "Line 2." }
  5080. )]
  5081. [InlineData (
  5082. "A sentence has words.\nLine 2.",
  5083. 30,
  5084. 1,
  5085. Alignment.Start,
  5086. false,
  5087. 2,
  5088. false,
  5089. new [] { "A sentence has words.", "Line 2." }
  5090. )]
  5091. [InlineData ("A sentence has words.\r\nLine 2.", 0, -30, Alignment.Start, false, 1, true, new [] { "" })]
  5092. [InlineData (
  5093. "A sentence has words.\r\nLine 2.",
  5094. 1,
  5095. -29,
  5096. Alignment.Start,
  5097. false,
  5098. 2,
  5099. false,
  5100. new [] { "A", "L" }
  5101. )]
  5102. [InlineData (
  5103. "A sentence has words.\r\nLine 2.",
  5104. 5,
  5105. -25,
  5106. Alignment.Start,
  5107. false,
  5108. 2,
  5109. false,
  5110. new [] { "A sen", "Line " }
  5111. )]
  5112. [InlineData (
  5113. "A sentence has words.\r\nLine 2.",
  5114. 29,
  5115. -1,
  5116. Alignment.Start,
  5117. false,
  5118. 2,
  5119. false,
  5120. new [] { "A sentence has words.", "Line 2." }
  5121. )]
  5122. [InlineData (
  5123. "A sentence has words.\r\nLine 2.",
  5124. 30,
  5125. 0,
  5126. Alignment.Start,
  5127. false,
  5128. 2,
  5129. false,
  5130. new [] { "A sentence has words.", "Line 2." }
  5131. )]
  5132. [InlineData (
  5133. "A sentence has words.\r\nLine 2.",
  5134. 31,
  5135. 1,
  5136. Alignment.Start,
  5137. false,
  5138. 2,
  5139. false,
  5140. new [] { "A sentence has words.", "Line 2." }
  5141. )]
  5142. public void Reformat_NoWordrap_NewLines_MultiLine_True (
  5143. string text,
  5144. int maxWidth,
  5145. int widthOffset,
  5146. Alignment alignment,
  5147. bool wrap,
  5148. int linesCount,
  5149. bool stringEmpty,
  5150. IEnumerable<string> resultLines
  5151. )
  5152. {
  5153. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5154. List<string> list = TextFormatter.Format (
  5155. text,
  5156. maxWidth,
  5157. alignment,
  5158. wrap,
  5159. false,
  5160. 0,
  5161. TextDirection.LeftRight_TopBottom,
  5162. true
  5163. );
  5164. Assert.NotEmpty (list);
  5165. Assert.True (list.Count == linesCount);
  5166. if (stringEmpty)
  5167. {
  5168. Assert.Equal (string.Empty, list [0]);
  5169. }
  5170. else
  5171. {
  5172. Assert.NotEqual (string.Empty, list [0]);
  5173. }
  5174. Assert.Equal (list, resultLines);
  5175. }
  5176. [Theory]
  5177. [InlineData ("A sentence has words.\nLine 2.", 0, -29, Alignment.Start, false, 1, true, new [] { "" })]
  5178. [InlineData (
  5179. "A sentence has words.\nLine 2.",
  5180. 1,
  5181. -28,
  5182. Alignment.Start,
  5183. false,
  5184. 2,
  5185. false,
  5186. new [] { "A", "L" }
  5187. )]
  5188. [InlineData (
  5189. "A sentence has words.\nLine 2.",
  5190. 5,
  5191. -24,
  5192. Alignment.Start,
  5193. false,
  5194. 2,
  5195. false,
  5196. new [] { "A sen", "Line " }
  5197. )]
  5198. [InlineData (
  5199. "A sentence has words.\nLine 2.",
  5200. 28,
  5201. -1,
  5202. Alignment.Start,
  5203. false,
  5204. 2,
  5205. false,
  5206. new [] { "A sentence has words.", "Line 2." }
  5207. )]
  5208. //// no clip
  5209. [InlineData (
  5210. "A sentence has words.\nLine 2.",
  5211. 29,
  5212. 0,
  5213. Alignment.Start,
  5214. false,
  5215. 2,
  5216. false,
  5217. new [] { "A sentence has words.", "Line 2." }
  5218. )]
  5219. [InlineData (
  5220. "A sentence has words.\nLine 2.",
  5221. 30,
  5222. 1,
  5223. Alignment.Start,
  5224. false,
  5225. 2,
  5226. false,
  5227. new [] { "A sentence has words.", "Line 2." }
  5228. )]
  5229. [InlineData ("A sentence has words.\r\nLine 2.", 0, -30, Alignment.Start, false, 1, true, new [] { "" })]
  5230. [InlineData (
  5231. "A sentence has words.\r\nLine 2.",
  5232. 1,
  5233. -29,
  5234. Alignment.Start,
  5235. false,
  5236. 2,
  5237. false,
  5238. new [] { "A", "L" }
  5239. )]
  5240. [InlineData (
  5241. "A sentence has words.\r\nLine 2.",
  5242. 5,
  5243. -25,
  5244. Alignment.Start,
  5245. false,
  5246. 2,
  5247. false,
  5248. new [] { "A sen", "Line " }
  5249. )]
  5250. [InlineData (
  5251. "A sentence has words.\r\nLine 2.",
  5252. 29,
  5253. -1,
  5254. Alignment.Start,
  5255. false,
  5256. 2,
  5257. false,
  5258. new [] { "A sentence has words.", "Line 2." }
  5259. )]
  5260. [InlineData (
  5261. "A sentence has words.\r\nLine 2.",
  5262. 30,
  5263. 0,
  5264. Alignment.Start,
  5265. false,
  5266. 2,
  5267. false,
  5268. new [] { "A sentence has words.", "Line 2." }
  5269. )]
  5270. [InlineData (
  5271. "A sentence has words.\r\nLine 2.",
  5272. 31,
  5273. 1,
  5274. Alignment.Start,
  5275. false,
  5276. 2,
  5277. false,
  5278. new [] { "A sentence has words.", "Line 2." }
  5279. )]
  5280. public void Reformat_NoWordrap_NewLines_MultiLine_True_Vertical (
  5281. string text,
  5282. int maxWidth,
  5283. int widthOffset,
  5284. Alignment alignment,
  5285. bool wrap,
  5286. int linesCount,
  5287. bool stringEmpty,
  5288. IEnumerable<string> resultLines
  5289. )
  5290. {
  5291. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5292. List<string> list = TextFormatter.Format (
  5293. text,
  5294. maxWidth,
  5295. alignment,
  5296. wrap,
  5297. false,
  5298. 0,
  5299. TextDirection.TopBottom_LeftRight,
  5300. true
  5301. );
  5302. Assert.NotEmpty (list);
  5303. Assert.True (list.Count == linesCount);
  5304. if (stringEmpty)
  5305. {
  5306. Assert.Equal (string.Empty, list [0]);
  5307. }
  5308. else
  5309. {
  5310. Assert.NotEqual (string.Empty, list [0]);
  5311. }
  5312. Assert.Equal (list, resultLines);
  5313. }
  5314. [Theory]
  5315. [InlineData ("", 0, 0, Alignment.Start, false, 1, true)]
  5316. [InlineData ("", 1, 1, Alignment.Start, false, 1, true)]
  5317. [InlineData ("A sentence has words.", 0, -21, Alignment.Start, false, 1, true)]
  5318. [InlineData ("A sentence has words.", 1, -20, Alignment.Start, false, 1, false)]
  5319. [InlineData ("A sentence has words.", 5, -16, Alignment.Start, false, 1, false)]
  5320. [InlineData ("A sentence has words.", 20, -1, Alignment.Start, false, 1, false)]
  5321. // no clip
  5322. [InlineData ("A sentence has words.", 21, 0, Alignment.Start, false, 1, false)]
  5323. [InlineData ("A sentence has words.", 22, 1, Alignment.Start, false, 1, false)]
  5324. public void Reformat_NoWordrap_SingleLine (
  5325. string text,
  5326. int maxWidth,
  5327. int widthOffset,
  5328. Alignment alignment,
  5329. bool wrap,
  5330. int linesCount,
  5331. bool stringEmpty
  5332. )
  5333. {
  5334. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5335. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5336. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap);
  5337. Assert.NotEmpty (list);
  5338. Assert.True (list.Count == linesCount);
  5339. if (stringEmpty)
  5340. {
  5341. Assert.Equal (string.Empty, list [0]);
  5342. }
  5343. else
  5344. {
  5345. Assert.NotEqual (string.Empty, list [0]);
  5346. }
  5347. Assert.Equal (StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth]), list [0]);
  5348. }
  5349. [Theory]
  5350. // Unicode
  5351. [InlineData (
  5352. "\u2460\u2461\u2462\n\u2460\u2461\u2462\u2463\u2464",
  5353. 8,
  5354. -1,
  5355. Alignment.Start,
  5356. true,
  5357. false,
  5358. new [] { "\u2460\u2461\u2462", "\u2460\u2461\u2462\u2463\u2464" }
  5359. )]
  5360. // no clip
  5361. [InlineData (
  5362. "\u2460\u2461\u2462\n\u2460\u2461\u2462\u2463\u2464",
  5363. 9,
  5364. 0,
  5365. Alignment.Start,
  5366. true,
  5367. false,
  5368. new [] { "\u2460\u2461\u2462", "\u2460\u2461\u2462\u2463\u2464" }
  5369. )]
  5370. [InlineData (
  5371. "\u2460\u2461\u2462\n\u2460\u2461\u2462\u2463\u2464",
  5372. 10,
  5373. 1,
  5374. Alignment.Start,
  5375. true,
  5376. false,
  5377. new [] { "\u2460\u2461\u2462", "\u2460\u2461\u2462\u2463\u2464" }
  5378. )]
  5379. public void Reformat_Unicode_Wrap_Spaces_NewLines (
  5380. string text,
  5381. int maxWidth,
  5382. int widthOffset,
  5383. Alignment alignment,
  5384. bool wrap,
  5385. bool preserveTrailingSpaces,
  5386. IEnumerable<string> resultLines
  5387. )
  5388. {
  5389. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5390. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
  5391. Assert.Equal (list.Count, resultLines.Count ());
  5392. Assert.Equal (resultLines, list);
  5393. }
  5394. [Theory]
  5395. // Unicode
  5396. // Even # of chars
  5397. // 0123456789
  5398. [InlineData ("\u2660пÑРвРÑ", 10, -1, Alignment.Start, true, false, new [] { "\u2660пÑРвÐ", "Ñ" })]
  5399. // no clip
  5400. [InlineData ("\u2660пÑРвРÑ", 11, 0, Alignment.Start, true, false, new [] { "\u2660пÑРвРÑ" })]
  5401. [InlineData ("\u2660пÑРвРÑ", 12, 1, Alignment.Start, true, false, new [] { "\u2660пÑРвРÑ" })]
  5402. // Unicode
  5403. // Odd # of chars
  5404. // 0123456789
  5405. [InlineData ("\u2660 ÑРвРÑ", 9, -1, Alignment.Start, true, false, new [] { "\u2660 ÑРвÐ", "Ñ" })]
  5406. // no clip
  5407. [InlineData ("\u2660 ÑРвРÑ", 10, 0, Alignment.Start, true, false, new [] { "\u2660 ÑРвРÑ" })]
  5408. [InlineData ("\u2660 ÑРвРÑ", 11, 1, Alignment.Start, true, false, new [] { "\u2660 ÑРвРÑ" })]
  5409. public void Reformat_Unicode_Wrap_Spaces_No_NewLines (
  5410. string text,
  5411. int maxWidth,
  5412. int widthOffset,
  5413. Alignment alignment,
  5414. bool wrap,
  5415. bool preserveTrailingSpaces,
  5416. IEnumerable<string> resultLines
  5417. )
  5418. {
  5419. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5420. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
  5421. Assert.Equal (list.Count, resultLines.Count ());
  5422. Assert.Equal (resultLines, list);
  5423. }
  5424. [Theory]
  5425. // Even # of spaces
  5426. // 0123456789
  5427. [InlineData ("012 456 89", 0, -10, Alignment.Start, true, true, true, new [] { "" })]
  5428. [InlineData (
  5429. "012 456 89",
  5430. 1,
  5431. -9,
  5432. Alignment.Start,
  5433. true,
  5434. true,
  5435. false,
  5436. new [] { "0", "1", "2", " ", "4", "5", "6", " ", "8", "9" },
  5437. "01245689"
  5438. )]
  5439. [InlineData ("012 456 89", 5, -5, Alignment.Start, true, true, false, new [] { "012 ", "456 ", "89" })]
  5440. [InlineData ("012 456 89", 9, -1, Alignment.Start, true, true, false, new [] { "012 456 ", "89" })]
  5441. // no clip
  5442. [InlineData ("012 456 89", 10, 0, Alignment.Start, true, true, false, new [] { "012 456 89" })]
  5443. [InlineData ("012 456 89", 11, 1, Alignment.Start, true, true, false, new [] { "012 456 89" })]
  5444. // Odd # of spaces
  5445. // 01234567890123
  5446. [InlineData ("012 456 89 end", 13, -1, Alignment.Start, true, true, false, new [] { "012 456 89 ", "end" })]
  5447. // no clip
  5448. [InlineData ("012 456 89 end", 14, 0, Alignment.Start, true, true, false, new [] { "012 456 89 end" })]
  5449. [InlineData ("012 456 89 end", 15, 1, Alignment.Start, true, true, false, new [] { "012 456 89 end" })]
  5450. public void Reformat_Wrap_Spaces_No_NewLines (
  5451. string text,
  5452. int maxWidth,
  5453. int widthOffset,
  5454. Alignment alignment,
  5455. bool wrap,
  5456. bool preserveTrailingSpaces,
  5457. bool stringEmpty,
  5458. IEnumerable<string> resultLines,
  5459. string noSpaceText = ""
  5460. )
  5461. {
  5462. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5463. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5464. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
  5465. Assert.NotEmpty (list);
  5466. Assert.True (list.Count == resultLines.Count ());
  5467. if (stringEmpty)
  5468. {
  5469. Assert.Equal (string.Empty, list [0]);
  5470. }
  5471. else
  5472. {
  5473. Assert.NotEqual (string.Empty, list [0]);
  5474. }
  5475. Assert.Equal (resultLines, list);
  5476. if (maxWidth > 0)
  5477. {
  5478. // remove whitespace chars
  5479. if (maxWidth < 5)
  5480. {
  5481. expectedClippedWidth = text.GetRuneCount () - text.Sum (r => r == ' ' ? 1 : 0);
  5482. }
  5483. else
  5484. {
  5485. expectedClippedWidth = Math.Min (
  5486. text.GetRuneCount (),
  5487. maxWidth - text.Sum (r => r == ' ' ? 1 : 0)
  5488. );
  5489. }
  5490. list = TextFormatter.Format (text, maxWidth, Alignment.Start, wrap);
  5491. if (maxWidth == 1)
  5492. {
  5493. Assert.Equal (expectedClippedWidth, list.Count);
  5494. Assert.Equal (noSpaceText, string.Concat (list.ToArray ()));
  5495. }
  5496. if (maxWidth > 1 && maxWidth < 10)
  5497. {
  5498. Assert.Equal (
  5499. StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth]),
  5500. list [0]
  5501. );
  5502. }
  5503. }
  5504. }
  5505. [Theory]
  5506. [InlineData (null)]
  5507. [InlineData ("")]
  5508. [InlineData ("a")]
  5509. public void RemoveHotKeySpecifier_InValid_ReturnsOriginal (string text)
  5510. {
  5511. var hotKeySpecifier = (Rune)'_';
  5512. if (text == null)
  5513. {
  5514. Assert.Null (TextFormatter.RemoveHotKeySpecifier (text, 0, hotKeySpecifier));
  5515. Assert.Null (TextFormatter.RemoveHotKeySpecifier (text, -1, hotKeySpecifier));
  5516. Assert.Null (TextFormatter.RemoveHotKeySpecifier (text, 100, hotKeySpecifier));
  5517. }
  5518. else
  5519. {
  5520. Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, 0, hotKeySpecifier));
  5521. Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, -1, hotKeySpecifier));
  5522. Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, 100, hotKeySpecifier));
  5523. }
  5524. }
  5525. [Theory]
  5526. [InlineData ("all lower case", 0)]
  5527. [InlineData ("K Before", 0)]
  5528. [InlineData ("aK Second", 1)]
  5529. [InlineData ("Last K", 5)]
  5530. [InlineData ("fter K", 7)]
  5531. [InlineData ("Multiple K and R", 9)]
  5532. [InlineData ("Non-english: Кдать", 13)]
  5533. public void RemoveHotKeySpecifier_Valid_Legacy_ReturnsOriginal (string text, int hotPos)
  5534. {
  5535. var hotKeySpecifier = (Rune)'_';
  5536. Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, hotPos, hotKeySpecifier));
  5537. }
  5538. [Theory]
  5539. [InlineData ("_K Before", 0, "K Before")]
  5540. [InlineData ("a_K Second", 1, "aK Second")]
  5541. [InlineData ("Last _K", 5, "Last K")]
  5542. [InlineData ("After K_", 7, "After K")]
  5543. [InlineData ("Multiple _K and _R", 9, "Multiple K and _R")]
  5544. [InlineData ("Non-english: _Кдать", 13, "Non-english: Кдать")]
  5545. public void RemoveHotKeySpecifier_Valid_ReturnsStripped (string text, int hotPos, string expectedText)
  5546. {
  5547. var hotKeySpecifier = (Rune)'_';
  5548. Assert.Equal (expectedText, TextFormatter.RemoveHotKeySpecifier (text, hotPos, hotKeySpecifier));
  5549. }
  5550. [Theory]
  5551. [InlineData ("test", 0, 't', "test")]
  5552. [InlineData ("test", 1, 'e', "test")]
  5553. [InlineData ("Ok", 0, 'O', "Ok")]
  5554. [InlineData ("[◦ Ok ◦]", 3, 'O', "[◦ Ok ◦]")]
  5555. [InlineData ("^k", 0, '^', "^k")]
  5556. public void ReplaceHotKeyWithTag (string text, int hotPos, uint tag, string expected)
  5557. {
  5558. var tf = new TextFormatter ();
  5559. List<Rune> runes = text.ToRuneList ();
  5560. Rune rune;
  5561. if (Rune.TryGetRuneAt (text, hotPos, out rune))
  5562. {
  5563. Assert.Equal (rune, (Rune)tag);
  5564. }
  5565. string result = TextFormatter.ReplaceHotKeyWithTag (text, hotPos);
  5566. Assert.Equal (result, expected);
  5567. Assert.Equal ((Rune)tag, result.ToRunes () [hotPos]);
  5568. Assert.Equal (text.GetRuneCount (), runes.Count);
  5569. Assert.Equal (text, StringExtensions.ToString (runes));
  5570. }
  5571. public static IEnumerable<object []> SplitEnvironmentNewLine =>
  5572. new List<object []>
  5573. {
  5574. new object []
  5575. {
  5576. $"First Line 界{Environment.NewLine}Second Line 界{Environment.NewLine}Third Line 界",
  5577. new [] { "First Line 界", "Second Line 界", "Third Line 界" }
  5578. },
  5579. new object []
  5580. {
  5581. $"First Line 界{Environment.NewLine}Second Line 界{Environment.NewLine}Third Line 界{Environment.NewLine}",
  5582. new [] { "First Line 界", "Second Line 界", "Third Line 界", "" }
  5583. }
  5584. };
  5585. [Theory]
  5586. [MemberData (nameof (SplitEnvironmentNewLine))]
  5587. public void SplitNewLine_Ending__With_Or_Without_NewLine_Probably_CRLF (
  5588. string text,
  5589. IEnumerable<string> expected
  5590. )
  5591. {
  5592. List<string> splited = TextFormatter.SplitNewLine (text);
  5593. Assert.Equal (expected, splited);
  5594. }
  5595. [Theory]
  5596. [InlineData (
  5597. "First Line 界\nSecond Line 界\nThird Line 界\n",
  5598. new [] { "First Line 界", "Second Line 界", "Third Line 界", "" }
  5599. )]
  5600. public void SplitNewLine_Ending_With_NewLine_Only_LF (string text, IEnumerable<string> expected)
  5601. {
  5602. List<string> splited = TextFormatter.SplitNewLine (text);
  5603. Assert.Equal (expected, splited);
  5604. }
  5605. [Theory]
  5606. [InlineData (
  5607. "First Line 界\nSecond Line 界\nThird Line 界",
  5608. new [] { "First Line 界", "Second Line 界", "Third Line 界" }
  5609. )]
  5610. public void SplitNewLine_Ending_Without_NewLine_Only_LF (string text, IEnumerable<string> expected)
  5611. {
  5612. List<string> splited = TextFormatter.SplitNewLine (text);
  5613. Assert.Equal (expected, splited);
  5614. }
  5615. [Theory]
  5616. [InlineData ("New Test 你", 10, 10, 20320, 20320, 9, "你")]
  5617. [InlineData ("New Test \U0001d539", 10, 11, 120121, 55349, 9, "𝔹")]
  5618. public void String_Array_Is_Not_Always_Equal_ToRunes_Array (
  5619. string text,
  5620. int runesLength,
  5621. int stringLength,
  5622. int runeValue,
  5623. int stringValue,
  5624. int index,
  5625. string expected
  5626. )
  5627. {
  5628. Rune [] usToRunes = text.ToRunes ();
  5629. Assert.Equal (runesLength, usToRunes.Length);
  5630. Assert.Equal (stringLength, text.Length);
  5631. Assert.Equal (runeValue, usToRunes [index].Value);
  5632. Assert.Equal (stringValue, text [index]);
  5633. Assert.Equal (expected, usToRunes [index].ToString ());
  5634. if (char.IsHighSurrogate (text [index]))
  5635. {
  5636. // Rune array length isn't equal to string array
  5637. Assert.Equal (expected, new (new [] { text [index], text [index + 1] }));
  5638. }
  5639. else
  5640. {
  5641. // Rune array length is equal to string array
  5642. Assert.Equal (expected, text [index].ToString ());
  5643. }
  5644. }
  5645. [Theory]
  5646. [InlineData (17, 1, TextDirection.LeftRight_TopBottom, 4, "This is a Tab")]
  5647. [InlineData (1, 17, TextDirection.TopBottom_LeftRight, 4, "T\nh\ni\ns\n \ni\ns\n \na\n \n \n \n \n \nT\na\nb")]
  5648. [InlineData (13, 1, TextDirection.LeftRight_TopBottom, 0, "This is a Tab")]
  5649. [InlineData (1, 13, TextDirection.TopBottom_LeftRight, 0, "T\nh\ni\ns\n \ni\ns\n \na\n \nT\na\nb")]
  5650. public void TabWith_PreserveTrailingSpaces_False (
  5651. int width,
  5652. int height,
  5653. TextDirection textDirection,
  5654. int tabWidth,
  5655. string expected
  5656. )
  5657. {
  5658. var driver = new FakeDriver ();
  5659. driver.Init ();
  5660. var text = "This is a \tTab";
  5661. var tf = new TextFormatter ();
  5662. tf.Direction = textDirection;
  5663. tf.TabWidth = tabWidth;
  5664. tf.Text = text;
  5665. tf.ConstrainToWidth = 20;
  5666. tf.ConstrainToHeight = 20;
  5667. Assert.True (tf.WordWrap);
  5668. Assert.False (tf.PreserveTrailingSpaces);
  5669. tf.Draw (
  5670. new (0, 0, width, height),
  5671. new (ColorName16.White, ColorName16.Black),
  5672. new (ColorName16.Blue, ColorName16.Black),
  5673. default (Rectangle),
  5674. driver
  5675. );
  5676. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
  5677. driver.End ();
  5678. }
  5679. [Theory]
  5680. [InlineData (17, 1, TextDirection.LeftRight_TopBottom, 4, "This is a Tab")]
  5681. [InlineData (1, 17, TextDirection.TopBottom_LeftRight, 4, "T\nh\ni\ns\n \ni\ns\n \na\n \n \n \n \n \nT\na\nb")]
  5682. [InlineData (13, 1, TextDirection.LeftRight_TopBottom, 0, "This is a Tab")]
  5683. [InlineData (1, 13, TextDirection.TopBottom_LeftRight, 0, "T\nh\ni\ns\n \ni\ns\n \na\n \nT\na\nb")]
  5684. public void TabWith_PreserveTrailingSpaces_True (
  5685. int width,
  5686. int height,
  5687. TextDirection textDirection,
  5688. int tabWidth,
  5689. string expected
  5690. )
  5691. {
  5692. var driver = new FakeDriver ();
  5693. driver.Init ();
  5694. var text = "This is a \tTab";
  5695. var tf = new TextFormatter ();
  5696. tf.Direction = textDirection;
  5697. tf.TabWidth = tabWidth;
  5698. tf.PreserveTrailingSpaces = true;
  5699. tf.Text = text;
  5700. tf.ConstrainToWidth = 20;
  5701. tf.ConstrainToHeight = 20;
  5702. Assert.True (tf.WordWrap);
  5703. tf.Draw (
  5704. new (0, 0, width, height),
  5705. new (ColorName16.White, ColorName16.Black),
  5706. new (ColorName16.Blue, ColorName16.Black),
  5707. default (Rectangle),
  5708. driver
  5709. );
  5710. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
  5711. driver.End ();
  5712. }
  5713. [Theory]
  5714. [InlineData (17, 1, TextDirection.LeftRight_TopBottom, 4, "This is a Tab")]
  5715. [InlineData (1, 17, TextDirection.TopBottom_LeftRight, 4, "T\nh\ni\ns\n \ni\ns\n \na\n \n \n \n \n \nT\na\nb")]
  5716. [InlineData (13, 1, TextDirection.LeftRight_TopBottom, 0, "This is a Tab")]
  5717. [InlineData (1, 13, TextDirection.TopBottom_LeftRight, 0, "T\nh\ni\ns\n \ni\ns\n \na\n \nT\na\nb")]
  5718. public void TabWith_WordWrap_True (
  5719. int width,
  5720. int height,
  5721. TextDirection textDirection,
  5722. int tabWidth,
  5723. string expected
  5724. )
  5725. {
  5726. var driver = new FakeDriver ();
  5727. driver.Init ();
  5728. var text = "This is a \tTab";
  5729. var tf = new TextFormatter ();
  5730. tf.Direction = textDirection;
  5731. tf.TabWidth = tabWidth;
  5732. tf.WordWrap = true;
  5733. tf.Text = text;
  5734. tf.ConstrainToWidth = 20;
  5735. tf.ConstrainToHeight = 20;
  5736. Assert.False (tf.PreserveTrailingSpaces);
  5737. tf.Draw (
  5738. new (0, 0, width, height),
  5739. new (ColorName16.White, ColorName16.Black),
  5740. new (ColorName16.Blue, ColorName16.Black),
  5741. default (Rectangle),
  5742. driver
  5743. );
  5744. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
  5745. driver.End ();
  5746. }
  5747. [Theory]
  5748. [InlineData ("123456789", 3, "123")]
  5749. [InlineData ("Hello World", 8, "Hello Wo")]
  5750. public void TestClipOrPad_LongWord (string text, int fillPad, string expectedText)
  5751. {
  5752. // word is long but we want it to fill # space only
  5753. Assert.Equal (expectedText, TextFormatter.ClipOrPad (text, fillPad));
  5754. }
  5755. [Theory]
  5756. [InlineData ("fff", 6, "fff ")]
  5757. [InlineData ("Hello World", 16, "Hello World ")]
  5758. public void TestClipOrPad_ShortWord (string text, int fillPad, string expectedText)
  5759. {
  5760. // word is short but we want it to fill # so it should be padded
  5761. Assert.Equal (expectedText, TextFormatter.ClipOrPad (text, fillPad));
  5762. }
  5763. [Theory]
  5764. [InlineData ("你", TextDirection.LeftRight_TopBottom, 2, 1)]
  5765. [InlineData ("你", TextDirection.TopBottom_LeftRight, 2, 1)]
  5766. [InlineData ("你你", TextDirection.LeftRight_TopBottom, 4, 1)]
  5767. [InlineData ("你你", TextDirection.TopBottom_LeftRight, 2, 2)]
  5768. public void Text_Set_SizeIsCorrect (string text, TextDirection textDirection, int expectedWidth, int expectedHeight)
  5769. {
  5770. var tf = new TextFormatter { Direction = textDirection, Text = text };
  5771. tf.ConstrainToWidth = 10;
  5772. tf.ConstrainToHeight = 10;
  5773. Assert.Equal (new (expectedWidth, expectedHeight), tf.FormatAndGetSize ());
  5774. }
  5775. [Fact]
  5776. [SetupFakeDriver]
  5777. public void UICatalog_AboutBox_Text ()
  5778. {
  5779. TextFormatter tf = new ()
  5780. {
  5781. Text = UICatalogApp.GetAboutBoxMessage (),
  5782. Alignment = Alignment.Center,
  5783. VerticalAlignment = Alignment.Start,
  5784. WordWrap = false,
  5785. MultiLine = true,
  5786. HotKeySpecifier = (Rune)0xFFFF
  5787. };
  5788. Size tfSize = tf.FormatAndGetSize ();
  5789. Assert.Equal (new (58, 13), tfSize);
  5790. ((FakeDriver)Application.Driver).SetBufferSize (tfSize.Width, tfSize.Height);
  5791. Application.Driver.FillRect (Application.Screen, (Rune)'*');
  5792. tf.Draw (Application.Screen, Attribute.Default, Attribute.Default);
  5793. var expectedText = """
  5794. ******UI Catalog: A comprehensive sample library for******
  5795. **********************************************************
  5796. _______ _ _ _____ _
  5797. |__ __| (_) | | / ____| (_)
  5798. | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _
  5799. | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
  5800. | | __/ | | | | | | | | | | | (_| | || |__| | |_| | |
  5801. |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
  5802. **********************************************************
  5803. **********************v2 - Pre-Alpha**********************
  5804. **********************************************************
  5805. **********https://github.com/gui-cs/Terminal.Gui**********
  5806. **********************************************************
  5807. """;
  5808. TestHelpers.AssertDriverContentsAre (expectedText.ReplaceLineEndings (), _output);
  5809. }
  5810. [Fact]
  5811. public void WordWrap_BigWidth ()
  5812. {
  5813. List<string> wrappedLines;
  5814. var text = "Constantinople";
  5815. wrappedLines = TextFormatter.WordWrapText (text, 100);
  5816. Assert.True (wrappedLines.Count == 1);
  5817. Assert.Equal ("Constantinople", wrappedLines [0]);
  5818. }
  5819. [Fact]
  5820. public void WordWrap_Invalid ()
  5821. {
  5822. var text = string.Empty;
  5823. var width = 0;
  5824. Assert.Empty (TextFormatter.WordWrapText (null, width));
  5825. Assert.Empty (TextFormatter.WordWrapText (text, width));
  5826. Assert.Throws<ArgumentOutOfRangeException> (() => TextFormatter.WordWrapText (text, -1));
  5827. }
  5828. [Theory]
  5829. [InlineData ("A sentence has words.", 3, -18, new [] { "A", "sen", "ten", "ce", "has", "wor", "ds." })]
  5830. [InlineData (
  5831. "A sentence has words.",
  5832. 2,
  5833. -19,
  5834. new [] { "A", "se", "nt", "en", "ce", "ha", "s", "wo", "rd", "s." }
  5835. )]
  5836. [InlineData (
  5837. "A sentence has words.",
  5838. 1,
  5839. -20,
  5840. new [] { "A", "s", "e", "n", "t", "e", "n", "c", "e", "h", "a", "s", "w", "o", "r", "d", "s", "." }
  5841. )]
  5842. public void WordWrap_Narrow_Default (
  5843. string text,
  5844. int maxWidth,
  5845. int widthOffset,
  5846. IEnumerable<string> resultLines
  5847. )
  5848. {
  5849. // Calls WordWrapText (text, width) and thus preserveTrailingSpaces defaults to false
  5850. List<string> wrappedLines;
  5851. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5852. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5853. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  5854. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  5855. Assert.True (
  5856. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  5857. );
  5858. Assert.True (
  5859. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  5860. );
  5861. Assert.Equal (resultLines, wrappedLines);
  5862. }
  5863. [Theory]
  5864. [InlineData ("A sentence has words.", 21, 0, new [] { "A sentence has words." })]
  5865. [InlineData ("A sentence has words.", 20, -1, new [] { "A sentence has", "words." })]
  5866. [InlineData ("A sentence has words.", 15, -6, new [] { "A sentence has", "words." })]
  5867. [InlineData ("A sentence has words.", 14, -7, new [] { "A sentence has", "words." })]
  5868. [InlineData ("A sentence has words.", 13, -8, new [] { "A sentence", "has words." })]
  5869. // Unicode
  5870. [InlineData (
  5871. "A Unicode sentence (пÑивеÑ) has words.",
  5872. 42,
  5873. 0,
  5874. new [] { "A Unicode sentence (пÑивеÑ) has words." }
  5875. )]
  5876. [InlineData (
  5877. "A Unicode sentence (пÑивеÑ) has words.",
  5878. 41,
  5879. -1,
  5880. new [] { "A Unicode sentence (пÑивеÑ) has", "words." }
  5881. )]
  5882. [InlineData (
  5883. "A Unicode sentence (пÑивеÑ) has words.",
  5884. 36,
  5885. -6,
  5886. new [] { "A Unicode sentence (пÑивеÑ) has", "words." }
  5887. )]
  5888. [InlineData (
  5889. "A Unicode sentence (пÑивеÑ) has words.",
  5890. 35,
  5891. -7,
  5892. new [] { "A Unicode sentence (пÑивеÑ) has", "words." }
  5893. )]
  5894. [InlineData (
  5895. "A Unicode sentence (пÑивеÑ) has words.",
  5896. 34,
  5897. -8,
  5898. new [] { "A Unicode sentence (пÑивеÑ)", "has words." }
  5899. )]
  5900. [InlineData (
  5901. "A Unicode sentence (пÑивеÑ) has words.",
  5902. 25,
  5903. -17,
  5904. new [] { "A Unicode sentence", "(пÑивеÑ) has words." }
  5905. )]
  5906. public void WordWrap_NoNewLines_Default (
  5907. string text,
  5908. int maxWidth,
  5909. int widthOffset,
  5910. IEnumerable<string> resultLines
  5911. )
  5912. {
  5913. // Calls WordWrapText (text, width) and thus preserveTrailingSpaces defaults to false
  5914. List<string> wrappedLines;
  5915. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5916. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5917. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  5918. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  5919. Assert.True (
  5920. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  5921. );
  5922. Assert.True (
  5923. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  5924. );
  5925. Assert.Equal (resultLines, wrappedLines);
  5926. }
  5927. [Theory]
  5928. [InlineData ("これが最初の行です。 こんにちは世界。 これが2行目です。", 29, 0, new [] { "これが最初の行です。", "こんにちは世界。", "これが2行目です。" })]
  5929. public void WordWrap_PreserveTrailingSpaces_False_Unicode_Wide_Runes (
  5930. string text,
  5931. int maxWidth,
  5932. int widthOffset,
  5933. IEnumerable<string> resultLines
  5934. )
  5935. {
  5936. List<string> wrappedLines;
  5937. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5938. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5939. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  5940. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  5941. Assert.True (
  5942. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  5943. );
  5944. Assert.True (
  5945. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  5946. );
  5947. Assert.Equal (resultLines, wrappedLines);
  5948. }
  5949. [Theory]
  5950. [InlineData ("文に は言葉 があり ます。", 14, 0, new [] { "文に は言葉", "があり ます。" })]
  5951. [InlineData ("文に は言葉 があり ます。", 3, -11, new [] { "文", "に", "は", "言", "葉", "が", "あ", "り", "ま", "す", "。" })]
  5952. [InlineData ("文に は言葉 があり ます。", 2, -12, new [] { "文", "に", "は", "言", "葉", "が", "あ", "り", "ま", "す", "。" })]
  5953. [InlineData (
  5954. "文に は言葉 があり ます。",
  5955. 1,
  5956. -13,
  5957. new [] { " ", " ", " " }
  5958. )] // Just Spaces; should result in a single space for each line
  5959. public void WordWrap_PreserveTrailingSpaces_False_Wide_Runes (
  5960. string text,
  5961. int maxWidth,
  5962. int widthOffset,
  5963. IEnumerable<string> resultLines
  5964. )
  5965. {
  5966. List<string> wrappedLines;
  5967. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5968. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5969. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  5970. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  5971. Assert.True (
  5972. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  5973. );
  5974. Assert.True (
  5975. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  5976. );
  5977. Assert.Equal (resultLines, wrappedLines);
  5978. }
  5979. [Theory]
  5980. [InlineData (null, 1, new string [] { })] // null input
  5981. [InlineData ("", 1, new string [] { })] // Empty input
  5982. [InlineData ("1 34", 1, new [] { "1", "3", "4" })] // Single Spaces
  5983. [InlineData ("1", 1, new [] { "1" })] // Short input
  5984. [InlineData ("12", 1, new [] { "1", "2" })]
  5985. [InlineData ("123", 1, new [] { "1", "2", "3" })]
  5986. [InlineData ("123456", 1, new [] { "1", "2", "3", "4", "5", "6" })] // No spaces
  5987. [InlineData (" ", 1, new [] { " " })] // Just Spaces; should result in a single space
  5988. [InlineData (" ", 1, new [] { " " })]
  5989. [InlineData (" ", 1, new [] { " ", " " })]
  5990. [InlineData (" ", 1, new [] { " ", " " })]
  5991. [InlineData ("12 456", 1, new [] { "1", "2", "4", "5", "6" })] // Single Spaces
  5992. [InlineData (" 2 456", 1, new [] { " ", "2", "4", "5", "6" })] // Leading spaces should be preserved.
  5993. [InlineData (" 2 456 8", 1, new [] { " ", "2", "4", "5", "6", "8" })]
  5994. [InlineData (
  5995. "A sentence has words. ",
  5996. 1,
  5997. new [] { "A", "s", "e", "n", "t", "e", "n", "c", "e", "h", "a", "s", "w", "o", "r", "d", "s", "." }
  5998. )] // Complex example
  5999. [InlineData ("12 567", 1, new [] { "1", "2", " ", "5", "6", "7" })] // Double Spaces
  6000. [InlineData (" 3 567", 1, new [] { " ", "3", "5", "6", "7" })] // Double Leading spaces should be preserved.
  6001. [InlineData (" 3 678 1", 1, new [] { " ", "3", " ", "6", "7", "8", " ", "1" })]
  6002. [InlineData ("1 456", 1, new [] { "1", " ", "4", "5", "6" })]
  6003. [InlineData (
  6004. "A sentence has words. ",
  6005. 1,
  6006. new []
  6007. {
  6008. "A", " ", "s", "e", "n", "t", "e", "n", "c", "e", " ", "h", "a", "s", "w", "o", "r", "d", "s", ".", " "
  6009. }
  6010. )] // Double space Complex example
  6011. public void WordWrap_PreserveTrailingSpaces_False_With_Simple_Runes_Width_1 (
  6012. string text,
  6013. int width,
  6014. IEnumerable<string> resultLines
  6015. )
  6016. {
  6017. List<string> wrappedLines = TextFormatter.WordWrapText (text, width);
  6018. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6019. Assert.Equal (resultLines, wrappedLines);
  6020. var breakLines = "";
  6021. foreach (string line in wrappedLines)
  6022. {
  6023. breakLines += $"{line}{Environment.NewLine}";
  6024. }
  6025. var expected = string.Empty;
  6026. foreach (string line in resultLines)
  6027. {
  6028. expected += $"{line}{Environment.NewLine}";
  6029. }
  6030. Assert.Equal (expected, breakLines);
  6031. }
  6032. [Theory]
  6033. [InlineData (null, 3, new string [] { })] // null input
  6034. [InlineData ("", 3, new string [] { })] // Empty input
  6035. [InlineData ("1", 3, new [] { "1" })] // Short input
  6036. [InlineData ("12", 3, new [] { "12" })]
  6037. [InlineData ("123", 3, new [] { "123" })]
  6038. [InlineData ("123456", 3, new [] { "123", "456" })] // No spaces
  6039. [InlineData ("1234567", 3, new [] { "123", "456", "7" })] // No spaces
  6040. [InlineData (" ", 3, new [] { " " })] // Just Spaces; should result in a single space
  6041. [InlineData (" ", 3, new [] { " " })]
  6042. [InlineData (" ", 3, new [] { " " })]
  6043. [InlineData (" ", 3, new [] { " " })]
  6044. [InlineData ("12 456", 3, new [] { "12", "456" })] // Single Spaces
  6045. [InlineData (" 2 456", 3, new [] { " 2", "456" })] // Leading spaces should be preserved.
  6046. [InlineData (" 2 456 8", 3, new [] { " 2", "456", "8" })]
  6047. [InlineData (
  6048. "A sentence has words. ",
  6049. 3,
  6050. new [] { "A", "sen", "ten", "ce", "has", "wor", "ds." }
  6051. )] // Complex example
  6052. [InlineData ("12 567", 3, new [] { "12 ", "567" })] // Double Spaces
  6053. [InlineData (" 3 567", 3, new [] { " 3", "567" })] // Double Leading spaces should be preserved.
  6054. [InlineData (" 3 678 1", 3, new [] { " 3", " 67", "8 ", "1" })]
  6055. [InlineData ("1 456", 3, new [] { "1 ", "456" })]
  6056. [InlineData (
  6057. "A sentence has words. ",
  6058. 3,
  6059. new [] { "A ", "sen", "ten", "ce ", " ", "has", "wor", "ds.", " " }
  6060. )] // Double space Complex example
  6061. public void WordWrap_PreserveTrailingSpaces_False_With_Simple_Runes_Width_3 (
  6062. string text,
  6063. int width,
  6064. IEnumerable<string> resultLines
  6065. )
  6066. {
  6067. List<string> wrappedLines = TextFormatter.WordWrapText (text, width);
  6068. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6069. Assert.Equal (resultLines, wrappedLines);
  6070. var breakLines = "";
  6071. foreach (string line in wrappedLines)
  6072. {
  6073. breakLines += $"{line}{Environment.NewLine}";
  6074. }
  6075. var expected = string.Empty;
  6076. foreach (string line in resultLines)
  6077. {
  6078. expected += $"{line}{Environment.NewLine}";
  6079. }
  6080. Assert.Equal (expected, breakLines);
  6081. }
  6082. [Theory]
  6083. [InlineData (null, 50, new string [] { })] // null input
  6084. [InlineData ("", 50, new string [] { })] // Empty input
  6085. [InlineData ("1", 50, new [] { "1" })] // Short input
  6086. [InlineData ("12", 50, new [] { "12" })]
  6087. [InlineData ("123", 50, new [] { "123" })]
  6088. [InlineData ("123456", 50, new [] { "123456" })] // No spaces
  6089. [InlineData ("1234567", 50, new [] { "1234567" })] // No spaces
  6090. [InlineData (" ", 50, new [] { " " })] // Just Spaces; should result in a single space
  6091. [InlineData (" ", 50, new [] { " " })]
  6092. [InlineData (" ", 50, new [] { " " })]
  6093. [InlineData ("12 456", 50, new [] { "12 456" })] // Single Spaces
  6094. [InlineData (" 2 456", 50, new [] { " 2 456" })] // Leading spaces should be preserved.
  6095. [InlineData (" 2 456 8", 50, new [] { " 2 456 8" })]
  6096. [InlineData ("A sentence has words. ", 50, new [] { "A sentence has words. " })] // Complex example
  6097. [InlineData ("12 567", 50, new [] { "12 567" })] // Double Spaces
  6098. [InlineData (" 3 567", 50, new [] { " 3 567" })] // Double Leading spaces should be preserved.
  6099. [InlineData (" 3 678 1", 50, new [] { " 3 678 1" })]
  6100. [InlineData ("1 456", 50, new [] { "1 456" })]
  6101. [InlineData (
  6102. "A sentence has words. ",
  6103. 50,
  6104. new [] { "A sentence has words. " }
  6105. )] // Double space Complex example
  6106. public void WordWrap_PreserveTrailingSpaces_False_With_Simple_Runes_Width_50 (
  6107. string text,
  6108. int width,
  6109. IEnumerable<string> resultLines
  6110. )
  6111. {
  6112. List<string> wrappedLines = TextFormatter.WordWrapText (text, width);
  6113. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6114. Assert.Equal (resultLines, wrappedLines);
  6115. var breakLines = "";
  6116. foreach (string line in wrappedLines)
  6117. {
  6118. breakLines += $"{line}{Environment.NewLine}";
  6119. }
  6120. var expected = string.Empty;
  6121. foreach (string line in resultLines)
  6122. {
  6123. expected += $"{line}{Environment.NewLine}";
  6124. }
  6125. Assert.Equal (expected, breakLines);
  6126. }
  6127. [Theory]
  6128. [InlineData ("A sentence has words.", 14, -7, new [] { "A sentence ", "has words." })]
  6129. [InlineData ("A sentence has words.", 8, -13, new [] { "A ", "sentence", " has ", "words." })]
  6130. [InlineData ("A sentence has words.", 6, -15, new [] { "A ", "senten", "ce ", "has ", "words." })]
  6131. [InlineData ("A sentence has words.", 3, -18, new [] { "A ", "sen", "ten", "ce ", "has", " ", "wor", "ds." })]
  6132. [InlineData (
  6133. "A sentence has words.",
  6134. 2,
  6135. -19,
  6136. new [] { "A ", "se", "nt", "en", "ce", " ", "ha", "s ", "wo", "rd", "s." }
  6137. )]
  6138. [InlineData (
  6139. "A sentence has words.",
  6140. 1,
  6141. -20,
  6142. new []
  6143. {
  6144. "A", " ", "s", "e", "n", "t", "e", "n", "c", "e", " ", "h", "a", "s", " ", "w", "o", "r", "d", "s", "."
  6145. }
  6146. )]
  6147. public void WordWrap_PreserveTrailingSpaces_True (
  6148. string text,
  6149. int maxWidth,
  6150. int widthOffset,
  6151. IEnumerable<string> resultLines
  6152. )
  6153. {
  6154. List<string> wrappedLines;
  6155. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6156. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6157. wrappedLines = TextFormatter.WordWrapText (text, maxWidth, true);
  6158. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6159. Assert.True (
  6160. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6161. );
  6162. Assert.True (
  6163. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6164. );
  6165. Assert.Equal (resultLines, wrappedLines);
  6166. }
  6167. [Theory]
  6168. [InlineData ("文に は言葉 があり ます。", 14, 0, new [] { "文に は言葉 ", "があり ます。" })]
  6169. [InlineData ("文に は言葉 があり ます。", 3, -11, new [] { "文", "に ", "は", "言", "葉 ", "が", "あ", "り ", "ま", "す", "。" })]
  6170. [InlineData (
  6171. "文に は言葉 があり ます。",
  6172. 2,
  6173. -12,
  6174. new [] { "文", "に", " ", "は", "言", "葉", " ", "が", "あ", "り", " ", "ま", "す", "。" }
  6175. )]
  6176. [InlineData ("文に は言葉 があり ます。", 1, -13, new string [] { })]
  6177. public void WordWrap_PreserveTrailingSpaces_True_Wide_Runes (
  6178. string text,
  6179. int maxWidth,
  6180. int widthOffset,
  6181. IEnumerable<string> resultLines
  6182. )
  6183. {
  6184. List<string> wrappedLines;
  6185. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6186. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6187. wrappedLines = TextFormatter.WordWrapText (text, maxWidth, true);
  6188. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6189. Assert.True (
  6190. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6191. );
  6192. Assert.True (
  6193. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6194. );
  6195. Assert.Equal (resultLines, wrappedLines);
  6196. }
  6197. [Theory]
  6198. [InlineData ("A sentence has words. ", 3, new [] { "A ", "sen", "ten", "ce ", "has", " ", "wor", "ds.", " " })]
  6199. [InlineData (
  6200. "A sentence has words. ",
  6201. 3,
  6202. new [] { "A ", " ", "sen", "ten", "ce ", " ", " ", " ", "has", " ", "wor", "ds.", " " }
  6203. )]
  6204. public void WordWrap_PreserveTrailingSpaces_True_With_Simple_Runes_Width_3 (
  6205. string text,
  6206. int width,
  6207. IEnumerable<string> resultLines
  6208. )
  6209. {
  6210. List<string> wrappedLines = TextFormatter.WordWrapText (text, width, true);
  6211. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6212. Assert.Equal (resultLines, wrappedLines);
  6213. var breakLines = "";
  6214. foreach (string line in wrappedLines)
  6215. {
  6216. breakLines += $"{line}{Environment.NewLine}";
  6217. }
  6218. var expected = string.Empty;
  6219. foreach (string line in resultLines)
  6220. {
  6221. expected += $"{line}{Environment.NewLine}";
  6222. }
  6223. Assert.Equal (expected, breakLines);
  6224. // Double space Complex example - this is how VS 2022 does it
  6225. //text = "A sentence has words. ";
  6226. //breakLines = "";
  6227. //wrappedLines = TextFormatter.WordWrapText (text, width, preserveTrailingSpaces: true);
  6228. //foreach (var line in wrappedLines) {
  6229. // breakLines += $"{line}{Environment.NewLine}";
  6230. //}
  6231. //expected = "A " + Environment.NewLine +
  6232. // " se" + Environment.NewLine +
  6233. // " nt" + Environment.NewLine +
  6234. // " en" + Environment.NewLine +
  6235. // " ce" + Environment.NewLine +
  6236. // " " + Environment.NewLine +
  6237. // " " + Environment.NewLine +
  6238. // " " + Environment.NewLine +
  6239. // " ha" + Environment.NewLine +
  6240. // " s " + Environment.NewLine +
  6241. // " wo" + Environment.NewLine +
  6242. // " rd" + Environment.NewLine +
  6243. // " s." + Environment.NewLine;
  6244. //Assert.Equal (expected, breakLines);
  6245. }
  6246. [Theory]
  6247. [InlineData ("A sentence\t\t\t has words.", 14, -10, new [] { "A sentence\t", "\t\t has ", "words." })]
  6248. [InlineData (
  6249. "A sentence\t\t\t has words.",
  6250. 8,
  6251. -16,
  6252. new [] { "A ", "sentence", "\t\t", "\t ", "has ", "words." }
  6253. )]
  6254. [InlineData (
  6255. "A sentence\t\t\t has words.",
  6256. 3,
  6257. -21,
  6258. new [] { "A ", "sen", "ten", "ce", "\t", "\t", "\t", " ", "has", " ", "wor", "ds." }
  6259. )]
  6260. [InlineData (
  6261. "A sentence\t\t\t has words.",
  6262. 2,
  6263. -22,
  6264. new [] { "A ", "se", "nt", "en", "ce", "\t", "\t", "\t", " ", "ha", "s ", "wo", "rd", "s." }
  6265. )]
  6266. [InlineData (
  6267. "A sentence\t\t\t has words.",
  6268. 1,
  6269. -23,
  6270. new []
  6271. {
  6272. "A",
  6273. " ",
  6274. "s",
  6275. "e",
  6276. "n",
  6277. "t",
  6278. "e",
  6279. "n",
  6280. "c",
  6281. "e",
  6282. "\t",
  6283. "\t",
  6284. "\t",
  6285. " ",
  6286. "h",
  6287. "a",
  6288. "s",
  6289. " ",
  6290. "w",
  6291. "o",
  6292. "r",
  6293. "d",
  6294. "s",
  6295. "."
  6296. }
  6297. )]
  6298. public void WordWrap_PreserveTrailingSpaces_True_With_Tab (
  6299. string text,
  6300. int maxWidth,
  6301. int widthOffset,
  6302. IEnumerable<string> resultLines,
  6303. int tabWidth = 4
  6304. )
  6305. {
  6306. List<string> wrappedLines;
  6307. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6308. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6309. wrappedLines = TextFormatter.WordWrapText (text, maxWidth, true, tabWidth);
  6310. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6311. Assert.True (
  6312. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6313. );
  6314. Assert.True (
  6315. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6316. );
  6317. Assert.Equal (resultLines, wrappedLines);
  6318. }
  6319. [Theory]
  6320. [InlineData ("Constantinople", 14, 0, new [] { "Constantinople" })]
  6321. [InlineData ("Constantinople", 12, -2, new [] { "Constantinop", "le" })]
  6322. [InlineData ("Constantinople", 9, -5, new [] { "Constanti", "nople" })]
  6323. [InlineData ("Constantinople", 7, -7, new [] { "Constan", "tinople" })]
  6324. [InlineData ("Constantinople", 5, -9, new [] { "Const", "antin", "ople" })]
  6325. [InlineData ("Constantinople", 4, -10, new [] { "Cons", "tant", "inop", "le" })]
  6326. [InlineData (
  6327. "Constantinople",
  6328. 1,
  6329. -13,
  6330. new [] { "C", "o", "n", "s", "t", "a", "n", "t", "i", "n", "o", "p", "l", "e" }
  6331. )]
  6332. public void WordWrap_SingleWordLine (
  6333. string text,
  6334. int maxWidth,
  6335. int widthOffset,
  6336. IEnumerable<string> resultLines
  6337. )
  6338. {
  6339. List<string> wrappedLines;
  6340. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6341. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6342. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6343. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6344. Assert.True (
  6345. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6346. );
  6347. Assert.True (
  6348. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6349. );
  6350. Assert.Equal (resultLines, wrappedLines);
  6351. }
  6352. [Theory]
  6353. [InlineData ("This\u00A0is\n\u00A0a\u00A0sentence.", 20, 0, new [] { "This\u00A0is\u00A0a\u00A0sentence." })]
  6354. [InlineData ("This\u00A0is\n\u00A0a\u00A0sentence.", 19, -1, new [] { "This\u00A0is\u00A0a\u00A0sentence." })]
  6355. [InlineData (
  6356. "\u00A0\u00A0\u00A0\u00A0\u00A0test\u00A0sentence.",
  6357. 19,
  6358. 0,
  6359. new [] { "\u00A0\u00A0\u00A0\u00A0\u00A0test\u00A0sentence." }
  6360. )]
  6361. public void WordWrap_Unicode_2LinesWithNonBreakingSpace (
  6362. string text,
  6363. int maxWidth,
  6364. int widthOffset,
  6365. IEnumerable<string> resultLines
  6366. )
  6367. {
  6368. List<string> wrappedLines;
  6369. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6370. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6371. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6372. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6373. Assert.True (
  6374. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6375. );
  6376. Assert.True (
  6377. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6378. );
  6379. Assert.Equal (resultLines, wrappedLines);
  6380. }
  6381. [Theory]
  6382. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 19, 0, new [] { "This\u00A0is\u00A0a\u00A0sentence." })]
  6383. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 18, -1, new [] { "This\u00A0is\u00A0a\u00A0sentence", "." })]
  6384. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 17, -2, new [] { "This\u00A0is\u00A0a\u00A0sentenc", "e." })]
  6385. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 14, -5, new [] { "This\u00A0is\u00A0a\u00A0sent", "ence." })]
  6386. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 10, -9, new [] { "This\u00A0is\u00A0a\u00A0", "sentence." })]
  6387. [InlineData (
  6388. "This\u00A0is\u00A0a\u00A0sentence.",
  6389. 7,
  6390. -12,
  6391. new [] { "This\u00A0is", "\u00A0a\u00A0sent", "ence." }
  6392. )]
  6393. [InlineData (
  6394. "This\u00A0is\u00A0a\u00A0sentence.",
  6395. 5,
  6396. -14,
  6397. new [] { "This\u00A0", "is\u00A0a\u00A0", "sente", "nce." }
  6398. )]
  6399. [InlineData (
  6400. "This\u00A0is\u00A0a\u00A0sentence.",
  6401. 1,
  6402. -18,
  6403. new []
  6404. {
  6405. "T", "h", "i", "s", "\u00A0", "i", "s", "\u00A0", "a", "\u00A0", "s", "e", "n", "t", "e", "n", "c", "e", "."
  6406. }
  6407. )]
  6408. public void WordWrap_Unicode_LineWithNonBreakingSpace (
  6409. string text,
  6410. int maxWidth,
  6411. int widthOffset,
  6412. IEnumerable<string> resultLines
  6413. )
  6414. {
  6415. List<string> wrappedLines;
  6416. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6417. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6418. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6419. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6420. Assert.True (
  6421. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6422. );
  6423. Assert.True (
  6424. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6425. );
  6426. Assert.Equal (resultLines, wrappedLines);
  6427. }
  6428. [Theory]
  6429. [InlineData (
  6430. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6431. 51,
  6432. 0,
  6433. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ" }
  6434. )]
  6435. [InlineData (
  6436. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6437. 50,
  6438. -1,
  6439. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ" }
  6440. )]
  6441. [InlineData (
  6442. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6443. 46,
  6444. -5,
  6445. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮ", "ฯะัาำ" }
  6446. )]
  6447. [InlineData (
  6448. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6449. 26,
  6450. -25,
  6451. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบ", "ปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ" }
  6452. )]
  6453. [InlineData (
  6454. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6455. 17,
  6456. -34,
  6457. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑ", "ฒณดตถทธนบปผฝพฟภมย", "รฤลฦวศษสหฬอฮฯะัาำ" }
  6458. )]
  6459. [InlineData (
  6460. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6461. 13,
  6462. -38,
  6463. new [] { "กขฃคฅฆงจฉชซฌญ", "ฎฏฐฑฒณดตถทธนบ", "ปผฝพฟภมยรฤลฦว", "ศษสหฬอฮฯะัาำ" }
  6464. )]
  6465. [InlineData (
  6466. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6467. 1,
  6468. -50,
  6469. new []
  6470. {
  6471. "ก",
  6472. "ข",
  6473. "ฃ",
  6474. "ค",
  6475. "ฅ",
  6476. "ฆ",
  6477. "ง",
  6478. "จ",
  6479. "ฉ",
  6480. "ช",
  6481. "ซ",
  6482. "ฌ",
  6483. "ญ",
  6484. "ฎ",
  6485. "ฏ",
  6486. "ฐ",
  6487. "ฑ",
  6488. "ฒ",
  6489. "ณ",
  6490. "ด",
  6491. "ต",
  6492. "ถ",
  6493. "ท",
  6494. "ธ",
  6495. "น",
  6496. "บ",
  6497. "ป",
  6498. "ผ",
  6499. "ฝ",
  6500. "พ",
  6501. "ฟ",
  6502. "ภ",
  6503. "ม",
  6504. "ย",
  6505. "ร",
  6506. "ฤ",
  6507. "ล",
  6508. "ฦ",
  6509. "ว",
  6510. "ศ",
  6511. "ษ",
  6512. "ส",
  6513. "ห",
  6514. "ฬ",
  6515. "อ",
  6516. "ฮ",
  6517. "ฯ",
  6518. "ะั",
  6519. "า",
  6520. "ำ"
  6521. }
  6522. )]
  6523. public void WordWrap_Unicode_SingleWordLine (
  6524. string text,
  6525. int maxWidth,
  6526. int widthOffset,
  6527. IEnumerable<string> resultLines
  6528. )
  6529. {
  6530. List<string> wrappedLines;
  6531. IEnumerable<Rune> zeroWidth = text.EnumerateRunes ().Where (r => r.GetColumns () == 0);
  6532. Assert.Single (zeroWidth);
  6533. Assert.Equal ('ั', zeroWidth.ElementAt (0).Value);
  6534. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6535. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6536. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6537. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6538. Assert.True (
  6539. expectedClippedWidth
  6540. >= (wrappedLines.Count > 0
  6541. ? wrappedLines.Max (
  6542. l => l.GetRuneCount ()
  6543. + zeroWidth.Count ()
  6544. - 1
  6545. + widthOffset
  6546. )
  6547. : 0)
  6548. );
  6549. Assert.True (
  6550. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6551. );
  6552. Assert.Equal (resultLines, wrappedLines);
  6553. }
  6554. /// <summary>WordWrap strips CRLF</summary>
  6555. [Theory]
  6556. [InlineData (
  6557. "A sentence has words.\nA paragraph has lines.",
  6558. 44,
  6559. 0,
  6560. new [] { "A sentence has words.A paragraph has lines." }
  6561. )]
  6562. [InlineData (
  6563. "A sentence has words.\nA paragraph has lines.",
  6564. 43,
  6565. -1,
  6566. new [] { "A sentence has words.A paragraph has lines." }
  6567. )]
  6568. [InlineData (
  6569. "A sentence has words.\nA paragraph has lines.",
  6570. 38,
  6571. -6,
  6572. new [] { "A sentence has words.A paragraph has", "lines." }
  6573. )]
  6574. [InlineData (
  6575. "A sentence has words.\nA paragraph has lines.",
  6576. 34,
  6577. -10,
  6578. new [] { "A sentence has words.A paragraph", "has lines." }
  6579. )]
  6580. [InlineData (
  6581. "A sentence has words.\nA paragraph has lines.",
  6582. 27,
  6583. -17,
  6584. new [] { "A sentence has words.A", "paragraph has lines." }
  6585. )]
  6586. // Unicode
  6587. [InlineData (
  6588. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6589. 69,
  6590. 0,
  6591. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт has Линии." }
  6592. )]
  6593. [InlineData (
  6594. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6595. 68,
  6596. -1,
  6597. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт has Линии." }
  6598. )]
  6599. [InlineData (
  6600. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6601. 63,
  6602. -6,
  6603. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт has", "Линии." }
  6604. )]
  6605. [InlineData (
  6606. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6607. 59,
  6608. -10,
  6609. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт", "has Линии." }
  6610. )]
  6611. [InlineData (
  6612. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6613. 52,
  6614. -17,
  6615. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode", "Пункт has Линии." }
  6616. )]
  6617. public void WordWrap_WithNewLines (string text, int maxWidth, int widthOffset, IEnumerable<string> resultLines)
  6618. {
  6619. List<string> wrappedLines;
  6620. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6621. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6622. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6623. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6624. Assert.True (
  6625. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6626. );
  6627. Assert.True (
  6628. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6629. );
  6630. Assert.Equal (resultLines, wrappedLines);
  6631. }
  6632. #region FormatAndGetSizeTests
  6633. // TODO: Add multi-line examples
  6634. // TODO: Add other TextDirection examples
  6635. [Theory]
  6636. [SetupFakeDriver]
  6637. [InlineData ("界1234", 10, 10, TextDirection.LeftRight_TopBottom, 6, 1, @"界1234")]
  6638. [InlineData ("01234", 10, 10, TextDirection.LeftRight_TopBottom, 5, 1, @"01234")]
  6639. [InlineData (
  6640. "界1234",
  6641. 10,
  6642. 10,
  6643. TextDirection.TopBottom_LeftRight,
  6644. 2,
  6645. 5,
  6646. """
  6647. 1
  6648. 2
  6649. 3
  6650. 4
  6651. """)]
  6652. [InlineData (
  6653. "01234",
  6654. 10,
  6655. 10,
  6656. TextDirection.TopBottom_LeftRight,
  6657. 1,
  6658. 5,
  6659. """
  6660. 0
  6661. 1
  6662. 2
  6663. 3
  6664. 4
  6665. """)]
  6666. [InlineData (
  6667. "界1234",
  6668. 3,
  6669. 3,
  6670. TextDirection.LeftRight_TopBottom,
  6671. 3,
  6672. 2,
  6673. """
  6674. 界1
  6675. 234
  6676. """)]
  6677. [InlineData (
  6678. "01234",
  6679. 3,
  6680. 3,
  6681. TextDirection.LeftRight_TopBottom,
  6682. 3,
  6683. 2,
  6684. """
  6685. 012
  6686. 34
  6687. """)]
  6688. [InlineData (
  6689. "界1234",
  6690. 3,
  6691. 3,
  6692. TextDirection.TopBottom_LeftRight,
  6693. 3,
  6694. 3,
  6695. """
  6696. 界3
  6697. 1 4
  6698. 2
  6699. """)]
  6700. [InlineData (
  6701. "01234",
  6702. 3,
  6703. 3,
  6704. TextDirection.TopBottom_LeftRight,
  6705. 2,
  6706. 3,
  6707. """
  6708. 03
  6709. 14
  6710. 2
  6711. """)]
  6712. [InlineData ("01234", 2, 1, TextDirection.LeftRight_TopBottom, 2, 1, @"01")]
  6713. public void FormatAndGetSize_Returns_Correct_Size (
  6714. string text,
  6715. int width,
  6716. int height,
  6717. TextDirection direction,
  6718. int expectedWidth,
  6719. int expectedHeight,
  6720. string expectedDraw
  6721. )
  6722. {
  6723. TextFormatter tf = new ()
  6724. {
  6725. Direction = direction,
  6726. ConstrainToWidth = width,
  6727. ConstrainToHeight = height,
  6728. Text = text
  6729. };
  6730. Assert.True (tf.WordWrap);
  6731. Size size = tf.FormatAndGetSize ();
  6732. Assert.Equal (new (expectedWidth, expectedHeight), size);
  6733. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  6734. TestHelpers.AssertDriverContentsWithFrameAre (expectedDraw, _output);
  6735. }
  6736. [Theory]
  6737. [SetupFakeDriver]
  6738. [InlineData ("界1234", 10, 10, TextDirection.LeftRight_TopBottom, 6, 1, @"界1234")]
  6739. [InlineData ("01234", 10, 10, TextDirection.LeftRight_TopBottom, 5, 1, @"01234")]
  6740. [InlineData (
  6741. "界1234",
  6742. 10,
  6743. 10,
  6744. TextDirection.TopBottom_LeftRight,
  6745. 2,
  6746. 5,
  6747. """
  6748. 1
  6749. 2
  6750. 3
  6751. 4
  6752. """)]
  6753. [InlineData (
  6754. "01234",
  6755. 10,
  6756. 10,
  6757. TextDirection.TopBottom_LeftRight,
  6758. 1,
  6759. 5,
  6760. """
  6761. 0
  6762. 1
  6763. 2
  6764. 3
  6765. 4
  6766. """)]
  6767. [InlineData ("界1234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 1, @"界1")]
  6768. [InlineData ("01234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 1, @"012")]
  6769. [InlineData (
  6770. "界1234",
  6771. 3,
  6772. 3,
  6773. TextDirection.TopBottom_LeftRight,
  6774. 2,
  6775. 3,
  6776. """
  6777. 1
  6778. 2
  6779. """)]
  6780. [InlineData (
  6781. "01234",
  6782. 3,
  6783. 3,
  6784. TextDirection.TopBottom_LeftRight,
  6785. 1,
  6786. 3,
  6787. """
  6788. 0
  6789. 1
  6790. 2
  6791. """)]
  6792. public void FormatAndGetSize_WordWrap_False_Returns_Correct_Size (
  6793. string text,
  6794. int width,
  6795. int height,
  6796. TextDirection direction,
  6797. int expectedWidth,
  6798. int expectedHeight,
  6799. string expectedDraw
  6800. )
  6801. {
  6802. TextFormatter tf = new ()
  6803. {
  6804. Direction = direction,
  6805. ConstrainToSize = new (width, height),
  6806. Text = text,
  6807. WordWrap = false
  6808. };
  6809. Assert.False (tf.WordWrap);
  6810. Size size = tf.FormatAndGetSize ();
  6811. Assert.Equal (new (expectedWidth, expectedHeight), size);
  6812. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  6813. TestHelpers.AssertDriverContentsWithFrameAre (expectedDraw, _output);
  6814. }
  6815. #endregion
  6816. }