TextFormatterTests.cs 205 KB

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