2
0

TextFormatterTests.cs 207 KB

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