TextFormatterTests.cs 207 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221
  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. Toplevel top = new ();
  3833. var view = new View { Y = -2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight, Text = "view" };
  3834. top.Add (view);
  3835. Application.Iteration += (s, a) =>
  3836. {
  3837. Assert.Equal (-2, view.Y);
  3838. Application.RequestStop ();
  3839. };
  3840. try
  3841. {
  3842. Application.Run (top);
  3843. }
  3844. catch (IndexOutOfRangeException ex)
  3845. {
  3846. // After the fix this exception will not be caught.
  3847. Assert.IsType<IndexOutOfRangeException> (ex);
  3848. }
  3849. top.Dispose ();
  3850. // Shutdown must be called to safely clean up Application if Init has been called
  3851. Application.Shutdown ();
  3852. }
  3853. [SetupFakeDriver]
  3854. [Theory]
  3855. [InlineData ("A", 5, 5, "A")]
  3856. [InlineData (
  3857. "AB12",
  3858. 5,
  3859. 5,
  3860. @"
  3861. A
  3862. B
  3863. 1
  3864. 2")]
  3865. [InlineData (
  3866. "AB\n12",
  3867. 5,
  3868. 5,
  3869. @"
  3870. A1
  3871. B2")]
  3872. [InlineData ("", 5, 1, "")]
  3873. [InlineData (
  3874. "Hello Worlds",
  3875. 1,
  3876. 12,
  3877. @"
  3878. H
  3879. e
  3880. l
  3881. l
  3882. o
  3883. W
  3884. o
  3885. r
  3886. l
  3887. d
  3888. s")]
  3889. [InlineData ("Hello Worlds", 12, 1, @"HelloWorlds")]
  3890. public void Draw_Vertical_TopBottom_LeftRight (string text, int width, int height, string expectedText)
  3891. {
  3892. TextFormatter tf = new ()
  3893. {
  3894. Text = text,
  3895. Direction = TextDirection.TopBottom_LeftRight
  3896. };
  3897. tf.ConstrainToWidth = width;
  3898. tf.ConstrainToHeight = height;
  3899. tf.Draw (new (0, 0, 20, 20), Attribute.Default, Attribute.Default);
  3900. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3901. }
  3902. [SetupFakeDriver]
  3903. [Theory]
  3904. // The expectedY param is to probe that the expectedText param start at that Y coordinate
  3905. [InlineData ("A", 0, "", 0)]
  3906. [InlineData ("A", 1, "A", 0)]
  3907. [InlineData ("A", 2, "A", 0)]
  3908. [InlineData ("A", 3, "A", 1)]
  3909. [InlineData ("AB", 1, "A", 0)]
  3910. [InlineData ("AB", 2, "A\nB", 0)]
  3911. [InlineData ("ABC", 2, "A\nB", 0)]
  3912. [InlineData ("ABC", 3, "A\nB\nC", 0)]
  3913. [InlineData ("ABC", 4, "A\nB\nC", 0)]
  3914. [InlineData ("ABC", 5, "A\nB\nC", 1)]
  3915. [InlineData ("ABC", 6, "A\nB\nC", 1)]
  3916. [InlineData ("ABC", 9, "A\nB\nC", 3)]
  3917. [InlineData ("ABCD", 2, "B\nC", 0)]
  3918. [InlineData ("こんにちは", 0, "", 0)]
  3919. [InlineData ("こんにちは", 1, "に", 0)]
  3920. [InlineData ("こんにちは", 2, "ん\nに", 0)]
  3921. [InlineData ("こんにちは", 3, "ん\nに\nち", 0)]
  3922. [InlineData ("こんにちは", 4, "こ\nん\nに\nち", 0)]
  3923. [InlineData ("こんにちは", 5, "こ\nん\nに\nち\nは", 0)]
  3924. [InlineData ("こんにちは", 6, "こ\nん\nに\nち\nは", 0)]
  3925. [InlineData ("ABCD\nこんにちは", 7, "Aこ\nBん\nCに\nDち\n は", 1)]
  3926. [InlineData ("こんにちは\nABCD", 7, "こA\nんB\nにC\nちD\nは ", 1)]
  3927. public void Draw_Vertical_TopBottom_LeftRight_Middle (string text, int height, string expectedText, int expectedY)
  3928. {
  3929. TextFormatter tf = new ()
  3930. {
  3931. Text = text,
  3932. Direction = TextDirection.TopBottom_LeftRight,
  3933. VerticalAlignment = Alignment.Center
  3934. };
  3935. int width = text.ToRunes ().Max (r => r.GetColumns ());
  3936. if (text.Contains ("\n"))
  3937. {
  3938. width++;
  3939. }
  3940. tf.ConstrainToWidth = width;
  3941. tf.ConstrainToHeight = height;
  3942. tf.Draw (new (0, 0, 5, height), Attribute.Default, Attribute.Default);
  3943. Rectangle rect = TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3944. Assert.Equal (expectedY, rect.Y);
  3945. }
  3946. [SetupFakeDriver]
  3947. [Theory]
  3948. [InlineData ("A", 5, "A")]
  3949. [InlineData (
  3950. "AB12",
  3951. 5,
  3952. @"
  3953. A
  3954. B
  3955. 1
  3956. 2")]
  3957. [InlineData (
  3958. "AB\n12",
  3959. 5,
  3960. @"
  3961. A1
  3962. B2")]
  3963. [InlineData ("", 1, "")]
  3964. [InlineData (
  3965. "AB1 2",
  3966. 2,
  3967. @"
  3968. A12
  3969. B ")]
  3970. [InlineData (
  3971. "こんにちは",
  3972. 1,
  3973. @"
  3974. こん")]
  3975. [InlineData (
  3976. "こんにちは",
  3977. 2,
  3978. @"
  3979. こに
  3980. んち")]
  3981. [InlineData (
  3982. "こんにちは",
  3983. 5,
  3984. @"
  3985. は")]
  3986. public void Draw_Vertical_TopBottom_LeftRight_Top (string text, int height, string expectedText)
  3987. {
  3988. TextFormatter tf = new ()
  3989. {
  3990. Text = text,
  3991. Direction = TextDirection.TopBottom_LeftRight
  3992. };
  3993. tf.ConstrainToWidth = 5;
  3994. tf.ConstrainToHeight = height;
  3995. tf.Draw (new (0, 0, 5, height), Attribute.Default, Attribute.Default);
  3996. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  3997. }
  3998. [Theory]
  3999. [InlineData (14, 1, TextDirection.LeftRight_TopBottom, "Les Misęrables")]
  4000. [InlineData (1, 14, TextDirection.TopBottom_LeftRight, "L\ne\ns\n \nM\ni\ns\nę\nr\na\nb\nl\ne\ns")]
  4001. [InlineData (
  4002. 4,
  4003. 4,
  4004. TextDirection.TopBottom_LeftRight,
  4005. @"
  4006. LMre
  4007. eias
  4008. ssb
  4009. ęl "
  4010. )]
  4011. public void Draw_With_Combining_Runes (int width, int height, TextDirection textDirection, string expected)
  4012. {
  4013. var driver = new FakeDriver ();
  4014. driver.Init ();
  4015. var text = "Les Mise\u0328\u0301rables";
  4016. var tf = new TextFormatter ();
  4017. tf.Direction = textDirection;
  4018. tf.Text = text;
  4019. Assert.True (tf.WordWrap);
  4020. tf.ConstrainToSize = new (width, height);
  4021. tf.Draw (
  4022. new (0, 0, width, height),
  4023. new (ColorName.White, ColorName.Black),
  4024. new (ColorName.Blue, ColorName.Black),
  4025. default (Rectangle),
  4026. driver
  4027. );
  4028. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
  4029. driver.End ();
  4030. }
  4031. [Fact]
  4032. [SetupFakeDriver]
  4033. public void FillRemaining_True_False ()
  4034. {
  4035. ((FakeDriver)Application.Driver!).SetBufferSize (22, 5);
  4036. Attribute [] attrs =
  4037. {
  4038. Attribute.Default, new (ColorName.Green, ColorName.BrightMagenta),
  4039. new (ColorName.Blue, ColorName.Cyan)
  4040. };
  4041. var tf = new TextFormatter { ConstrainToSize = new (14, 3), Text = "Test\nTest long\nTest long long\n", MultiLine = true };
  4042. tf.Draw (
  4043. new (1, 1, 19, 3),
  4044. attrs [1],
  4045. attrs [2]);
  4046. Assert.False (tf.FillRemaining);
  4047. TestHelpers.AssertDriverContentsWithFrameAre (
  4048. @"
  4049. Test
  4050. Test long
  4051. Test long long",
  4052. _output);
  4053. TestHelpers.AssertDriverAttributesAre (
  4054. @"
  4055. 000000000000000000000
  4056. 011110000000000000000
  4057. 011111111100000000000
  4058. 011111111111111000000
  4059. 000000000000000000000",
  4060. null,
  4061. attrs);
  4062. tf.FillRemaining = true;
  4063. tf.Draw (
  4064. new (1, 1, 19, 3),
  4065. attrs [1],
  4066. attrs [2]);
  4067. TestHelpers.AssertDriverAttributesAre (
  4068. @"
  4069. 000000000000000000000
  4070. 011111111111111111110
  4071. 011111111111111111110
  4072. 011111111111111111110
  4073. 000000000000000000000",
  4074. null,
  4075. attrs);
  4076. }
  4077. [Theory]
  4078. [InlineData ("_k Before", true, 0, (KeyCode)'K')] // lower case should return uppercase Hotkey
  4079. [InlineData ("a_k Second", true, 1, (KeyCode)'K')]
  4080. [InlineData ("Last _k", true, 5, (KeyCode)'K')]
  4081. [InlineData ("After k_", false, -1, KeyCode.Null)]
  4082. [InlineData ("Multiple _k and _R", true, 9, (KeyCode)'K')]
  4083. [InlineData ("Non-english: _кдать", true, 13, (KeyCode)'к')] // Lower case Cryllic K (к)
  4084. [InlineData ("_k Before", true, 0, (KeyCode)'K', true)] // Turn on FirstUpperCase and verify same results
  4085. [InlineData ("a_k Second", true, 1, (KeyCode)'K', true)]
  4086. [InlineData ("Last _k", true, 5, (KeyCode)'K', true)]
  4087. [InlineData ("After k_", false, -1, KeyCode.Null, true)]
  4088. [InlineData ("Multiple _k and _r", true, 9, (KeyCode)'K', true)]
  4089. [InlineData ("Non-english: _кдать", true, 13, (KeyCode)'к', true)] // Cryllic K (К)
  4090. public void FindHotKey_AlphaLowerCase_Succeeds (
  4091. string text,
  4092. bool expectedResult,
  4093. int expectedHotPos,
  4094. KeyCode expectedKey,
  4095. bool supportFirstUpperCase = false
  4096. )
  4097. {
  4098. var hotKeySpecifier = (Rune)'_';
  4099. bool result = TextFormatter.FindHotKey (
  4100. text,
  4101. hotKeySpecifier,
  4102. out int hotPos,
  4103. out Key hotKey,
  4104. supportFirstUpperCase
  4105. );
  4106. if (expectedResult)
  4107. {
  4108. Assert.True (result);
  4109. }
  4110. else
  4111. {
  4112. Assert.False (result);
  4113. }
  4114. Assert.Equal (expectedResult, result);
  4115. Assert.Equal (expectedHotPos, hotPos);
  4116. Assert.Equal (expectedKey, hotKey);
  4117. }
  4118. [Theory]
  4119. [InlineData ("_K Before", true, 0, (KeyCode)'K')]
  4120. [InlineData ("a_K Second", true, 1, (KeyCode)'K')]
  4121. [InlineData ("Last _K", true, 5, (KeyCode)'K')]
  4122. [InlineData ("After K_", false, -1, KeyCode.Null)]
  4123. [InlineData ("Multiple _K and _R", true, 9, (KeyCode)'K')]
  4124. [InlineData ("Non-english: _Кдать", true, 13, (KeyCode)'К')] // Cryllic K (К)
  4125. [InlineData ("_K Before", true, 0, (KeyCode)'K', true)] // Turn on FirstUpperCase and verify same results
  4126. [InlineData ("a_K Second", true, 1, (KeyCode)'K', true)]
  4127. [InlineData ("Last _K", true, 5, (KeyCode)'K', true)]
  4128. [InlineData ("After K_", false, -1, KeyCode.Null, true)]
  4129. [InlineData ("Multiple _K and _R", true, 9, (KeyCode)'K', true)]
  4130. [InlineData ("Non-english: _Кдать", true, 13, (KeyCode)'К', true)] // Cryllic K (К)
  4131. public void FindHotKey_AlphaUpperCase_Succeeds (
  4132. string text,
  4133. bool expectedResult,
  4134. int expectedHotPos,
  4135. KeyCode expectedKey,
  4136. bool supportFirstUpperCase = false
  4137. )
  4138. {
  4139. var hotKeySpecifier = (Rune)'_';
  4140. bool result = TextFormatter.FindHotKey (
  4141. text,
  4142. hotKeySpecifier,
  4143. out int hotPos,
  4144. out Key hotKey,
  4145. supportFirstUpperCase
  4146. );
  4147. if (expectedResult)
  4148. {
  4149. Assert.True (result);
  4150. }
  4151. else
  4152. {
  4153. Assert.False (result);
  4154. }
  4155. Assert.Equal (expectedResult, result);
  4156. Assert.Equal (expectedHotPos, hotPos);
  4157. Assert.Equal (expectedKey, hotKey);
  4158. }
  4159. [Theory]
  4160. [InlineData (null)]
  4161. [InlineData ("")]
  4162. [InlineData ("no hotkey")]
  4163. [InlineData ("No hotkey, Upper Case")]
  4164. [InlineData ("Non-english: Сохранить")]
  4165. public void FindHotKey_Invalid_ReturnsFalse (string text)
  4166. {
  4167. var hotKeySpecifier = (Rune)'_';
  4168. var supportFirstUpperCase = false;
  4169. var hotPos = 0;
  4170. Key hotKey = KeyCode.Null;
  4171. var result = false;
  4172. result = TextFormatter.FindHotKey (
  4173. text,
  4174. hotKeySpecifier,
  4175. out hotPos,
  4176. out hotKey,
  4177. supportFirstUpperCase
  4178. );
  4179. Assert.False (result);
  4180. Assert.Equal (-1, hotPos);
  4181. Assert.Equal (KeyCode.Null, hotKey);
  4182. }
  4183. [Theory]
  4184. [InlineData ("\"k before")]
  4185. [InlineData ("ak second")]
  4186. [InlineData ("last k")]
  4187. [InlineData ("multiple k and r")]
  4188. [InlineData ("12345")]
  4189. [InlineData ("`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?")] // punctuation
  4190. [InlineData (" ~  s  gui.cs   master ↑10")] // ~IsLetterOrDigit + Unicode
  4191. [InlineData ("non-english: кдать")] // Lower case Cryllic K (к)
  4192. public void FindHotKey_Legacy_FirstUpperCase_NotFound_Returns_False (string text)
  4193. {
  4194. var supportFirstUpperCase = true;
  4195. var hotKeySpecifier = (Rune)0;
  4196. bool result = TextFormatter.FindHotKey (
  4197. text,
  4198. hotKeySpecifier,
  4199. out int hotPos,
  4200. out Key hotKey,
  4201. supportFirstUpperCase
  4202. );
  4203. Assert.False (result);
  4204. Assert.Equal (-1, hotPos);
  4205. Assert.Equal (KeyCode.Null, hotKey);
  4206. }
  4207. [Theory]
  4208. [InlineData ("K Before", true, 0, (KeyCode)'K')]
  4209. [InlineData ("aK Second", true, 1, (KeyCode)'K')]
  4210. [InlineData ("last K", true, 5, (KeyCode)'K')]
  4211. [InlineData ("multiple K and R", true, 9, (KeyCode)'K')]
  4212. [InlineData ("non-english: Кдать", true, 13, (KeyCode)'К')] // Cryllic K (К)
  4213. public void FindHotKey_Legacy_FirstUpperCase_Succeeds (
  4214. string text,
  4215. bool expectedResult,
  4216. int expectedHotPos,
  4217. KeyCode expectedKey
  4218. )
  4219. {
  4220. var supportFirstUpperCase = true;
  4221. var hotKeySpecifier = (Rune)0;
  4222. bool result = TextFormatter.FindHotKey (
  4223. text,
  4224. hotKeySpecifier,
  4225. out int hotPos,
  4226. out Key hotKey,
  4227. supportFirstUpperCase
  4228. );
  4229. if (expectedResult)
  4230. {
  4231. Assert.True (result);
  4232. }
  4233. else
  4234. {
  4235. Assert.False (result);
  4236. }
  4237. Assert.Equal (expectedResult, result);
  4238. Assert.Equal (expectedHotPos, hotPos);
  4239. Assert.Equal (expectedKey, hotKey);
  4240. }
  4241. [Theory]
  4242. [InlineData ("_1 Before", true, 0, (KeyCode)'1')] // Digits
  4243. [InlineData ("a_1 Second", true, 1, (KeyCode)'1')]
  4244. [InlineData ("Last _1", true, 5, (KeyCode)'1')]
  4245. [InlineData ("After 1_", false, -1, KeyCode.Null)]
  4246. [InlineData ("Multiple _1 and _2", true, 9, (KeyCode)'1')]
  4247. [InlineData ("_1 Before", true, 0, (KeyCode)'1', true)] // Turn on FirstUpperCase and verify same results
  4248. [InlineData ("a_1 Second", true, 1, (KeyCode)'1', true)]
  4249. [InlineData ("Last _1", true, 5, (KeyCode)'1', true)]
  4250. [InlineData ("After 1_", false, -1, KeyCode.Null, true)]
  4251. [InlineData ("Multiple _1 and _2", true, 9, (KeyCode)'1', true)]
  4252. public void FindHotKey_Numeric_Succeeds (
  4253. string text,
  4254. bool expectedResult,
  4255. int expectedHotPos,
  4256. KeyCode expectedKey,
  4257. bool supportFirstUpperCase = false
  4258. )
  4259. {
  4260. var hotKeySpecifier = (Rune)'_';
  4261. bool result = TextFormatter.FindHotKey (
  4262. text,
  4263. hotKeySpecifier,
  4264. out int hotPos,
  4265. out Key hotKey,
  4266. supportFirstUpperCase
  4267. );
  4268. if (expectedResult)
  4269. {
  4270. Assert.True (result);
  4271. }
  4272. else
  4273. {
  4274. Assert.False (result);
  4275. }
  4276. Assert.Equal (expectedResult, result);
  4277. Assert.Equal (expectedHotPos, hotPos);
  4278. Assert.Equal (expectedKey, hotKey);
  4279. }
  4280. [Theory]
  4281. [InlineData ("_\"k before", true, (KeyCode)'"')] // BUGBUG: Not sure why this fails. " is a normal char
  4282. [InlineData ("\"_k before", true, KeyCode.K)]
  4283. [InlineData ("_`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?", true, (KeyCode)'`')]
  4284. [InlineData ("`_~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?", true, (KeyCode)'~')]
  4285. [InlineData (
  4286. "`~!@#$%^&*()-__=+[{]}\\|;:'\",<.>/?",
  4287. true,
  4288. (KeyCode)'='
  4289. )] // BUGBUG: Not sure why this fails. Ignore the first and consider the second
  4290. [InlineData ("_ ~  s  gui.cs   master ↑10", true, (KeyCode)'')] // ~IsLetterOrDigit + Unicode
  4291. [InlineData (" ~  s  gui.cs  _ master ↑10", true, (KeyCode)'')] // ~IsLetterOrDigit + Unicode
  4292. [InlineData ("non-english: _кдать", true, (KeyCode)'к')] // Lower case Cryllic K (к)
  4293. public void FindHotKey_Symbols_Returns_Symbol (string text, bool found, KeyCode expected)
  4294. {
  4295. var hotKeySpecifier = (Rune)'_';
  4296. bool result = TextFormatter.FindHotKey (text, hotKeySpecifier, out int _, out Key hotKey);
  4297. Assert.Equal (found, result);
  4298. Assert.Equal (expected, hotKey);
  4299. }
  4300. [Fact]
  4301. public void Format_Dont_Throw_ArgumentException_With_WordWrap_As_False_And_Keep_End_Spaces_As_True ()
  4302. {
  4303. Exception exception = Record.Exception (
  4304. () =>
  4305. TextFormatter.Format (
  4306. "Some text",
  4307. 4,
  4308. Alignment.Start,
  4309. false,
  4310. true
  4311. )
  4312. );
  4313. Assert.Null (exception);
  4314. }
  4315. [Theory]
  4316. [InlineData (
  4317. "Hello world, how are you today? Pretty neat!",
  4318. 44,
  4319. 80,
  4320. "Hello world, how are you today? Pretty neat!"
  4321. )]
  4322. public void Format_Justified_Always_Returns_Text_Width_Equal_To_Passed_Width_Horizontal (
  4323. string text,
  4324. int runeCount,
  4325. int maxWidth,
  4326. string justifiedText
  4327. )
  4328. {
  4329. Assert.Equal (runeCount, text.GetRuneCount ());
  4330. var fmtText = string.Empty;
  4331. for (int i = text.GetRuneCount (); i < maxWidth; i++)
  4332. {
  4333. fmtText = TextFormatter.Format (text, i, Alignment.Fill, true) [0];
  4334. Assert.Equal (i, fmtText.GetRuneCount ());
  4335. char c = fmtText [^1];
  4336. Assert.True (text.EndsWith (c));
  4337. }
  4338. Assert.Equal (justifiedText, fmtText);
  4339. }
  4340. [Theory]
  4341. [InlineData (
  4342. "Hello world, how are you today? Pretty neat!",
  4343. 44,
  4344. 80,
  4345. "Hello world, how are you today? Pretty neat!"
  4346. )]
  4347. public void Format_Justified_Always_Returns_Text_Width_Equal_To_Passed_Width_Vertical (
  4348. string text,
  4349. int runeCount,
  4350. int maxWidth,
  4351. string justifiedText
  4352. )
  4353. {
  4354. Assert.Equal (runeCount, text.GetRuneCount ());
  4355. var fmtText = string.Empty;
  4356. for (int i = text.GetRuneCount (); i < maxWidth; i++)
  4357. {
  4358. fmtText = TextFormatter.Format (
  4359. text,
  4360. i,
  4361. Alignment.Fill,
  4362. false,
  4363. true,
  4364. 0,
  4365. TextDirection.TopBottom_LeftRight
  4366. ) [0];
  4367. Assert.Equal (i, fmtText.GetRuneCount ());
  4368. char c = fmtText [^1];
  4369. Assert.True (text.EndsWith (c));
  4370. }
  4371. Assert.Equal (justifiedText, fmtText);
  4372. }
  4373. [Theory]
  4374. [InlineData ("Truncate", 3, "Tru")]
  4375. [InlineData ("デモエムポンズ", 3, "デ")]
  4376. public void Format_Truncate_Simple_And_Wide_Runes (string text, int width, string expected)
  4377. {
  4378. List<string> list = TextFormatter.Format (text, width, false, false);
  4379. Assert.Equal (expected, list [^1]);
  4380. }
  4381. [Theory]
  4382. [MemberData (nameof (FormatEnvironmentNewLine))]
  4383. public void Format_With_PreserveTrailingSpaces_And_Without_PreserveTrailingSpaces (
  4384. string text,
  4385. int width,
  4386. IEnumerable<string> expected
  4387. )
  4388. {
  4389. var preserveTrailingSpaces = false;
  4390. List<string> formated = TextFormatter.Format (text, width, false, true, preserveTrailingSpaces);
  4391. Assert.Equal (expected, formated);
  4392. preserveTrailingSpaces = true;
  4393. formated = TextFormatter.Format (text, width, false, true, preserveTrailingSpaces);
  4394. Assert.Equal (expected, formated);
  4395. }
  4396. [Theory]
  4397. [InlineData (
  4398. " A sentence has words. \n This is the second Line - 2. ",
  4399. 4,
  4400. -50,
  4401. Alignment.Start,
  4402. true,
  4403. false,
  4404. new [] { " A", "sent", "ence", "has", "word", "s. ", " Thi", "s is", "the", "seco", "nd", "Line", "- 2." },
  4405. " Asentencehaswords. This isthesecondLine- 2."
  4406. )]
  4407. [InlineData (
  4408. " A sentence has words. \n This is the second Line - 2. ",
  4409. 4,
  4410. -50,
  4411. Alignment.Start,
  4412. true,
  4413. true,
  4414. new []
  4415. {
  4416. " A ",
  4417. "sent",
  4418. "ence",
  4419. " ",
  4420. "has ",
  4421. "word",
  4422. "s. ",
  4423. " ",
  4424. "This",
  4425. " is ",
  4426. "the ",
  4427. "seco",
  4428. "nd ",
  4429. "Line",
  4430. " - ",
  4431. "2. "
  4432. },
  4433. " A sentence has words. This is the second Line - 2. "
  4434. )]
  4435. public void Format_WordWrap_PreserveTrailingSpaces (
  4436. string text,
  4437. int maxWidth,
  4438. int widthOffset,
  4439. Alignment alignment,
  4440. bool wrap,
  4441. bool preserveTrailingSpaces,
  4442. IEnumerable<string> resultLines,
  4443. string expectedWrappedText
  4444. )
  4445. {
  4446. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  4447. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
  4448. Assert.Equal (list.Count, resultLines.Count ());
  4449. Assert.Equal (resultLines, list);
  4450. var wrappedText = string.Empty;
  4451. foreach (string txt in list)
  4452. {
  4453. wrappedText += txt;
  4454. }
  4455. Assert.Equal (expectedWrappedText, wrappedText);
  4456. }
  4457. public static IEnumerable<object []> FormatEnvironmentNewLine =>
  4458. new List<object []>
  4459. {
  4460. new object []
  4461. {
  4462. $"Line1{Environment.NewLine}Line2{Environment.NewLine}Line3{Environment.NewLine}",
  4463. 60,
  4464. new [] { "Line1", "Line2", "Line3" }
  4465. }
  4466. };
  4467. [Theory]
  4468. [InlineData ("Hello World", 11)]
  4469. [InlineData ("こんにちは世界", 14)]
  4470. public void GetColumns_Simple_And_Wide_Runes (string text, int width) { Assert.Equal (width, text.GetColumns ()); }
  4471. [Theory]
  4472. [InlineData (new [] { "0123456789" }, 1)]
  4473. [InlineData (new [] { "Hello World" }, 1)]
  4474. [InlineData (new [] { "Hello", "World" }, 2)]
  4475. [InlineData (new [] { "こんにちは", "世界" }, 4)]
  4476. public void GetColumnsRequiredForVerticalText_List_GetsWidth (IEnumerable<string> text, int expectedWidth)
  4477. {
  4478. Assert.Equal (expectedWidth, TextFormatter.GetColumnsRequiredForVerticalText (text.ToList ()));
  4479. }
  4480. [Theory]
  4481. [InlineData (new [] { "Hello World" }, 1, 0, 1, 1)]
  4482. [InlineData (new [] { "Hello", "World" }, 2, 1, 1, 1)]
  4483. [InlineData (new [] { "こんにちは", "世界" }, 4, 1, 1, 2)]
  4484. public void GetColumnsRequiredForVerticalText_List_Simple_And_Wide_Runes (
  4485. IEnumerable<string> text,
  4486. int expectedWidth,
  4487. int index,
  4488. int length,
  4489. int expectedIndexWidth
  4490. )
  4491. {
  4492. Assert.Equal (expectedWidth, TextFormatter.GetColumnsRequiredForVerticalText (text.ToList ()));
  4493. Assert.Equal (expectedIndexWidth, TextFormatter.GetColumnsRequiredForVerticalText (text.ToList (), index, length));
  4494. }
  4495. [Fact]
  4496. public void GetColumnsRequiredForVerticalText_List_With_Combining_Runes ()
  4497. {
  4498. List<string> text = new () { "Les Mis", "e\u0328\u0301", "rables" };
  4499. Assert.Equal (1, TextFormatter.GetColumnsRequiredForVerticalText (text, 1, 1));
  4500. }
  4501. [Theory]
  4502. [InlineData ("Hello World", 6, 6)]
  4503. [InlineData ("こんにちは 世界", 6, 3)]
  4504. [MemberData (nameof (CMGlyphs))]
  4505. public void GetLengthThatFits_List_Simple_And_Wide_Runes (string text, int columns, int expectedLength)
  4506. {
  4507. List<Rune> runes = text.ToRuneList ();
  4508. Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (runes, columns));
  4509. }
  4510. [Theory]
  4511. [InlineData ("test", 3, 3)]
  4512. [InlineData ("test", 4, 4)]
  4513. [InlineData ("test", 10, 4)]
  4514. public void GetLengthThatFits_Runelist (string text, int columns, int expectedLength)
  4515. {
  4516. List<Rune> runes = text.ToRuneList ();
  4517. Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (runes, columns));
  4518. }
  4519. [Theory]
  4520. [InlineData ("Hello World", 6, 6)]
  4521. [InlineData ("こんにちは 世界", 6, 3)]
  4522. public void GetLengthThatFits_Simple_And_Wide_Runes (string text, int columns, int expectedLength)
  4523. {
  4524. Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (text, columns));
  4525. }
  4526. [Theory]
  4527. [InlineData ("test", 3, 3)]
  4528. [InlineData ("test", 4, 4)]
  4529. [InlineData ("test", 10, 4)]
  4530. [InlineData ("test", 1, 1)]
  4531. [InlineData ("test", 0, 0)]
  4532. [InlineData ("test", -1, 0)]
  4533. [InlineData (null, -1, 0)]
  4534. [InlineData ("", -1, 0)]
  4535. public void GetLengthThatFits_String (string text, int columns, int expectedLength)
  4536. {
  4537. Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (text, columns));
  4538. }
  4539. [Fact]
  4540. public void GetLengthThatFits_With_Combining_Runes ()
  4541. {
  4542. var text = "Les Mise\u0328\u0301rables";
  4543. Assert.Equal (16, TextFormatter.GetLengthThatFits (text, 14));
  4544. }
  4545. [Fact]
  4546. public void GetMaxColsForWidth_With_Combining_Runes ()
  4547. {
  4548. List<string> text = new () { "Les Mis", "e\u0328\u0301", "rables" };
  4549. Assert.Equal (1, TextFormatter.GetMaxColsForWidth (text, 1));
  4550. }
  4551. //[Fact]
  4552. //public void GetWidestLineLength_With_Combining_Runes ()
  4553. //{
  4554. // var text = "Les Mise\u0328\u0301rables";
  4555. // Assert.Equal (1, TextFormatter.GetWidestLineLength (text, 1, 1));
  4556. //}
  4557. [Fact]
  4558. public void Internal_Tests ()
  4559. {
  4560. var tf = new TextFormatter ();
  4561. Assert.Equal (KeyCode.Null, tf.HotKey);
  4562. tf.HotKey = KeyCode.CtrlMask | KeyCode.Q;
  4563. Assert.Equal (KeyCode.CtrlMask | KeyCode.Q, tf.HotKey);
  4564. }
  4565. [SetupFakeDriver]
  4566. [Theory]
  4567. [InlineData ("Hello World", 15, 1, "Hello World")]
  4568. [InlineData (
  4569. "Well Done\nNice Work",
  4570. 15,
  4571. 2,
  4572. @"
  4573. Well Done
  4574. Nice Work")]
  4575. [InlineData ("你好 世界", 15, 1, "你好 世界")]
  4576. [InlineData (
  4577. "做 得好\n幹 得好",
  4578. 15,
  4579. 2,
  4580. @"
  4581. 做 得好
  4582. 幹 得好")]
  4583. public void Justify_Horizontal (string text, int width, int height, string expectedText)
  4584. {
  4585. TextFormatter tf = new ()
  4586. {
  4587. Text = text,
  4588. Alignment = Alignment.Fill,
  4589. ConstrainToSize = new Size (width, height),
  4590. MultiLine = true
  4591. };
  4592. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  4593. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  4594. }
  4595. [Theory]
  4596. [InlineData ("")]
  4597. [InlineData (null)]
  4598. [InlineData ("test")]
  4599. public void Justify_Invalid (string text)
  4600. {
  4601. Assert.Equal (text, TextFormatter.Justify (text, 0));
  4602. Assert.Equal (text, TextFormatter.Justify (text, 0));
  4603. Assert.Throws<ArgumentOutOfRangeException> (() => TextFormatter.Justify (text, -1));
  4604. }
  4605. [Theory]
  4606. // Even # of spaces
  4607. // 0123456789
  4608. [InlineData ("012 456 89", "012 456 89", 10, 0, "+", true)]
  4609. [InlineData ("012 456 89", "012++456+89", 11, 1)]
  4610. [InlineData ("012 456 89", "012 456 89", 12, 2, "++", true)]
  4611. [InlineData ("012 456 89", "012+++456++89", 13, 3)]
  4612. [InlineData ("012 456 89", "012 456 89", 14, 4, "+++", true)]
  4613. [InlineData ("012 456 89", "012++++456+++89", 15, 5)]
  4614. [InlineData ("012 456 89", "012 456 89", 16, 6, "++++", true)]
  4615. [InlineData ("012 456 89", "012 456 89", 30, 20, "+++++++++++", true)]
  4616. [InlineData ("012 456 89", "012+++++++++++++456++++++++++++89", 33, 23)]
  4617. // Odd # of spaces
  4618. // 01234567890123
  4619. [InlineData ("012 456 89 end", "012 456 89 end", 14, 0, "+", true)]
  4620. [InlineData ("012 456 89 end", "012++456+89+end", 15, 1)]
  4621. [InlineData ("012 456 89 end", "012++456++89+end", 16, 2)]
  4622. [InlineData ("012 456 89 end", "012 456 89 end", 17, 3, "++", true)]
  4623. [InlineData ("012 456 89 end", "012+++456++89++end", 18, 4)]
  4624. [InlineData ("012 456 89 end", "012+++456+++89++end", 19, 5)]
  4625. [InlineData ("012 456 89 end", "012 456 89 end", 20, 6, "+++", true)]
  4626. [InlineData ("012 456 89 end", "012++++++++456++++++++89+++++++end", 34, 20)]
  4627. [InlineData ("012 456 89 end", "012+++++++++456+++++++++89++++++++end", 37, 23)]
  4628. // Unicode
  4629. // Even # of chars
  4630. // 0123456789
  4631. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 10, 0, "+", true)]
  4632. [InlineData ("пÑРвРÑ", "пÑÐ++вÐ+Ñ", 11, 1)]
  4633. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 12, 2, "++", true)]
  4634. [InlineData ("пÑРвРÑ", "пÑÐ+++вÐ++Ñ", 13, 3)]
  4635. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 14, 4, "+++", true)]
  4636. [InlineData ("пÑРвРÑ", "пÑÐ++++вÐ+++Ñ", 15, 5)]
  4637. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 16, 6, "++++", true)]
  4638. [InlineData ("пÑРвРÑ", "пÑРвРÑ", 30, 20, "+++++++++++", true)]
  4639. [InlineData ("пÑРвРÑ", "пÑÐ+++++++++++++вÐ++++++++++++Ñ", 33, 23)]
  4640. // Unicode
  4641. // Odd # of chars
  4642. // 0123456789
  4643. [InlineData ("Ð ÑРвРÑ", "Ð ÑРвРÑ", 10, 0, "+", true)]
  4644. [InlineData ("Ð ÑРвРÑ", "Ð++ÑÐ+вÐ+Ñ", 11, 1)]
  4645. [InlineData ("Ð ÑРвРÑ", "Ð++ÑÐ++вÐ+Ñ", 12, 2)]
  4646. [InlineData ("Ð ÑРвРÑ", "Ð ÑРвРÑ", 13, 3, "++", true)]
  4647. [InlineData ("Ð ÑРвРÑ", "Ð+++ÑÐ++вÐ++Ñ", 14, 4)]
  4648. [InlineData ("Ð ÑРвРÑ", "Ð+++ÑÐ+++вÐ++Ñ", 15, 5)]
  4649. [InlineData ("Ð ÑРвРÑ", "Ð ÑРвРÑ", 16, 6, "+++", true)]
  4650. [InlineData ("Ð ÑРвРÑ", "Ð++++++++ÑÐ++++++++вÐ+++++++Ñ", 30, 20)]
  4651. [InlineData ("Ð ÑРвРÑ", "Ð+++++++++ÑÐ+++++++++вÐ++++++++Ñ", 33, 23)]
  4652. public void Justify_Sentence (
  4653. string text,
  4654. string justifiedText,
  4655. int forceToWidth,
  4656. int widthOffset,
  4657. string replaceWith = null,
  4658. bool replace = false
  4659. )
  4660. {
  4661. var fillChar = '+';
  4662. Assert.Equal (forceToWidth, text.GetRuneCount () + widthOffset);
  4663. if (replace)
  4664. {
  4665. justifiedText = text.Replace (" ", replaceWith);
  4666. }
  4667. Assert.Equal (justifiedText, TextFormatter.Justify (text, forceToWidth, fillChar));
  4668. Assert.True (Math.Abs (forceToWidth - justifiedText.GetRuneCount ()) < text.Count (s => s == ' '));
  4669. Assert.True (Math.Abs (forceToWidth - justifiedText.GetColumns ()) < text.Count (s => s == ' '));
  4670. }
  4671. [Theory]
  4672. [InlineData ("word")] // Even # of chars
  4673. [InlineData ("word.")] // Odd # of chars
  4674. [InlineData ("пÑивеÑ")] // Unicode (even #)
  4675. [InlineData ("пÑивеÑ.")] // Unicode (odd # of chars)
  4676. public void Justify_SingleWord (string text)
  4677. {
  4678. string justifiedText = text;
  4679. var fillChar = '+';
  4680. int width = text.GetRuneCount ();
  4681. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4682. width = text.GetRuneCount () + 1;
  4683. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4684. width = text.GetRuneCount () + 2;
  4685. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4686. width = text.GetRuneCount () + 10;
  4687. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4688. width = text.GetRuneCount () + 11;
  4689. Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
  4690. }
  4691. [SetupFakeDriver]
  4692. [Theory]
  4693. [InlineData ("Hello World", 1, 15, "H\ne\nl\nl\no\n \n \n \n \n \nW\no\nr\nl\nd")]
  4694. [InlineData (
  4695. "Well Done\nNice Work",
  4696. 2,
  4697. 15,
  4698. @"
  4699. WN
  4700. ei
  4701. lc
  4702. le
  4703. DW
  4704. oo
  4705. nr
  4706. ek")]
  4707. [InlineData ("你好 世界", 2, 15, "你\n好\n \n \n \n \n \n \n \n \n \n \n \n世\n界")]
  4708. [InlineData (
  4709. "做 得好\n幹 得好",
  4710. 4,
  4711. 15,
  4712. @"
  4713. 做幹
  4714. 得得
  4715. 好好")]
  4716. public void Justify_Vertical (string text, int width, int height, string expectedText)
  4717. {
  4718. TextFormatter tf = new ()
  4719. {
  4720. Text = text,
  4721. Direction = TextDirection.TopBottom_LeftRight,
  4722. VerticalAlignment = Alignment.Fill,
  4723. ConstrainToSize = new Size (width, height),
  4724. MultiLine = true
  4725. };
  4726. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  4727. TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
  4728. }
  4729. [Theory]
  4730. [InlineData ("Single Line 界", 14)]
  4731. [InlineData ("First Line 界\nSecond Line 界\nThird Line 界\n", 14)]
  4732. public void MaxWidthLine_With_And_Without_Newlines (string text, int expected) { Assert.Equal (expected, TextFormatter.GetWidestLineLength (text)); }
  4733. [Theory]
  4734. [InlineData (
  4735. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4736. 0,
  4737. 0,
  4738. false,
  4739. new [] { "" }
  4740. )]
  4741. [InlineData (
  4742. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4743. 0,
  4744. 1,
  4745. false,
  4746. new [] { "" }
  4747. )]
  4748. [InlineData (
  4749. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4750. 1,
  4751. 0,
  4752. false,
  4753. new [] { "" }
  4754. )]
  4755. [InlineData (
  4756. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4757. 0,
  4758. 0,
  4759. true,
  4760. new [] { "" }
  4761. )]
  4762. [InlineData (
  4763. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4764. 0,
  4765. 1,
  4766. true,
  4767. new [] { "" }
  4768. )]
  4769. [InlineData (
  4770. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4771. 1,
  4772. 0,
  4773. true,
  4774. new [] { "" }
  4775. )]
  4776. [InlineData (
  4777. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4778. 6,
  4779. 5,
  4780. false,
  4781. new [] { "First " }
  4782. )]
  4783. [InlineData ("1\n2\n3\n4\n5\n6", 6, 5, false, new [] { "1 2 3 " })]
  4784. [InlineData (
  4785. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4786. 6,
  4787. 5,
  4788. true,
  4789. new [] { "First ", "Second", "Third ", "Forty ", "Fiftee" }
  4790. )]
  4791. [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, false, new [] { "第一" })]
  4792. [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, true, new [] { "第一", "第二", "第三", "四十", "第十" })]
  4793. public void MultiLine_WordWrap_False_Horizontal_Direction (
  4794. string text,
  4795. int maxWidth,
  4796. int maxHeight,
  4797. bool multiLine,
  4798. IEnumerable<string> resultLines
  4799. )
  4800. {
  4801. var tf = new TextFormatter
  4802. {
  4803. Text = text, ConstrainToSize = new (maxWidth, maxHeight), WordWrap = false, MultiLine = multiLine
  4804. };
  4805. Assert.False (tf.WordWrap);
  4806. Assert.True (tf.MultiLine == multiLine);
  4807. Assert.Equal (TextDirection.LeftRight_TopBottom, tf.Direction);
  4808. List<string> splitLines = tf.GetLines ();
  4809. Assert.Equal (splitLines.Count, resultLines.Count ());
  4810. Assert.Equal (splitLines, resultLines);
  4811. }
  4812. [Theory]
  4813. [InlineData (
  4814. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4815. 0,
  4816. 0,
  4817. false,
  4818. new [] { "" }
  4819. )]
  4820. [InlineData (
  4821. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4822. 0,
  4823. 1,
  4824. false,
  4825. new [] { "" }
  4826. )]
  4827. [InlineData (
  4828. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4829. 1,
  4830. 0,
  4831. false,
  4832. new [] { "" }
  4833. )]
  4834. [InlineData (
  4835. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4836. 0,
  4837. 0,
  4838. true,
  4839. new [] { "" }
  4840. )]
  4841. [InlineData (
  4842. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4843. 0,
  4844. 1,
  4845. true,
  4846. new [] { "" }
  4847. )]
  4848. [InlineData (
  4849. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4850. 1,
  4851. 0,
  4852. true,
  4853. new [] { "" }
  4854. )]
  4855. [InlineData (
  4856. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4857. 6,
  4858. 5,
  4859. false,
  4860. new [] { "First" }
  4861. )]
  4862. [InlineData ("1\n2\n3\n4\n5\n6", 6, 5, false, new [] { "1 2 3" })]
  4863. [InlineData (
  4864. "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
  4865. 6,
  4866. 5,
  4867. true,
  4868. new [] { "First", "Secon", "Third", "Forty", "Fifte", "Seven" }
  4869. )]
  4870. [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, false, new [] { "第一行 第" })]
  4871. [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, true, new [] { "第一行", "第二行" })]
  4872. public void MultiLine_WordWrap_False_Vertical_Direction (
  4873. string text,
  4874. int maxWidth,
  4875. int maxHeight,
  4876. bool multiLine,
  4877. IEnumerable<string> resultLines
  4878. )
  4879. {
  4880. var tf = new TextFormatter
  4881. {
  4882. Text = text,
  4883. ConstrainToSize = new (maxWidth, maxHeight),
  4884. WordWrap = false,
  4885. MultiLine = multiLine,
  4886. Direction = TextDirection.TopBottom_LeftRight
  4887. };
  4888. Assert.False (tf.WordWrap);
  4889. Assert.True (tf.MultiLine == multiLine);
  4890. Assert.Equal (TextDirection.TopBottom_LeftRight, tf.Direction);
  4891. List<string> splitLines = tf.GetLines ();
  4892. Assert.Equal (splitLines.Count, resultLines.Count ());
  4893. Assert.Equal (splitLines, resultLines);
  4894. }
  4895. [Fact]
  4896. public void NeedsFormat_Sets ()
  4897. {
  4898. var testText = "test";
  4899. var testBounds = new Rectangle (0, 0, 100, 1);
  4900. var tf = new TextFormatter ();
  4901. tf.Text = "test";
  4902. Assert.True (tf.NeedsFormat); // get_Lines causes a Format
  4903. Assert.NotEmpty (tf.GetLines ());
  4904. Assert.False (tf.NeedsFormat); // get_Lines causes a Format
  4905. Assert.Equal (testText, tf.Text);
  4906. tf.Draw (testBounds, new (), new ());
  4907. Assert.False (tf.NeedsFormat);
  4908. tf.ConstrainToSize = new (1, 1);
  4909. Assert.True (tf.NeedsFormat);
  4910. Assert.NotEmpty (tf.GetLines ());
  4911. Assert.False (tf.NeedsFormat); // get_Lines causes a Format
  4912. tf.Alignment = Alignment.Center;
  4913. Assert.True (tf.NeedsFormat);
  4914. Assert.NotEmpty (tf.GetLines ());
  4915. Assert.False (tf.NeedsFormat); // get_Lines causes a Format
  4916. }
  4917. // Test that changing TextFormatter does not impact View dimensions if Dim.Auto is not in play
  4918. [Fact]
  4919. public void Not_Used_TextFormatter_Does_Not_Change_View_Size ()
  4920. {
  4921. View view = new ()
  4922. {
  4923. Text = "_1234"
  4924. };
  4925. Assert.Equal (Size.Empty, view.Frame.Size);
  4926. view.TextFormatter.Text = "ABC";
  4927. Assert.Equal (Size.Empty, view.Frame.Size);
  4928. view.TextFormatter.Alignment = Alignment.Fill;
  4929. Assert.Equal (Size.Empty, view.Frame.Size);
  4930. view.TextFormatter.VerticalAlignment = Alignment.Center;
  4931. Assert.Equal (Size.Empty, view.Frame.Size);
  4932. view.TextFormatter.HotKeySpecifier = (Rune)'*';
  4933. Assert.Equal (Size.Empty, view.Frame.Size);
  4934. view.TextFormatter.Text = "*ABC";
  4935. Assert.Equal (Size.Empty, view.Frame.Size);
  4936. }
  4937. [Fact]
  4938. public void Not_Used_TextSettings_Do_Not_Change_View_Size ()
  4939. {
  4940. View view = new ()
  4941. {
  4942. Text = "_1234"
  4943. };
  4944. Assert.Equal (Size.Empty, view.Frame.Size);
  4945. view.TextAlignment = Alignment.Fill;
  4946. Assert.Equal (Size.Empty, view.Frame.Size);
  4947. view.VerticalTextAlignment = Alignment.Center;
  4948. Assert.Equal (Size.Empty, view.Frame.Size);
  4949. view.HotKeySpecifier = (Rune)'*';
  4950. Assert.Equal (Size.Empty, view.Frame.Size);
  4951. view.Text = "*ABC";
  4952. Assert.Equal (Size.Empty, view.Frame.Size);
  4953. }
  4954. [Theory]
  4955. [InlineData ("", -1, Alignment.Start, false, 0)]
  4956. [InlineData (null, 0, Alignment.Start, false, 1)]
  4957. [InlineData (null, 0, Alignment.Start, true, 1)]
  4958. [InlineData ("", 0, Alignment.Start, false, 1)]
  4959. [InlineData ("", 0, Alignment.Start, true, 1)]
  4960. public void Reformat_Invalid (string text, int maxWidth, Alignment alignment, bool wrap, int linesCount)
  4961. {
  4962. if (maxWidth < 0)
  4963. {
  4964. Assert.Throws<ArgumentOutOfRangeException> (
  4965. () =>
  4966. TextFormatter.Format (text, maxWidth, alignment, wrap)
  4967. );
  4968. }
  4969. else
  4970. {
  4971. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap);
  4972. Assert.NotEmpty (list);
  4973. Assert.True (list.Count == linesCount);
  4974. Assert.Equal (string.Empty, list [0]);
  4975. }
  4976. }
  4977. [Theory]
  4978. [InlineData ("A sentence has words.\nLine 2.", 0, -29, Alignment.Start, false, 1, true)]
  4979. [InlineData ("A sentence has words.\nLine 2.", 1, -28, Alignment.Start, false, 1, false)]
  4980. [InlineData ("A sentence has words.\nLine 2.", 5, -24, Alignment.Start, false, 1, false)]
  4981. [InlineData ("A sentence has words.\nLine 2.", 28, -1, Alignment.Start, false, 1, false)]
  4982. // no clip
  4983. [InlineData ("A sentence has words.\nLine 2.", 29, 0, Alignment.Start, false, 1, false)]
  4984. [InlineData ("A sentence has words.\nLine 2.", 30, 1, Alignment.Start, false, 1, false)]
  4985. [InlineData ("A sentence has words.\r\nLine 2.", 0, -30, Alignment.Start, false, 1, true)]
  4986. [InlineData ("A sentence has words.\r\nLine 2.", 1, -29, Alignment.Start, false, 1, false)]
  4987. [InlineData ("A sentence has words.\r\nLine 2.", 5, -25, Alignment.Start, false, 1, false)]
  4988. [InlineData ("A sentence has words.\r\nLine 2.", 29, -1, Alignment.Start, false, 1, false, 1)]
  4989. [InlineData ("A sentence has words.\r\nLine 2.", 30, 0, Alignment.Start, false, 1, false)]
  4990. [InlineData ("A sentence has words.\r\nLine 2.", 31, 1, Alignment.Start, false, 1, false)]
  4991. public void Reformat_NoWordrap_NewLines_MultiLine_False (
  4992. string text,
  4993. int maxWidth,
  4994. int widthOffset,
  4995. Alignment alignment,
  4996. bool wrap,
  4997. int linesCount,
  4998. bool stringEmpty,
  4999. int clipWidthOffset = 0
  5000. )
  5001. {
  5002. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5003. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth) + clipWidthOffset;
  5004. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap);
  5005. Assert.NotEmpty (list);
  5006. Assert.True (list.Count == linesCount);
  5007. if (stringEmpty)
  5008. {
  5009. Assert.Equal (string.Empty, list [0]);
  5010. }
  5011. else
  5012. {
  5013. Assert.NotEqual (string.Empty, list [0]);
  5014. }
  5015. if (text.Contains ("\r\n") && maxWidth > 0)
  5016. {
  5017. Assert.Equal (
  5018. StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth])
  5019. .Replace ("\r\n", " "),
  5020. list [0]
  5021. );
  5022. }
  5023. else if (text.Contains ('\n') && maxWidth > 0)
  5024. {
  5025. Assert.Equal (
  5026. StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth])
  5027. .Replace ("\n", " "),
  5028. list [0]
  5029. );
  5030. }
  5031. else
  5032. {
  5033. Assert.Equal (StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth]), list [0]);
  5034. }
  5035. }
  5036. [Theory]
  5037. [InlineData ("A sentence has words.\nLine 2.", 0, -29, Alignment.Start, false, 1, true, new [] { "" })]
  5038. [InlineData (
  5039. "A sentence has words.\nLine 2.",
  5040. 1,
  5041. -28,
  5042. Alignment.Start,
  5043. false,
  5044. 2,
  5045. false,
  5046. new [] { "A", "L" }
  5047. )]
  5048. [InlineData (
  5049. "A sentence has words.\nLine 2.",
  5050. 5,
  5051. -24,
  5052. Alignment.Start,
  5053. false,
  5054. 2,
  5055. false,
  5056. new [] { "A sen", "Line " }
  5057. )]
  5058. [InlineData (
  5059. "A sentence has words.\nLine 2.",
  5060. 28,
  5061. -1,
  5062. Alignment.Start,
  5063. false,
  5064. 2,
  5065. false,
  5066. new [] { "A sentence has words.", "Line 2." }
  5067. )]
  5068. //// no clip
  5069. [InlineData (
  5070. "A sentence has words.\nLine 2.",
  5071. 29,
  5072. 0,
  5073. Alignment.Start,
  5074. false,
  5075. 2,
  5076. false,
  5077. new [] { "A sentence has words.", "Line 2." }
  5078. )]
  5079. [InlineData (
  5080. "A sentence has words.\nLine 2.",
  5081. 30,
  5082. 1,
  5083. Alignment.Start,
  5084. false,
  5085. 2,
  5086. false,
  5087. new [] { "A sentence has words.", "Line 2." }
  5088. )]
  5089. [InlineData ("A sentence has words.\r\nLine 2.", 0, -30, Alignment.Start, false, 1, true, new [] { "" })]
  5090. [InlineData (
  5091. "A sentence has words.\r\nLine 2.",
  5092. 1,
  5093. -29,
  5094. Alignment.Start,
  5095. false,
  5096. 2,
  5097. false,
  5098. new [] { "A", "L" }
  5099. )]
  5100. [InlineData (
  5101. "A sentence has words.\r\nLine 2.",
  5102. 5,
  5103. -25,
  5104. Alignment.Start,
  5105. false,
  5106. 2,
  5107. false,
  5108. new [] { "A sen", "Line " }
  5109. )]
  5110. [InlineData (
  5111. "A sentence has words.\r\nLine 2.",
  5112. 29,
  5113. -1,
  5114. Alignment.Start,
  5115. false,
  5116. 2,
  5117. false,
  5118. new [] { "A sentence has words.", "Line 2." }
  5119. )]
  5120. [InlineData (
  5121. "A sentence has words.\r\nLine 2.",
  5122. 30,
  5123. 0,
  5124. Alignment.Start,
  5125. false,
  5126. 2,
  5127. false,
  5128. new [] { "A sentence has words.", "Line 2." }
  5129. )]
  5130. [InlineData (
  5131. "A sentence has words.\r\nLine 2.",
  5132. 31,
  5133. 1,
  5134. Alignment.Start,
  5135. false,
  5136. 2,
  5137. false,
  5138. new [] { "A sentence has words.", "Line 2." }
  5139. )]
  5140. public void Reformat_NoWordrap_NewLines_MultiLine_True (
  5141. string text,
  5142. int maxWidth,
  5143. int widthOffset,
  5144. Alignment alignment,
  5145. bool wrap,
  5146. int linesCount,
  5147. bool stringEmpty,
  5148. IEnumerable<string> resultLines
  5149. )
  5150. {
  5151. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5152. List<string> list = TextFormatter.Format (
  5153. text,
  5154. maxWidth,
  5155. alignment,
  5156. wrap,
  5157. false,
  5158. 0,
  5159. TextDirection.LeftRight_TopBottom,
  5160. true
  5161. );
  5162. Assert.NotEmpty (list);
  5163. Assert.True (list.Count == linesCount);
  5164. if (stringEmpty)
  5165. {
  5166. Assert.Equal (string.Empty, list [0]);
  5167. }
  5168. else
  5169. {
  5170. Assert.NotEqual (string.Empty, list [0]);
  5171. }
  5172. Assert.Equal (list, resultLines);
  5173. }
  5174. [Theory]
  5175. [InlineData ("A sentence has words.\nLine 2.", 0, -29, Alignment.Start, false, 1, true, new [] { "" })]
  5176. [InlineData (
  5177. "A sentence has words.\nLine 2.",
  5178. 1,
  5179. -28,
  5180. Alignment.Start,
  5181. false,
  5182. 2,
  5183. false,
  5184. new [] { "A", "L" }
  5185. )]
  5186. [InlineData (
  5187. "A sentence has words.\nLine 2.",
  5188. 5,
  5189. -24,
  5190. Alignment.Start,
  5191. false,
  5192. 2,
  5193. false,
  5194. new [] { "A sen", "Line " }
  5195. )]
  5196. [InlineData (
  5197. "A sentence has words.\nLine 2.",
  5198. 28,
  5199. -1,
  5200. Alignment.Start,
  5201. false,
  5202. 2,
  5203. false,
  5204. new [] { "A sentence has words.", "Line 2." }
  5205. )]
  5206. //// no clip
  5207. [InlineData (
  5208. "A sentence has words.\nLine 2.",
  5209. 29,
  5210. 0,
  5211. Alignment.Start,
  5212. false,
  5213. 2,
  5214. false,
  5215. new [] { "A sentence has words.", "Line 2." }
  5216. )]
  5217. [InlineData (
  5218. "A sentence has words.\nLine 2.",
  5219. 30,
  5220. 1,
  5221. Alignment.Start,
  5222. false,
  5223. 2,
  5224. false,
  5225. new [] { "A sentence has words.", "Line 2." }
  5226. )]
  5227. [InlineData ("A sentence has words.\r\nLine 2.", 0, -30, Alignment.Start, false, 1, true, new [] { "" })]
  5228. [InlineData (
  5229. "A sentence has words.\r\nLine 2.",
  5230. 1,
  5231. -29,
  5232. Alignment.Start,
  5233. false,
  5234. 2,
  5235. false,
  5236. new [] { "A", "L" }
  5237. )]
  5238. [InlineData (
  5239. "A sentence has words.\r\nLine 2.",
  5240. 5,
  5241. -25,
  5242. Alignment.Start,
  5243. false,
  5244. 2,
  5245. false,
  5246. new [] { "A sen", "Line " }
  5247. )]
  5248. [InlineData (
  5249. "A sentence has words.\r\nLine 2.",
  5250. 29,
  5251. -1,
  5252. Alignment.Start,
  5253. false,
  5254. 2,
  5255. false,
  5256. new [] { "A sentence has words.", "Line 2." }
  5257. )]
  5258. [InlineData (
  5259. "A sentence has words.\r\nLine 2.",
  5260. 30,
  5261. 0,
  5262. Alignment.Start,
  5263. false,
  5264. 2,
  5265. false,
  5266. new [] { "A sentence has words.", "Line 2." }
  5267. )]
  5268. [InlineData (
  5269. "A sentence has words.\r\nLine 2.",
  5270. 31,
  5271. 1,
  5272. Alignment.Start,
  5273. false,
  5274. 2,
  5275. false,
  5276. new [] { "A sentence has words.", "Line 2." }
  5277. )]
  5278. public void Reformat_NoWordrap_NewLines_MultiLine_True_Vertical (
  5279. string text,
  5280. int maxWidth,
  5281. int widthOffset,
  5282. Alignment alignment,
  5283. bool wrap,
  5284. int linesCount,
  5285. bool stringEmpty,
  5286. IEnumerable<string> resultLines
  5287. )
  5288. {
  5289. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5290. List<string> list = TextFormatter.Format (
  5291. text,
  5292. maxWidth,
  5293. alignment,
  5294. wrap,
  5295. false,
  5296. 0,
  5297. TextDirection.TopBottom_LeftRight,
  5298. true
  5299. );
  5300. Assert.NotEmpty (list);
  5301. Assert.True (list.Count == linesCount);
  5302. if (stringEmpty)
  5303. {
  5304. Assert.Equal (string.Empty, list [0]);
  5305. }
  5306. else
  5307. {
  5308. Assert.NotEqual (string.Empty, list [0]);
  5309. }
  5310. Assert.Equal (list, resultLines);
  5311. }
  5312. [Theory]
  5313. [InlineData ("", 0, 0, Alignment.Start, false, 1, true)]
  5314. [InlineData ("", 1, 1, Alignment.Start, false, 1, true)]
  5315. [InlineData ("A sentence has words.", 0, -21, Alignment.Start, false, 1, true)]
  5316. [InlineData ("A sentence has words.", 1, -20, Alignment.Start, false, 1, false)]
  5317. [InlineData ("A sentence has words.", 5, -16, Alignment.Start, false, 1, false)]
  5318. [InlineData ("A sentence has words.", 20, -1, Alignment.Start, false, 1, false)]
  5319. // no clip
  5320. [InlineData ("A sentence has words.", 21, 0, Alignment.Start, false, 1, false)]
  5321. [InlineData ("A sentence has words.", 22, 1, Alignment.Start, false, 1, false)]
  5322. public void Reformat_NoWordrap_SingleLine (
  5323. string text,
  5324. int maxWidth,
  5325. int widthOffset,
  5326. Alignment alignment,
  5327. bool wrap,
  5328. int linesCount,
  5329. bool stringEmpty
  5330. )
  5331. {
  5332. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5333. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5334. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap);
  5335. Assert.NotEmpty (list);
  5336. Assert.True (list.Count == linesCount);
  5337. if (stringEmpty)
  5338. {
  5339. Assert.Equal (string.Empty, list [0]);
  5340. }
  5341. else
  5342. {
  5343. Assert.NotEqual (string.Empty, list [0]);
  5344. }
  5345. Assert.Equal (StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth]), list [0]);
  5346. }
  5347. [Theory]
  5348. // Unicode
  5349. [InlineData (
  5350. "\u2460\u2461\u2462\n\u2460\u2461\u2462\u2463\u2464",
  5351. 8,
  5352. -1,
  5353. Alignment.Start,
  5354. true,
  5355. false,
  5356. new [] { "\u2460\u2461\u2462", "\u2460\u2461\u2462\u2463\u2464" }
  5357. )]
  5358. // no clip
  5359. [InlineData (
  5360. "\u2460\u2461\u2462\n\u2460\u2461\u2462\u2463\u2464",
  5361. 9,
  5362. 0,
  5363. Alignment.Start,
  5364. true,
  5365. false,
  5366. new [] { "\u2460\u2461\u2462", "\u2460\u2461\u2462\u2463\u2464" }
  5367. )]
  5368. [InlineData (
  5369. "\u2460\u2461\u2462\n\u2460\u2461\u2462\u2463\u2464",
  5370. 10,
  5371. 1,
  5372. Alignment.Start,
  5373. true,
  5374. false,
  5375. new [] { "\u2460\u2461\u2462", "\u2460\u2461\u2462\u2463\u2464" }
  5376. )]
  5377. public void Reformat_Unicode_Wrap_Spaces_NewLines (
  5378. string text,
  5379. int maxWidth,
  5380. int widthOffset,
  5381. Alignment alignment,
  5382. bool wrap,
  5383. bool preserveTrailingSpaces,
  5384. IEnumerable<string> resultLines
  5385. )
  5386. {
  5387. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5388. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
  5389. Assert.Equal (list.Count, resultLines.Count ());
  5390. Assert.Equal (resultLines, list);
  5391. }
  5392. [Theory]
  5393. // Unicode
  5394. // Even # of chars
  5395. // 0123456789
  5396. [InlineData ("\u2660пÑРвРÑ", 10, -1, Alignment.Start, true, false, new [] { "\u2660пÑРвÐ", "Ñ" })]
  5397. // no clip
  5398. [InlineData ("\u2660пÑРвРÑ", 11, 0, Alignment.Start, true, false, new [] { "\u2660пÑРвРÑ" })]
  5399. [InlineData ("\u2660пÑРвРÑ", 12, 1, Alignment.Start, true, false, new [] { "\u2660пÑРвРÑ" })]
  5400. // Unicode
  5401. // Odd # of chars
  5402. // 0123456789
  5403. [InlineData ("\u2660 ÑРвРÑ", 9, -1, Alignment.Start, true, false, new [] { "\u2660 ÑРвÐ", "Ñ" })]
  5404. // no clip
  5405. [InlineData ("\u2660 ÑРвРÑ", 10, 0, Alignment.Start, true, false, new [] { "\u2660 ÑРвРÑ" })]
  5406. [InlineData ("\u2660 ÑРвРÑ", 11, 1, Alignment.Start, true, false, new [] { "\u2660 ÑРвРÑ" })]
  5407. public void Reformat_Unicode_Wrap_Spaces_No_NewLines (
  5408. string text,
  5409. int maxWidth,
  5410. int widthOffset,
  5411. Alignment alignment,
  5412. bool wrap,
  5413. bool preserveTrailingSpaces,
  5414. IEnumerable<string> resultLines
  5415. )
  5416. {
  5417. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5418. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
  5419. Assert.Equal (list.Count, resultLines.Count ());
  5420. Assert.Equal (resultLines, list);
  5421. }
  5422. [Theory]
  5423. // Even # of spaces
  5424. // 0123456789
  5425. [InlineData ("012 456 89", 0, -10, Alignment.Start, true, true, true, new [] { "" })]
  5426. [InlineData (
  5427. "012 456 89",
  5428. 1,
  5429. -9,
  5430. Alignment.Start,
  5431. true,
  5432. true,
  5433. false,
  5434. new [] { "0", "1", "2", " ", "4", "5", "6", " ", "8", "9" },
  5435. "01245689"
  5436. )]
  5437. [InlineData ("012 456 89", 5, -5, Alignment.Start, true, true, false, new [] { "012 ", "456 ", "89" })]
  5438. [InlineData ("012 456 89", 9, -1, Alignment.Start, true, true, false, new [] { "012 456 ", "89" })]
  5439. // no clip
  5440. [InlineData ("012 456 89", 10, 0, Alignment.Start, true, true, false, new [] { "012 456 89" })]
  5441. [InlineData ("012 456 89", 11, 1, Alignment.Start, true, true, false, new [] { "012 456 89" })]
  5442. // Odd # of spaces
  5443. // 01234567890123
  5444. [InlineData ("012 456 89 end", 13, -1, Alignment.Start, true, true, false, new [] { "012 456 89 ", "end" })]
  5445. // no clip
  5446. [InlineData ("012 456 89 end", 14, 0, Alignment.Start, true, true, false, new [] { "012 456 89 end" })]
  5447. [InlineData ("012 456 89 end", 15, 1, Alignment.Start, true, true, false, new [] { "012 456 89 end" })]
  5448. public void Reformat_Wrap_Spaces_No_NewLines (
  5449. string text,
  5450. int maxWidth,
  5451. int widthOffset,
  5452. Alignment alignment,
  5453. bool wrap,
  5454. bool preserveTrailingSpaces,
  5455. bool stringEmpty,
  5456. IEnumerable<string> resultLines,
  5457. string noSpaceText = ""
  5458. )
  5459. {
  5460. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5461. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5462. List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
  5463. Assert.NotEmpty (list);
  5464. Assert.True (list.Count == resultLines.Count ());
  5465. if (stringEmpty)
  5466. {
  5467. Assert.Equal (string.Empty, list [0]);
  5468. }
  5469. else
  5470. {
  5471. Assert.NotEqual (string.Empty, list [0]);
  5472. }
  5473. Assert.Equal (resultLines, list);
  5474. if (maxWidth > 0)
  5475. {
  5476. // remove whitespace chars
  5477. if (maxWidth < 5)
  5478. {
  5479. expectedClippedWidth = text.GetRuneCount () - text.Sum (r => r == ' ' ? 1 : 0);
  5480. }
  5481. else
  5482. {
  5483. expectedClippedWidth = Math.Min (
  5484. text.GetRuneCount (),
  5485. maxWidth - text.Sum (r => r == ' ' ? 1 : 0)
  5486. );
  5487. }
  5488. list = TextFormatter.Format (text, maxWidth, Alignment.Start, wrap);
  5489. if (maxWidth == 1)
  5490. {
  5491. Assert.Equal (expectedClippedWidth, list.Count);
  5492. Assert.Equal (noSpaceText, string.Concat (list.ToArray ()));
  5493. }
  5494. if (maxWidth > 1 && maxWidth < 10)
  5495. {
  5496. Assert.Equal (
  5497. StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth]),
  5498. list [0]
  5499. );
  5500. }
  5501. }
  5502. }
  5503. [Theory]
  5504. [InlineData (null)]
  5505. [InlineData ("")]
  5506. [InlineData ("a")]
  5507. public void RemoveHotKeySpecifier_InValid_ReturnsOriginal (string text)
  5508. {
  5509. var hotKeySpecifier = (Rune)'_';
  5510. if (text == null)
  5511. {
  5512. Assert.Null (TextFormatter.RemoveHotKeySpecifier (text, 0, hotKeySpecifier));
  5513. Assert.Null (TextFormatter.RemoveHotKeySpecifier (text, -1, hotKeySpecifier));
  5514. Assert.Null (TextFormatter.RemoveHotKeySpecifier (text, 100, hotKeySpecifier));
  5515. }
  5516. else
  5517. {
  5518. Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, 0, hotKeySpecifier));
  5519. Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, -1, hotKeySpecifier));
  5520. Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, 100, hotKeySpecifier));
  5521. }
  5522. }
  5523. [Theory]
  5524. [InlineData ("all lower case", 0)]
  5525. [InlineData ("K Before", 0)]
  5526. [InlineData ("aK Second", 1)]
  5527. [InlineData ("Last K", 5)]
  5528. [InlineData ("fter K", 7)]
  5529. [InlineData ("Multiple K and R", 9)]
  5530. [InlineData ("Non-english: Кдать", 13)]
  5531. public void RemoveHotKeySpecifier_Valid_Legacy_ReturnsOriginal (string text, int hotPos)
  5532. {
  5533. var hotKeySpecifier = (Rune)'_';
  5534. Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, hotPos, hotKeySpecifier));
  5535. }
  5536. [Theory]
  5537. [InlineData ("_K Before", 0, "K Before")]
  5538. [InlineData ("a_K Second", 1, "aK Second")]
  5539. [InlineData ("Last _K", 5, "Last K")]
  5540. [InlineData ("After K_", 7, "After K")]
  5541. [InlineData ("Multiple _K and _R", 9, "Multiple K and _R")]
  5542. [InlineData ("Non-english: _Кдать", 13, "Non-english: Кдать")]
  5543. public void RemoveHotKeySpecifier_Valid_ReturnsStripped (string text, int hotPos, string expectedText)
  5544. {
  5545. var hotKeySpecifier = (Rune)'_';
  5546. Assert.Equal (expectedText, TextFormatter.RemoveHotKeySpecifier (text, hotPos, hotKeySpecifier));
  5547. }
  5548. [Theory]
  5549. [InlineData ("test", 0, 't', "test")]
  5550. [InlineData ("test", 1, 'e', "test")]
  5551. [InlineData ("Ok", 0, 'O', "Ok")]
  5552. [InlineData ("[◦ Ok ◦]", 3, 'O', "[◦ Ok ◦]")]
  5553. [InlineData ("^k", 0, '^', "^k")]
  5554. public void ReplaceHotKeyWithTag (string text, int hotPos, uint tag, string expected)
  5555. {
  5556. var tf = new TextFormatter ();
  5557. List<Rune> runes = text.ToRuneList ();
  5558. Rune rune;
  5559. if (Rune.TryGetRuneAt (text, hotPos, out rune))
  5560. {
  5561. Assert.Equal (rune, (Rune)tag);
  5562. }
  5563. string result = TextFormatter.ReplaceHotKeyWithTag (text, hotPos);
  5564. Assert.Equal (result, expected);
  5565. Assert.Equal ((Rune)tag, result.ToRunes () [hotPos]);
  5566. Assert.Equal (text.GetRuneCount (), runes.Count);
  5567. Assert.Equal (text, StringExtensions.ToString (runes));
  5568. }
  5569. public static IEnumerable<object []> SplitEnvironmentNewLine =>
  5570. new List<object []>
  5571. {
  5572. new object []
  5573. {
  5574. $"First Line 界{Environment.NewLine}Second Line 界{Environment.NewLine}Third Line 界",
  5575. new [] { "First Line 界", "Second Line 界", "Third Line 界" }
  5576. },
  5577. new object []
  5578. {
  5579. $"First Line 界{Environment.NewLine}Second Line 界{Environment.NewLine}Third Line 界{Environment.NewLine}",
  5580. new [] { "First Line 界", "Second Line 界", "Third Line 界", "" }
  5581. }
  5582. };
  5583. [Theory]
  5584. [MemberData (nameof (SplitEnvironmentNewLine))]
  5585. public void SplitNewLine_Ending__With_Or_Without_NewLine_Probably_CRLF (
  5586. string text,
  5587. IEnumerable<string> expected
  5588. )
  5589. {
  5590. List<string> splited = TextFormatter.SplitNewLine (text);
  5591. Assert.Equal (expected, splited);
  5592. }
  5593. [Theory]
  5594. [InlineData (
  5595. "First Line 界\nSecond Line 界\nThird Line 界\n",
  5596. new [] { "First Line 界", "Second Line 界", "Third Line 界", "" }
  5597. )]
  5598. public void SplitNewLine_Ending_With_NewLine_Only_LF (string text, IEnumerable<string> expected)
  5599. {
  5600. List<string> splited = TextFormatter.SplitNewLine (text);
  5601. Assert.Equal (expected, splited);
  5602. }
  5603. [Theory]
  5604. [InlineData (
  5605. "First Line 界\nSecond Line 界\nThird Line 界",
  5606. new [] { "First Line 界", "Second Line 界", "Third Line 界" }
  5607. )]
  5608. public void SplitNewLine_Ending_Without_NewLine_Only_LF (string text, IEnumerable<string> expected)
  5609. {
  5610. List<string> splited = TextFormatter.SplitNewLine (text);
  5611. Assert.Equal (expected, splited);
  5612. }
  5613. [Theory]
  5614. [InlineData ("New Test 你", 10, 10, 20320, 20320, 9, "你")]
  5615. [InlineData ("New Test \U0001d539", 10, 11, 120121, 55349, 9, "𝔹")]
  5616. public void String_Array_Is_Not_Always_Equal_ToRunes_Array (
  5617. string text,
  5618. int runesLength,
  5619. int stringLength,
  5620. int runeValue,
  5621. int stringValue,
  5622. int index,
  5623. string expected
  5624. )
  5625. {
  5626. Rune [] usToRunes = text.ToRunes ();
  5627. Assert.Equal (runesLength, usToRunes.Length);
  5628. Assert.Equal (stringLength, text.Length);
  5629. Assert.Equal (runeValue, usToRunes [index].Value);
  5630. Assert.Equal (stringValue, text [index]);
  5631. Assert.Equal (expected, usToRunes [index].ToString ());
  5632. if (char.IsHighSurrogate (text [index]))
  5633. {
  5634. // Rune array length isn't equal to string array
  5635. Assert.Equal (expected, new (new [] { text [index], text [index + 1] }));
  5636. }
  5637. else
  5638. {
  5639. // Rune array length is equal to string array
  5640. Assert.Equal (expected, text [index].ToString ());
  5641. }
  5642. }
  5643. [Theory]
  5644. [InlineData (17, 1, TextDirection.LeftRight_TopBottom, 4, "This is a Tab")]
  5645. [InlineData (1, 17, TextDirection.TopBottom_LeftRight, 4, "T\nh\ni\ns\n \ni\ns\n \na\n \n \n \n \n \nT\na\nb")]
  5646. [InlineData (13, 1, TextDirection.LeftRight_TopBottom, 0, "This is a Tab")]
  5647. [InlineData (1, 13, TextDirection.TopBottom_LeftRight, 0, "T\nh\ni\ns\n \ni\ns\n \na\n \nT\na\nb")]
  5648. public void TabWith_PreserveTrailingSpaces_False (
  5649. int width,
  5650. int height,
  5651. TextDirection textDirection,
  5652. int tabWidth,
  5653. string expected
  5654. )
  5655. {
  5656. var driver = new FakeDriver ();
  5657. driver.Init ();
  5658. var text = "This is a \tTab";
  5659. var tf = new TextFormatter ();
  5660. tf.Direction = textDirection;
  5661. tf.TabWidth = tabWidth;
  5662. tf.Text = text;
  5663. tf.ConstrainToWidth = 20;
  5664. tf.ConstrainToHeight = 20;
  5665. Assert.True (tf.WordWrap);
  5666. Assert.False (tf.PreserveTrailingSpaces);
  5667. tf.Draw (
  5668. new (0, 0, width, height),
  5669. new (ColorName.White, ColorName.Black),
  5670. new (ColorName.Blue, ColorName.Black),
  5671. default (Rectangle),
  5672. driver
  5673. );
  5674. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
  5675. driver.End ();
  5676. }
  5677. [Theory]
  5678. [InlineData (17, 1, TextDirection.LeftRight_TopBottom, 4, "This is a Tab")]
  5679. [InlineData (1, 17, TextDirection.TopBottom_LeftRight, 4, "T\nh\ni\ns\n \ni\ns\n \na\n \n \n \n \n \nT\na\nb")]
  5680. [InlineData (13, 1, TextDirection.LeftRight_TopBottom, 0, "This is a Tab")]
  5681. [InlineData (1, 13, TextDirection.TopBottom_LeftRight, 0, "T\nh\ni\ns\n \ni\ns\n \na\n \nT\na\nb")]
  5682. public void TabWith_PreserveTrailingSpaces_True (
  5683. int width,
  5684. int height,
  5685. TextDirection textDirection,
  5686. int tabWidth,
  5687. string expected
  5688. )
  5689. {
  5690. var driver = new FakeDriver ();
  5691. driver.Init ();
  5692. var text = "This is a \tTab";
  5693. var tf = new TextFormatter ();
  5694. tf.Direction = textDirection;
  5695. tf.TabWidth = tabWidth;
  5696. tf.PreserveTrailingSpaces = true;
  5697. tf.Text = text;
  5698. tf.ConstrainToWidth = 20;
  5699. tf.ConstrainToHeight = 20;
  5700. Assert.True (tf.WordWrap);
  5701. tf.Draw (
  5702. new (0, 0, width, height),
  5703. new (ColorName.White, ColorName.Black),
  5704. new (ColorName.Blue, ColorName.Black),
  5705. default (Rectangle),
  5706. driver
  5707. );
  5708. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
  5709. driver.End ();
  5710. }
  5711. [Theory]
  5712. [InlineData (17, 1, TextDirection.LeftRight_TopBottom, 4, "This is a Tab")]
  5713. [InlineData (1, 17, TextDirection.TopBottom_LeftRight, 4, "T\nh\ni\ns\n \ni\ns\n \na\n \n \n \n \n \nT\na\nb")]
  5714. [InlineData (13, 1, TextDirection.LeftRight_TopBottom, 0, "This is a Tab")]
  5715. [InlineData (1, 13, TextDirection.TopBottom_LeftRight, 0, "T\nh\ni\ns\n \ni\ns\n \na\n \nT\na\nb")]
  5716. public void TabWith_WordWrap_True (
  5717. int width,
  5718. int height,
  5719. TextDirection textDirection,
  5720. int tabWidth,
  5721. string expected
  5722. )
  5723. {
  5724. var driver = new FakeDriver ();
  5725. driver.Init ();
  5726. var text = "This is a \tTab";
  5727. var tf = new TextFormatter ();
  5728. tf.Direction = textDirection;
  5729. tf.TabWidth = tabWidth;
  5730. tf.WordWrap = true;
  5731. tf.Text = text;
  5732. tf.ConstrainToWidth = 20;
  5733. tf.ConstrainToHeight = 20;
  5734. Assert.False (tf.PreserveTrailingSpaces);
  5735. tf.Draw (
  5736. new (0, 0, width, height),
  5737. new (ColorName.White, ColorName.Black),
  5738. new (ColorName.Blue, ColorName.Black),
  5739. default (Rectangle),
  5740. driver
  5741. );
  5742. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
  5743. driver.End ();
  5744. }
  5745. [Theory]
  5746. [InlineData ("123456789", 3, "123")]
  5747. [InlineData ("Hello World", 8, "Hello Wo")]
  5748. public void TestClipOrPad_LongWord (string text, int fillPad, string expectedText)
  5749. {
  5750. // word is long but we want it to fill # space only
  5751. Assert.Equal (expectedText, TextFormatter.ClipOrPad (text, fillPad));
  5752. }
  5753. [Theory]
  5754. [InlineData ("fff", 6, "fff ")]
  5755. [InlineData ("Hello World", 16, "Hello World ")]
  5756. public void TestClipOrPad_ShortWord (string text, int fillPad, string expectedText)
  5757. {
  5758. // word is short but we want it to fill # so it should be padded
  5759. Assert.Equal (expectedText, TextFormatter.ClipOrPad (text, fillPad));
  5760. }
  5761. [Theory]
  5762. [InlineData ("你", TextDirection.LeftRight_TopBottom, 2, 1)]
  5763. [InlineData ("你", TextDirection.TopBottom_LeftRight, 2, 1)]
  5764. [InlineData ("你你", TextDirection.LeftRight_TopBottom, 4, 1)]
  5765. [InlineData ("你你", TextDirection.TopBottom_LeftRight, 2, 2)]
  5766. public void Text_Set_SizeIsCorrect (string text, TextDirection textDirection, int expectedWidth, int expectedHeight)
  5767. {
  5768. var tf = new TextFormatter { Direction = textDirection, Text = text };
  5769. tf.ConstrainToWidth = 10;
  5770. tf.ConstrainToHeight = 10;
  5771. Assert.Equal (new (expectedWidth, expectedHeight), tf.FormatAndGetSize ());
  5772. }
  5773. [Fact]
  5774. [SetupFakeDriver]
  5775. public void UICatalog_AboutBox_Text ()
  5776. {
  5777. TextFormatter tf = new ()
  5778. {
  5779. Text = UICatalogApp.GetAboutBoxMessage (),
  5780. Alignment = Alignment.Center,
  5781. VerticalAlignment = Alignment.Start,
  5782. WordWrap = false,
  5783. MultiLine = true,
  5784. HotKeySpecifier = (Rune)0xFFFF
  5785. };
  5786. Size tfSize = tf.FormatAndGetSize ();
  5787. Assert.Equal (new (58, 13), tfSize);
  5788. ((FakeDriver)Application.Driver).SetBufferSize (tfSize.Width, tfSize.Height);
  5789. Application.Driver.FillRect (Application.Screen, (Rune)'*');
  5790. tf.Draw (Application.Screen, Attribute.Default, Attribute.Default);
  5791. var expectedText = """
  5792. ******UI Catalog: A comprehensive sample library for******
  5793. **********************************************************
  5794. _______ _ _ _____ _
  5795. |__ __| (_) | | / ____| (_)
  5796. | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _
  5797. | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
  5798. | | __/ | | | | | | | | | | | (_| | || |__| | |_| | |
  5799. |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
  5800. **********************************************************
  5801. **********************v2 - Pre-Alpha**********************
  5802. **********************************************************
  5803. **********https://github.com/gui-cs/Terminal.Gui**********
  5804. **********************************************************
  5805. """;
  5806. TestHelpers.AssertDriverContentsAre (expectedText.ReplaceLineEndings (), _output);
  5807. }
  5808. [Fact]
  5809. public void WordWrap_BigWidth ()
  5810. {
  5811. List<string> wrappedLines;
  5812. var text = "Constantinople";
  5813. wrappedLines = TextFormatter.WordWrapText (text, 100);
  5814. Assert.True (wrappedLines.Count == 1);
  5815. Assert.Equal ("Constantinople", wrappedLines [0]);
  5816. }
  5817. [Fact]
  5818. public void WordWrap_Invalid ()
  5819. {
  5820. var text = string.Empty;
  5821. var width = 0;
  5822. Assert.Empty (TextFormatter.WordWrapText (null, width));
  5823. Assert.Empty (TextFormatter.WordWrapText (text, width));
  5824. Assert.Throws<ArgumentOutOfRangeException> (() => TextFormatter.WordWrapText (text, -1));
  5825. }
  5826. [Theory]
  5827. [InlineData ("A sentence has words.", 3, -18, new [] { "A", "sen", "ten", "ce", "has", "wor", "ds." })]
  5828. [InlineData (
  5829. "A sentence has words.",
  5830. 2,
  5831. -19,
  5832. new [] { "A", "se", "nt", "en", "ce", "ha", "s", "wo", "rd", "s." }
  5833. )]
  5834. [InlineData (
  5835. "A sentence has words.",
  5836. 1,
  5837. -20,
  5838. new [] { "A", "s", "e", "n", "t", "e", "n", "c", "e", "h", "a", "s", "w", "o", "r", "d", "s", "." }
  5839. )]
  5840. public void WordWrap_Narrow_Default (
  5841. string text,
  5842. int maxWidth,
  5843. int widthOffset,
  5844. IEnumerable<string> resultLines
  5845. )
  5846. {
  5847. // Calls WordWrapText (text, width) and thus preserveTrailingSpaces defaults to false
  5848. List<string> wrappedLines;
  5849. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5850. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5851. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  5852. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  5853. Assert.True (
  5854. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  5855. );
  5856. Assert.True (
  5857. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  5858. );
  5859. Assert.Equal (resultLines, wrappedLines);
  5860. }
  5861. [Theory]
  5862. [InlineData ("A sentence has words.", 21, 0, new [] { "A sentence has words." })]
  5863. [InlineData ("A sentence has words.", 20, -1, new [] { "A sentence has", "words." })]
  5864. [InlineData ("A sentence has words.", 15, -6, new [] { "A sentence has", "words." })]
  5865. [InlineData ("A sentence has words.", 14, -7, new [] { "A sentence has", "words." })]
  5866. [InlineData ("A sentence has words.", 13, -8, new [] { "A sentence", "has words." })]
  5867. // Unicode
  5868. [InlineData (
  5869. "A Unicode sentence (пÑивеÑ) has words.",
  5870. 42,
  5871. 0,
  5872. new [] { "A Unicode sentence (пÑивеÑ) has words." }
  5873. )]
  5874. [InlineData (
  5875. "A Unicode sentence (пÑивеÑ) has words.",
  5876. 41,
  5877. -1,
  5878. new [] { "A Unicode sentence (пÑивеÑ) has", "words." }
  5879. )]
  5880. [InlineData (
  5881. "A Unicode sentence (пÑивеÑ) has words.",
  5882. 36,
  5883. -6,
  5884. new [] { "A Unicode sentence (пÑивеÑ) has", "words." }
  5885. )]
  5886. [InlineData (
  5887. "A Unicode sentence (пÑивеÑ) has words.",
  5888. 35,
  5889. -7,
  5890. new [] { "A Unicode sentence (пÑивеÑ) has", "words." }
  5891. )]
  5892. [InlineData (
  5893. "A Unicode sentence (пÑивеÑ) has words.",
  5894. 34,
  5895. -8,
  5896. new [] { "A Unicode sentence (пÑивеÑ)", "has words." }
  5897. )]
  5898. [InlineData (
  5899. "A Unicode sentence (пÑивеÑ) has words.",
  5900. 25,
  5901. -17,
  5902. new [] { "A Unicode sentence", "(пÑивеÑ) has words." }
  5903. )]
  5904. public void WordWrap_NoNewLines_Default (
  5905. string text,
  5906. int maxWidth,
  5907. int widthOffset,
  5908. IEnumerable<string> resultLines
  5909. )
  5910. {
  5911. // Calls WordWrapText (text, width) and thus preserveTrailingSpaces defaults to false
  5912. List<string> wrappedLines;
  5913. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5914. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5915. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  5916. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  5917. Assert.True (
  5918. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  5919. );
  5920. Assert.True (
  5921. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  5922. );
  5923. Assert.Equal (resultLines, wrappedLines);
  5924. }
  5925. [Theory]
  5926. [InlineData ("これが最初の行です。 こんにちは世界。 これが2行目です。", 29, 0, new [] { "これが最初の行です。", "こんにちは世界。", "これが2行目です。" })]
  5927. public void WordWrap_PreserveTrailingSpaces_False_Unicode_Wide_Runes (
  5928. string text,
  5929. int maxWidth,
  5930. int widthOffset,
  5931. IEnumerable<string> resultLines
  5932. )
  5933. {
  5934. List<string> wrappedLines;
  5935. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5936. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5937. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  5938. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  5939. Assert.True (
  5940. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  5941. );
  5942. Assert.True (
  5943. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  5944. );
  5945. Assert.Equal (resultLines, wrappedLines);
  5946. }
  5947. [Theory]
  5948. [InlineData ("文に は言葉 があり ます。", 14, 0, new [] { "文に は言葉", "があり ます。" })]
  5949. [InlineData ("文に は言葉 があり ます。", 3, -11, new [] { "文", "に", "は", "言", "葉", "が", "あ", "り", "ま", "す", "。" })]
  5950. [InlineData ("文に は言葉 があり ます。", 2, -12, new [] { "文", "に", "は", "言", "葉", "が", "あ", "り", "ま", "す", "。" })]
  5951. [InlineData (
  5952. "文に は言葉 があり ます。",
  5953. 1,
  5954. -13,
  5955. new [] { " ", " ", " " }
  5956. )] // Just Spaces; should result in a single space for each line
  5957. public void WordWrap_PreserveTrailingSpaces_False_Wide_Runes (
  5958. string text,
  5959. int maxWidth,
  5960. int widthOffset,
  5961. IEnumerable<string> resultLines
  5962. )
  5963. {
  5964. List<string> wrappedLines;
  5965. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  5966. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  5967. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  5968. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  5969. Assert.True (
  5970. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  5971. );
  5972. Assert.True (
  5973. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  5974. );
  5975. Assert.Equal (resultLines, wrappedLines);
  5976. }
  5977. [Theory]
  5978. [InlineData (null, 1, new string [] { })] // null input
  5979. [InlineData ("", 1, new string [] { })] // Empty input
  5980. [InlineData ("1 34", 1, new [] { "1", "3", "4" })] // Single Spaces
  5981. [InlineData ("1", 1, new [] { "1" })] // Short input
  5982. [InlineData ("12", 1, new [] { "1", "2" })]
  5983. [InlineData ("123", 1, new [] { "1", "2", "3" })]
  5984. [InlineData ("123456", 1, new [] { "1", "2", "3", "4", "5", "6" })] // No spaces
  5985. [InlineData (" ", 1, new [] { " " })] // Just Spaces; should result in a single space
  5986. [InlineData (" ", 1, new [] { " " })]
  5987. [InlineData (" ", 1, new [] { " ", " " })]
  5988. [InlineData (" ", 1, new [] { " ", " " })]
  5989. [InlineData ("12 456", 1, new [] { "1", "2", "4", "5", "6" })] // Single Spaces
  5990. [InlineData (" 2 456", 1, new [] { " ", "2", "4", "5", "6" })] // Leading spaces should be preserved.
  5991. [InlineData (" 2 456 8", 1, new [] { " ", "2", "4", "5", "6", "8" })]
  5992. [InlineData (
  5993. "A sentence has words. ",
  5994. 1,
  5995. new [] { "A", "s", "e", "n", "t", "e", "n", "c", "e", "h", "a", "s", "w", "o", "r", "d", "s", "." }
  5996. )] // Complex example
  5997. [InlineData ("12 567", 1, new [] { "1", "2", " ", "5", "6", "7" })] // Double Spaces
  5998. [InlineData (" 3 567", 1, new [] { " ", "3", "5", "6", "7" })] // Double Leading spaces should be preserved.
  5999. [InlineData (" 3 678 1", 1, new [] { " ", "3", " ", "6", "7", "8", " ", "1" })]
  6000. [InlineData ("1 456", 1, new [] { "1", " ", "4", "5", "6" })]
  6001. [InlineData (
  6002. "A sentence has words. ",
  6003. 1,
  6004. new []
  6005. {
  6006. "A", " ", "s", "e", "n", "t", "e", "n", "c", "e", " ", "h", "a", "s", "w", "o", "r", "d", "s", ".", " "
  6007. }
  6008. )] // Double space Complex example
  6009. public void WordWrap_PreserveTrailingSpaces_False_With_Simple_Runes_Width_1 (
  6010. string text,
  6011. int width,
  6012. IEnumerable<string> resultLines
  6013. )
  6014. {
  6015. List<string> wrappedLines = TextFormatter.WordWrapText (text, width);
  6016. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6017. Assert.Equal (resultLines, wrappedLines);
  6018. var breakLines = "";
  6019. foreach (string line in wrappedLines)
  6020. {
  6021. breakLines += $"{line}{Environment.NewLine}";
  6022. }
  6023. var expected = string.Empty;
  6024. foreach (string line in resultLines)
  6025. {
  6026. expected += $"{line}{Environment.NewLine}";
  6027. }
  6028. Assert.Equal (expected, breakLines);
  6029. }
  6030. [Theory]
  6031. [InlineData (null, 3, new string [] { })] // null input
  6032. [InlineData ("", 3, new string [] { })] // Empty input
  6033. [InlineData ("1", 3, new [] { "1" })] // Short input
  6034. [InlineData ("12", 3, new [] { "12" })]
  6035. [InlineData ("123", 3, new [] { "123" })]
  6036. [InlineData ("123456", 3, new [] { "123", "456" })] // No spaces
  6037. [InlineData ("1234567", 3, new [] { "123", "456", "7" })] // No spaces
  6038. [InlineData (" ", 3, new [] { " " })] // Just Spaces; should result in a single space
  6039. [InlineData (" ", 3, new [] { " " })]
  6040. [InlineData (" ", 3, new [] { " " })]
  6041. [InlineData (" ", 3, new [] { " " })]
  6042. [InlineData ("12 456", 3, new [] { "12", "456" })] // Single Spaces
  6043. [InlineData (" 2 456", 3, new [] { " 2", "456" })] // Leading spaces should be preserved.
  6044. [InlineData (" 2 456 8", 3, new [] { " 2", "456", "8" })]
  6045. [InlineData (
  6046. "A sentence has words. ",
  6047. 3,
  6048. new [] { "A", "sen", "ten", "ce", "has", "wor", "ds." }
  6049. )] // Complex example
  6050. [InlineData ("12 567", 3, new [] { "12 ", "567" })] // Double Spaces
  6051. [InlineData (" 3 567", 3, new [] { " 3", "567" })] // Double Leading spaces should be preserved.
  6052. [InlineData (" 3 678 1", 3, new [] { " 3", " 67", "8 ", "1" })]
  6053. [InlineData ("1 456", 3, new [] { "1 ", "456" })]
  6054. [InlineData (
  6055. "A sentence has words. ",
  6056. 3,
  6057. new [] { "A ", "sen", "ten", "ce ", " ", "has", "wor", "ds.", " " }
  6058. )] // Double space Complex example
  6059. public void WordWrap_PreserveTrailingSpaces_False_With_Simple_Runes_Width_3 (
  6060. string text,
  6061. int width,
  6062. IEnumerable<string> resultLines
  6063. )
  6064. {
  6065. List<string> wrappedLines = TextFormatter.WordWrapText (text, width);
  6066. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6067. Assert.Equal (resultLines, wrappedLines);
  6068. var breakLines = "";
  6069. foreach (string line in wrappedLines)
  6070. {
  6071. breakLines += $"{line}{Environment.NewLine}";
  6072. }
  6073. var expected = string.Empty;
  6074. foreach (string line in resultLines)
  6075. {
  6076. expected += $"{line}{Environment.NewLine}";
  6077. }
  6078. Assert.Equal (expected, breakLines);
  6079. }
  6080. [Theory]
  6081. [InlineData (null, 50, new string [] { })] // null input
  6082. [InlineData ("", 50, new string [] { })] // Empty input
  6083. [InlineData ("1", 50, new [] { "1" })] // Short input
  6084. [InlineData ("12", 50, new [] { "12" })]
  6085. [InlineData ("123", 50, new [] { "123" })]
  6086. [InlineData ("123456", 50, new [] { "123456" })] // No spaces
  6087. [InlineData ("1234567", 50, new [] { "1234567" })] // No spaces
  6088. [InlineData (" ", 50, new [] { " " })] // Just Spaces; should result in a single space
  6089. [InlineData (" ", 50, new [] { " " })]
  6090. [InlineData (" ", 50, new [] { " " })]
  6091. [InlineData ("12 456", 50, new [] { "12 456" })] // Single Spaces
  6092. [InlineData (" 2 456", 50, new [] { " 2 456" })] // Leading spaces should be preserved.
  6093. [InlineData (" 2 456 8", 50, new [] { " 2 456 8" })]
  6094. [InlineData ("A sentence has words. ", 50, new [] { "A sentence has words. " })] // Complex example
  6095. [InlineData ("12 567", 50, new [] { "12 567" })] // Double Spaces
  6096. [InlineData (" 3 567", 50, new [] { " 3 567" })] // Double Leading spaces should be preserved.
  6097. [InlineData (" 3 678 1", 50, new [] { " 3 678 1" })]
  6098. [InlineData ("1 456", 50, new [] { "1 456" })]
  6099. [InlineData (
  6100. "A sentence has words. ",
  6101. 50,
  6102. new [] { "A sentence has words. " }
  6103. )] // Double space Complex example
  6104. public void WordWrap_PreserveTrailingSpaces_False_With_Simple_Runes_Width_50 (
  6105. string text,
  6106. int width,
  6107. IEnumerable<string> resultLines
  6108. )
  6109. {
  6110. List<string> wrappedLines = TextFormatter.WordWrapText (text, width);
  6111. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6112. Assert.Equal (resultLines, wrappedLines);
  6113. var breakLines = "";
  6114. foreach (string line in wrappedLines)
  6115. {
  6116. breakLines += $"{line}{Environment.NewLine}";
  6117. }
  6118. var expected = string.Empty;
  6119. foreach (string line in resultLines)
  6120. {
  6121. expected += $"{line}{Environment.NewLine}";
  6122. }
  6123. Assert.Equal (expected, breakLines);
  6124. }
  6125. [Theory]
  6126. [InlineData ("A sentence has words.", 14, -7, new [] { "A sentence ", "has words." })]
  6127. [InlineData ("A sentence has words.", 8, -13, new [] { "A ", "sentence", " has ", "words." })]
  6128. [InlineData ("A sentence has words.", 6, -15, new [] { "A ", "senten", "ce ", "has ", "words." })]
  6129. [InlineData ("A sentence has words.", 3, -18, new [] { "A ", "sen", "ten", "ce ", "has", " ", "wor", "ds." })]
  6130. [InlineData (
  6131. "A sentence has words.",
  6132. 2,
  6133. -19,
  6134. new [] { "A ", "se", "nt", "en", "ce", " ", "ha", "s ", "wo", "rd", "s." }
  6135. )]
  6136. [InlineData (
  6137. "A sentence has words.",
  6138. 1,
  6139. -20,
  6140. new []
  6141. {
  6142. "A", " ", "s", "e", "n", "t", "e", "n", "c", "e", " ", "h", "a", "s", " ", "w", "o", "r", "d", "s", "."
  6143. }
  6144. )]
  6145. public void WordWrap_PreserveTrailingSpaces_True (
  6146. string text,
  6147. int maxWidth,
  6148. int widthOffset,
  6149. IEnumerable<string> resultLines
  6150. )
  6151. {
  6152. List<string> wrappedLines;
  6153. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6154. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6155. wrappedLines = TextFormatter.WordWrapText (text, maxWidth, true);
  6156. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6157. Assert.True (
  6158. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6159. );
  6160. Assert.True (
  6161. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6162. );
  6163. Assert.Equal (resultLines, wrappedLines);
  6164. }
  6165. [Theory]
  6166. [InlineData ("文に は言葉 があり ます。", 14, 0, new [] { "文に は言葉 ", "があり ます。" })]
  6167. [InlineData ("文に は言葉 があり ます。", 3, -11, new [] { "文", "に ", "は", "言", "葉 ", "が", "あ", "り ", "ま", "す", "。" })]
  6168. [InlineData (
  6169. "文に は言葉 があり ます。",
  6170. 2,
  6171. -12,
  6172. new [] { "文", "に", " ", "は", "言", "葉", " ", "が", "あ", "り", " ", "ま", "す", "。" }
  6173. )]
  6174. [InlineData ("文に は言葉 があり ます。", 1, -13, new string [] { })]
  6175. public void WordWrap_PreserveTrailingSpaces_True_Wide_Runes (
  6176. string text,
  6177. int maxWidth,
  6178. int widthOffset,
  6179. IEnumerable<string> resultLines
  6180. )
  6181. {
  6182. List<string> wrappedLines;
  6183. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6184. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6185. wrappedLines = TextFormatter.WordWrapText (text, maxWidth, true);
  6186. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6187. Assert.True (
  6188. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6189. );
  6190. Assert.True (
  6191. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6192. );
  6193. Assert.Equal (resultLines, wrappedLines);
  6194. }
  6195. [Theory]
  6196. [InlineData ("A sentence has words. ", 3, new [] { "A ", "sen", "ten", "ce ", "has", " ", "wor", "ds.", " " })]
  6197. [InlineData (
  6198. "A sentence has words. ",
  6199. 3,
  6200. new [] { "A ", " ", "sen", "ten", "ce ", " ", " ", " ", "has", " ", "wor", "ds.", " " }
  6201. )]
  6202. public void WordWrap_PreserveTrailingSpaces_True_With_Simple_Runes_Width_3 (
  6203. string text,
  6204. int width,
  6205. IEnumerable<string> resultLines
  6206. )
  6207. {
  6208. List<string> wrappedLines = TextFormatter.WordWrapText (text, width, true);
  6209. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6210. Assert.Equal (resultLines, wrappedLines);
  6211. var breakLines = "";
  6212. foreach (string line in wrappedLines)
  6213. {
  6214. breakLines += $"{line}{Environment.NewLine}";
  6215. }
  6216. var expected = string.Empty;
  6217. foreach (string line in resultLines)
  6218. {
  6219. expected += $"{line}{Environment.NewLine}";
  6220. }
  6221. Assert.Equal (expected, breakLines);
  6222. // Double space Complex example - this is how VS 2022 does it
  6223. //text = "A sentence has words. ";
  6224. //breakLines = "";
  6225. //wrappedLines = TextFormatter.WordWrapText (text, width, preserveTrailingSpaces: true);
  6226. //foreach (var line in wrappedLines) {
  6227. // breakLines += $"{line}{Environment.NewLine}";
  6228. //}
  6229. //expected = "A " + Environment.NewLine +
  6230. // " se" + Environment.NewLine +
  6231. // " nt" + Environment.NewLine +
  6232. // " en" + Environment.NewLine +
  6233. // " ce" + Environment.NewLine +
  6234. // " " + Environment.NewLine +
  6235. // " " + Environment.NewLine +
  6236. // " " + Environment.NewLine +
  6237. // " ha" + Environment.NewLine +
  6238. // " s " + Environment.NewLine +
  6239. // " wo" + Environment.NewLine +
  6240. // " rd" + Environment.NewLine +
  6241. // " s." + Environment.NewLine;
  6242. //Assert.Equal (expected, breakLines);
  6243. }
  6244. [Theory]
  6245. [InlineData ("A sentence\t\t\t has words.", 14, -10, new [] { "A sentence\t", "\t\t has ", "words." })]
  6246. [InlineData (
  6247. "A sentence\t\t\t has words.",
  6248. 8,
  6249. -16,
  6250. new [] { "A ", "sentence", "\t\t", "\t ", "has ", "words." }
  6251. )]
  6252. [InlineData (
  6253. "A sentence\t\t\t has words.",
  6254. 3,
  6255. -21,
  6256. new [] { "A ", "sen", "ten", "ce", "\t", "\t", "\t", " ", "has", " ", "wor", "ds." }
  6257. )]
  6258. [InlineData (
  6259. "A sentence\t\t\t has words.",
  6260. 2,
  6261. -22,
  6262. new [] { "A ", "se", "nt", "en", "ce", "\t", "\t", "\t", " ", "ha", "s ", "wo", "rd", "s." }
  6263. )]
  6264. [InlineData (
  6265. "A sentence\t\t\t has words.",
  6266. 1,
  6267. -23,
  6268. new []
  6269. {
  6270. "A",
  6271. " ",
  6272. "s",
  6273. "e",
  6274. "n",
  6275. "t",
  6276. "e",
  6277. "n",
  6278. "c",
  6279. "e",
  6280. "\t",
  6281. "\t",
  6282. "\t",
  6283. " ",
  6284. "h",
  6285. "a",
  6286. "s",
  6287. " ",
  6288. "w",
  6289. "o",
  6290. "r",
  6291. "d",
  6292. "s",
  6293. "."
  6294. }
  6295. )]
  6296. public void WordWrap_PreserveTrailingSpaces_True_With_Tab (
  6297. string text,
  6298. int maxWidth,
  6299. int widthOffset,
  6300. IEnumerable<string> resultLines,
  6301. int tabWidth = 4
  6302. )
  6303. {
  6304. List<string> wrappedLines;
  6305. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6306. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6307. wrappedLines = TextFormatter.WordWrapText (text, maxWidth, true, tabWidth);
  6308. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6309. Assert.True (
  6310. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6311. );
  6312. Assert.True (
  6313. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6314. );
  6315. Assert.Equal (resultLines, wrappedLines);
  6316. }
  6317. [Theory]
  6318. [InlineData ("Constantinople", 14, 0, new [] { "Constantinople" })]
  6319. [InlineData ("Constantinople", 12, -2, new [] { "Constantinop", "le" })]
  6320. [InlineData ("Constantinople", 9, -5, new [] { "Constanti", "nople" })]
  6321. [InlineData ("Constantinople", 7, -7, new [] { "Constan", "tinople" })]
  6322. [InlineData ("Constantinople", 5, -9, new [] { "Const", "antin", "ople" })]
  6323. [InlineData ("Constantinople", 4, -10, new [] { "Cons", "tant", "inop", "le" })]
  6324. [InlineData (
  6325. "Constantinople",
  6326. 1,
  6327. -13,
  6328. new [] { "C", "o", "n", "s", "t", "a", "n", "t", "i", "n", "o", "p", "l", "e" }
  6329. )]
  6330. public void WordWrap_SingleWordLine (
  6331. string text,
  6332. int maxWidth,
  6333. int widthOffset,
  6334. IEnumerable<string> resultLines
  6335. )
  6336. {
  6337. List<string> wrappedLines;
  6338. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6339. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6340. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6341. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6342. Assert.True (
  6343. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6344. );
  6345. Assert.True (
  6346. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6347. );
  6348. Assert.Equal (resultLines, wrappedLines);
  6349. }
  6350. [Theory]
  6351. [InlineData ("This\u00A0is\n\u00A0a\u00A0sentence.", 20, 0, new [] { "This\u00A0is\u00A0a\u00A0sentence." })]
  6352. [InlineData ("This\u00A0is\n\u00A0a\u00A0sentence.", 19, -1, new [] { "This\u00A0is\u00A0a\u00A0sentence." })]
  6353. [InlineData (
  6354. "\u00A0\u00A0\u00A0\u00A0\u00A0test\u00A0sentence.",
  6355. 19,
  6356. 0,
  6357. new [] { "\u00A0\u00A0\u00A0\u00A0\u00A0test\u00A0sentence." }
  6358. )]
  6359. public void WordWrap_Unicode_2LinesWithNonBreakingSpace (
  6360. string text,
  6361. int maxWidth,
  6362. int widthOffset,
  6363. IEnumerable<string> resultLines
  6364. )
  6365. {
  6366. List<string> wrappedLines;
  6367. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6368. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6369. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6370. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6371. Assert.True (
  6372. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6373. );
  6374. Assert.True (
  6375. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6376. );
  6377. Assert.Equal (resultLines, wrappedLines);
  6378. }
  6379. [Theory]
  6380. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 19, 0, new [] { "This\u00A0is\u00A0a\u00A0sentence." })]
  6381. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 18, -1, new [] { "This\u00A0is\u00A0a\u00A0sentence", "." })]
  6382. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 17, -2, new [] { "This\u00A0is\u00A0a\u00A0sentenc", "e." })]
  6383. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 14, -5, new [] { "This\u00A0is\u00A0a\u00A0sent", "ence." })]
  6384. [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 10, -9, new [] { "This\u00A0is\u00A0a\u00A0", "sentence." })]
  6385. [InlineData (
  6386. "This\u00A0is\u00A0a\u00A0sentence.",
  6387. 7,
  6388. -12,
  6389. new [] { "This\u00A0is", "\u00A0a\u00A0sent", "ence." }
  6390. )]
  6391. [InlineData (
  6392. "This\u00A0is\u00A0a\u00A0sentence.",
  6393. 5,
  6394. -14,
  6395. new [] { "This\u00A0", "is\u00A0a\u00A0", "sente", "nce." }
  6396. )]
  6397. [InlineData (
  6398. "This\u00A0is\u00A0a\u00A0sentence.",
  6399. 1,
  6400. -18,
  6401. new []
  6402. {
  6403. "T", "h", "i", "s", "\u00A0", "i", "s", "\u00A0", "a", "\u00A0", "s", "e", "n", "t", "e", "n", "c", "e", "."
  6404. }
  6405. )]
  6406. public void WordWrap_Unicode_LineWithNonBreakingSpace (
  6407. string text,
  6408. int maxWidth,
  6409. int widthOffset,
  6410. IEnumerable<string> resultLines
  6411. )
  6412. {
  6413. List<string> wrappedLines;
  6414. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6415. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6416. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6417. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6418. Assert.True (
  6419. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6420. );
  6421. Assert.True (
  6422. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6423. );
  6424. Assert.Equal (resultLines, wrappedLines);
  6425. }
  6426. [Theory]
  6427. [InlineData (
  6428. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6429. 51,
  6430. 0,
  6431. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ" }
  6432. )]
  6433. [InlineData (
  6434. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6435. 50,
  6436. -1,
  6437. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ" }
  6438. )]
  6439. [InlineData (
  6440. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6441. 46,
  6442. -5,
  6443. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮ", "ฯะัาำ" }
  6444. )]
  6445. [InlineData (
  6446. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6447. 26,
  6448. -25,
  6449. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบ", "ปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ" }
  6450. )]
  6451. [InlineData (
  6452. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6453. 17,
  6454. -34,
  6455. new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑ", "ฒณดตถทธนบปผฝพฟภมย", "รฤลฦวศษสหฬอฮฯะัาำ" }
  6456. )]
  6457. [InlineData (
  6458. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6459. 13,
  6460. -38,
  6461. new [] { "กขฃคฅฆงจฉชซฌญ", "ฎฏฐฑฒณดตถทธนบ", "ปผฝพฟภมยรฤลฦว", "ศษสหฬอฮฯะัาำ" }
  6462. )]
  6463. [InlineData (
  6464. "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
  6465. 1,
  6466. -50,
  6467. new []
  6468. {
  6469. "ก",
  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. public void WordWrap_Unicode_SingleWordLine (
  6522. string text,
  6523. int maxWidth,
  6524. int widthOffset,
  6525. IEnumerable<string> resultLines
  6526. )
  6527. {
  6528. List<string> wrappedLines;
  6529. IEnumerable<Rune> zeroWidth = text.EnumerateRunes ().Where (r => r.GetColumns () == 0);
  6530. Assert.Single (zeroWidth);
  6531. Assert.Equal ('ั', zeroWidth.ElementAt (0).Value);
  6532. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6533. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6534. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6535. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6536. Assert.True (
  6537. expectedClippedWidth
  6538. >= (wrappedLines.Count > 0
  6539. ? wrappedLines.Max (
  6540. l => l.GetRuneCount ()
  6541. + zeroWidth.Count ()
  6542. - 1
  6543. + widthOffset
  6544. )
  6545. : 0)
  6546. );
  6547. Assert.True (
  6548. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6549. );
  6550. Assert.Equal (resultLines, wrappedLines);
  6551. }
  6552. /// <summary>WordWrap strips CRLF</summary>
  6553. [Theory]
  6554. [InlineData (
  6555. "A sentence has words.\nA paragraph has lines.",
  6556. 44,
  6557. 0,
  6558. new [] { "A sentence has words.A paragraph has lines." }
  6559. )]
  6560. [InlineData (
  6561. "A sentence has words.\nA paragraph has lines.",
  6562. 43,
  6563. -1,
  6564. new [] { "A sentence has words.A paragraph has lines." }
  6565. )]
  6566. [InlineData (
  6567. "A sentence has words.\nA paragraph has lines.",
  6568. 38,
  6569. -6,
  6570. new [] { "A sentence has words.A paragraph has", "lines." }
  6571. )]
  6572. [InlineData (
  6573. "A sentence has words.\nA paragraph has lines.",
  6574. 34,
  6575. -10,
  6576. new [] { "A sentence has words.A paragraph", "has lines." }
  6577. )]
  6578. [InlineData (
  6579. "A sentence has words.\nA paragraph has lines.",
  6580. 27,
  6581. -17,
  6582. new [] { "A sentence has words.A", "paragraph has lines." }
  6583. )]
  6584. // Unicode
  6585. [InlineData (
  6586. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6587. 69,
  6588. 0,
  6589. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт has Линии." }
  6590. )]
  6591. [InlineData (
  6592. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6593. 68,
  6594. -1,
  6595. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт has Линии." }
  6596. )]
  6597. [InlineData (
  6598. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6599. 63,
  6600. -6,
  6601. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт has", "Линии." }
  6602. )]
  6603. [InlineData (
  6604. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6605. 59,
  6606. -10,
  6607. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт", "has Линии." }
  6608. )]
  6609. [InlineData (
  6610. "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
  6611. 52,
  6612. -17,
  6613. new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode", "Пункт has Линии." }
  6614. )]
  6615. public void WordWrap_WithNewLines (string text, int maxWidth, int widthOffset, IEnumerable<string> resultLines)
  6616. {
  6617. List<string> wrappedLines;
  6618. Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
  6619. int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
  6620. wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
  6621. Assert.Equal (wrappedLines.Count, resultLines.Count ());
  6622. Assert.True (
  6623. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
  6624. );
  6625. Assert.True (
  6626. expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
  6627. );
  6628. Assert.Equal (resultLines, wrappedLines);
  6629. }
  6630. #region FormatAndGetSizeTests
  6631. // TODO: Add multi-line examples
  6632. // TODO: Add other TextDirection examples
  6633. [Theory]
  6634. [SetupFakeDriver]
  6635. [InlineData ("界1234", 10, 10, TextDirection.LeftRight_TopBottom, 6, 1, @"界1234")]
  6636. [InlineData ("01234", 10, 10, TextDirection.LeftRight_TopBottom, 5, 1, @"01234")]
  6637. [InlineData (
  6638. "界1234",
  6639. 10,
  6640. 10,
  6641. TextDirection.TopBottom_LeftRight,
  6642. 2,
  6643. 5,
  6644. """
  6645. 1
  6646. 2
  6647. 3
  6648. 4
  6649. """)]
  6650. [InlineData (
  6651. "01234",
  6652. 10,
  6653. 10,
  6654. TextDirection.TopBottom_LeftRight,
  6655. 1,
  6656. 5,
  6657. """
  6658. 0
  6659. 1
  6660. 2
  6661. 3
  6662. 4
  6663. """)]
  6664. [InlineData (
  6665. "界1234",
  6666. 3,
  6667. 3,
  6668. TextDirection.LeftRight_TopBottom,
  6669. 3,
  6670. 2,
  6671. """
  6672. 界1
  6673. 234
  6674. """)]
  6675. [InlineData (
  6676. "01234",
  6677. 3,
  6678. 3,
  6679. TextDirection.LeftRight_TopBottom,
  6680. 3,
  6681. 2,
  6682. """
  6683. 012
  6684. 34
  6685. """)]
  6686. [InlineData (
  6687. "界1234",
  6688. 3,
  6689. 3,
  6690. TextDirection.TopBottom_LeftRight,
  6691. 3,
  6692. 3,
  6693. """
  6694. 界3
  6695. 1 4
  6696. 2
  6697. """)]
  6698. [InlineData (
  6699. "01234",
  6700. 3,
  6701. 3,
  6702. TextDirection.TopBottom_LeftRight,
  6703. 2,
  6704. 3,
  6705. """
  6706. 03
  6707. 14
  6708. 2
  6709. """)]
  6710. [InlineData ("01234", 2, 1, TextDirection.LeftRight_TopBottom, 2, 1, @"01")]
  6711. public void FormatAndGetSize_Returns_Correct_Size (
  6712. string text,
  6713. int width,
  6714. int height,
  6715. TextDirection direction,
  6716. int expectedWidth,
  6717. int expectedHeight,
  6718. string expectedDraw
  6719. )
  6720. {
  6721. TextFormatter tf = new ()
  6722. {
  6723. Direction = direction,
  6724. ConstrainToWidth = width,
  6725. ConstrainToHeight = height,
  6726. Text = text
  6727. };
  6728. Assert.True (tf.WordWrap);
  6729. Size size = tf.FormatAndGetSize ();
  6730. Assert.Equal (new (expectedWidth, expectedHeight), size);
  6731. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  6732. TestHelpers.AssertDriverContentsWithFrameAre (expectedDraw, _output);
  6733. }
  6734. [Theory]
  6735. [SetupFakeDriver]
  6736. [InlineData ("界1234", 10, 10, TextDirection.LeftRight_TopBottom, 6, 1, @"界1234")]
  6737. [InlineData ("01234", 10, 10, TextDirection.LeftRight_TopBottom, 5, 1, @"01234")]
  6738. [InlineData (
  6739. "界1234",
  6740. 10,
  6741. 10,
  6742. TextDirection.TopBottom_LeftRight,
  6743. 2,
  6744. 5,
  6745. """
  6746. 1
  6747. 2
  6748. 3
  6749. 4
  6750. """)]
  6751. [InlineData (
  6752. "01234",
  6753. 10,
  6754. 10,
  6755. TextDirection.TopBottom_LeftRight,
  6756. 1,
  6757. 5,
  6758. """
  6759. 0
  6760. 1
  6761. 2
  6762. 3
  6763. 4
  6764. """)]
  6765. [InlineData ("界1234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 1, @"界1")]
  6766. [InlineData ("01234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 1, @"012")]
  6767. [InlineData (
  6768. "界1234",
  6769. 3,
  6770. 3,
  6771. TextDirection.TopBottom_LeftRight,
  6772. 2,
  6773. 3,
  6774. """
  6775. 1
  6776. 2
  6777. """)]
  6778. [InlineData (
  6779. "01234",
  6780. 3,
  6781. 3,
  6782. TextDirection.TopBottom_LeftRight,
  6783. 1,
  6784. 3,
  6785. """
  6786. 0
  6787. 1
  6788. 2
  6789. """)]
  6790. public void FormatAndGetSize_WordWrap_False_Returns_Correct_Size (
  6791. string text,
  6792. int width,
  6793. int height,
  6794. TextDirection direction,
  6795. int expectedWidth,
  6796. int expectedHeight,
  6797. string expectedDraw
  6798. )
  6799. {
  6800. TextFormatter tf = new ()
  6801. {
  6802. Direction = direction,
  6803. ConstrainToSize = new (width, height),
  6804. Text = text,
  6805. WordWrap = false
  6806. };
  6807. Assert.False (tf.WordWrap);
  6808. Size size = tf.FormatAndGetSize ();
  6809. Assert.Equal (new (expectedWidth, expectedHeight), size);
  6810. tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
  6811. TestHelpers.AssertDriverContentsWithFrameAre (expectedDraw, _output);
  6812. }
  6813. #endregion
  6814. }