TextFormatterTests.cs 210 KB

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