/* Ċ Ġ* ĠCopyright Ġ 2 0 2 0 ĠThe ĠAndroid ĠOpen ĠSource ĠProject Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġandroidx . compose . ui . text . android Ċ Ċ import Ġandroid . os . Build Ċ import Ġandroid . text . Layout Ċ import Ġandroid . text . Static Layout Ċ import Ġandroid . text . Text Paint Ċ import Ġandroidx . test . filters . Small Test Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ Ċ @ Small Test Ċ @ Opt In ( Internal Platform Text Api :: class ) Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠLayout Helper Paragraph Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval ĠWIDTH Ġ= Ġ 1 0 0 ĊĠĠĠ Ġprivate Ġval ĠTEXT _ PA INT Ġ= ĠText Paint () ĊĊĠĠĠ Ġprivate Ġfun Ġbuild Layout Helper ( text : ĠString ): ĠLayout Helper Ġ= ĊĠĠĠĠĠĠĠ Ġif Ġ( Build . VERSION . SDK _ INT Ġ< Ġ 2 3 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Suppress (" DE PREC ATION ") ĠStatic Layout ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtext , ĠTEXT _ PA INT , ĠWIDTH , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLayout . Alignment . ALIGN _ NORMAL , Ġ 1 f , Ġ 0 f , Ġfalse ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠStatic Layout . Builder . obtain ( text , Ġ 0 , Ġtext . length , ĠTEXT _ PA INT , ĠWIDTH ). build () ĊĠĠĠĠĠĠĠ Ġ}. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLayout Helper ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Paragraph Info () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper (" a \ nb \ nc ") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . paragraph Count ). isEqualTo ( 3 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph Start ( 0 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph End ( 0 )). isEqualTo ( 2 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph Start ( 1 )). isEqualTo ( 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph End ( 1 )). isEqualTo ( 4 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph Start ( 2 )). isEqualTo ( 4 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph End ( 2 )). isEqualTo ( 5 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Paragraph Info _ single Paragraph () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper (" Hello , ĠWorld .") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . paragraph Count ). isEqualTo ( 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph Start ( 0 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph End ( 0 )). isEqualTo ( layout Helper . layout . text . length ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Paragraph Info _ ignore Last Line Feed () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper (" Hello , ĠWorld .\ n ") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . paragraph Count ). isEqualTo ( 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph Start ( 0 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph End ( 0 )). isEqualTo ( layout Helper . layout . text . length ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Paragraph Info _ empty Text () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper ("") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . paragraph Count ). isEqualTo ( 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph Start ( 0 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph End ( 0 )). isEqualTo ( 0 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Paragraph Info _ line Feed Only Cases () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper ("\ n ") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . paragraph Count ). isEqualTo ( 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph Start ( 0 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph End ( 0 )). isEqualTo ( layout Helper . layout . text . length ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Paragraph Info _ line Feed Only Cases 2 () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper ("\ n \ n ") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . paragraph Count ). isEqualTo ( 2 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph Start ( 0 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph End ( 0 )). isEqualTo ( 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph Start ( 1 )). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph End ( 1 )). isEqualTo ( layout Helper . layout . text . length ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Paragraph For Offset () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper (" aa \ nb b \ n cc ") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 0 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 1 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 2 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 3 )). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 4 )). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 5 )). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 6 )). isEqualTo ( 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 7 )). isEqualTo ( 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Paragraph For Offset _ line Feed Only Case () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper ("\ n \ n ") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 0 )). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . get Paragraph For Offset ( 1 )). isEqualTo ( 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Par ag ar ph Direction () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper (" aa \ n ×Ĳ ×Ĳ \ n cc ") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . is R tl Paragraph ( 0 )). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . is R tl Paragraph ( 1 )). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . is R tl Paragraph ( 2 )). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Par ag ar ph Direction _ case 2 () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Helper Ġ= Ġbuild Layout Helper (" ×Ĳ ×Ĳ \ nb b \ n ×Ĳ ×Ĳ ") ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . is R tl Paragraph ( 0 )). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . is R tl Paragraph ( 1 )). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( layout Helper . is R tl Paragraph ( 2 )). isTrue () ĊĠĠĠ Ġ} Ċ }