TextFormatterTests.cs 197 KB

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