123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219 |
- using System.Text;
- using Microsoft.VisualStudio.TestPlatform.Utilities;
- using Xunit.Abstractions;
- using static Terminal.Gui.SpinnerStyle;
- // Alias Console to MockConsole so we don't accidentally use Console
- namespace Terminal.Gui.TextTests;
- public class TextFormatterTests
- {
- private readonly ITestOutputHelper _output;
- public TextFormatterTests (ITestOutputHelper output) { _output = output; }
- public static IEnumerable<object []> CMGlyphs =>
- new List<object []> { new object [] { $"{CM.Glyphs.LeftBracket} Say Hello 你 {CM.Glyphs.RightBracket}", 16, 15 } };
- public static IEnumerable<object []> FormatEnvironmentNewLine =>
- new List<object []>
- {
- new object []
- {
- $"Line1{Environment.NewLine}Line2{Environment.NewLine}Line3{Environment.NewLine}",
- 60,
- new [] { "Line1", "Line2", "Line3" }
- }
- };
- public static IEnumerable<object []> SplitEnvironmentNewLine =>
- new List<object []>
- {
- new object []
- {
- $"First Line 界{Environment.NewLine}Second Line 界{Environment.NewLine}Third Line 界",
- new [] { "First Line 界", "Second Line 界", "Third Line 界" }
- },
- new object []
- {
- $"First Line 界{Environment.NewLine}Second Line 界{Environment.NewLine}Third Line 界{Environment.NewLine}",
- new [] { "First Line 界", "Second Line 界", "Third Line 界", "" }
- }
- };
- [Fact]
- public void Basic_Usage_With_AutoSize_True ()
- {
- var testText = "test";
- var testBounds = new Rectangle (0, 0, 100, 1);
- var tf = new TextFormatter ();
- // Manually set AutoSize to true
- tf.AutoSize = true;
- tf.Text = testText;
- Size expectedSize = new (testText.Length, 1);
- Assert.Equal (testText, tf.Text);
- Assert.Equal (Alignment.Start, tf.Alignment);
- Assert.Equal (expectedSize, tf.Size);
- tf.Draw (testBounds, new Attribute (), new Attribute ());
- Assert.Equal (expectedSize, tf.Size);
- Assert.NotEmpty (tf.GetLines ());
- tf.Alignment = Alignment.End;
- expectedSize = new (testText.Length, 1);
- Assert.Equal (testText, tf.Text);
- Assert.Equal (Alignment.End, tf.Alignment);
- Assert.Equal (expectedSize, tf.Size);
- tf.Draw (testBounds, new Attribute (), new Attribute ());
- Assert.Equal (expectedSize, tf.Size);
- Assert.NotEmpty (tf.GetLines ());
- tf.Alignment = Alignment.End;
- expectedSize = new (testText.Length, 1);
- tf.Size = expectedSize;
- Assert.Equal (testText, tf.Text);
- Assert.Equal (Alignment.End, tf.Alignment);
- Assert.Equal (expectedSize, tf.Size);
- tf.Draw (testBounds, new Attribute (), new Attribute ());
- Assert.Equal (expectedSize, tf.Size);
- Assert.NotEmpty (tf.GetLines ());
- tf.Alignment = Alignment.Center;
- expectedSize = new (testText.Length, 1);
- tf.Size = expectedSize;
- Assert.Equal (testText, tf.Text);
- Assert.Equal (Alignment.Center, tf.Alignment);
- Assert.Equal (expectedSize, tf.Size);
- tf.Draw (testBounds, new Attribute (), new Attribute ());
- Assert.Equal (expectedSize, tf.Size);
- Assert.NotEmpty (tf.GetLines ());
- }
- [Theory]
- [InlineData (null)]
- [InlineData ("")]
- public void CalcRect_Invalid_Returns_Empty (string text)
- {
- Assert.Equal (Rectangle.Empty, TextFormatter.CalcRect (0, 0, text));
- Assert.Equal (new (new (1, 2), Size.Empty), TextFormatter.CalcRect (1, 2, text));
- Assert.Equal (new (new (-1, -2), Size.Empty), TextFormatter.CalcRect (-1, -2, text));
- }
- [Theory]
- [InlineData ("line1\nline2", 5, 2)]
- [InlineData ("\nline2", 5, 2)]
- [InlineData ("\n\n", 0, 3)]
- [InlineData ("\n\n\n", 0, 4)]
- [InlineData ("line1\nline2\nline3long!", 10, 3)]
- [InlineData ("line1\nline2\n\n", 5, 4)]
- [InlineData ("line1\r\nline2", 5, 2)]
- [InlineData (" ~ s gui.cs master ↑10\n", 31, 2)]
- [InlineData ("\n ~ s gui.cs master ↑10", 31, 2)]
- [InlineData (" ~ s gui.cs master\n↑10", 27, 2)]
- public void CalcRect_MultiLine_Returns_nHigh (string text, int expectedWidth, int expectedLines)
- {
- Assert.Equal (new (0, 0, expectedWidth, expectedLines), TextFormatter.CalcRect (0, 0, text));
- string [] lines = text.Split (text.Contains (Environment.NewLine) ? Environment.NewLine : "\n");
- int maxWidth = lines.Max (s => s.GetColumns ());
- var lineWider = 0;
- for (var i = 0; i < lines.Length; i++)
- {
- int w = lines [i].GetColumns ();
- if (w == maxWidth)
- {
- lineWider = i;
- }
- }
- Assert.Equal (new (0, 0, maxWidth, expectedLines), TextFormatter.CalcRect (0, 0, text));
- Assert.Equal (
- new (
- 0,
- 0,
- lines [lineWider].ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 0)),
- expectedLines
- ),
- TextFormatter.CalcRect (0, 0, text)
- );
- }
- [Theory]
- [InlineData ("test")]
- [InlineData (" ~ s gui.cs master ↑10")]
- public void CalcRect_SingleLine_Returns_1High (string text)
- {
- Assert.Equal (new (0, 0, text.GetRuneCount (), 1), TextFormatter.CalcRect (0, 0, text));
- Assert.Equal (new (0, 0, text.GetColumns (), 1), TextFormatter.CalcRect (0, 0, text));
- }
- [Theory]
- [InlineData (14, 1, TextDirection.LeftRight_TopBottom)]
- [InlineData (1, 14, TextDirection.TopBottom_LeftRight)]
- public void CalcRect_With_Combining_Runes (int width, int height, TextDirection textDirection)
- {
- var text = "Les Mise\u0328\u0301rables";
- Assert.Equal (new (0, 0, width, height), TextFormatter.CalcRect (0, 0, text, textDirection));
- }
- [Theory]
- [InlineData ("test", TextDirection.LeftRight_TopBottom)]
- [InlineData (" ~ s gui.cs master ↑10", TextDirection.LeftRight_TopBottom)]
- [InlineData ("Say Hello view4 你", TextDirection.LeftRight_TopBottom)]
- [InlineData ("Say Hello view4 你", TextDirection.RightLeft_TopBottom)]
- [InlineData ("Say Hello view4 你", TextDirection.LeftRight_BottomTop)]
- [InlineData ("Say Hello view4 你", TextDirection.RightLeft_BottomTop)]
- public void CalcRect_Horizontal_Width_Correct (string text, TextDirection textDirection)
- {
- // The width is the number of columns in the text
- Assert.Equal (new Size (text.GetColumns (), 1), TextFormatter.CalcRect (0, 0, text, textDirection).Size);
- }
- [Theory]
- [InlineData ("test", TextDirection.TopBottom_LeftRight)]
- [InlineData (" ~ s gui.cs master ↑10", TextDirection.TopBottom_LeftRight)]
- [InlineData ("Say Hello view4 你", TextDirection.TopBottom_LeftRight)]
- [InlineData ("Say Hello view4 你", TextDirection.TopBottom_RightLeft)]
- [InlineData ("Say Hello view4 你", TextDirection.BottomTop_LeftRight)]
- [InlineData ("Say Hello view4 你", TextDirection.BottomTop_RightLeft)]
- public void CalcRect_Vertical_Height_Correct (string text, TextDirection textDirection)
- {
- // The height is based both the number of lines and the number of wide chars
- Assert.Equal (new Size (1 + text.GetColumns () - text.Length, text.Length), TextFormatter.CalcRect (0, 0, text, textDirection).Size);
- }
- [Theory]
- [InlineData ("")]
- [InlineData (null)]
- [InlineData ("test")]
- public void ClipAndJustify_Invalid_Returns_Original (string text)
- {
- string expected = string.IsNullOrEmpty (text) ? text : "";
- Assert.Equal (expected, TextFormatter.ClipAndJustify (text, 0, Alignment.Start));
- Assert.Equal (expected, TextFormatter.ClipAndJustify (text, 0, Alignment.Start));
- Assert.Throws<ArgumentOutOfRangeException> (
- () =>
- TextFormatter.ClipAndJustify (text, -1, Alignment.Start)
- );
- }
- [Theory]
- [InlineData ("test", "", 0)]
- [InlineData ("test", "te", 2)]
- [InlineData ("test", "test", int.MaxValue)]
- [InlineData ("A sentence has words.", "A sentence has words.", 22)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words.", 21)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words.", int.MaxValue)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words", 20)] // Should not fit
- [InlineData ("A sentence has words.", "A sentence", 10)] // Should not fit
- [InlineData ("A\tsentence\thas\twords.", "A sentence has words.", int.MaxValue)]
- [InlineData ("A\tsentence\thas\twords.", "A sentence", 10)]
- [InlineData ("line1\nline2\nline3long!", "line1\nline2\nline3long!", int.MaxValue)]
- [InlineData ("line1\nline2\nline3long!", "line1\nline", 10)]
- [InlineData (" ~ s gui.cs master ↑10", " ~ s ", 10)] // Unicode
- [InlineData ("Ð ÑÐ", "Ð ÑÐ", 5)] // should fit
- [InlineData ("Ð ÑÐ", "Ð ÑÐ", 4)] // should fit
- [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit
- public void ClipAndJustify_Valid_Centered (string text, string justifiedText, int maxWidth)
- {
- var alignment = Alignment.Center;
- var textDirection = TextDirection.LeftRight_TopBottom;
- var tabWidth = 1;
- Assert.Equal (
- justifiedText,
- TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
- );
- int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth);
- Assert.Equal (
- justifiedText,
- TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
- );
- Assert.True (justifiedText.GetRuneCount () <= maxWidth);
- Assert.True (justifiedText.GetColumns () <= maxWidth);
- Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ());
- Assert.Equal (
- expectedClippedWidth,
- justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))
- );
- Assert.True (expectedClippedWidth <= maxWidth);
- Assert.Equal (
- StringExtensions.ToString (justifiedText.ToRunes () [..expectedClippedWidth]),
- justifiedText
- );
- }
- [Theory]
- [InlineData ("test", "", 0)]
- [InlineData ("test", "te", 2)]
- [InlineData ("test", "test", int.MaxValue)] // This doesn't throw because it only create a word with length 1
- [InlineData ("A sentence has words.", "A sentence has words.", 22)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words.", 21)] // should fit
- [InlineData (
- "A sentence has words.",
- "A sentence has words.",
- 500
- )] // should fit
- [InlineData ("A sentence has words.", "A sentence has words", 20)] // Should not fit
- [InlineData ("A sentence has words.", "A sentence", 10)] // Should not fit
- // Now throw System.OutOfMemoryException. See https://stackoverflow.com/questions/20672920/maxcapacity-of-stringbuilder
- //[InlineData ("A\tsentence\thas\twords.", "A sentence has words.", int.MaxValue)]
- [InlineData ("A\tsentence\thas\twords.", "A sentence", 10)]
- [InlineData (
- "line1\nline2\nline3long!",
- "line1\nline2\nline3long!",
- int.MaxValue
- )] // This doesn't throw because it only create a line with length 1
- [InlineData ("line1\nline2\nline3long!", "line1\nline", 10)]
- [InlineData (" ~ s gui.cs master ↑10", " ~ s ", 10)] // Unicode
- [InlineData ("Ð ÑÐ", "Ð ÑÐ", 5)] // should fit
- [InlineData ("Ð ÑÐ", "Ð ÑÐ", 4)] // should fit
- [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit
- public void ClipAndJustify_Valid_Justified (string text, string justifiedText, int maxWidth)
- {
- var alignment = Alignment.Fill;
- var textDirection = TextDirection.LeftRight_TopBottom;
- var tabWidth = 1;
- Assert.Equal (
- justifiedText,
- TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
- );
- int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth);
- Assert.Equal (
- justifiedText,
- TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
- );
- Assert.True (justifiedText.GetRuneCount () <= maxWidth);
- Assert.True (justifiedText.GetColumns () <= maxWidth);
- Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ());
- Assert.Equal (
- expectedClippedWidth,
- justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))
- );
- Assert.True (expectedClippedWidth <= maxWidth);
- Assert.Equal (
- StringExtensions.ToString (justifiedText.ToRunes () [..expectedClippedWidth]),
- justifiedText
- );
- // see Justify_ tests below
- }
- [Theory]
- [InlineData ("test", "", 0)]
- [InlineData ("test", "te", 2)]
- [InlineData ("test", "test", int.MaxValue)]
- [InlineData ("A sentence has words.", "A sentence has words.", 22)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words.", 21)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words.", int.MaxValue)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words", 20)] // Should not fit
- [InlineData ("A sentence has words.", "A sentence", 10)] // Should not fit
- [InlineData ("A\tsentence\thas\twords.", "A sentence has words.", int.MaxValue)]
- [InlineData ("A\tsentence\thas\twords.", "A sentence", 10)]
- [InlineData ("line1\nline2\nline3long!", "line1\nline2\nline3long!", int.MaxValue)]
- [InlineData ("line1\nline2\nline3long!", "line1\nline", 10)]
- [InlineData (" ~ s gui.cs master ↑10", " ~ s ", 10)] // Unicode
- [InlineData ("Ð ÑÐ", "Ð ÑÐ", 5)] // should fit
- [InlineData ("Ð ÑÐ", "Ð ÑÐ", 4)] // should fit
- [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit
- public void ClipAndJustify_Valid_Left (string text, string justifiedText, int maxWidth)
- {
- var alignment = Alignment.Start;
- var textDirection = TextDirection.LeftRight_BottomTop;
- var tabWidth = 1;
- Assert.Equal (
- justifiedText,
- TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
- );
- int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth);
- Assert.Equal (
- justifiedText,
- TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
- );
- Assert.True (justifiedText.GetRuneCount () <= maxWidth);
- Assert.True (justifiedText.GetColumns () <= maxWidth);
- Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ());
- Assert.Equal (
- expectedClippedWidth,
- justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))
- );
- Assert.True (expectedClippedWidth <= maxWidth);
- Assert.Equal (
- StringExtensions.ToString (justifiedText.ToRunes () [..expectedClippedWidth]),
- justifiedText
- );
- }
- [Theory]
- [InlineData ("test", "", 0)]
- [InlineData ("test", "te", 2)]
- [InlineData ("test", "test", int.MaxValue)]
- [InlineData ("A sentence has words.", "A sentence has words.", 22)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words.", 21)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words.", int.MaxValue)] // should fit
- [InlineData ("A sentence has words.", "A sentence has words", 20)] // Should not fit
- [InlineData ("A sentence has words.", "A sentence", 10)] // Should not fit
- [InlineData ("A\tsentence\thas\twords.", "A sentence has words.", int.MaxValue)]
- [InlineData ("A\tsentence\thas\twords.", "A sentence", 10)]
- [InlineData ("line1\nline2\nline3long!", "line1\nline2\nline3long!", int.MaxValue)]
- [InlineData ("line1\nline2\nline3long!", "line1\nline", 10)]
- [InlineData (" ~ s gui.cs master ↑10", " ~ s ", 10)] // Unicode
- [InlineData ("Ð ÑÐ", "Ð ÑÐ", 5)] // should fit
- [InlineData ("Ð ÑÐ", "Ð ÑÐ", 4)] // should fit
- [InlineData ("Ð ÑÐ", "Ð Ñ", 3)] // Should not fit
- public void ClipAndJustify_Valid_Right (string text, string justifiedText, int maxWidth)
- {
- var alignment = Alignment.End;
- var textDirection = TextDirection.LeftRight_BottomTop;
- var tabWidth = 1;
- Assert.Equal (
- justifiedText,
- TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
- );
- int expectedClippedWidth = Math.Min (justifiedText.GetRuneCount (), maxWidth);
- Assert.Equal (
- justifiedText,
- TextFormatter.ClipAndJustify (text, maxWidth, alignment, textDirection, tabWidth)
- );
- Assert.True (justifiedText.GetRuneCount () <= maxWidth);
- Assert.True (justifiedText.GetColumns () <= maxWidth);
- Assert.Equal (expectedClippedWidth, justifiedText.GetRuneCount ());
- Assert.Equal (
- expectedClippedWidth,
- justifiedText.ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 1))
- );
- Assert.True (expectedClippedWidth <= maxWidth);
- Assert.Equal (
- StringExtensions.ToString (justifiedText.ToRunes () [..expectedClippedWidth]),
- justifiedText
- );
- }
- [Theory]
- [InlineData (14, 1, TextDirection.LeftRight_TopBottom, "Les Misęrables")]
- [InlineData (1, 14, TextDirection.TopBottom_LeftRight, "L\ne\ns\n \nM\ni\ns\nę\nr\na\nb\nl\ne\ns")]
- [InlineData (
- 4,
- 4,
- TextDirection.TopBottom_LeftRight,
- @"
- LMre
- eias
- ssb
- ęl "
- )]
- public void Draw_With_Combining_Runes (int width, int height, TextDirection textDirection, string expected)
- {
- var driver = new FakeDriver ();
- driver.Init ();
- var text = "Les Mise\u0328\u0301rables";
- var tf = new TextFormatter ();
- tf.Direction = textDirection;
- tf.Text = text;
- Assert.True (tf.WordWrap);
- tf.Size = new (width, height);
- tf.Draw (
- new (0, 0, width, height),
- new Attribute (ColorName.White, ColorName.Black),
- new Attribute (ColorName.Blue, ColorName.Black),
- default (Rectangle),
- driver
- );
- TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
- driver.End ();
- }
- [Fact]
- [SetupFakeDriver]
- public void FillRemaining_True_False ()
- {
- ((FakeDriver)Application.Driver).SetBufferSize (22, 5);
- Attribute [] attrs =
- {
- Attribute.Default, new Attribute (ColorName.Green, ColorName.BrightMagenta),
- new Attribute (ColorName.Blue, ColorName.Cyan)
- };
- var tf = new TextFormatter { Size = new (14, 3), Text = "Test\nTest long\nTest long long\n", MultiLine = true };
- tf.Draw (
- new (1, 1, 19, 3),
- attrs [1],
- attrs [2]);
- Assert.False (tf.FillRemaining);
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- Test
- Test long
- Test long long",
- _output);
- TestHelpers.AssertDriverAttributesAre (
- @"
- 000000000000000000000
- 011110000000000000000
- 011111111100000000000
- 011111111111111000000
- 000000000000000000000",
- null,
- attrs);
- tf.FillRemaining = true;
- tf.Draw (
- new (1, 1, 19, 3),
- attrs [1],
- attrs [2]);
- TestHelpers.AssertDriverAttributesAre (
- @"
- 000000000000000000000
- 011111111111111111110
- 011111111111111111110
- 011111111111111111110
- 000000000000000000000",
- null,
- attrs);
- }
- [Theory]
- [InlineData ("_k Before", true, 0, (KeyCode)'K')] // lower case should return uppercase Hotkey
- [InlineData ("a_k Second", true, 1, (KeyCode)'K')]
- [InlineData ("Last _k", true, 5, (KeyCode)'K')]
- [InlineData ("After k_", false, -1, KeyCode.Null)]
- [InlineData ("Multiple _k and _R", true, 9, (KeyCode)'K')]
- [InlineData ("Non-english: _кдать", true, 13, (KeyCode)'к')] // Lower case Cryllic K (к)
- [InlineData ("_k Before", true, 0, (KeyCode)'K', true)] // Turn on FirstUpperCase and verify same results
- [InlineData ("a_k Second", true, 1, (KeyCode)'K', true)]
- [InlineData ("Last _k", true, 5, (KeyCode)'K', true)]
- [InlineData ("After k_", false, -1, KeyCode.Null, true)]
- [InlineData ("Multiple _k and _r", true, 9, (KeyCode)'K', true)]
- [InlineData ("Non-english: _кдать", true, 13, (KeyCode)'к', true)] // Cryllic K (К)
- public void FindHotKey_AlphaLowerCase_Succeeds (
- string text,
- bool expectedResult,
- int expectedHotPos,
- KeyCode expectedKey,
- bool supportFirstUpperCase = false
- )
- {
- var hotKeySpecifier = (Rune)'_';
- bool result = TextFormatter.FindHotKey (
- text,
- hotKeySpecifier,
- out int hotPos,
- out Key hotKey,
- supportFirstUpperCase
- );
- if (expectedResult)
- {
- Assert.True (result);
- }
- else
- {
- Assert.False (result);
- }
- Assert.Equal (expectedResult, result);
- Assert.Equal (expectedHotPos, hotPos);
- Assert.Equal (expectedKey, hotKey);
- }
- [Theory]
- [InlineData ("_K Before", true, 0, (KeyCode)'K')]
- [InlineData ("a_K Second", true, 1, (KeyCode)'K')]
- [InlineData ("Last _K", true, 5, (KeyCode)'K')]
- [InlineData ("After K_", false, -1, KeyCode.Null)]
- [InlineData ("Multiple _K and _R", true, 9, (KeyCode)'K')]
- [InlineData ("Non-english: _Кдать", true, 13, (KeyCode)'К')] // Cryllic K (К)
- [InlineData ("_K Before", true, 0, (KeyCode)'K', true)] // Turn on FirstUpperCase and verify same results
- [InlineData ("a_K Second", true, 1, (KeyCode)'K', true)]
- [InlineData ("Last _K", true, 5, (KeyCode)'K', true)]
- [InlineData ("After K_", false, -1, KeyCode.Null, true)]
- [InlineData ("Multiple _K and _R", true, 9, (KeyCode)'K', true)]
- [InlineData ("Non-english: _Кдать", true, 13, (KeyCode)'К', true)] // Cryllic K (К)
- public void FindHotKey_AlphaUpperCase_Succeeds (
- string text,
- bool expectedResult,
- int expectedHotPos,
- KeyCode expectedKey,
- bool supportFirstUpperCase = false
- )
- {
- var hotKeySpecifier = (Rune)'_';
- bool result = TextFormatter.FindHotKey (
- text,
- hotKeySpecifier,
- out int hotPos,
- out Key hotKey,
- supportFirstUpperCase
- );
- if (expectedResult)
- {
- Assert.True (result);
- }
- else
- {
- Assert.False (result);
- }
- Assert.Equal (expectedResult, result);
- Assert.Equal (expectedHotPos, hotPos);
- Assert.Equal (expectedKey, hotKey);
- }
- [Theory]
- [InlineData (null)]
- [InlineData ("")]
- [InlineData ("no hotkey")]
- [InlineData ("No hotkey, Upper Case")]
- [InlineData ("Non-english: Сохранить")]
- public void FindHotKey_Invalid_ReturnsFalse (string text)
- {
- var hotKeySpecifier = (Rune)'_';
- var supportFirstUpperCase = false;
- var hotPos = 0;
- Key hotKey = KeyCode.Null;
- var result = false;
- result = TextFormatter.FindHotKey (
- text,
- hotKeySpecifier,
- out hotPos,
- out hotKey,
- supportFirstUpperCase
- );
- Assert.False (result);
- Assert.Equal (-1, hotPos);
- Assert.Equal (KeyCode.Null, hotKey);
- }
- [Theory]
- [InlineData ("\"k before")]
- [InlineData ("ak second")]
- [InlineData ("last k")]
- [InlineData ("multiple k and r")]
- [InlineData ("12345")]
- [InlineData ("`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?")] // punctuation
- [InlineData (" ~ s gui.cs master ↑10")] // ~IsLetterOrDigit + Unicode
- [InlineData ("non-english: кдать")] // Lower case Cryllic K (к)
- public void FindHotKey_Legacy_FirstUpperCase_NotFound_Returns_False (string text)
- {
- var supportFirstUpperCase = true;
- var hotKeySpecifier = (Rune)0;
- bool result = TextFormatter.FindHotKey (
- text,
- hotKeySpecifier,
- out int hotPos,
- out Key hotKey,
- supportFirstUpperCase
- );
- Assert.False (result);
- Assert.Equal (-1, hotPos);
- Assert.Equal (KeyCode.Null, hotKey);
- }
- [Theory]
- [InlineData ("K Before", true, 0, (KeyCode)'K')]
- [InlineData ("aK Second", true, 1, (KeyCode)'K')]
- [InlineData ("last K", true, 5, (KeyCode)'K')]
- [InlineData ("multiple K and R", true, 9, (KeyCode)'K')]
- [InlineData ("non-english: Кдать", true, 13, (KeyCode)'К')] // Cryllic K (К)
- public void FindHotKey_Legacy_FirstUpperCase_Succeeds (
- string text,
- bool expectedResult,
- int expectedHotPos,
- KeyCode expectedKey
- )
- {
- var supportFirstUpperCase = true;
- var hotKeySpecifier = (Rune)0;
- bool result = TextFormatter.FindHotKey (
- text,
- hotKeySpecifier,
- out int hotPos,
- out Key hotKey,
- supportFirstUpperCase
- );
- if (expectedResult)
- {
- Assert.True (result);
- }
- else
- {
- Assert.False (result);
- }
- Assert.Equal (expectedResult, result);
- Assert.Equal (expectedHotPos, hotPos);
- Assert.Equal (expectedKey, hotKey);
- }
- [Theory]
- [InlineData ("_1 Before", true, 0, (KeyCode)'1')] // Digits
- [InlineData ("a_1 Second", true, 1, (KeyCode)'1')]
- [InlineData ("Last _1", true, 5, (KeyCode)'1')]
- [InlineData ("After 1_", false, -1, KeyCode.Null)]
- [InlineData ("Multiple _1 and _2", true, 9, (KeyCode)'1')]
- [InlineData ("_1 Before", true, 0, (KeyCode)'1', true)] // Turn on FirstUpperCase and verify same results
- [InlineData ("a_1 Second", true, 1, (KeyCode)'1', true)]
- [InlineData ("Last _1", true, 5, (KeyCode)'1', true)]
- [InlineData ("After 1_", false, -1, KeyCode.Null, true)]
- [InlineData ("Multiple _1 and _2", true, 9, (KeyCode)'1', true)]
- public void FindHotKey_Numeric_Succeeds (
- string text,
- bool expectedResult,
- int expectedHotPos,
- KeyCode expectedKey,
- bool supportFirstUpperCase = false
- )
- {
- var hotKeySpecifier = (Rune)'_';
- bool result = TextFormatter.FindHotKey (
- text,
- hotKeySpecifier,
- out int hotPos,
- out Key hotKey,
- supportFirstUpperCase
- );
- if (expectedResult)
- {
- Assert.True (result);
- }
- else
- {
- Assert.False (result);
- }
- Assert.Equal (expectedResult, result);
- Assert.Equal (expectedHotPos, hotPos);
- Assert.Equal (expectedKey, hotKey);
- }
- [Theory]
- [InlineData ("_\"k before", true, (KeyCode)'"')] // BUGBUG: Not sure why this fails. " is a normal char
- [InlineData ("\"_k before", true, KeyCode.K)]
- [InlineData ("_`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?", true, (KeyCode)'`')]
- [InlineData ("`_~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?", true, (KeyCode)'~')]
- [InlineData (
- "`~!@#$%^&*()-__=+[{]}\\|;:'\",<.>/?",
- true,
- (KeyCode)'='
- )] // BUGBUG: Not sure why this fails. Ignore the first and consider the second
- [InlineData ("_ ~ s gui.cs master ↑10", true, (KeyCode)'')] // ~IsLetterOrDigit + Unicode
- [InlineData (" ~ s gui.cs _ master ↑10", true, (KeyCode)'')] // ~IsLetterOrDigit + Unicode
- [InlineData ("non-english: _кдать", true, (KeyCode)'к')] // Lower case Cryllic K (к)
- public void FindHotKey_Symbols_Returns_Symbol (string text, bool found, KeyCode expected)
- {
- var hotKeySpecifier = (Rune)'_';
- bool result = TextFormatter.FindHotKey (text, hotKeySpecifier, out int _, out Key hotKey);
- Assert.Equal (found, result);
- Assert.Equal (expected, hotKey);
- }
- [Fact]
- public void Format_Dont_Throw_ArgumentException_With_WordWrap_As_False_And_Keep_End_Spaces_As_True ()
- {
- Exception exception = Record.Exception (
- () =>
- TextFormatter.Format (
- "Some text",
- 4,
- Alignment.Start,
- false,
- true
- )
- );
- Assert.Null (exception);
- }
- [Theory]
- [InlineData (
- "Hello world, how are you today? Pretty neat!",
- 44,
- 80,
- "Hello world, how are you today? Pretty neat!"
- )]
- public void Format_Justified_Always_Returns_Text_Width_Equal_To_Passed_Width_Horizontal (
- string text,
- int runeCount,
- int maxWidth,
- string justifiedText
- )
- {
- Assert.Equal (runeCount, text.GetRuneCount ());
- var fmtText = string.Empty;
- for (int i = text.GetRuneCount (); i < maxWidth; i++)
- {
- fmtText = TextFormatter.Format (text, i, Alignment.Fill, false, true) [0];
- Assert.Equal (i, fmtText.GetRuneCount ());
- char c = fmtText [^1];
- Assert.True (text.EndsWith (c));
- }
- Assert.Equal (justifiedText, fmtText);
- }
- [Theory]
- [InlineData (
- "Hello world, how are you today? Pretty neat!",
- 44,
- 80,
- "Hello world, how are you today? Pretty neat!"
- )]
- public void Format_Justified_Always_Returns_Text_Width_Equal_To_Passed_Width_Vertical (
- string text,
- int runeCount,
- int maxWidth,
- string justifiedText
- )
- {
- Assert.Equal (runeCount, text.GetRuneCount ());
- var fmtText = string.Empty;
- for (int i = text.GetRuneCount (); i < maxWidth; i++)
- {
- fmtText = TextFormatter.Format (
- text,
- i,
- Alignment.Fill,
- false,
- true,
- 0,
- TextDirection.TopBottom_LeftRight
- ) [0];
- Assert.Equal (i, fmtText.GetRuneCount ());
- char c = fmtText [^1];
- Assert.True (text.EndsWith (c));
- }
- Assert.Equal (justifiedText, fmtText);
- }
- [Theory]
- [InlineData ("Truncate", 3, "Tru")]
- [InlineData ("デモエムポンズ", 3, "デ")]
- public void Format_Truncate_Simple_And_Wide_Runes (string text, int width, string expected)
- {
- List<string> list = TextFormatter.Format (text, width, false, false);
- Assert.Equal (expected, list [^1]);
- }
- [Theory]
- [MemberData (nameof (FormatEnvironmentNewLine))]
- public void Format_With_PreserveTrailingSpaces_And_Without_PreserveTrailingSpaces (
- string text,
- int width,
- IEnumerable<string> expected
- )
- {
- var preserveTrailingSpaces = false;
- List<string> formated = TextFormatter.Format (text, width, false, true, preserveTrailingSpaces);
- Assert.Equal (expected, formated);
- preserveTrailingSpaces = true;
- formated = TextFormatter.Format (text, width, false, true, preserveTrailingSpaces);
- Assert.Equal (expected, formated);
- }
- [Theory]
- [InlineData (
- " A sentence has words. \n This is the second Line - 2. ",
- 4,
- -50,
- Alignment.Start,
- true,
- false,
- new [] { " A", "sent", "ence", "has", "word", "s. ", " Thi", "s is", "the", "seco", "nd", "Line", "- 2." },
- " Asentencehaswords. This isthesecondLine- 2."
- )]
- [InlineData (
- " A sentence has words. \n This is the second Line - 2. ",
- 4,
- -50,
- Alignment.Start,
- true,
- true,
- new []
- {
- " A ",
- "sent",
- "ence",
- " ",
- "has ",
- "word",
- "s. ",
- " ",
- "This",
- " is ",
- "the ",
- "seco",
- "nd ",
- "Line",
- " - ",
- "2. "
- },
- " A sentence has words. This is the second Line - 2. "
- )]
- public void Format_WordWrap_PreserveTrailingSpaces (
- string text,
- int maxWidth,
- int widthOffset,
- Alignment alignment,
- bool wrap,
- bool preserveTrailingSpaces,
- IEnumerable<string> resultLines,
- string expectedWrappedText
- )
- {
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
- Assert.Equal (list.Count, resultLines.Count ());
- Assert.Equal (resultLines, list);
- var wrappedText = string.Empty;
- foreach (string txt in list)
- {
- wrappedText += txt;
- }
- Assert.Equal (expectedWrappedText, wrappedText);
- }
- [Theory]
- [InlineData ("Hello World", 11)]
- [InlineData ("こんにちは世界", 14)]
- public void GetColumns_Simple_And_Wide_Runes (string text, int width) { Assert.Equal (width, text.GetColumns ()); }
- [Theory]
- [InlineData ("Hello World", 6, 6)]
- [InlineData ("こんにちは 世界", 6, 3)]
- [MemberData (nameof (CMGlyphs))]
- public void GetLengthThatFits_List_Simple_And_Wide_Runes (string text, int columns, int expectedLength)
- {
- List<Rune> runes = text.ToRuneList ();
- Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (runes, columns));
- }
- [Theory]
- [InlineData ("test", 3, 3)]
- [InlineData ("test", 4, 4)]
- [InlineData ("test", 10, 4)]
- public void GetLengthThatFits_Runelist (string text, int columns, int expectedLength)
- {
- List<Rune> runes = text.ToRuneList ();
- Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (runes, columns));
- }
- [Theory]
- [InlineData ("Hello World", 6, 6)]
- [InlineData ("こんにちは 世界", 6, 3)]
- public void GetLengthThatFits_Simple_And_Wide_Runes (string text, int columns, int expectedLength)
- {
- Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (text, columns));
- }
- [Theory]
- [InlineData ("test", 3, 3)]
- [InlineData ("test", 4, 4)]
- [InlineData ("test", 10, 4)]
- [InlineData ("test", 1, 1)]
- [InlineData ("test", 0, 0)]
- [InlineData ("test", -1, 0)]
- [InlineData (null, -1, 0)]
- [InlineData ("", -1, 0)]
- public void GetLengthThatFits_String (string text, int columns, int expectedLength)
- {
- Assert.Equal (expectedLength, TextFormatter.GetLengthThatFits (text, columns));
- }
- [Fact]
- public void GetLengthThatFits_With_Combining_Runes ()
- {
- var text = "Les Mise\u0328\u0301rables";
- Assert.Equal (16, TextFormatter.GetLengthThatFits (text, 14));
- }
- [Fact]
- public void GetMaxColsForWidth_With_Combining_Runes ()
- {
- List<string> text = new () { "Les Mis", "e\u0328\u0301", "rables" };
- Assert.Equal (1, TextFormatter.GetMaxColsForWidth (text, 1));
- }
- [Theory]
- [InlineData (new [] { "0123456789" }, 1)]
- [InlineData (new [] { "Hello World" }, 1)]
- [InlineData (new [] { "Hello", "World" }, 2)]
- [InlineData (new [] { "こんにちは", "世界" }, 4)]
- public void GetColumnsRequiredForVerticalText_List_GetsWidth (IEnumerable<string> text, int expectedWidth)
- {
- Assert.Equal (expectedWidth, TextFormatter.GetColumnsRequiredForVerticalText (text.ToList ()));
- }
- [Theory]
- [InlineData (new [] { "Hello World" }, 1, 0, 1, 1)]
- [InlineData (new [] { "Hello", "World" }, 2, 1, 1, 1)]
- [InlineData (new [] { "こんにちは", "世界" }, 4, 1, 1, 2)]
- public void GetColumnsRequiredForVerticalText_List_Simple_And_Wide_Runes (
- IEnumerable<string> text,
- int expectedWidth,
- int index,
- int length,
- int expectedIndexWidth
- )
- {
- Assert.Equal (expectedWidth, TextFormatter.GetColumnsRequiredForVerticalText (text.ToList ()));
- Assert.Equal (expectedIndexWidth, TextFormatter.GetColumnsRequiredForVerticalText (text.ToList (), index, length));
- }
- [Fact]
- public void GetColumnsRequiredForVerticalText_List_With_Combining_Runes ()
- {
- List<string> text = new () { "Les Mis", "e\u0328\u0301", "rables" };
- Assert.Equal (1, TextFormatter.GetColumnsRequiredForVerticalText (text, 1, 1));
- }
- //[Fact]
- //public void GetWidestLineLength_With_Combining_Runes ()
- //{
- // var text = "Les Mise\u0328\u0301rables";
- // Assert.Equal (1, TextFormatter.GetWidestLineLength (text, 1, 1));
- //}
- [Fact]
- public void Internal_Tests ()
- {
- var tf = new TextFormatter ();
- Assert.Equal (KeyCode.Null, tf.HotKey);
- tf.HotKey = KeyCode.CtrlMask | KeyCode.Q;
- Assert.Equal (KeyCode.CtrlMask | KeyCode.Q, tf.HotKey);
- }
- [Theory]
- [InlineData ("")]
- [InlineData (null)]
- [InlineData ("test")]
- public void Justify_Invalid (string text)
- {
- Assert.Equal (text, TextFormatter.Justify (text, 0));
- Assert.Equal (text, TextFormatter.Justify (text, 0));
- Assert.Throws<ArgumentOutOfRangeException> (() => TextFormatter.Justify (text, -1));
- }
- [Theory]
- // Even # of spaces
- // 0123456789
- [InlineData ("012 456 89", "012 456 89", 10, 0, "+", true)]
- [InlineData ("012 456 89", "012++456+89", 11, 1)]
- [InlineData ("012 456 89", "012 456 89", 12, 2, "++", true)]
- [InlineData ("012 456 89", "012+++456++89", 13, 3)]
- [InlineData ("012 456 89", "012 456 89", 14, 4, "+++", true)]
- [InlineData ("012 456 89", "012++++456+++89", 15, 5)]
- [InlineData ("012 456 89", "012 456 89", 16, 6, "++++", true)]
- [InlineData ("012 456 89", "012 456 89", 30, 20, "+++++++++++", true)]
- [InlineData ("012 456 89", "012+++++++++++++456++++++++++++89", 33, 23)]
- // Odd # of spaces
- // 01234567890123
- [InlineData ("012 456 89 end", "012 456 89 end", 14, 0, "+", true)]
- [InlineData ("012 456 89 end", "012++456+89+end", 15, 1)]
- [InlineData ("012 456 89 end", "012++456++89+end", 16, 2)]
- [InlineData ("012 456 89 end", "012 456 89 end", 17, 3, "++", true)]
- [InlineData ("012 456 89 end", "012+++456++89++end", 18, 4)]
- [InlineData ("012 456 89 end", "012+++456+++89++end", 19, 5)]
- [InlineData ("012 456 89 end", "012 456 89 end", 20, 6, "+++", true)]
- [InlineData ("012 456 89 end", "012++++++++456++++++++89+++++++end", 34, 20)]
- [InlineData ("012 456 89 end", "012+++++++++456+++++++++89++++++++end", 37, 23)]
- // Unicode
- // Even # of chars
- // 0123456789
- [InlineData ("пÑРвРÑ", "пÑРвРÑ", 10, 0, "+", true)]
- [InlineData ("пÑРвРÑ", "пÑÐ++вÐ+Ñ", 11, 1)]
- [InlineData ("пÑРвРÑ", "пÑРвРÑ", 12, 2, "++", true)]
- [InlineData ("пÑРвРÑ", "пÑÐ+++вÐ++Ñ", 13, 3)]
- [InlineData ("пÑРвРÑ", "пÑРвРÑ", 14, 4, "+++", true)]
- [InlineData ("пÑРвРÑ", "пÑÐ++++вÐ+++Ñ", 15, 5)]
- [InlineData ("пÑРвРÑ", "пÑРвРÑ", 16, 6, "++++", true)]
- [InlineData ("пÑРвРÑ", "пÑРвРÑ", 30, 20, "+++++++++++", true)]
- [InlineData ("пÑРвРÑ", "пÑÐ+++++++++++++вÐ++++++++++++Ñ", 33, 23)]
- // Unicode
- // Odd # of chars
- // 0123456789
- [InlineData ("Ð ÑРвРÑ", "Ð ÑРвРÑ", 10, 0, "+", true)]
- [InlineData ("Ð ÑРвРÑ", "Ð++ÑÐ+вÐ+Ñ", 11, 1)]
- [InlineData ("Ð ÑРвРÑ", "Ð++ÑÐ++вÐ+Ñ", 12, 2)]
- [InlineData ("Ð ÑРвРÑ", "Ð ÑРвРÑ", 13, 3, "++", true)]
- [InlineData ("Ð ÑРвРÑ", "Ð+++ÑÐ++вÐ++Ñ", 14, 4)]
- [InlineData ("Ð ÑРвРÑ", "Ð+++ÑÐ+++вÐ++Ñ", 15, 5)]
- [InlineData ("Ð ÑРвРÑ", "Ð ÑРвРÑ", 16, 6, "+++", true)]
- [InlineData ("Ð ÑРвРÑ", "Ð++++++++ÑÐ++++++++вÐ+++++++Ñ", 30, 20)]
- [InlineData ("Ð ÑРвРÑ", "Ð+++++++++ÑÐ+++++++++вÐ++++++++Ñ", 33, 23)]
- public void Justify_Sentence (
- string text,
- string justifiedText,
- int forceToWidth,
- int widthOffset,
- string replaceWith = null,
- bool replace = false
- )
- {
- var fillChar = '+';
- Assert.Equal (forceToWidth, text.GetRuneCount () + widthOffset);
- if (replace)
- {
- justifiedText = text.Replace (" ", replaceWith);
- }
- Assert.Equal (justifiedText, TextFormatter.Justify (text, forceToWidth, fillChar));
- Assert.True (Math.Abs (forceToWidth - justifiedText.GetRuneCount ()) < text.Count (s => s == ' '));
- Assert.True (Math.Abs (forceToWidth - justifiedText.GetColumns ()) < text.Count (s => s == ' '));
- }
- [Theory]
- [InlineData ("word")] // Even # of chars
- [InlineData ("word.")] // Odd # of chars
- [InlineData ("пÑивеÑ")] // Unicode (even #)
- [InlineData ("пÑивеÑ.")] // Unicode (odd # of chars)
- public void Justify_SingleWord (string text)
- {
- string justifiedText = text;
- var fillChar = '+';
- int width = text.GetRuneCount ();
- Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
- width = text.GetRuneCount () + 1;
- Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
- width = text.GetRuneCount () + 2;
- Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
- width = text.GetRuneCount () + 10;
- Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
- width = text.GetRuneCount () + 11;
- Assert.Equal (justifiedText, TextFormatter.Justify (text, width, fillChar));
- }
- [Theory]
- [InlineData ("Single Line 界", 14)]
- [InlineData ("First Line 界\nSecond Line 界\nThird Line 界\n", 14)]
- public void MaxWidthLine_With_And_Without_Newlines (string text, int expected) { Assert.Equal (expected, TextFormatter.GetWidestLineLength (text)); }
- [Theory]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 0,
- 0,
- false,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 0,
- 1,
- false,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 1,
- 0,
- false,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 0,
- 0,
- true,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 0,
- 1,
- true,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 1,
- 0,
- true,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 6,
- 5,
- false,
- new [] { "First " }
- )]
- [InlineData ("1\n2\n3\n4\n5\n6", 6, 5, false, new [] { "1 2 3 " })]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 6,
- 5,
- true,
- new [] { "First ", "Second", "Third ", "Forty ", "Fiftee" }
- )]
- [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, false, new [] { "第一" })]
- [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, true, new [] { "第一", "第二", "第三", "四十", "第十" })]
- public void MultiLine_WordWrap_False_Horizontal_Direction (
- string text,
- int maxWidth,
- int maxHeight,
- bool multiLine,
- IEnumerable<string> resultLines
- )
- {
- var tf = new TextFormatter
- {
- Text = text, Size = new (maxWidth, maxHeight), WordWrap = false, MultiLine = multiLine
- };
- Assert.False (tf.AutoSize);
- Assert.False (tf.WordWrap);
- Assert.True (tf.MultiLine == multiLine);
- Assert.Equal (TextDirection.LeftRight_TopBottom, tf.Direction);
- List<string> splitLines = tf.GetLines ();
- Assert.Equal (splitLines.Count, resultLines.Count ());
- Assert.Equal (splitLines, resultLines);
- }
- [Theory]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 0,
- 0,
- false,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 0,
- 1,
- false,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 1,
- 0,
- false,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 0,
- 0,
- true,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 0,
- 1,
- true,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 1,
- 0,
- true,
- new [] { "" }
- )]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 6,
- 5,
- false,
- new [] { "First" }
- )]
- [InlineData ("1\n2\n3\n4\n5\n6", 6, 5, false, new [] { "1 2 3" })]
- [InlineData (
- "First Line\nSecond Line\nThird Line\nForty Line\nFifteenth Line\nSeventy Line",
- 6,
- 5,
- true,
- new [] { "First", "Secon", "Third", "Forty", "Fifte", "Seven" }
- )]
- [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, false, new [] { "第一行 第" })]
- [InlineData ("第一行\n第二行\n第三行\n四十行\n第十五行\n七十行", 5, 5, true, new [] { "第一行", "第二行" })]
- public void MultiLine_WordWrap_False_Vertical_Direction (
- string text,
- int maxWidth,
- int maxHeight,
- bool multiLine,
- IEnumerable<string> resultLines
- )
- {
- var tf = new TextFormatter
- {
- Text = text,
- Size = new (maxWidth, maxHeight),
- WordWrap = false,
- MultiLine = multiLine,
- Direction = TextDirection.TopBottom_LeftRight
- };
- Assert.False (tf.AutoSize);
- Assert.False (tf.WordWrap);
- Assert.True (tf.MultiLine == multiLine);
- Assert.Equal (TextDirection.TopBottom_LeftRight, tf.Direction);
- List<string> splitLines = tf.GetLines ();
- Assert.Equal (splitLines.Count, resultLines.Count ());
- Assert.Equal (splitLines, resultLines);
- }
- [Fact]
- public void NeedsFormat_Sets ()
- {
- var testText = "test";
- var testBounds = new Rectangle (0, 0, 100, 1);
- var tf = new TextFormatter ();
- tf.Text = "test";
- Assert.True (tf.NeedsFormat); // get_Lines causes a Format
- Assert.NotEmpty (tf.GetLines ());
- Assert.False (tf.NeedsFormat); // get_Lines causes a Format
- Assert.Equal (testText, tf.Text);
- tf.Draw (testBounds, new Attribute (), new Attribute ());
- Assert.False (tf.NeedsFormat);
- tf.Size = new (1, 1);
- Assert.True (tf.NeedsFormat);
- Assert.NotEmpty (tf.GetLines ());
- Assert.False (tf.NeedsFormat); // get_Lines causes a Format
- tf.Alignment = Alignment.Center;
- Assert.True (tf.NeedsFormat);
- Assert.NotEmpty (tf.GetLines ());
- Assert.False (tf.NeedsFormat); // get_Lines causes a Format
- }
- [Theory]
- [InlineData ("", -1, Alignment.Start, false, 0)]
- [InlineData (null, 0, Alignment.Start, false, 1)]
- [InlineData (null, 0, Alignment.Start, true, 1)]
- [InlineData ("", 0, Alignment.Start, false, 1)]
- [InlineData ("", 0, Alignment.Start, true, 1)]
- public void Reformat_Invalid (string text, int maxWidth, Alignment alignment, bool wrap, int linesCount)
- {
- if (maxWidth < 0)
- {
- Assert.Throws<ArgumentOutOfRangeException> (
- () =>
- TextFormatter.Format (text, maxWidth, alignment, wrap)
- );
- }
- else
- {
- List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap);
- Assert.NotEmpty (list);
- Assert.True (list.Count == linesCount);
- Assert.Equal (string.Empty, list [0]);
- }
- }
- [Theory]
- [InlineData ("A sentence has words.\nLine 2.", 0, -29, Alignment.Start, false, 1, true)]
- [InlineData ("A sentence has words.\nLine 2.", 1, -28, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.\nLine 2.", 5, -24, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.\nLine 2.", 28, -1, Alignment.Start, false, 1, false)]
- // no clip
- [InlineData ("A sentence has words.\nLine 2.", 29, 0, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.\nLine 2.", 30, 1, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.\r\nLine 2.", 0, -30, Alignment.Start, false, 1, true)]
- [InlineData ("A sentence has words.\r\nLine 2.", 1, -29, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.\r\nLine 2.", 5, -25, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.\r\nLine 2.", 29, -1, Alignment.Start, false, 1, false, 1)]
- [InlineData ("A sentence has words.\r\nLine 2.", 30, 0, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.\r\nLine 2.", 31, 1, Alignment.Start, false, 1, false)]
- public void Reformat_NoWordrap_NewLines_MultiLine_False (
- string text,
- int maxWidth,
- int widthOffset,
- Alignment alignment,
- bool wrap,
- int linesCount,
- bool stringEmpty,
- int clipWidthOffset = 0
- )
- {
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth) + clipWidthOffset;
- List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap);
- Assert.NotEmpty (list);
- Assert.True (list.Count == linesCount);
- if (stringEmpty)
- {
- Assert.Equal (string.Empty, list [0]);
- }
- else
- {
- Assert.NotEqual (string.Empty, list [0]);
- }
- if (text.Contains ("\r\n") && maxWidth > 0)
- {
- Assert.Equal (
- StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth])
- .Replace ("\r\n", " "),
- list [0]
- );
- }
- else if (text.Contains ('\n') && maxWidth > 0)
- {
- Assert.Equal (
- StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth])
- .Replace ("\n", " "),
- list [0]
- );
- }
- else
- {
- Assert.Equal (StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth]), list [0]);
- }
- }
- [Theory]
- [InlineData ("A sentence has words.\nLine 2.", 0, -29, Alignment.Start, false, 1, true, new [] { "" })]
- [InlineData (
- "A sentence has words.\nLine 2.",
- 1,
- -28,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A", "L" }
- )]
- [InlineData (
- "A sentence has words.\nLine 2.",
- 5,
- -24,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sen", "Line " }
- )]
- [InlineData (
- "A sentence has words.\nLine 2.",
- 28,
- -1,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- //// no clip
- [InlineData (
- "A sentence has words.\nLine 2.",
- 29,
- 0,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- [InlineData (
- "A sentence has words.\nLine 2.",
- 30,
- 1,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- [InlineData ("A sentence has words.\r\nLine 2.", 0, -30, Alignment.Start, false, 1, true, new [] { "" })]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 1,
- -29,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A", "L" }
- )]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 5,
- -25,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sen", "Line " }
- )]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 29,
- -1,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 30,
- 0,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 31,
- 1,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- public void Reformat_NoWordrap_NewLines_MultiLine_True (
- string text,
- int maxWidth,
- int widthOffset,
- Alignment alignment,
- bool wrap,
- int linesCount,
- bool stringEmpty,
- IEnumerable<string> resultLines
- )
- {
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- List<string> list = TextFormatter.Format (
- text,
- maxWidth,
- alignment,
- wrap,
- false,
- 0,
- TextDirection.LeftRight_TopBottom,
- true
- );
- Assert.NotEmpty (list);
- Assert.True (list.Count == linesCount);
- if (stringEmpty)
- {
- Assert.Equal (string.Empty, list [0]);
- }
- else
- {
- Assert.NotEqual (string.Empty, list [0]);
- }
- Assert.Equal (list, resultLines);
- }
- [Theory]
- [InlineData ("A sentence has words.\nLine 2.", 0, -29, Alignment.Start, false, 1, true, new [] { "" })]
- [InlineData (
- "A sentence has words.\nLine 2.",
- 1,
- -28,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A", "L" }
- )]
- [InlineData (
- "A sentence has words.\nLine 2.",
- 5,
- -24,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sen", "Line " }
- )]
- [InlineData (
- "A sentence has words.\nLine 2.",
- 28,
- -1,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- //// no clip
- [InlineData (
- "A sentence has words.\nLine 2.",
- 29,
- 0,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- [InlineData (
- "A sentence has words.\nLine 2.",
- 30,
- 1,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- [InlineData ("A sentence has words.\r\nLine 2.", 0, -30, Alignment.Start, false, 1, true, new [] { "" })]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 1,
- -29,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A", "L" }
- )]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 5,
- -25,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sen", "Line " }
- )]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 29,
- -1,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 30,
- 0,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- [InlineData (
- "A sentence has words.\r\nLine 2.",
- 31,
- 1,
- Alignment.Start,
- false,
- 2,
- false,
- new [] { "A sentence has words.", "Line 2." }
- )]
- public void Reformat_NoWordrap_NewLines_MultiLine_True_Vertical (
- string text,
- int maxWidth,
- int widthOffset,
- Alignment alignment,
- bool wrap,
- int linesCount,
- bool stringEmpty,
- IEnumerable<string> resultLines
- )
- {
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- List<string> list = TextFormatter.Format (
- text,
- maxWidth,
- alignment,
- wrap,
- false,
- 0,
- TextDirection.TopBottom_LeftRight,
- true
- );
- Assert.NotEmpty (list);
- Assert.True (list.Count == linesCount);
- if (stringEmpty)
- {
- Assert.Equal (string.Empty, list [0]);
- }
- else
- {
- Assert.NotEqual (string.Empty, list [0]);
- }
- Assert.Equal (list, resultLines);
- }
- [Theory]
- [InlineData ("", 0, 0, Alignment.Start, false, 1, true)]
- [InlineData ("", 1, 1, Alignment.Start, false, 1, true)]
- [InlineData ("A sentence has words.", 0, -21, Alignment.Start, false, 1, true)]
- [InlineData ("A sentence has words.", 1, -20, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.", 5, -16, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.", 20, -1, Alignment.Start, false, 1, false)]
- // no clip
- [InlineData ("A sentence has words.", 21, 0, Alignment.Start, false, 1, false)]
- [InlineData ("A sentence has words.", 22, 1, Alignment.Start, false, 1, false)]
- public void Reformat_NoWordrap_SingleLine (
- string text,
- int maxWidth,
- int widthOffset,
- Alignment alignment,
- bool wrap,
- int linesCount,
- bool stringEmpty
- )
- {
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap);
- Assert.NotEmpty (list);
- Assert.True (list.Count == linesCount);
- if (stringEmpty)
- {
- Assert.Equal (string.Empty, list [0]);
- }
- else
- {
- Assert.NotEqual (string.Empty, list [0]);
- }
- Assert.Equal (StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth]), list [0]);
- }
- [Theory]
- // Unicode
- [InlineData (
- "\u2460\u2461\u2462\n\u2460\u2461\u2462\u2463\u2464",
- 8,
- -1,
- Alignment.Start,
- true,
- false,
- new [] { "\u2460\u2461\u2462", "\u2460\u2461\u2462\u2463\u2464" }
- )]
- // no clip
- [InlineData (
- "\u2460\u2461\u2462\n\u2460\u2461\u2462\u2463\u2464",
- 9,
- 0,
- Alignment.Start,
- true,
- false,
- new [] { "\u2460\u2461\u2462", "\u2460\u2461\u2462\u2463\u2464" }
- )]
- [InlineData (
- "\u2460\u2461\u2462\n\u2460\u2461\u2462\u2463\u2464",
- 10,
- 1,
- Alignment.Start,
- true,
- false,
- new [] { "\u2460\u2461\u2462", "\u2460\u2461\u2462\u2463\u2464" }
- )]
- public void Reformat_Unicode_Wrap_Spaces_NewLines (
- string text,
- int maxWidth,
- int widthOffset,
- Alignment alignment,
- bool wrap,
- bool preserveTrailingSpaces,
- IEnumerable<string> resultLines
- )
- {
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
- Assert.Equal (list.Count, resultLines.Count ());
- Assert.Equal (resultLines, list);
- }
- [Theory]
- // Unicode
- // Even # of chars
- // 0123456789
- [InlineData ("\u2660пÑРвРÑ", 10, -1, Alignment.Start, true, false, new [] { "\u2660пÑРвÐ", "Ñ" })]
- // no clip
- [InlineData ("\u2660пÑРвРÑ", 11, 0, Alignment.Start, true, false, new [] { "\u2660пÑРвРÑ" })]
- [InlineData ("\u2660пÑРвРÑ", 12, 1, Alignment.Start, true, false, new [] { "\u2660пÑРвРÑ" })]
- // Unicode
- // Odd # of chars
- // 0123456789
- [InlineData ("\u2660 ÑРвРÑ", 9, -1, Alignment.Start, true, false, new [] { "\u2660 ÑРвÐ", "Ñ" })]
- // no clip
- [InlineData ("\u2660 ÑРвРÑ", 10, 0, Alignment.Start, true, false, new [] { "\u2660 ÑРвРÑ" })]
- [InlineData ("\u2660 ÑРвРÑ", 11, 1, Alignment.Start, true, false, new [] { "\u2660 ÑРвРÑ" })]
- public void Reformat_Unicode_Wrap_Spaces_No_NewLines (
- string text,
- int maxWidth,
- int widthOffset,
- Alignment alignment,
- bool wrap,
- bool preserveTrailingSpaces,
- IEnumerable<string> resultLines
- )
- {
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
- Assert.Equal (list.Count, resultLines.Count ());
- Assert.Equal (resultLines, list);
- }
- [Theory]
- // Even # of spaces
- // 0123456789
- [InlineData ("012 456 89", 0, -10, Alignment.Start, true, true, true, new [] { "" })]
- [InlineData (
- "012 456 89",
- 1,
- -9,
- Alignment.Start,
- true,
- true,
- false,
- new [] { "0", "1", "2", " ", "4", "5", "6", " ", "8", "9" },
- "01245689"
- )]
- [InlineData ("012 456 89", 5, -5, Alignment.Start, true, true, false, new [] { "012 ", "456 ", "89" })]
- [InlineData ("012 456 89", 9, -1, Alignment.Start, true, true, false, new [] { "012 456 ", "89" })]
- // no clip
- [InlineData ("012 456 89", 10, 0, Alignment.Start, true, true, false, new [] { "012 456 89" })]
- [InlineData ("012 456 89", 11, 1, Alignment.Start, true, true, false, new [] { "012 456 89" })]
- // Odd # of spaces
- // 01234567890123
- [InlineData ("012 456 89 end", 13, -1, Alignment.Start, true, true, false, new [] { "012 456 89 ", "end" })]
- // no clip
- [InlineData ("012 456 89 end", 14, 0, Alignment.Start, true, true, false, new [] { "012 456 89 end" })]
- [InlineData ("012 456 89 end", 15, 1, Alignment.Start, true, true, false, new [] { "012 456 89 end" })]
- public void Reformat_Wrap_Spaces_No_NewLines (
- string text,
- int maxWidth,
- int widthOffset,
- Alignment alignment,
- bool wrap,
- bool preserveTrailingSpaces,
- bool stringEmpty,
- IEnumerable<string> resultLines,
- string noSpaceText = ""
- )
- {
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- List<string> list = TextFormatter.Format (text, maxWidth, alignment, wrap, preserveTrailingSpaces);
- Assert.NotEmpty (list);
- Assert.True (list.Count == resultLines.Count ());
- if (stringEmpty)
- {
- Assert.Equal (string.Empty, list [0]);
- }
- else
- {
- Assert.NotEqual (string.Empty, list [0]);
- }
- Assert.Equal (resultLines, list);
- if (maxWidth > 0)
- {
- // remove whitespace chars
- if (maxWidth < 5)
- {
- expectedClippedWidth = text.GetRuneCount () - text.Sum (r => r == ' ' ? 1 : 0);
- }
- else
- {
- expectedClippedWidth = Math.Min (
- text.GetRuneCount (),
- maxWidth - text.Sum (r => r == ' ' ? 1 : 0)
- );
- }
- list = TextFormatter.Format (text, maxWidth, Alignment.Start, wrap);
- if (maxWidth == 1)
- {
- Assert.Equal (expectedClippedWidth, list.Count);
- Assert.Equal (noSpaceText, string.Concat (list.ToArray ()));
- }
- if (maxWidth > 1 && maxWidth < 10)
- {
- Assert.Equal (
- StringExtensions.ToString (text.ToRunes () [..expectedClippedWidth]),
- list [0]
- );
- }
- }
- }
- [Theory]
- [InlineData (null)]
- [InlineData ("")]
- [InlineData ("a")]
- public void RemoveHotKeySpecifier_InValid_ReturnsOriginal (string text)
- {
- var hotKeySpecifier = (Rune)'_';
- if (text == null)
- {
- Assert.Null (TextFormatter.RemoveHotKeySpecifier (text, 0, hotKeySpecifier));
- Assert.Null (TextFormatter.RemoveHotKeySpecifier (text, -1, hotKeySpecifier));
- Assert.Null (TextFormatter.RemoveHotKeySpecifier (text, 100, hotKeySpecifier));
- }
- else
- {
- Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, 0, hotKeySpecifier));
- Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, -1, hotKeySpecifier));
- Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, 100, hotKeySpecifier));
- }
- }
- [Theory]
- [InlineData ("all lower case", 0)]
- [InlineData ("K Before", 0)]
- [InlineData ("aK Second", 1)]
- [InlineData ("Last K", 5)]
- [InlineData ("fter K", 7)]
- [InlineData ("Multiple K and R", 9)]
- [InlineData ("Non-english: Кдать", 13)]
- public void RemoveHotKeySpecifier_Valid_Legacy_ReturnsOriginal (string text, int hotPos)
- {
- var hotKeySpecifier = (Rune)'_';
- Assert.Equal (text, TextFormatter.RemoveHotKeySpecifier (text, hotPos, hotKeySpecifier));
- }
- [Theory]
- [InlineData ("_K Before", 0, "K Before")]
- [InlineData ("a_K Second", 1, "aK Second")]
- [InlineData ("Last _K", 5, "Last K")]
- [InlineData ("After K_", 7, "After K")]
- [InlineData ("Multiple _K and _R", 9, "Multiple K and _R")]
- [InlineData ("Non-english: _Кдать", 13, "Non-english: Кдать")]
- public void RemoveHotKeySpecifier_Valid_ReturnsStripped (string text, int hotPos, string expectedText)
- {
- var hotKeySpecifier = (Rune)'_';
- Assert.Equal (expectedText, TextFormatter.RemoveHotKeySpecifier (text, hotPos, hotKeySpecifier));
- }
- [Theory]
- [InlineData ("test", 0, 't', "test")]
- [InlineData ("test", 1, 'e', "test")]
- [InlineData ("Ok", 0, 'O', "Ok")]
- [InlineData ("[◦ Ok ◦]", 3, 'O', "[◦ Ok ◦]")]
- [InlineData ("^k", 0, '^', "^k")]
- public void ReplaceHotKeyWithTag (string text, int hotPos, uint tag, string expected)
- {
- var tf = new TextFormatter ();
- List<Rune> runes = text.ToRuneList ();
- Rune rune;
- if (Rune.TryGetRuneAt (text, hotPos, out rune))
- {
- Assert.Equal (rune, (Rune)tag);
- }
- string result = TextFormatter.ReplaceHotKeyWithTag (text, hotPos);
- Assert.Equal (result, expected);
- Assert.Equal ((Rune)tag, result.ToRunes () [hotPos]);
- Assert.Equal (text.GetRuneCount (), runes.Count);
- Assert.Equal (text, StringExtensions.ToString (runes));
- }
- [Theory]
- [MemberData (nameof (SplitEnvironmentNewLine))]
- public void SplitNewLine_Ending__With_Or_Without_NewLine_Probably_CRLF (
- string text,
- IEnumerable<string> expected
- )
- {
- List<string> splited = TextFormatter.SplitNewLine (text);
- Assert.Equal (expected, splited);
- }
- [Theory]
- [InlineData (
- "First Line 界\nSecond Line 界\nThird Line 界\n",
- new [] { "First Line 界", "Second Line 界", "Third Line 界", "" }
- )]
- public void SplitNewLine_Ending_With_NewLine_Only_LF (string text, IEnumerable<string> expected)
- {
- List<string> splited = TextFormatter.SplitNewLine (text);
- Assert.Equal (expected, splited);
- }
- [Theory]
- [InlineData (
- "First Line 界\nSecond Line 界\nThird Line 界",
- new [] { "First Line 界", "Second Line 界", "Third Line 界" }
- )]
- public void SplitNewLine_Ending_Without_NewLine_Only_LF (string text, IEnumerable<string> expected)
- {
- List<string> splited = TextFormatter.SplitNewLine (text);
- Assert.Equal (expected, splited);
- }
- [Theory]
- [InlineData ("New Test 你", 10, 10, 20320, 20320, 9, "你")]
- [InlineData ("New Test \U0001d539", 10, 11, 120121, 55349, 9, "𝔹")]
- public void String_Array_Is_Not_Always_Equal_ToRunes_Array (
- string text,
- int runesLength,
- int stringLength,
- int runeValue,
- int stringValue,
- int index,
- string expected
- )
- {
- Rune [] usToRunes = text.ToRunes ();
- Assert.Equal (runesLength, usToRunes.Length);
- Assert.Equal (stringLength, text.Length);
- Assert.Equal (runeValue, usToRunes [index].Value);
- Assert.Equal (stringValue, text [index]);
- Assert.Equal (expected, usToRunes [index].ToString ());
- if (char.IsHighSurrogate (text [index]))
- {
- // Rune array length isn't equal to string array
- Assert.Equal (expected, new string (new [] { text [index], text [index + 1] }));
- }
- else
- {
- // Rune array length is equal to string array
- Assert.Equal (expected, text [index].ToString ());
- }
- }
- [Theory]
- [InlineData (17, 1, TextDirection.LeftRight_TopBottom, 4, "This is a Tab")]
- [InlineData (1, 17, TextDirection.TopBottom_LeftRight, 4, "T\nh\ni\ns\n \ni\ns\n \na\n \n \n \n \n \nT\na\nb")]
- [InlineData (13, 1, TextDirection.LeftRight_TopBottom, 0, "This is a Tab")]
- [InlineData (1, 13, TextDirection.TopBottom_LeftRight, 0, "T\nh\ni\ns\n \ni\ns\n \na\n \nT\na\nb")]
- public void TabWith_PreserveTrailingSpaces_False (
- int width,
- int height,
- TextDirection textDirection,
- int tabWidth,
- string expected
- )
- {
- var driver = new FakeDriver ();
- driver.Init ();
- var text = "This is a \tTab";
- var tf = new TextFormatter ();
- tf.AutoSize = true;
- tf.Direction = textDirection;
- tf.TabWidth = tabWidth;
- tf.Text = text;
- Assert.True (tf.WordWrap);
- Assert.False (tf.PreserveTrailingSpaces);
- Assert.Equal (new (width, height), tf.Size);
- tf.Draw (
- new (0, 0, width, height),
- new Attribute (ColorName.White, ColorName.Black),
- new Attribute (ColorName.Blue, ColorName.Black),
- default (Rectangle),
- driver
- );
- TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
- driver.End ();
- }
- [Theory]
- [InlineData (17, 1, TextDirection.LeftRight_TopBottom, 4, "This is a Tab")]
- [InlineData (1, 17, TextDirection.TopBottom_LeftRight, 4, "T\nh\ni\ns\n \ni\ns\n \na\n \n \n \n \n \nT\na\nb")]
- [InlineData (13, 1, TextDirection.LeftRight_TopBottom, 0, "This is a Tab")]
- [InlineData (1, 13, TextDirection.TopBottom_LeftRight, 0, "T\nh\ni\ns\n \ni\ns\n \na\n \nT\na\nb")]
- public void TabWith_PreserveTrailingSpaces_True (
- int width,
- int height,
- TextDirection textDirection,
- int tabWidth,
- string expected
- )
- {
- var driver = new FakeDriver ();
- driver.Init ();
- var text = "This is a \tTab";
- var tf = new TextFormatter ();
- tf.AutoSize = true;
- tf.Direction = textDirection;
- tf.TabWidth = tabWidth;
- tf.PreserveTrailingSpaces = true;
- tf.Text = text;
- Assert.True (tf.WordWrap);
- Assert.Equal (new (width, height), tf.Size);
- tf.Draw (
- new (0, 0, width, height),
- new Attribute (ColorName.White, ColorName.Black),
- new Attribute (ColorName.Blue, ColorName.Black),
- default (Rectangle),
- driver
- );
- TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
- driver.End ();
- }
- [Theory]
- [InlineData (17, 1, TextDirection.LeftRight_TopBottom, 4, "This is a Tab")]
- [InlineData (1, 17, TextDirection.TopBottom_LeftRight, 4, "T\nh\ni\ns\n \ni\ns\n \na\n \n \n \n \n \nT\na\nb")]
- [InlineData (13, 1, TextDirection.LeftRight_TopBottom, 0, "This is a Tab")]
- [InlineData (1, 13, TextDirection.TopBottom_LeftRight, 0, "T\nh\ni\ns\n \ni\ns\n \na\n \nT\na\nb")]
- public void TabWith_WordWrap_True (
- int width,
- int height,
- TextDirection textDirection,
- int tabWidth,
- string expected
- )
- {
- var driver = new FakeDriver ();
- driver.Init ();
- var text = "This is a \tTab";
- var tf = new TextFormatter ();
- tf.AutoSize = true;
- tf.Direction = textDirection;
- tf.TabWidth = tabWidth;
- tf.WordWrap = true;
- tf.Text = text;
- Assert.False (tf.PreserveTrailingSpaces);
- Assert.Equal (new (width, height), tf.Size);
- tf.Draw (
- new (0, 0, width, height),
- new Attribute (ColorName.White, ColorName.Black),
- new Attribute (ColorName.Blue, ColorName.Black),
- default (Rectangle),
- driver
- );
- TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
- driver.End ();
- }
- [Theory]
- [InlineData ("123456789", 3, "123")]
- [InlineData ("Hello World", 8, "Hello Wo")]
- public void TestClipOrPad_LongWord (string text, int fillPad, string expectedText)
- {
- // word is long but we want it to fill # space only
- Assert.Equal (expectedText, TextFormatter.ClipOrPad (text, fillPad));
- }
- [Theory]
- [InlineData ("fff", 6, "fff ")]
- [InlineData ("Hello World", 16, "Hello World ")]
- public void TestClipOrPad_ShortWord (string text, int fillPad, string expectedText)
- {
- // word is short but we want it to fill # so it should be padded
- Assert.Equal (expectedText, TextFormatter.ClipOrPad (text, fillPad));
- }
- [Theory]
- [InlineData ("你你", TextDirection.LeftRight_TopBottom, 4, 1)]
- [InlineData ("AB", TextDirection.LeftRight_TopBottom, 2, 1)]
- [InlineData ("你你", TextDirection.TopBottom_LeftRight, 2, 2)]
- [InlineData ("AB", TextDirection.TopBottom_LeftRight, 1, 2)]
- public void AutoSize_True_TextDirection_Correct_Size (string text, TextDirection textDirection, int expectedWidth, int expectedHeight)
- {
- var tf = new TextFormatter { Direction = textDirection, Text = text };
- Assert.False (tf.AutoSize);
- // If autosize is false, no auto sizing!
- Assert.Equal (Size.Empty, tf.Size);
- tf.Size = new (1, 1); // This should have no impact (autosize overrides)
- tf.AutoSize = true;
- Assert.Equal (new Size (expectedWidth, expectedHeight), tf.Size);
- }
- [Theory]
- [InlineData ("你", TextDirection.LeftRight_TopBottom, false, 0, 0)]
- [InlineData ("你", TextDirection.LeftRight_TopBottom, true, 2, 1)]
- [InlineData ("你", TextDirection.TopBottom_LeftRight, false, 0, 0)]
- [InlineData ("你", TextDirection.TopBottom_LeftRight, true, 2, 1)]
- [InlineData ("你你", TextDirection.LeftRight_TopBottom, false, 0, 0)]
- [InlineData ("你你", TextDirection.LeftRight_TopBottom, true, 4, 1)]
- [InlineData ("你你", TextDirection.TopBottom_LeftRight, false, 0, 0)]
- [InlineData ("你你", TextDirection.TopBottom_LeftRight, true, 2, 2)]
- public void Text_Set_SizeIsCorrect (string text, TextDirection textDirection, bool autoSize, int expectedWidth, int expectedHeight)
- {
- var tf = new TextFormatter { Direction = textDirection, Text = text, AutoSize = autoSize };
- Assert.Equal (new Size (expectedWidth, expectedHeight), tf.Size);
- }
- [Fact]
- public void WordWrap_BigWidth ()
- {
- List<string> wrappedLines;
- var text = "Constantinople";
- wrappedLines = TextFormatter.WordWrapText (text, 100);
- Assert.True (wrappedLines.Count == 1);
- Assert.Equal ("Constantinople", wrappedLines [0]);
- }
- [Fact]
- public void WordWrap_Invalid ()
- {
- var text = string.Empty;
- var width = 0;
- Assert.Empty (TextFormatter.WordWrapText (null, width));
- Assert.Empty (TextFormatter.WordWrapText (text, width));
- Assert.Throws<ArgumentOutOfRangeException> (() => TextFormatter.WordWrapText (text, -1));
- }
- [Theory]
- [InlineData ("A sentence has words.", 3, -18, new [] { "A", "sen", "ten", "ce", "has", "wor", "ds." })]
- [InlineData (
- "A sentence has words.",
- 2,
- -19,
- new [] { "A", "se", "nt", "en", "ce", "ha", "s", "wo", "rd", "s." }
- )]
- [InlineData (
- "A sentence has words.",
- 1,
- -20,
- new [] { "A", "s", "e", "n", "t", "e", "n", "c", "e", "h", "a", "s", "w", "o", "r", "d", "s", "." }
- )]
- public void WordWrap_Narrow_Default (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- // Calls WordWrapText (text, width) and thus preserveTrailingSpaces defaults to false
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData ("A sentence has words.", 21, 0, new [] { "A sentence has words." })]
- [InlineData ("A sentence has words.", 20, -1, new [] { "A sentence has", "words." })]
- [InlineData ("A sentence has words.", 15, -6, new [] { "A sentence has", "words." })]
- [InlineData ("A sentence has words.", 14, -7, new [] { "A sentence has", "words." })]
- [InlineData ("A sentence has words.", 13, -8, new [] { "A sentence", "has words." })]
- // Unicode
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.",
- 42,
- 0,
- new [] { "A Unicode sentence (пÑивеÑ) has words." }
- )]
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.",
- 41,
- -1,
- new [] { "A Unicode sentence (пÑивеÑ) has", "words." }
- )]
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.",
- 36,
- -6,
- new [] { "A Unicode sentence (пÑивеÑ) has", "words." }
- )]
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.",
- 35,
- -7,
- new [] { "A Unicode sentence (пÑивеÑ) has", "words." }
- )]
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.",
- 34,
- -8,
- new [] { "A Unicode sentence (пÑивеÑ)", "has words." }
- )]
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.",
- 25,
- -17,
- new [] { "A Unicode sentence", "(пÑивеÑ) has words." }
- )]
- public void WordWrap_NoNewLines_Default (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- // Calls WordWrapText (text, width) and thus preserveTrailingSpaces defaults to false
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData ("これが最初の行です。 こんにちは世界。 これが2行目です。", 29, 0, new [] { "これが最初の行です。", "こんにちは世界。", "これが2行目です。" })]
- public void WordWrap_PreserveTrailingSpaces_False_Unicode_Wide_Runes (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData ("文に は言葉 があり ます。", 14, 0, new [] { "文に は言葉", "があり ます。" })]
- [InlineData ("文に は言葉 があり ます。", 3, -11, new [] { "文", "に", "は", "言", "葉", "が", "あ", "り", "ま", "す", "。" })]
- [InlineData ("文に は言葉 があり ます。", 2, -12, new [] { "文", "に", "は", "言", "葉", "が", "あ", "り", "ま", "す", "。" })]
- [InlineData (
- "文に は言葉 があり ます。",
- 1,
- -13,
- new [] { " ", " ", " " }
- )] // Just Spaces; should result in a single space for each line
- public void WordWrap_PreserveTrailingSpaces_False_Wide_Runes (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData (null, 1, new string [] { })] // null input
- [InlineData ("", 1, new string [] { })] // Empty input
- [InlineData ("1 34", 1, new [] { "1", "3", "4" })] // Single Spaces
- [InlineData ("1", 1, new [] { "1" })] // Short input
- [InlineData ("12", 1, new [] { "1", "2" })]
- [InlineData ("123", 1, new [] { "1", "2", "3" })]
- [InlineData ("123456", 1, new [] { "1", "2", "3", "4", "5", "6" })] // No spaces
- [InlineData (" ", 1, new [] { " " })] // Just Spaces; should result in a single space
- [InlineData (" ", 1, new [] { " " })]
- [InlineData (" ", 1, new [] { " ", " " })]
- [InlineData (" ", 1, new [] { " ", " " })]
- [InlineData ("12 456", 1, new [] { "1", "2", "4", "5", "6" })] // Single Spaces
- [InlineData (" 2 456", 1, new [] { " ", "2", "4", "5", "6" })] // Leading spaces should be preserved.
- [InlineData (" 2 456 8", 1, new [] { " ", "2", "4", "5", "6", "8" })]
- [InlineData (
- "A sentence has words. ",
- 1,
- new [] { "A", "s", "e", "n", "t", "e", "n", "c", "e", "h", "a", "s", "w", "o", "r", "d", "s", "." }
- )] // Complex example
- [InlineData ("12 567", 1, new [] { "1", "2", " ", "5", "6", "7" })] // Double Spaces
- [InlineData (" 3 567", 1, new [] { " ", "3", "5", "6", "7" })] // Double Leading spaces should be preserved.
- [InlineData (" 3 678 1", 1, new [] { " ", "3", " ", "6", "7", "8", " ", "1" })]
- [InlineData ("1 456", 1, new [] { "1", " ", "4", "5", "6" })]
- [InlineData (
- "A sentence has words. ",
- 1,
- new []
- {
- "A", " ", "s", "e", "n", "t", "e", "n", "c", "e", " ", "h", "a", "s", "w", "o", "r", "d", "s", ".", " "
- }
- )] // Double space Complex example
- public void WordWrap_PreserveTrailingSpaces_False_With_Simple_Runes_Width_1 (
- string text,
- int width,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines = TextFormatter.WordWrapText (text, width);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.Equal (resultLines, wrappedLines);
- var breakLines = "";
- foreach (string line in wrappedLines)
- {
- breakLines += $"{line}{Environment.NewLine}";
- }
- var expected = string.Empty;
- foreach (string line in resultLines)
- {
- expected += $"{line}{Environment.NewLine}";
- }
- Assert.Equal (expected, breakLines);
- }
- [Theory]
- [InlineData (null, 3, new string [] { })] // null input
- [InlineData ("", 3, new string [] { })] // Empty input
- [InlineData ("1", 3, new [] { "1" })] // Short input
- [InlineData ("12", 3, new [] { "12" })]
- [InlineData ("123", 3, new [] { "123" })]
- [InlineData ("123456", 3, new [] { "123", "456" })] // No spaces
- [InlineData ("1234567", 3, new [] { "123", "456", "7" })] // No spaces
- [InlineData (" ", 3, new [] { " " })] // Just Spaces; should result in a single space
- [InlineData (" ", 3, new [] { " " })]
- [InlineData (" ", 3, new [] { " " })]
- [InlineData (" ", 3, new [] { " " })]
- [InlineData ("12 456", 3, new [] { "12", "456" })] // Single Spaces
- [InlineData (" 2 456", 3, new [] { " 2", "456" })] // Leading spaces should be preserved.
- [InlineData (" 2 456 8", 3, new [] { " 2", "456", "8" })]
- [InlineData (
- "A sentence has words. ",
- 3,
- new [] { "A", "sen", "ten", "ce", "has", "wor", "ds." }
- )] // Complex example
- [InlineData ("12 567", 3, new [] { "12 ", "567" })] // Double Spaces
- [InlineData (" 3 567", 3, new [] { " 3", "567" })] // Double Leading spaces should be preserved.
- [InlineData (" 3 678 1", 3, new [] { " 3", " 67", "8 ", "1" })]
- [InlineData ("1 456", 3, new [] { "1 ", "456" })]
- [InlineData (
- "A sentence has words. ",
- 3,
- new [] { "A ", "sen", "ten", "ce ", " ", "has", "wor", "ds.", " " }
- )] // Double space Complex example
- public void WordWrap_PreserveTrailingSpaces_False_With_Simple_Runes_Width_3 (
- string text,
- int width,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines = TextFormatter.WordWrapText (text, width);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.Equal (resultLines, wrappedLines);
- var breakLines = "";
- foreach (string line in wrappedLines)
- {
- breakLines += $"{line}{Environment.NewLine}";
- }
- var expected = string.Empty;
- foreach (string line in resultLines)
- {
- expected += $"{line}{Environment.NewLine}";
- }
- Assert.Equal (expected, breakLines);
- }
- [Theory]
- [InlineData (null, 50, new string [] { })] // null input
- [InlineData ("", 50, new string [] { })] // Empty input
- [InlineData ("1", 50, new [] { "1" })] // Short input
- [InlineData ("12", 50, new [] { "12" })]
- [InlineData ("123", 50, new [] { "123" })]
- [InlineData ("123456", 50, new [] { "123456" })] // No spaces
- [InlineData ("1234567", 50, new [] { "1234567" })] // No spaces
- [InlineData (" ", 50, new [] { " " })] // Just Spaces; should result in a single space
- [InlineData (" ", 50, new [] { " " })]
- [InlineData (" ", 50, new [] { " " })]
- [InlineData ("12 456", 50, new [] { "12 456" })] // Single Spaces
- [InlineData (" 2 456", 50, new [] { " 2 456" })] // Leading spaces should be preserved.
- [InlineData (" 2 456 8", 50, new [] { " 2 456 8" })]
- [InlineData ("A sentence has words. ", 50, new [] { "A sentence has words. " })] // Complex example
- [InlineData ("12 567", 50, new [] { "12 567" })] // Double Spaces
- [InlineData (" 3 567", 50, new [] { " 3 567" })] // Double Leading spaces should be preserved.
- [InlineData (" 3 678 1", 50, new [] { " 3 678 1" })]
- [InlineData ("1 456", 50, new [] { "1 456" })]
- [InlineData (
- "A sentence has words. ",
- 50,
- new [] { "A sentence has words. " }
- )] // Double space Complex example
- public void WordWrap_PreserveTrailingSpaces_False_With_Simple_Runes_Width_50 (
- string text,
- int width,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines = TextFormatter.WordWrapText (text, width);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.Equal (resultLines, wrappedLines);
- var breakLines = "";
- foreach (string line in wrappedLines)
- {
- breakLines += $"{line}{Environment.NewLine}";
- }
- var expected = string.Empty;
- foreach (string line in resultLines)
- {
- expected += $"{line}{Environment.NewLine}";
- }
- Assert.Equal (expected, breakLines);
- }
- [Theory]
- [InlineData ("A sentence has words.", 14, -7, new [] { "A sentence ", "has words." })]
- [InlineData ("A sentence has words.", 8, -13, new [] { "A ", "sentence", " has ", "words." })]
- [InlineData ("A sentence has words.", 6, -15, new [] { "A ", "senten", "ce ", "has ", "words." })]
- [InlineData ("A sentence has words.", 3, -18, new [] { "A ", "sen", "ten", "ce ", "has", " ", "wor", "ds." })]
- [InlineData (
- "A sentence has words.",
- 2,
- -19,
- new [] { "A ", "se", "nt", "en", "ce", " ", "ha", "s ", "wo", "rd", "s." }
- )]
- [InlineData (
- "A sentence has words.",
- 1,
- -20,
- new []
- {
- "A", " ", "s", "e", "n", "t", "e", "n", "c", "e", " ", "h", "a", "s", " ", "w", "o", "r", "d", "s", "."
- }
- )]
- public void WordWrap_PreserveTrailingSpaces_True (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth, true);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData ("文に は言葉 があり ます。", 14, 0, new [] { "文に は言葉 ", "があり ます。" })]
- [InlineData ("文に は言葉 があり ます。", 3, -11, new [] { "文", "に ", "は", "言", "葉 ", "が", "あ", "り ", "ま", "す", "。" })]
- [InlineData (
- "文に は言葉 があり ます。",
- 2,
- -12,
- new [] { "文", "に", " ", "は", "言", "葉", " ", "が", "あ", "り", " ", "ま", "す", "。" }
- )]
- [InlineData ("文に は言葉 があり ます。", 1, -13, new string [] { })]
- public void WordWrap_PreserveTrailingSpaces_True_Wide_Runes (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth, true);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData ("A sentence has words. ", 3, new [] { "A ", "sen", "ten", "ce ", "has", " ", "wor", "ds.", " " })]
- [InlineData (
- "A sentence has words. ",
- 3,
- new [] { "A ", " ", "sen", "ten", "ce ", " ", " ", " ", "has", " ", "wor", "ds.", " " }
- )]
- public void WordWrap_PreserveTrailingSpaces_True_With_Simple_Runes_Width_3 (
- string text,
- int width,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines = TextFormatter.WordWrapText (text, width, true);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.Equal (resultLines, wrappedLines);
- var breakLines = "";
- foreach (string line in wrappedLines)
- {
- breakLines += $"{line}{Environment.NewLine}";
- }
- var expected = string.Empty;
- foreach (string line in resultLines)
- {
- expected += $"{line}{Environment.NewLine}";
- }
- Assert.Equal (expected, breakLines);
- // Double space Complex example - this is how VS 2022 does it
- //text = "A sentence has words. ";
- //breakLines = "";
- //wrappedLines = TextFormatter.WordWrapText (text, width, preserveTrailingSpaces: true);
- //foreach (var line in wrappedLines) {
- // breakLines += $"{line}{Environment.NewLine}";
- //}
- //expected = "A " + Environment.NewLine +
- // " se" + Environment.NewLine +
- // " nt" + Environment.NewLine +
- // " en" + Environment.NewLine +
- // " ce" + Environment.NewLine +
- // " " + Environment.NewLine +
- // " " + Environment.NewLine +
- // " " + Environment.NewLine +
- // " ha" + Environment.NewLine +
- // " s " + Environment.NewLine +
- // " wo" + Environment.NewLine +
- // " rd" + Environment.NewLine +
- // " s." + Environment.NewLine;
- //Assert.Equal (expected, breakLines);
- }
- [Theory]
- [InlineData ("A sentence\t\t\t has words.", 14, -10, new [] { "A sentence\t", "\t\t has ", "words." })]
- [InlineData (
- "A sentence\t\t\t has words.",
- 8,
- -16,
- new [] { "A ", "sentence", "\t\t", "\t ", "has ", "words." }
- )]
- [InlineData (
- "A sentence\t\t\t has words.",
- 3,
- -21,
- new [] { "A ", "sen", "ten", "ce", "\t", "\t", "\t", " ", "has", " ", "wor", "ds." }
- )]
- [InlineData (
- "A sentence\t\t\t has words.",
- 2,
- -22,
- new [] { "A ", "se", "nt", "en", "ce", "\t", "\t", "\t", " ", "ha", "s ", "wo", "rd", "s." }
- )]
- [InlineData (
- "A sentence\t\t\t has words.",
- 1,
- -23,
- new []
- {
- "A",
- " ",
- "s",
- "e",
- "n",
- "t",
- "e",
- "n",
- "c",
- "e",
- "\t",
- "\t",
- "\t",
- " ",
- "h",
- "a",
- "s",
- " ",
- "w",
- "o",
- "r",
- "d",
- "s",
- "."
- }
- )]
- public void WordWrap_PreserveTrailingSpaces_True_With_Tab (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines,
- int tabWidth = 4
- )
- {
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth, true, tabWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData ("Constantinople", 14, 0, new [] { "Constantinople" })]
- [InlineData ("Constantinople", 12, -2, new [] { "Constantinop", "le" })]
- [InlineData ("Constantinople", 9, -5, new [] { "Constanti", "nople" })]
- [InlineData ("Constantinople", 7, -7, new [] { "Constan", "tinople" })]
- [InlineData ("Constantinople", 5, -9, new [] { "Const", "antin", "ople" })]
- [InlineData ("Constantinople", 4, -10, new [] { "Cons", "tant", "inop", "le" })]
- [InlineData (
- "Constantinople",
- 1,
- -13,
- new [] { "C", "o", "n", "s", "t", "a", "n", "t", "i", "n", "o", "p", "l", "e" }
- )]
- public void WordWrap_SingleWordLine (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData ("This\u00A0is\n\u00A0a\u00A0sentence.", 20, 0, new [] { "This\u00A0is\u00A0a\u00A0sentence." })]
- [InlineData ("This\u00A0is\n\u00A0a\u00A0sentence.", 19, -1, new [] { "This\u00A0is\u00A0a\u00A0sentence." })]
- [InlineData (
- "\u00A0\u00A0\u00A0\u00A0\u00A0test\u00A0sentence.",
- 19,
- 0,
- new [] { "\u00A0\u00A0\u00A0\u00A0\u00A0test\u00A0sentence." }
- )]
- public void WordWrap_Unicode_2LinesWithNonBreakingSpace (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 19, 0, new [] { "This\u00A0is\u00A0a\u00A0sentence." })]
- [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 18, -1, new [] { "This\u00A0is\u00A0a\u00A0sentence", "." })]
- [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 17, -2, new [] { "This\u00A0is\u00A0a\u00A0sentenc", "e." })]
- [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 14, -5, new [] { "This\u00A0is\u00A0a\u00A0sent", "ence." })]
- [InlineData ("This\u00A0is\u00A0a\u00A0sentence.", 10, -9, new [] { "This\u00A0is\u00A0a\u00A0", "sentence." })]
- [InlineData (
- "This\u00A0is\u00A0a\u00A0sentence.",
- 7,
- -12,
- new [] { "This\u00A0is", "\u00A0a\u00A0sent", "ence." }
- )]
- [InlineData (
- "This\u00A0is\u00A0a\u00A0sentence.",
- 5,
- -14,
- new [] { "This\u00A0", "is\u00A0a\u00A0", "sente", "nce." }
- )]
- [InlineData (
- "This\u00A0is\u00A0a\u00A0sentence.",
- 1,
- -18,
- new []
- {
- "T", "h", "i", "s", "\u00A0", "i", "s", "\u00A0", "a", "\u00A0", "s", "e", "n", "t", "e", "n", "c", "e", "."
- }
- )]
- public void WordWrap_Unicode_LineWithNonBreakingSpace (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [Theory]
- [InlineData (
- "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
- 51,
- 0,
- new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ" }
- )]
- [InlineData (
- "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
- 50,
- -1,
- new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ" }
- )]
- [InlineData (
- "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
- 46,
- -5,
- new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮ", "ฯะัาำ" }
- )]
- [InlineData (
- "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
- 26,
- -25,
- new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบ", "ปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ" }
- )]
- [InlineData (
- "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
- 17,
- -34,
- new [] { "กขฃคฅฆงจฉชซฌญฎฏฐฑ", "ฒณดตถทธนบปผฝพฟภมย", "รฤลฦวศษสหฬอฮฯะัาำ" }
- )]
- [InlineData (
- "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
- 13,
- -38,
- new [] { "กขฃคฅฆงจฉชซฌญ", "ฎฏฐฑฒณดตถทธนบ", "ปผฝพฟภมยรฤลฦว", "ศษสหฬอฮฯะัาำ" }
- )]
- [InlineData (
- "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำ",
- 1,
- -50,
- new []
- {
- "ก",
- "ข",
- "ฃ",
- "ค",
- "ฅ",
- "ฆ",
- "ง",
- "จ",
- "ฉ",
- "ช",
- "ซ",
- "ฌ",
- "ญ",
- "ฎ",
- "ฏ",
- "ฐ",
- "ฑ",
- "ฒ",
- "ณ",
- "ด",
- "ต",
- "ถ",
- "ท",
- "ธ",
- "น",
- "บ",
- "ป",
- "ผ",
- "ฝ",
- "พ",
- "ฟ",
- "ภ",
- "ม",
- "ย",
- "ร",
- "ฤ",
- "ล",
- "ฦ",
- "ว",
- "ศ",
- "ษ",
- "ส",
- "ห",
- "ฬ",
- "อ",
- "ฮ",
- "ฯ",
- "ะั",
- "า",
- "ำ"
- }
- )]
- public void WordWrap_Unicode_SingleWordLine (
- string text,
- int maxWidth,
- int widthOffset,
- IEnumerable<string> resultLines
- )
- {
- List<string> wrappedLines;
- IEnumerable<Rune> zeroWidth = text.EnumerateRunes ().Where (r => r.GetColumns () == 0);
- Assert.Single (zeroWidth);
- Assert.Equal ('ั', zeroWidth.ElementAt (0).Value);
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth
- >= (wrappedLines.Count > 0
- ? wrappedLines.Max (
- l => l.GetRuneCount ()
- + zeroWidth.Count ()
- - 1
- + widthOffset
- )
- : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- /// <summary>WordWrap strips CRLF</summary>
- [Theory]
- [InlineData (
- "A sentence has words.\nA paragraph has lines.",
- 44,
- 0,
- new [] { "A sentence has words.A paragraph has lines." }
- )]
- [InlineData (
- "A sentence has words.\nA paragraph has lines.",
- 43,
- -1,
- new [] { "A sentence has words.A paragraph has lines." }
- )]
- [InlineData (
- "A sentence has words.\nA paragraph has lines.",
- 38,
- -6,
- new [] { "A sentence has words.A paragraph has", "lines." }
- )]
- [InlineData (
- "A sentence has words.\nA paragraph has lines.",
- 34,
- -10,
- new [] { "A sentence has words.A paragraph", "has lines." }
- )]
- [InlineData (
- "A sentence has words.\nA paragraph has lines.",
- 27,
- -17,
- new [] { "A sentence has words.A", "paragraph has lines." }
- )]
- // Unicode
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
- 69,
- 0,
- new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт has Линии." }
- )]
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
- 68,
- -1,
- new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт has Линии." }
- )]
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
- 63,
- -6,
- new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт has", "Линии." }
- )]
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
- 59,
- -10,
- new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode Пункт", "has Линии." }
- )]
- [InlineData (
- "A Unicode sentence (пÑивеÑ) has words.\nA Unicode Пункт has Линии.",
- 52,
- -17,
- new [] { "A Unicode sentence (пÑивеÑ) has words.A Unicode", "Пункт has Линии." }
- )]
- public void WordWrap_WithNewLines (string text, int maxWidth, int widthOffset, IEnumerable<string> resultLines)
- {
- List<string> wrappedLines;
- Assert.Equal (maxWidth, text.GetRuneCount () + widthOffset);
- int expectedClippedWidth = Math.Min (text.GetRuneCount (), maxWidth);
- wrappedLines = TextFormatter.WordWrapText (text, maxWidth);
- Assert.Equal (wrappedLines.Count, resultLines.Count ());
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetRuneCount ()) : 0)
- );
- Assert.True (
- expectedClippedWidth >= (wrappedLines.Count > 0 ? wrappedLines.Max (l => l.GetColumns ()) : 0)
- );
- Assert.Equal (resultLines, wrappedLines);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 0, false, "")]
- [InlineData ("A", 1, false, "A")]
- [InlineData ("A", 2, false, "A")]
- [InlineData ("AB", 1, false, "A")]
- [InlineData ("AB", 2, false, "AB")]
- [InlineData ("ABC", 3, false, "ABC")]
- [InlineData ("ABC", 4, false, "ABC")]
- [InlineData ("ABC", 6, false, "ABC")]
- [InlineData ("A", 0, true, "")]
- [InlineData ("A", 1, true, "A")]
- [InlineData ("A", 2, true, "A")]
- [InlineData ("AB", 1, true, "A")]
- [InlineData ("AB", 2, true, "AB")]
- [InlineData ("ABC", 3, true, "ABC")]
- [InlineData ("ABC", 4, true, "ABC")]
- [InlineData ("ABC", 6, true, "ABC")]
- public void Draw_Horizontal_Left (string text, int width, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Alignment = Alignment.Start,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, 1);
- }
- tf.Draw (new Rectangle (0, 0, width, 1), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 0, false, "")]
- [InlineData ("A", 1, false, "A")]
- [InlineData ("A", 2, false, " A")]
- [InlineData ("AB", 1, false, "B")]
- [InlineData ("AB", 2, false, "AB")]
- [InlineData ("ABC", 3, false, "ABC")]
- [InlineData ("ABC", 4, false, " ABC")]
- [InlineData ("ABC", 6, false, " ABC")]
- [InlineData ("A", 0, true, "")]
- [InlineData ("A", 1, true, "A")]
- [InlineData ("A", 2, true, " A")]
- [InlineData ("AB", 1, true, "B")]
- [InlineData ("AB", 2, true, "AB")]
- [InlineData ("ABC", 3, true, "ABC")]
- [InlineData ("ABC", 4, true, " ABC")]
- [InlineData ("ABC", 6, true, " ABC")]
- public void Draw_Horizontal_Right (string text, int width, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Alignment = Alignment.End,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, 1);
- }
- tf.Draw (new Rectangle (Point.Empty, new (width, 1)), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 0, false, "")]
- [InlineData ("A", 1, false, "A")]
- [InlineData ("A", 2, false, "A")]
- [InlineData ("A", 3, false, " A")]
- [InlineData ("AB", 1, false, "A")]
- [InlineData ("AB", 2, false, "AB")]
- [InlineData ("ABC", 3, false, "ABC")]
- [InlineData ("ABC", 4, false, "ABC")]
- [InlineData ("ABC", 5, false, " ABC")]
- [InlineData ("ABC", 6, false, " ABC")]
- [InlineData ("ABC", 9, false, " ABC")]
- [InlineData ("A", 0, true, "")]
- [InlineData ("A", 1, true, "A")]
- [InlineData ("A", 2, true, "A")]
- [InlineData ("A", 3, true, " A")]
- [InlineData ("AB", 1, true, "A")]
- [InlineData ("AB", 2, true, "AB")]
- [InlineData ("ABC", 3, true, "ABC")]
- [InlineData ("ABC", 4, true, "ABC")]
- [InlineData ("ABC", 5, true, " ABC")]
- [InlineData ("ABC", 6, true, " ABC")]
- [InlineData ("ABC", 9, true, " ABC")]
- public void Draw_Horizontal_Centered (string text, int width, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Alignment = Alignment.Center,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, 1);
- }
- tf.Draw (new Rectangle (0, 0, width, 1), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 0, false, "")]
- [InlineData ("A", 1, false, "A")]
- [InlineData ("A", 2, false, "A")]
- [InlineData ("A B", 3, false, "A B")]
- [InlineData ("A B", 1, false, "A")]
- [InlineData ("A B", 2, false, "A")]
- [InlineData ("A B", 4, false, "A B")]
- [InlineData ("A B", 5, false, "A B")]
- [InlineData ("A B", 6, false, "A B")]
- [InlineData ("A B", 10, false, "A B")]
- [InlineData ("ABC ABC", 10, false, "ABC ABC")]
- [InlineData ("A", 0, true, "")]
- [InlineData ("A", 1, true, "A")]
- [InlineData ("A", 2, true, "A")]
- [InlineData ("A B", 1, true, "A")]
- [InlineData ("A B", 2, true, "A")]
- [InlineData ("A B", 3, true, "A B")]
- [InlineData ("A B", 4, true, "A B")]
- [InlineData ("A B", 5, true, "A B")]
- [InlineData ("A B", 6, true, "A B")]
- [InlineData ("A B", 10, true, "A B")]
- [InlineData ("ABC ABC", 10, true, "ABC ABC")]
- public void Draw_Horizontal_Justified (string text, int width, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Alignment = Alignment.Fill,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, 1);
- }
- tf.Draw (new Rectangle (0, 0, width, 1), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 5, 5, false, "A")]
- [InlineData ("AB12", 5, 5, false, @"
- A
- B
- 1
- 2")]
- [InlineData ("AB\n12", 5, 5, false, @"
- A1
- B2")]
- [InlineData ("", 5, 1, false, "")]
- [InlineData ("Hello Worlds", 1, 12, true, @"
- H
- e
- l
- l
- o
-
- W
- o
- r
- l
- d
- s")]
- [InlineData ("Hello Worlds", 1, 12, false, @"
- H
- e
- l
- l
- o
-
- W
- o
- r
- l
- d
- s")]
- [InlineData ("Hello Worlds", 12, 1, false, @"HelloWorlds")]
- public void Draw_Vertical_TopBottom_LeftRight (string text, int width, int height, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- AutoSize = autoSize,
- Direction = TextDirection.TopBottom_LeftRight,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, height);
- }
- tf.Draw (new Rectangle (0, 0, 20, 20), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("Hello World", 15, 1, "Hello World")]
- [InlineData ("Well Done\nNice Work", 15, 2, @"
- Well Done
- Nice Work")]
- [InlineData ("你好 世界", 15, 1, "你好 世界")]
- [InlineData ("做 得好\n幹 得好", 15, 2, @"
- 做 得好
- 幹 得好")]
- public void Justify_Horizontal (string text, int width, int height, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Alignment = Alignment.Fill,
- Size = new Size (width, height),
- MultiLine = true
- };
- tf.Draw (new Rectangle (0, 0, width, height), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("Hello World", 1, 15, "H\ne\nl\nl\no\n \n \n \n \n \nW\no\nr\nl\nd")]
- [InlineData ("Well Done\nNice Work", 2, 15, @"
- WN
- ei
- lc
- le
-
-
-
-
-
-
-
- DW
- oo
- nr
- ek")]
- [InlineData ("你好 世界", 2, 15, "你\n好\n \n \n \n \n \n \n \n \n \n \n \n世\n界")]
- [InlineData ("做 得好\n幹 得好", 4, 15, @"
- 做幹
-
-
-
-
-
-
-
-
-
-
-
-
- 得得
- 好好")]
- public void Justify_Vertical (string text, int width, int height, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Direction = TextDirection.TopBottom_LeftRight,
- VerticalAlignment = Alignment.Fill,
- Size = new Size (width, height),
- MultiLine = true
- };
- tf.Draw (new Rectangle (0, 0, width, height), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 0, 1, false, "", 0)]
- [InlineData ("A", 1, 1, false, "A", 0)]
- [InlineData ("A", 2, 2, false, " A", 1)]
- [InlineData ("AB", 1, 1, false, "B", 0)]
- [InlineData ("AB", 2, 2, false, " A\n B", 0)]
- [InlineData ("ABC", 3, 2, false, " B\n C", 0)]
- [InlineData ("ABC", 4, 2, false, " B\n C", 0)]
- [InlineData ("ABC", 6, 2, false, " B\n C", 0)]
- [InlineData ("こんにちは", 0, 1, false, "", 0)]
- [InlineData ("こんにちは", 1, 0, false, "", 0)]
- [InlineData ("こんにちは", 1, 1, false, "", 0)]
- [InlineData ("こんにちは", 2, 1, false, "は", 0)]
- [InlineData ("こんにちは", 2, 2, false, "ち\nは", 0)]
- [InlineData ("こんにちは", 2, 3, false, "に\nち\nは", 0)]
- [InlineData ("こんにちは", 2, 4, false, "ん\nに\nち\nは", 0)]
- [InlineData ("こんにちは", 2, 5, false, "こ\nん\nに\nち\nは", 0)]
- [InlineData ("こんにちは", 2, 6, false, "こ\nん\nに\nち\nは", 1)]
- [InlineData ("ABCD\nこんにちは", 4, 7, false, " こ\n Aん\n Bに\n Cち\n Dは", 2)]
- [InlineData ("こんにちは\nABCD", 3, 7, false, "こ \nんA\nにB\nちC\nはD", 2)]
- [InlineData ("A", 0, 1, true, "", 0)]
- [InlineData ("A", 1, 1, true, "A", 0)]
- [InlineData ("A", 2, 2, true, " A", 1)]
- [InlineData ("AB", 1, 1, true, "B", 0)]
- [InlineData ("AB", 2, 2, true, " A\n B", 0)]
- [InlineData ("ABC", 3, 2, true, " B\n C", 0)]
- [InlineData ("ABC", 4, 2, true, " B\n C", 0)]
- [InlineData ("ABC", 6, 2, true, " B\n C", 0)]
- [InlineData ("こんにちは", 0, 1, true, "", 0)]
- [InlineData ("こんにちは", 1, 0, true, "", 0)]
- [InlineData ("こんにちは", 1, 1, true, "", 0)]
- [InlineData ("こんにちは", 2, 1, true, "は", 0)]
- [InlineData ("こんにちは", 2, 2, true, "ち\nは", 0)]
- [InlineData ("こんにちは", 2, 3, true, "に\nち\nは", 0)]
- [InlineData ("こんにちは", 2, 4, true, "ん\nに\nち\nは", 0)]
- [InlineData ("こんにちは", 2, 5, true, "こ\nん\nに\nち\nは", 0)]
- [InlineData ("こんにちは", 2, 6, true, "こ\nん\nに\nち\nは", 1)]
- [InlineData ("ABCD\nこんにちは", 4, 7, true, " こ\n Aん\n Bに\n Cち\n Dは", 2)]
- [InlineData ("こんにちは\nABCD", 3, 7, true, "こ \nんA\nにB\nちC\nはD", 2)]
- public void Draw_Vertical_Bottom_Horizontal_Right (string text, int width, int height, bool autoSize, string expectedText, int expectedY)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Alignment = Alignment.End,
- Direction = TextDirection.TopBottom_LeftRight,
- VerticalAlignment = Alignment.End,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, height);
- }
- tf.Draw (new Rectangle (Point.Empty, new (width, height)), Attribute.Default, Attribute.Default);
- Rectangle rect = TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- Assert.Equal (expectedY, rect.Y);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 5, false, "A")]
- [InlineData ("AB12", 5, false, @"
- A
- B
- 1
- 2")]
- [InlineData ("AB\n12", 5, false, @"
- A1
- B2")]
- [InlineData ("", 1, false, "")]
- [InlineData ("AB1 2", 2, false, @"
- A12
- B ")]
- [InlineData ("こんにちは", 1, false, @"
- こん")]
- [InlineData ("こんにちは", 2, false, @"
- こに
- んち")]
- [InlineData ("こんにちは", 5, false, @"
- こ
- ん
- に
- ち
- は")]
- [InlineData ("A", 5, true, "A")]
- [InlineData ("AB12", 5, true, @"
- A
- B
- 1
- 2")]
- [InlineData ("AB\n12", 5, true, @"
- A1
- B2")]
- [InlineData ("", 1, true, "")]
- [InlineData ("AB1 2", 2, true, @"
- A
- B")]
- [InlineData ("こんにちは", 1, true, @"
- こ")]
- [InlineData ("こんにちは", 2, true, @"
- こ
- ん")]
- [InlineData ("こんにちは", 5, true, @"
- こ
- ん
- に
- ち
- は")]
- public void Draw_Vertical_TopBottom_LeftRight_Top (string text, int height, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- AutoSize = autoSize,
- Direction = TextDirection.TopBottom_LeftRight,
- };
- if (!autoSize)
- {
- tf.Size = new Size (5, height);
- }
- tf.Draw (new Rectangle (0, 0, 5, height), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- // The expectedY param is to probe that the expectedText param start at that Y coordinate
- [InlineData ("A", 0, false, "", 0)]
- [InlineData ("A", 1, false, "A", 0)]
- [InlineData ("A", 2, false, "A", 0)]
- [InlineData ("A", 3, false, "A", 1)]
- [InlineData ("AB", 1, false, "A", 0)]
- [InlineData ("AB", 2, false, "A\nB", 0)]
- [InlineData ("ABC", 2, false, "A\nB", 0)]
- [InlineData ("ABC", 3, false, "A\nB\nC", 0)]
- [InlineData ("ABC", 4, false, "A\nB\nC", 0)]
- [InlineData ("ABC", 5, false, "A\nB\nC", 1)]
- [InlineData ("ABC", 6, false, "A\nB\nC", 1)]
- [InlineData ("ABC", 9, false, "A\nB\nC", 3)]
- [InlineData ("ABCD", 2, false, "B\nC", 0)]
- [InlineData ("こんにちは", 0, false, "", 0)]
- [InlineData ("こんにちは", 1, false, "に", 0)]
- [InlineData ("こんにちは", 2, false, "ん\nに", 0)]
- [InlineData ("こんにちは", 3, false, "ん\nに\nち", 0)]
- [InlineData ("こんにちは", 4, false, "こ\nん\nに\nち", 0)]
- [InlineData ("こんにちは", 5, false, "こ\nん\nに\nち\nは", 0)]
- [InlineData ("こんにちは", 6, false, "こ\nん\nに\nち\nは", 0)]
- [InlineData ("ABCD\nこんにちは", 7, false, "Aこ\nBん\nCに\nDち\n は", 1)]
- [InlineData ("こんにちは\nABCD", 7, false, "こA\nんB\nにC\nちD\nは ", 1)]
- [InlineData ("A", 0, true, "", 0)]
- [InlineData ("A", 1, true, "A", 0)]
- [InlineData ("A", 2, true, "A", 0)]
- [InlineData ("A", 3, true, "A", 1)]
- [InlineData ("AB", 1, true, "A", 0)]
- [InlineData ("AB", 2, true, "A\nB", 0)]
- [InlineData ("ABC", 2, true, "A\nB", 0)]
- [InlineData ("ABC", 3, true, "A\nB\nC", 0)]
- [InlineData ("ABC", 4, true, "A\nB\nC", 0)]
- [InlineData ("ABC", 5, true, "A\nB\nC", 1)]
- [InlineData ("ABC", 6, true, "A\nB\nC", 1)]
- [InlineData ("ABC", 9, true, "A\nB\nC", 3)]
- [InlineData ("ABCD", 2, true, "B\nC", 0)]
- [InlineData ("こんにちは", 0, true, "", 0)]
- [InlineData ("こんにちは", 1, true, "に", 0)]
- [InlineData ("こんにちは", 2, true, "ん\nに", 0)]
- [InlineData ("こんにちは", 3, true, "ん\nに\nち", 0)]
- [InlineData ("こんにちは", 4, true, "こ\nん\nに\nち", 0)]
- [InlineData ("こんにちは", 5, true, "こ\nん\nに\nち\nは", 0)]
- [InlineData ("こんにちは", 6, true, "こ\nん\nに\nち\nは", 0)]
- [InlineData ("こんにちは", 7, true, "こ\nん\nに\nち\nは", 1)]
- [InlineData ("ABCD\nこんにちは", 7, true, "Aこ\nBん\nCに\nDち\n は", 1)]
- [InlineData ("こんにちは\nABCD", 7, true, "こA\nんB\nにC\nちD\nは ", 1)]
- public void Draw_Vertical_TopBottom_LeftRight_Middle (string text, int height, bool autoSize, string expectedText, int expectedY)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Direction = TextDirection.TopBottom_LeftRight,
- VerticalAlignment = Alignment.Center,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- int width = text.ToRunes ().Max (r => r.GetColumns ());
- if (text.Contains ("\n"))
- {
- width++;
- }
- tf.Size = new Size (width, height);
- }
- tf.Draw (new Rectangle (0, 0, 5, height), Attribute.Default, Attribute.Default);
- Rectangle rect = TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- Assert.Equal (expectedY, rect.Y);
- }
- [Theory]
- [InlineData ("1234", 4)]
- [InlineData ("_1234", 4)]
- public void AutoSize_HotKey_Size_Correct (string text, int expected)
- {
- // Horizontal
- TextFormatter tf = new ()
- {
- AutoSize = true,
- HotKeySpecifier = (Rune)'_',
- Text = text,
- };
- Assert.Equal (new (expected, 1), tf.Size);
- // Vertical
- tf = new ()
- {
- HotKeySpecifier = (Rune)'_',
- Direction = TextDirection.TopBottom_LeftRight,
- Text = text,
- AutoSize = true,
- };
- Assert.Equal (new (1, expected), tf.Size);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 1, 0, false, "")]
- [InlineData ("A", 0, 1, false, "")]
- [InlineData ("AB1 2", 2, 1, false, "2")]
- [InlineData ("AB12", 5, 1, false, "21BA")]
- [InlineData ("AB\n12", 5, 2, false, "BA\n21")]
- [InlineData ("ABC 123 456", 7, 2, false, "654 321\nCBA ")]
- [InlineData ("こんにちは", 1, 1, false, "")]
- [InlineData ("こんにちは", 2, 1, false, "は")]
- [InlineData ("こんにちは", 5, 1, false, "はち")]
- [InlineData ("こんにちは", 10, 1, false, "はちにんこ")]
- [InlineData ("こんにちは\nAB\n12", 10, 3, false, "はちにんこ\nBA \n21 ")]
- [InlineData ("A", 1, 0, true, "")]
- [InlineData ("A", 0, 1, true, "")]
- [InlineData ("AB1 2", 2, 1, true, "2")]
- [InlineData ("AB12", 5, 1, true, "21BA")]
- [InlineData ("AB\n12", 5, 2, true, "BA\n21")]
- [InlineData ("ABC 123 456", 7, 2, true, "654 321")]
- [InlineData ("こんにちは", 1, 1, true, "")]
- [InlineData ("こんにちは", 2, 1, true, "は")]
- [InlineData ("こんにちは", 5, 1, true, "はち")]
- [InlineData ("こんにちは", 10, 1, true, "はちにんこ")]
- [InlineData ("こんにちは\nAB\n12", 10, 3, true, "はちにんこ\nBA \n21 ")]
- public void Draw_Horizontal_RightLeft_TopBottom (string text, int width, int height, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Direction = TextDirection.RightLeft_TopBottom,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, height);
- }
- tf.Draw (new Rectangle (0, 0, width, height), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 1, 0, false, "")]
- [InlineData ("A", 0, 1, false, "")]
- [InlineData ("AB1 2", 2, 1, false, "2")]
- [InlineData ("AB12", 5, 1, false, "21BA")]
- [InlineData ("AB\n12", 5, 2, false, "21\nBA")]
- [InlineData ("ABC 123 456", 7, 2, false, "CBA \n654 321")]
- [InlineData ("こんにちは", 1, 1, false, "")]
- [InlineData ("こんにちは", 2, 1, false, "は")]
- [InlineData ("こんにちは", 5, 1, false, "はち")]
- [InlineData ("こんにちは", 10, 1, false, "はちにんこ")]
- [InlineData ("こんにちは\nAB\n12", 10, 3, false, "21 \nBA \nはちにんこ")]
- [InlineData ("A", 1, 0, true, "")]
- [InlineData ("A", 0, 1, true, "")]
- [InlineData ("AB1 2", 2, 1, true, "2")]
- [InlineData ("AB12", 5, 1, true, "21BA")]
- [InlineData ("AB\n12", 5, 2, true, "21\nBA")]
- [InlineData ("ABC 123 456", 7, 2, true, "654 321")]
- [InlineData ("こんにちは", 1, 1, true, "")]
- [InlineData ("こんにちは", 2, 1, true, "は")]
- [InlineData ("こんにちは", 5, 1, true, "はち")]
- [InlineData ("こんにちは", 10, 1, true, "はちにんこ")]
- [InlineData ("こんにちは\nAB\n12", 10, 3, true, "21 \nBA \nはちにんこ")]
- public void Draw_Horizontal_RightLeft_BottomTop (string text, int width, int height, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Direction = TextDirection.RightLeft_BottomTop,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, height);
- }
- tf.Draw (new Rectangle (0, 0, width, height), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 1, 0, false, "")]
- [InlineData ("A", 0, 1, false, "")]
- [InlineData ("AB1 2", 1, 2, false, "2")]
- [InlineData ("AB12", 1, 5, false, "2\n1\nB\nA")]
- [InlineData ("AB\n12", 2, 5, false, "B2\nA1")]
- [InlineData ("ABC 123 456", 2, 7, false, "6C\n5B\n4A\n \n3 \n2 \n1 ")]
- [InlineData ("こんにちは", 1, 1, false, "")]
- [InlineData ("こんにちは", 2, 1, false, "は")]
- [InlineData ("こんにちは", 2, 5, false, "は\nち\nに\nん\nこ")]
- [InlineData ("こんにちは", 2, 10, false, "は\nち\nに\nん\nこ")]
- [InlineData ("こんにちは\nAB\n12", 4, 10, false, "はB2\nちA1\nに \nん \nこ ")]
- [InlineData ("A", 1, 0, true, "")]
- [InlineData ("A", 0, 1, true, "")]
- [InlineData ("AB1 2", 1, 2, true, "2")]
- [InlineData ("AB12", 1, 5, true, "2\n1\nB\nA")]
- [InlineData ("AB\n12", 2, 5, true, "B2\nA1")]
- [InlineData ("ABC 123 456", 2, 7, true, "6\n5\n4\n \n3\n2\n1")]
- [InlineData ("こんにちは", 1, 1, true, "")]
- [InlineData ("こんにちは", 2, 1, true, "は")]
- [InlineData ("こんにちは", 2, 5, true, "は\nち\nに\nん\nこ")]
- [InlineData ("こんにちは", 2, 10, true, "は\nち\nに\nん\nこ")]
- [InlineData ("こんにちは\nAB\n12", 4, 10, true, "はB2\nちA1\nに \nん \nこ ")]
- public void Draw_Vertical_BottomTop_LeftRight (string text, int width, int height, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Direction = TextDirection.BottomTop_LeftRight,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, height);
- }
- tf.Draw (new Rectangle (0, 0, width, height), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- [SetupFakeDriver]
- [Theory]
- [InlineData ("A", 1, 0, false, "")]
- [InlineData ("A", 0, 1, false, "")]
- [InlineData ("AB1 2", 1, 2, false, "2")]
- [InlineData ("AB12", 1, 5, false, "2\n1\nB\nA")]
- [InlineData ("AB\n12", 2, 5, false, "2B\n1A")]
- [InlineData ("ABC 123 456", 2, 7, false, "C6\nB5\nA4\n \n 3\n 2\n 1")]
- [InlineData ("こんにちは", 1, 1, false, "")]
- [InlineData ("こんにちは", 2, 1, false, "は")]
- [InlineData ("こんにちは", 2, 5, false, "は\nち\nに\nん\nこ")]
- [InlineData ("こんにちは", 2, 10, false, "は\nち\nに\nん\nこ")]
- [InlineData ("こんにちは\nAB\n12", 4, 10, false, "2Bは\n1Aち\n に\n ん\n こ")]
- [InlineData ("A", 1, 0, true, "")]
- [InlineData ("A", 0, 1, true, "")]
- [InlineData ("AB1 2", 1, 2, true, "2")]
- [InlineData ("AB12", 1, 5, true, "2\n1\nB\nA")]
- [InlineData ("AB\n12", 2, 5, true, "2B\n1A")]
- [InlineData ("ABC 123 456", 2, 7, true, "6\n5\n4\n \n3\n2\n1")]
- [InlineData ("こんにちは", 1, 1, true, "")]
- [InlineData ("こんにちは", 2, 1, true, "は")]
- [InlineData ("こんにちは", 2, 5, true, "は\nち\nに\nん\nこ")]
- [InlineData ("こんにちは", 2, 10, true, "は\nち\nに\nん\nこ")]
- [InlineData ("こんにちは\nAB\n12", 4, 10, true, "2Bは\n1Aち\n に\n ん\n こ")]
- public void Draw_Vertical_BottomTop_RightLeft (string text, int width, int height, bool autoSize, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Text = text,
- Direction = TextDirection.BottomTop_RightLeft,
- AutoSize = autoSize,
- };
- if (!autoSize)
- {
- tf.Size = new Size (width, height);
- }
- tf.Draw (new Rectangle (0, 0, width, height), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- // Draw tests - Note that these depend on View
- [Fact]
- [TestRespondersDisposed]
- public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
- {
- Application.Init (new FakeDriver ());
- Toplevel top = new ();
- var view = new View { Y = -2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight, Text = "view" };
- top.Add (view);
- Application.Iteration += (s, a) =>
- {
- Assert.Equal (-2, view.Y);
- Application.RequestStop ();
- };
- try
- {
- Application.Run (top);
- }
- catch (IndexOutOfRangeException ex)
- {
- // After the fix this exception will not be caught.
- Assert.IsType<IndexOutOfRangeException> (ex);
- }
- top.Dispose ();
- // Shutdown must be called to safely clean up Application if Init has been called
- Application.Shutdown ();
- }
- [SetupFakeDriver]
- [Theory]
- // Horizontal with Alignment.Start
- // LeftRight_TopBottom
- [InlineData ("0 2 4", Alignment.Start, Alignment.Start, TextDirection.LeftRight_TopBottom, @"
- 0 2 4**
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Start, TextDirection.LeftRight_TopBottom, @"
- **0 2 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Start, TextDirection.LeftRight_TopBottom, @"
- *0 2 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Start, TextDirection.LeftRight_TopBottom, @"
- 0 2 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Start, TextDirection.LeftRight_TopBottom, @"
- 0 你 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Start, TextDirection.LeftRight_TopBottom, @"
- *0 你 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Start, TextDirection.LeftRight_TopBottom, @"
- 0 你 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Start, TextDirection.LeftRight_TopBottom, @"
- 0 你 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- // LeftRight_BottomTop
- [InlineData ("0 2 4", Alignment.Start, Alignment.Start, TextDirection.LeftRight_BottomTop, @"
- 0 2 4**
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Start, TextDirection.LeftRight_BottomTop, @"
- **0 2 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Start, TextDirection.LeftRight_BottomTop, @"
- *0 2 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Start, TextDirection.LeftRight_BottomTop, @"
- 0 2 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Start, TextDirection.LeftRight_BottomTop, @"
- 0 你 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Start, TextDirection.LeftRight_BottomTop, @"
- *0 你 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Start, TextDirection.LeftRight_BottomTop, @"
- 0 你 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Start, TextDirection.LeftRight_BottomTop, @"
- 0 你 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- // RightLeft_TopBottom
- [InlineData ("0 2 4", Alignment.Start, Alignment.Start, TextDirection.RightLeft_TopBottom, @"
- 4 2 0**
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Start, TextDirection.RightLeft_TopBottom, @"
- **4 2 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Start, TextDirection.RightLeft_TopBottom, @"
- *4 2 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Start, TextDirection.RightLeft_TopBottom, @"
- 4 2 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Start, TextDirection.RightLeft_TopBottom, @"
- 4 你 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Start, TextDirection.RightLeft_TopBottom, @"
- *4 你 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Start, TextDirection.RightLeft_TopBottom, @"
- 4 你 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Start, TextDirection.RightLeft_TopBottom, @"
- 4 你 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- // RightLeft_BottomTop
- [InlineData ("0 2 4", Alignment.Start, Alignment.Start, TextDirection.RightLeft_BottomTop, @"
- 4 2 0**
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Start, TextDirection.RightLeft_BottomTop, @"
- **4 2 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Start, TextDirection.RightLeft_BottomTop, @"
- *4 2 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Start, TextDirection.RightLeft_BottomTop, @"
- 4 2 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Start, TextDirection.RightLeft_BottomTop, @"
- 4 你 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Start, TextDirection.RightLeft_BottomTop, @"
- *4 你 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Start, TextDirection.RightLeft_BottomTop, @"
- 4 你 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Start, TextDirection.RightLeft_BottomTop, @"
- 4 你 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- // Horizontal with Alignment.End
- // LeftRight_TopBottom
- [InlineData ("0 2 4", Alignment.Start, Alignment.End, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 2 4**")]
- [InlineData ("0 2 4", Alignment.End, Alignment.End, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- **0 2 4")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.End, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- *0 2 4*")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.End, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 2 4")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.End, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 你 4*")]
- [InlineData ("0 你 4", Alignment.End, Alignment.End, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- *0 你 4")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.End, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 你 4*")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.End, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 你 4")]
- // LeftRight_BottomTop
- [InlineData ("0 2 4", Alignment.Start, Alignment.End, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 2 4**")]
- [InlineData ("0 2 4", Alignment.End, Alignment.End, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- **0 2 4")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.End, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- *0 2 4*")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.End, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 2 4")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.End, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 你 4*")]
- [InlineData ("0 你 4", Alignment.End, Alignment.End, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- *0 你 4")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.End, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 你 4*")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.End, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 0 你 4")]
- // RightLeft_TopBottom
- [InlineData ("0 2 4", Alignment.Start, Alignment.End, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 2 0**")]
- [InlineData ("0 2 4", Alignment.End, Alignment.End, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- **4 2 0")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.End, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- *4 2 0*")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.End, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 2 0")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.End, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 你 0*")]
- [InlineData ("0 你 4", Alignment.End, Alignment.End, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- *4 你 0")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.End, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 你 0*")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.End, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 你 0")]
- // RightLeft_BottomTop
- [InlineData ("0 2 4", Alignment.Start, Alignment.End, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 2 0**")]
- [InlineData ("0 2 4", Alignment.End, Alignment.End, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- **4 2 0")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.End, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- *4 2 0*")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.End, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 2 0")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.End, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 你 0*")]
- [InlineData ("0 你 4", Alignment.End, Alignment.End, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- *4 你 0")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.End, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 你 0*")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.End, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *******
- *******
- *******
- 4 你 0")]
- // Horizontal with alignment.Centered
- // LeftRight_TopBottom
- [InlineData ("0 2 4", Alignment.Start, Alignment.Center, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- 0 2 4**
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Center, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- **0 2 4
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Center, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *0 2 4*
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Center, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- 0 2 4
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Center, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- 0 你 4*
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Center, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- *0 你 4
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Center, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- 0 你 4*
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Center, TextDirection.LeftRight_TopBottom, @"
- *******
- *******
- *******
- 0 你 4
- *******
- *******
- *******")]
- // LeftRight_BottomTop
- [InlineData ("0 2 4", Alignment.Start, Alignment.Center, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- 0 2 4**
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Center, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- **0 2 4
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Center, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *0 2 4*
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Center, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- 0 2 4
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Center, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- 0 你 4*
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Center, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- *0 你 4
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Center, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- 0 你 4*
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Center, TextDirection.LeftRight_BottomTop, @"
- *******
- *******
- *******
- 0 你 4
- *******
- *******
- *******")]
- // RightLeft_TopBottom
- [InlineData ("0 2 4", Alignment.Start, Alignment.Center, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- 4 2 0**
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Center, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- **4 2 0
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Center, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *4 2 0*
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Center, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- 4 2 0
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Center, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- 4 你 0*
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Center, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- *4 你 0
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Center, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- 4 你 0*
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Center, TextDirection.RightLeft_TopBottom, @"
- *******
- *******
- *******
- 4 你 0
- *******
- *******
- *******")]
- // RightLeft_BottomTop
- [InlineData ("0 2 4", Alignment.Start, Alignment.Center, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- 4 2 0**
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Center, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- **4 2 0
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Center, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *4 2 0*
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Center, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- 4 2 0
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Center, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- 4 你 0*
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Center, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- *4 你 0
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Center, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- 4 你 0*
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Center, TextDirection.RightLeft_BottomTop, @"
- *******
- *******
- *******
- 4 你 0
- *******
- *******
- *******")]
- // Horizontal with alignment.Justified
- // LeftRight_TopBottom
- [InlineData ("0 2 4", Alignment.Start, Alignment.Fill, TextDirection.LeftRight_TopBottom, @"
- 0 2 4**
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Fill, TextDirection.LeftRight_TopBottom, @"
- **0 2 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Fill, TextDirection.LeftRight_TopBottom, @"
- *0 2 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Fill, TextDirection.LeftRight_TopBottom, @"
- 0 2 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Fill, TextDirection.LeftRight_TopBottom, @"
- 0 你 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Fill, TextDirection.LeftRight_TopBottom, @"
- *0 你 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Fill, TextDirection.LeftRight_TopBottom, @"
- 0 你 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Fill, TextDirection.LeftRight_TopBottom, @"
- 0 你 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- // LeftRight_BottomTop
- [InlineData ("0 2 4", Alignment.Start, Alignment.Fill, TextDirection.LeftRight_BottomTop, @"
- 0 2 4**
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Fill, TextDirection.LeftRight_BottomTop, @"
- **0 2 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Fill, TextDirection.LeftRight_BottomTop, @"
- *0 2 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Fill, TextDirection.LeftRight_BottomTop, @"
- 0 2 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Fill, TextDirection.LeftRight_BottomTop, @"
- 0 你 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Fill, TextDirection.LeftRight_BottomTop, @"
- *0 你 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Fill, TextDirection.LeftRight_BottomTop, @"
- 0 你 4*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Fill, TextDirection.LeftRight_BottomTop, @"
- 0 你 4
- *******
- *******
- *******
- *******
- *******
- *******")]
- // RightLeft_TopBottom
- [InlineData ("0 2 4", Alignment.Start, Alignment.Fill, TextDirection.RightLeft_TopBottom, @"
- 4 2 0**
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Fill, TextDirection.RightLeft_TopBottom, @"
- **4 2 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Fill, TextDirection.RightLeft_TopBottom, @"
- *4 2 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Fill, TextDirection.RightLeft_TopBottom, @"
- 4 2 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Fill, TextDirection.RightLeft_TopBottom, @"
- 4 你 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Fill, TextDirection.RightLeft_TopBottom, @"
- *4 你 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Fill, TextDirection.RightLeft_TopBottom, @"
- 4 你 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Fill, TextDirection.RightLeft_TopBottom, @"
- 4 你 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- // RightLeft_BottomTop
- [InlineData ("0 2 4", Alignment.Start, Alignment.Fill, TextDirection.RightLeft_BottomTop, @"
- 4 2 0**
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Fill, TextDirection.RightLeft_BottomTop, @"
- **4 2 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Fill, TextDirection.RightLeft_BottomTop, @"
- *4 2 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Fill, TextDirection.RightLeft_BottomTop, @"
- 4 2 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Fill, TextDirection.RightLeft_BottomTop, @"
- 4 你 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Fill, TextDirection.RightLeft_BottomTop, @"
- *4 你 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Fill, TextDirection.RightLeft_BottomTop, @"
- 4 你 0*
- *******
- *******
- *******
- *******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Fill, TextDirection.RightLeft_BottomTop, @"
- 4 你 0
- *******
- *******
- *******
- *******
- *******
- *******")]
- // Vertical with alignment.Left
- // TopBottom_LeftRight
- [InlineData ("0 2 4", Alignment.Start, Alignment.Start, TextDirection.TopBottom_LeftRight, @"
- 0******
- ******
- 2******
- ******
- 4******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.End, TextDirection.TopBottom_LeftRight, @"
- *******
- *******
- 0******
- ******
- 2******
- ******
- 4******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.Center, TextDirection.TopBottom_LeftRight, @"
- *******
- 0******
- ******
- 2******
- ******
- 4******
- *******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.Fill, TextDirection.TopBottom_LeftRight, @"
- 0******
- ******
- ******
- 2******
- ******
- ******
- 4******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Start, TextDirection.TopBottom_LeftRight, @"
- 0******
- ******
- 你*****
- ******
- 4******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.End, TextDirection.TopBottom_LeftRight, @"
- *******
- *******
- 0******
- ******
- 你*****
- ******
- 4******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Center, TextDirection.TopBottom_LeftRight, @"
- *******
- 0******
- ******
- 你*****
- ******
- 4******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Fill, TextDirection.TopBottom_LeftRight, @"
- 0******
- ******
- ******
- 你*****
- ******
- ******
- 4******")]
- // TopBottom_RightLeft
- [InlineData ("0 2 4", Alignment.Start, Alignment.Start, TextDirection.TopBottom_RightLeft, @"
- 0******
- ******
- 2******
- ******
- 4******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.End, TextDirection.TopBottom_RightLeft, @"
- *******
- *******
- 0******
- ******
- 2******
- ******
- 4******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.Center, TextDirection.TopBottom_RightLeft, @"
- *******
- 0******
- ******
- 2******
- ******
- 4******
- *******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.Fill, TextDirection.TopBottom_RightLeft, @"
- 0******
- ******
- ******
- 2******
- ******
- ******
- 4******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Start, TextDirection.TopBottom_RightLeft, @"
- 0******
- ******
- 你*****
- ******
- 4******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.End, TextDirection.TopBottom_RightLeft, @"
- *******
- *******
- 0******
- ******
- 你*****
- ******
- 4******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Center, TextDirection.TopBottom_RightLeft, @"
- *******
- 0******
- ******
- 你*****
- ******
- 4******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Fill, TextDirection.TopBottom_RightLeft, @"
- 0******
- ******
- ******
- 你*****
- ******
- ******
- 4******")]
- // BottomTop_LeftRight
- [InlineData ("0 2 4", Alignment.Start, Alignment.Start, TextDirection.BottomTop_LeftRight, @"
- 4******
- ******
- 2******
- ******
- 0******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.End, TextDirection.BottomTop_LeftRight, @"
- *******
- *******
- 4******
- ******
- 2******
- ******
- 0******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.Center, TextDirection.BottomTop_LeftRight, @"
- *******
- 4******
- ******
- 2******
- ******
- 0******
- *******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.Fill, TextDirection.BottomTop_LeftRight, @"
- 4******
- ******
- ******
- 2******
- ******
- ******
- 0******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Start, TextDirection.BottomTop_LeftRight, @"
- 4******
- ******
- 你*****
- ******
- 0******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.End, TextDirection.BottomTop_LeftRight, @"
- *******
- *******
- 4******
- ******
- 你*****
- ******
- 0******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Center, TextDirection.BottomTop_LeftRight, @"
- *******
- 4******
- ******
- 你*****
- ******
- 0******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Fill, TextDirection.BottomTop_LeftRight, @"
- 4******
- ******
- ******
- 你*****
- ******
- ******
- 0******")]
- // BottomTop_RightLeft
- [InlineData ("0 2 4", Alignment.Start, Alignment.Start, TextDirection.BottomTop_RightLeft, @"
- 4******
- ******
- 2******
- ******
- 0******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.End, TextDirection.BottomTop_RightLeft, @"
- *******
- *******
- 4******
- ******
- 2******
- ******
- 0******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.Center, TextDirection.BottomTop_RightLeft, @"
- *******
- 4******
- ******
- 2******
- ******
- 0******
- *******")]
- [InlineData ("0 2 4", Alignment.Start, Alignment.Fill, TextDirection.BottomTop_RightLeft, @"
- 4******
- ******
- ******
- 2******
- ******
- ******
- 0******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Start, TextDirection.BottomTop_RightLeft, @"
- 4******
- ******
- 你*****
- ******
- 0******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.End, TextDirection.BottomTop_RightLeft, @"
- *******
- *******
- 4******
- ******
- 你*****
- ******
- 0******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Center, TextDirection.BottomTop_RightLeft, @"
- *******
- 4******
- ******
- 你*****
- ******
- 0******
- *******")]
- [InlineData ("0 你 4", Alignment.Start, Alignment.Fill, TextDirection.BottomTop_RightLeft, @"
- 4******
- ******
- ******
- 你*****
- ******
- ******
- 0******")]
- // Vertical with alignment.Right
- // TopBottom_LeftRight
- [InlineData ("0 2 4", Alignment.End, Alignment.Start, TextDirection.TopBottom_LeftRight, @"
- ******0
- ******
- ******2
- ******
- ******4
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.End, TextDirection.TopBottom_LeftRight, @"
- *******
- *******
- ******0
- ******
- ******2
- ******
- ******4")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Center, TextDirection.TopBottom_LeftRight, @"
- *******
- ******0
- ******
- ******2
- ******
- ******4
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Fill, TextDirection.TopBottom_LeftRight, @"
- ******0
- ******
- ******
- ******2
- ******
- ******
- ******4")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Start, TextDirection.TopBottom_LeftRight, @"
- *****0*
- ***** *
- *****你
- ***** *
- *****4*
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.End, TextDirection.TopBottom_LeftRight, @"
- *******
- *******
- *****0*
- ***** *
- *****你
- ***** *
- *****4*")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Center, TextDirection.TopBottom_LeftRight, @"
- *******
- *****0*
- ***** *
- *****你
- ***** *
- *****4*
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Fill, TextDirection.TopBottom_LeftRight, @"
- *****0*
- ***** *
- ***** *
- *****你
- ***** *
- ***** *
- *****4*")]
- // TopBottom_RightLeft
- [InlineData ("0 2 4", Alignment.End, Alignment.Start, TextDirection.TopBottom_RightLeft, @"
- ******0
- ******
- ******2
- ******
- ******4
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.End, TextDirection.TopBottom_RightLeft, @"
- *******
- *******
- ******0
- ******
- ******2
- ******
- ******4")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Center, TextDirection.TopBottom_RightLeft, @"
- *******
- ******0
- ******
- ******2
- ******
- ******4
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Fill, TextDirection.TopBottom_RightLeft, @"
- ******0
- ******
- ******
- ******2
- ******
- ******
- ******4")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Start, TextDirection.TopBottom_RightLeft, @"
- *****0*
- ***** *
- *****你
- ***** *
- *****4*
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.End, TextDirection.TopBottom_RightLeft, @"
- *******
- *******
- *****0*
- ***** *
- *****你
- ***** *
- *****4*")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Center, TextDirection.TopBottom_RightLeft, @"
- *******
- *****0*
- ***** *
- *****你
- ***** *
- *****4*
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Fill, TextDirection.TopBottom_RightLeft, @"
- *****0*
- ***** *
- ***** *
- *****你
- ***** *
- ***** *
- *****4*")]
- // BottomTop_LeftRight
- [InlineData ("0 2 4", Alignment.End, Alignment.Start, TextDirection.BottomTop_LeftRight, @"
- ******4
- ******
- ******2
- ******
- ******0
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.End, TextDirection.BottomTop_LeftRight, @"
- *******
- *******
- ******4
- ******
- ******2
- ******
- ******0")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Center, TextDirection.BottomTop_LeftRight, @"
- *******
- ******4
- ******
- ******2
- ******
- ******0
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Fill, TextDirection.BottomTop_LeftRight, @"
- ******4
- ******
- ******
- ******2
- ******
- ******
- ******0")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Start, TextDirection.BottomTop_LeftRight, @"
- *****4*
- ***** *
- *****你
- ***** *
- *****0*
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.End, TextDirection.BottomTop_LeftRight, @"
- *******
- *******
- *****4*
- ***** *
- *****你
- ***** *
- *****0*")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Center, TextDirection.BottomTop_LeftRight, @"
- *******
- *****4*
- ***** *
- *****你
- ***** *
- *****0*
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Fill, TextDirection.BottomTop_LeftRight, @"
- *****4*
- ***** *
- ***** *
- *****你
- ***** *
- ***** *
- *****0*")]
- // BottomTop_RightLeft
- [InlineData ("0 2 4", Alignment.End, Alignment.Start, TextDirection.BottomTop_RightLeft, @"
- ******4
- ******
- ******2
- ******
- ******0
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.End, TextDirection.BottomTop_RightLeft, @"
- *******
- *******
- ******4
- ******
- ******2
- ******
- ******0")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Center, TextDirection.BottomTop_RightLeft, @"
- *******
- ******4
- ******
- ******2
- ******
- ******0
- *******")]
- [InlineData ("0 2 4", Alignment.End, Alignment.Fill, TextDirection.BottomTop_RightLeft, @"
- ******4
- ******
- ******
- ******2
- ******
- ******
- ******0")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Start, TextDirection.BottomTop_RightLeft, @"
- *****4*
- ***** *
- *****你
- ***** *
- *****0*
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.End, TextDirection.BottomTop_RightLeft, @"
- *******
- *******
- *****4*
- ***** *
- *****你
- ***** *
- *****0*")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Center, TextDirection.BottomTop_RightLeft, @"
- *******
- *****4*
- ***** *
- *****你
- ***** *
- *****0*
- *******")]
- [InlineData ("0 你 4", Alignment.End, Alignment.Fill, TextDirection.BottomTop_RightLeft, @"
- *****4*
- ***** *
- ***** *
- *****你
- ***** *
- ***** *
- *****0*")]
- // Vertical with alignment.Centered
- // TopBottom_LeftRight
- [InlineData ("0 2 4", Alignment.Center, Alignment.Start, TextDirection.TopBottom_LeftRight, @"
- ***0***
- *** ***
- ***2***
- *** ***
- ***4***
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.End, TextDirection.TopBottom_LeftRight, @"
- *******
- *******
- ***0***
- *** ***
- ***2***
- *** ***
- ***4***")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Center, TextDirection.TopBottom_LeftRight, @"
- *******
- ***0***
- *** ***
- ***2***
- *** ***
- ***4***
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Fill, TextDirection.TopBottom_LeftRight, @"
- ***0***
- *** ***
- *** ***
- ***2***
- *** ***
- *** ***
- ***4***")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Start, TextDirection.TopBottom_LeftRight, @"
- **0****
- ** ****
- **你***
- ** ****
- **4****
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.End, TextDirection.TopBottom_LeftRight, @"
- *******
- *******
- **0****
- ** ****
- **你***
- ** ****
- **4****")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Center, TextDirection.TopBottom_LeftRight, @"
- *******
- **0****
- ** ****
- **你***
- ** ****
- **4****
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Fill, TextDirection.TopBottom_LeftRight, @"
- **0****
- ** ****
- ** ****
- **你***
- ** ****
- ** ****
- **4****")]
- // TopBottom_RightLeft
- [InlineData ("0 2 4", Alignment.Center, Alignment.Start, TextDirection.TopBottom_RightLeft, @"
- ***0***
- *** ***
- ***2***
- *** ***
- ***4***
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.End, TextDirection.TopBottom_RightLeft, @"
- *******
- *******
- ***0***
- *** ***
- ***2***
- *** ***
- ***4***")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Center, TextDirection.TopBottom_RightLeft, @"
- *******
- ***0***
- *** ***
- ***2***
- *** ***
- ***4***
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Fill, TextDirection.TopBottom_RightLeft, @"
- ***0***
- *** ***
- *** ***
- ***2***
- *** ***
- *** ***
- ***4***")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Start, TextDirection.TopBottom_RightLeft, @"
- **0****
- ** ****
- **你***
- ** ****
- **4****
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.End, TextDirection.TopBottom_RightLeft, @"
- *******
- *******
- **0****
- ** ****
- **你***
- ** ****
- **4****")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Center, TextDirection.TopBottom_RightLeft, @"
- *******
- **0****
- ** ****
- **你***
- ** ****
- **4****
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Fill, TextDirection.TopBottom_RightLeft, @"
- **0****
- ** ****
- ** ****
- **你***
- ** ****
- ** ****
- **4****")]
- // BottomTop_LeftRight
- [InlineData ("0 2 4", Alignment.Center, Alignment.Start, TextDirection.BottomTop_LeftRight, @"
- ***4***
- *** ***
- ***2***
- *** ***
- ***0***
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.End, TextDirection.BottomTop_LeftRight, @"
- *******
- *******
- ***4***
- *** ***
- ***2***
- *** ***
- ***0***")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Center, TextDirection.BottomTop_LeftRight, @"
- *******
- ***4***
- *** ***
- ***2***
- *** ***
- ***0***
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Fill, TextDirection.BottomTop_LeftRight, @"
- ***4***
- *** ***
- *** ***
- ***2***
- *** ***
- *** ***
- ***0***")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Start, TextDirection.BottomTop_LeftRight, @"
- **4****
- ** ****
- **你***
- ** ****
- **0****
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.End, TextDirection.BottomTop_LeftRight, @"
- *******
- *******
- **4****
- ** ****
- **你***
- ** ****
- **0****")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Center, TextDirection.BottomTop_LeftRight, @"
- *******
- **4****
- ** ****
- **你***
- ** ****
- **0****
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Fill, TextDirection.BottomTop_LeftRight, @"
- **4****
- ** ****
- ** ****
- **你***
- ** ****
- ** ****
- **0****")]
- // BottomTop_RightLeft
- [InlineData ("0 2 4", Alignment.Center, Alignment.Start, TextDirection.BottomTop_RightLeft, @"
- ***4***
- *** ***
- ***2***
- *** ***
- ***0***
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.End, TextDirection.BottomTop_RightLeft, @"
- *******
- *******
- ***4***
- *** ***
- ***2***
- *** ***
- ***0***")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Center, TextDirection.BottomTop_RightLeft, @"
- *******
- ***4***
- *** ***
- ***2***
- *** ***
- ***0***
- *******")]
- [InlineData ("0 2 4", Alignment.Center, Alignment.Fill, TextDirection.BottomTop_RightLeft, @"
- ***4***
- *** ***
- *** ***
- ***2***
- *** ***
- *** ***
- ***0***")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Start, TextDirection.BottomTop_RightLeft, @"
- **4****
- ** ****
- **你***
- ** ****
- **0****
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.End, TextDirection.BottomTop_RightLeft, @"
- *******
- *******
- **4****
- ** ****
- **你***
- ** ****
- **0****")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Center, TextDirection.BottomTop_RightLeft, @"
- *******
- **4****
- ** ****
- **你***
- ** ****
- **0****
- *******")]
- [InlineData ("0 你 4", Alignment.Center, Alignment.Fill, TextDirection.BottomTop_RightLeft, @"
- **4****
- ** ****
- ** ****
- **你***
- ** ****
- ** ****
- **0****")]
- // Vertical with alignment.Justified
- // TopBottom_LeftRight
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Start, TextDirection.TopBottom_LeftRight, @"
- 0******
- ******
- 2******
- ******
- 4******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.End, TextDirection.TopBottom_LeftRight, @"
- *******
- *******
- 0******
- ******
- 2******
- ******
- 4******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Center, TextDirection.TopBottom_LeftRight, @"
- *******
- 0******
- ******
- 2******
- ******
- 4******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Fill, TextDirection.TopBottom_LeftRight, @"
- 0******
- ******
- ******
- 2******
- ******
- ******
- 4******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Start, TextDirection.TopBottom_LeftRight, @"
- 0******
- ******
- 你*****
- ******
- 4******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.End, TextDirection.TopBottom_LeftRight, @"
- *******
- *******
- 0******
- ******
- 你*****
- ******
- 4******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Center, TextDirection.TopBottom_LeftRight, @"
- *******
- 0******
- ******
- 你*****
- ******
- 4******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Fill, TextDirection.TopBottom_LeftRight, @"
- 0******
- ******
- ******
- 你*****
- ******
- ******
- 4******")]
- // TopBottom_RightLeft
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Start, TextDirection.TopBottom_RightLeft, @"
- 0******
- ******
- 2******
- ******
- 4******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.End, TextDirection.TopBottom_RightLeft, @"
- *******
- *******
- 0******
- ******
- 2******
- ******
- 4******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Center, TextDirection.TopBottom_RightLeft, @"
- *******
- 0******
- ******
- 2******
- ******
- 4******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Fill, TextDirection.TopBottom_RightLeft, @"
- 0******
- ******
- ******
- 2******
- ******
- ******
- 4******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Start, TextDirection.TopBottom_RightLeft, @"
- 0******
- ******
- 你*****
- ******
- 4******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.End, TextDirection.TopBottom_RightLeft, @"
- *******
- *******
- 0******
- ******
- 你*****
- ******
- 4******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Center, TextDirection.TopBottom_RightLeft, @"
- *******
- 0******
- ******
- 你*****
- ******
- 4******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Fill, TextDirection.TopBottom_RightLeft, @"
- 0******
- ******
- ******
- 你*****
- ******
- ******
- 4******")]
- // BottomTop_LeftRight
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Start, TextDirection.BottomTop_LeftRight, @"
- 4******
- ******
- 2******
- ******
- 0******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.End, TextDirection.BottomTop_LeftRight, @"
- *******
- *******
- 4******
- ******
- 2******
- ******
- 0******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Center, TextDirection.BottomTop_LeftRight, @"
- *******
- 4******
- ******
- 2******
- ******
- 0******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Fill, TextDirection.BottomTop_LeftRight, @"
- 4******
- ******
- ******
- 2******
- ******
- ******
- 0******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Start, TextDirection.BottomTop_LeftRight, @"
- 4******
- ******
- 你*****
- ******
- 0******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.End, TextDirection.BottomTop_LeftRight, @"
- *******
- *******
- 4******
- ******
- 你*****
- ******
- 0******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Center, TextDirection.BottomTop_LeftRight, @"
- *******
- 4******
- ******
- 你*****
- ******
- 0******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Fill, TextDirection.BottomTop_LeftRight, @"
- 4******
- ******
- ******
- 你*****
- ******
- ******
- 0******")]
- // BottomTop_RightLeft
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Start, TextDirection.BottomTop_RightLeft, @"
- 4******
- ******
- 2******
- ******
- 0******
- *******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.End, TextDirection.BottomTop_RightLeft, @"
- *******
- *******
- 4******
- ******
- 2******
- ******
- 0******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Center, TextDirection.BottomTop_RightLeft, @"
- *******
- 4******
- ******
- 2******
- ******
- 0******
- *******")]
- [InlineData ("0 2 4", Alignment.Fill, Alignment.Fill, TextDirection.BottomTop_RightLeft, @"
- 4******
- ******
- ******
- 2******
- ******
- ******
- 0******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Start, TextDirection.BottomTop_RightLeft, @"
- 4******
- ******
- 你*****
- ******
- 0******
- *******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.End, TextDirection.BottomTop_RightLeft, @"
- *******
- *******
- 4******
- ******
- 你*****
- ******
- 0******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Center, TextDirection.BottomTop_RightLeft, @"
- *******
- 4******
- ******
- 你*****
- ******
- 0******
- *******")]
- [InlineData ("0 你 4", Alignment.Fill, Alignment.Fill, TextDirection.BottomTop_RightLeft, @"
- 4******
- ******
- ******
- 你*****
- ******
- ******
- 0******")]
- public void Draw_Text_Justification (string text, Alignment horizontalTextAlignment, Alignment alignment, TextDirection textDirection, string expectedText)
- {
- TextFormatter tf = new ()
- {
- Alignment = horizontalTextAlignment,
- VerticalAlignment = alignment,
- Direction = textDirection,
- Size = new (7, 7),
- Text = text
- };
- Application.Driver.FillRect (new Rectangle (0, 0, 7, 7), (Rune)'*');
- tf.Draw (new Rectangle (0, 0, 7, 7), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
- }
- // Test that changing TextFormatter does not impact View dimensions if Dim.Auto is not in play
- [Fact]
- public void Not_Used_TextFormatter_Does_Not_Change_View_Size ()
- {
- View view = new ()
- {
- Text = "_1234"
- };
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- view.TextFormatter.Text = "ABC";
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- view.TextFormatter.Alignment = Alignment.Fill;
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- view.TextFormatter.VerticalAlignment = Alignment.Center;
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- view.TextFormatter.HotKeySpecifier = (Rune)'*';
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- view.TextFormatter.Text = "*ABC";
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- }
- [Fact]
- public void Not_Used_TextSettings_Do_Not_Change_View_Size ()
- {
- View view = new ()
- {
- Text = "_1234"
- };
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- view.TextAlignment = Alignment.Fill;
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- view.VerticalTextAlignment = Alignment.Center;
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- view.HotKeySpecifier = (Rune)'*';
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- view.Text = "*ABC";
- Assert.False (view.TextFormatter.AutoSize);
- Assert.Equal (Size.Empty, view.Frame.Size);
- }
- #region FormatAndGetSizeTests
- // TODO: Add multi-line examples
- // TODO: Add other TextDirection examples
- [Theory]
- [SetupFakeDriver]
- [InlineData ("界1234", 10, 10, TextDirection.LeftRight_TopBottom, 6, 1, @"界1234")]
- [InlineData ("01234", 10, 10, TextDirection.LeftRight_TopBottom, 5, 1, @"01234")]
- [InlineData ("界1234", 10, 10, TextDirection.TopBottom_LeftRight, 2, 5, """
- 界
- 1
- 2
- 3
- 4
- """)]
- [InlineData ("01234", 10, 10, TextDirection.TopBottom_LeftRight, 1, 5, """
- 0
- 1
- 2
- 3
- 4
- """)]
- [InlineData ("界1234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 2, """
- 界1
- 234
- """)]
- [InlineData ("01234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 2, """
- 012
- 34
- """)]
- [InlineData ("界1234", 3, 3, TextDirection.TopBottom_LeftRight, 3, 3, """
- 界3
- 1 4
- 2
- """)]
- [InlineData ("01234", 3, 3, TextDirection.TopBottom_LeftRight, 2, 3, """
- 03
- 14
- 2
- """)]
- public void FormatAndGetSize_Returns_Correct_Size (string text, int width, int height, TextDirection direction, int expectedWidth, int expectedHeight, string expectedDraw)
- {
- TextFormatter tf = new ()
- {
- Direction = direction,
- Size = new (width, height),
- Text = text
- };
- Assert.True (tf.WordWrap);
- Size size = tf.FormatAndGetSize ();
- Assert.Equal (new (expectedWidth, expectedHeight), size);
- tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedDraw, _output);
- }
- [Theory]
- [SetupFakeDriver]
- [InlineData ("界1234", 10, 10, TextDirection.LeftRight_TopBottom, 6, 1, @"界1234")]
- [InlineData ("01234", 10, 10, TextDirection.LeftRight_TopBottom, 5, 1, @"01234")]
- [InlineData ("界1234", 10, 10, TextDirection.TopBottom_LeftRight, 2, 5, """
- 界
- 1
- 2
- 3
- 4
- """)]
- [InlineData ("01234", 10, 10, TextDirection.TopBottom_LeftRight, 1, 5, """
- 0
- 1
- 2
- 3
- 4
- """)]
- [InlineData ("界1234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 1, @"界1")]
- [InlineData ("01234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 1, @"012")]
- [InlineData ("界1234", 3, 3, TextDirection.TopBottom_LeftRight, 2, 3, """
- 界
- 1
- 2
- """)]
- [InlineData ("01234", 3, 3, TextDirection.TopBottom_LeftRight, 1, 3, """
- 0
- 1
- 2
- """)]
- public void FormatAndGetSize_WordWrap_False_Returns_Correct_Size (string text, int width, int height, TextDirection direction, int expectedWidth, int expectedHeight, string expectedDraw)
- {
- TextFormatter tf = new ()
- {
- Direction = direction,
- Size = new (width, height),
- Text = text,
- WordWrap = false
- };
- Assert.False (tf.WordWrap);
- Size size = tf.FormatAndGetSize ();
- Assert.Equal (new (expectedWidth, expectedHeight), size);
- tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default);
- TestHelpers.AssertDriverContentsWithFrameAre (expectedDraw, _output);
- }
- #endregion
- }
|