TextFormatterTests.cs 206 KB

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