kernel_repeated_test.js 283 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807
  1. /**
  2. * @fileoverview Tests for repeated methods in kernel.js.
  3. */
  4. goog.module('protobuf.runtime.KernelTest');
  5. goog.setTestOnly();
  6. const ByteString = goog.require('protobuf.ByteString');
  7. const Int64 = goog.require('protobuf.Int64');
  8. const InternalMessage = goog.require('protobuf.binary.InternalMessage');
  9. const Kernel = goog.require('protobuf.runtime.Kernel');
  10. const TestMessage = goog.require('protobuf.testing.binary.TestMessage');
  11. // Note to the reader:
  12. // Since the lazy accessor behavior changes with the checking level some of the
  13. // tests in this file have to know which checking level is enable to make
  14. // correct assertions.
  15. const {CHECK_CRITICAL_STATE} = goog.require('protobuf.internal.checks');
  16. /**
  17. * @param {...number} bytes
  18. * @return {!ArrayBuffer}
  19. */
  20. function createArrayBuffer(...bytes) {
  21. return new Uint8Array(bytes).buffer;
  22. }
  23. /**
  24. * Expects the Iterable instance yield the same values as the expected array.
  25. * @param {!Iterable<T>} iterable
  26. * @param {!Array<T>} expected
  27. * @template T
  28. * TODO: Implement this as a custom matcher.
  29. */
  30. function expectEqualToArray(iterable, expected) {
  31. const array = Array.from(iterable);
  32. expect(array).toEqual(expected);
  33. }
  34. /**
  35. * Expects the Iterable instance yield qualified values.
  36. * @param {!Iterable<T>} iterable
  37. * @param {(function(T): boolean)=} verify
  38. * @template T
  39. */
  40. function expectQualifiedIterable(iterable, verify) {
  41. if (verify) {
  42. for (const value of iterable) {
  43. expect(verify(value)).toBe(true);
  44. }
  45. }
  46. }
  47. /**
  48. * Expects the Iterable instance yield the same values as the expected array of
  49. * messages.
  50. * @param {!Iterable<!TestMessage>} iterable
  51. * @param {!Array<!TestMessage>} expected
  52. * @template T
  53. * TODO: Implement this as a custom matcher.
  54. */
  55. function expectEqualToMessageArray(iterable, expected) {
  56. const array = Array.from(iterable);
  57. expect(array.length).toEqual(expected.length);
  58. for (let i = 0; i < array.length; i++) {
  59. const value = array[i].getBoolWithDefault(1, false);
  60. const expectedValue = expected[i].getBoolWithDefault(1, false);
  61. expect(value).toBe(expectedValue);
  62. }
  63. }
  64. describe('Kernel for repeated boolean does', () => {
  65. it('return empty array for the empty input', () => {
  66. const accessor = Kernel.createEmpty();
  67. expectEqualToArray(accessor.getRepeatedBoolIterable(1), []);
  68. });
  69. it('ensure not the same instance returned for the empty input', () => {
  70. const accessor = Kernel.createEmpty();
  71. const list1 = accessor.getRepeatedBoolIterable(1);
  72. const list2 = accessor.getRepeatedBoolIterable(1);
  73. expect(list1).not.toBe(list2);
  74. });
  75. it('return size for the empty input', () => {
  76. const accessor = Kernel.createEmpty();
  77. expect(accessor.getRepeatedBoolSize(1)).toEqual(0);
  78. });
  79. it('return unpacked values from the input', () => {
  80. const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  81. const accessor = Kernel.fromArrayBuffer(bytes);
  82. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
  83. });
  84. it('ensure not the same instance returned for unpacked values', () => {
  85. const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  86. const accessor = Kernel.fromArrayBuffer(bytes);
  87. const list1 = accessor.getRepeatedBoolIterable(1);
  88. const list2 = accessor.getRepeatedBoolIterable(1);
  89. expect(list1).not.toBe(list2);
  90. });
  91. it('return unpacked multibytes values from the input', () => {
  92. const bytes = createArrayBuffer(0x08, 0x80, 0x01, 0x08, 0x80, 0x00);
  93. const accessor = Kernel.fromArrayBuffer(bytes);
  94. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
  95. });
  96. it('return for adding single unpacked value', () => {
  97. const accessor = Kernel.createEmpty();
  98. accessor.addUnpackedBoolElement(1, true);
  99. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
  100. accessor.addUnpackedBoolElement(1, false);
  101. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
  102. });
  103. it('return for adding unpacked values', () => {
  104. const accessor = Kernel.createEmpty();
  105. accessor.addUnpackedBoolIterable(1, [true]);
  106. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
  107. accessor.addUnpackedBoolIterable(1, [false]);
  108. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
  109. });
  110. it('return for setting single unpacked value', () => {
  111. const accessor =
  112. Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00, 0x08, 0x01));
  113. accessor.setUnpackedBoolElement(1, 0, true);
  114. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, true]);
  115. });
  116. it('return for setting unpacked values', () => {
  117. const accessor = Kernel.createEmpty();
  118. accessor.setUnpackedBoolIterable(1, [true]);
  119. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
  120. accessor.setUnpackedBoolIterable(1, [false]);
  121. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [false]);
  122. });
  123. it('encode for adding single unpacked value', () => {
  124. const accessor = Kernel.createEmpty();
  125. const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  126. accessor.addUnpackedBoolElement(1, true);
  127. accessor.addUnpackedBoolElement(1, false);
  128. expect(accessor.serialize()).toEqual(bytes);
  129. });
  130. it('encode for adding unpacked values', () => {
  131. const accessor = Kernel.createEmpty();
  132. const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  133. accessor.addUnpackedBoolIterable(1, [true, false]);
  134. expect(accessor.serialize()).toEqual(bytes);
  135. });
  136. it('encode for setting single unpacked value', () => {
  137. const accessor =
  138. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x02, 0x00, 0x01));
  139. const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x01);
  140. accessor.setUnpackedBoolElement(1, 0, true);
  141. expect(accessor.serialize()).toEqual(bytes);
  142. });
  143. it('encode for setting unpacked values', () => {
  144. const accessor = Kernel.createEmpty();
  145. const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  146. accessor.setUnpackedBoolIterable(1, [true, false]);
  147. expect(accessor.serialize()).toEqual(bytes);
  148. });
  149. it('return packed values from the input', () => {
  150. const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  151. const accessor = Kernel.fromArrayBuffer(bytes);
  152. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
  153. });
  154. it('ensure not the same instance returned for packed values', () => {
  155. const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  156. const accessor = Kernel.fromArrayBuffer(bytes);
  157. const list1 = accessor.getRepeatedBoolIterable(1);
  158. const list2 = accessor.getRepeatedBoolIterable(1);
  159. expect(list1).not.toBe(list2);
  160. });
  161. it('return packed multibytes values from the input', () => {
  162. const bytes = createArrayBuffer(0x0A, 0x04, 0x80, 0x01, 0x80, 0x00);
  163. const accessor = Kernel.fromArrayBuffer(bytes);
  164. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
  165. });
  166. it('return for adding single packed value', () => {
  167. const accessor = Kernel.createEmpty();
  168. accessor.addPackedBoolElement(1, true);
  169. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
  170. accessor.addPackedBoolElement(1, false);
  171. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
  172. });
  173. it('return for adding packed values', () => {
  174. const accessor = Kernel.createEmpty();
  175. accessor.addPackedBoolIterable(1, [true]);
  176. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
  177. accessor.addPackedBoolIterable(1, [false]);
  178. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
  179. });
  180. it('return for setting single packed value', () => {
  181. const accessor =
  182. Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00, 0x08, 0x01));
  183. accessor.setPackedBoolElement(1, 0, true);
  184. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, true]);
  185. });
  186. it('return for setting packed values', () => {
  187. const accessor = Kernel.createEmpty();
  188. accessor.setPackedBoolIterable(1, [true]);
  189. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
  190. accessor.setPackedBoolIterable(1, [false]);
  191. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [false]);
  192. });
  193. it('encode for adding single packed value', () => {
  194. const accessor = Kernel.createEmpty();
  195. const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  196. accessor.addPackedBoolElement(1, true);
  197. accessor.addPackedBoolElement(1, false);
  198. expect(accessor.serialize()).toEqual(bytes);
  199. });
  200. it('encode for adding packed values', () => {
  201. const accessor = Kernel.createEmpty();
  202. const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  203. accessor.addPackedBoolIterable(1, [true, false]);
  204. expect(accessor.serialize()).toEqual(bytes);
  205. });
  206. it('encode for setting single packed value', () => {
  207. const accessor =
  208. Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00, 0x08, 0x01));
  209. const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x01);
  210. accessor.setPackedBoolElement(1, 0, true);
  211. expect(accessor.serialize()).toEqual(bytes);
  212. });
  213. it('encode for setting packed values', () => {
  214. const accessor = Kernel.createEmpty();
  215. const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  216. accessor.setPackedBoolIterable(1, [true, false]);
  217. expect(accessor.serialize()).toEqual(bytes);
  218. });
  219. it('return combined values from the input', () => {
  220. const bytes =
  221. createArrayBuffer(0x08, 0x01, 0x0A, 0x02, 0x01, 0x00, 0x08, 0x00);
  222. const accessor = Kernel.fromArrayBuffer(bytes);
  223. expectEqualToArray(
  224. accessor.getRepeatedBoolIterable(1), [true, true, false, false]);
  225. });
  226. it('return the repeated field element from the input', () => {
  227. const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  228. const accessor = Kernel.fromArrayBuffer(bytes);
  229. expect(accessor.getRepeatedBoolElement(
  230. /* fieldNumber= */ 1, /* index= */ 0))
  231. .toEqual(true);
  232. expect(accessor.getRepeatedBoolElement(
  233. /* fieldNumber= */ 1, /* index= */ 1))
  234. .toEqual(false);
  235. });
  236. it('return the size from the input', () => {
  237. const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  238. const accessor = Kernel.fromArrayBuffer(bytes);
  239. expect(accessor.getRepeatedBoolSize(1)).toEqual(2);
  240. });
  241. it('fail when getting unpacked bool value with other wire types', () => {
  242. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  243. 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  244. if (CHECK_CRITICAL_STATE) {
  245. expect(() => {
  246. accessor.getRepeatedBoolIterable(1);
  247. }).toThrowError('Expected wire type: 0 but found: 1');
  248. } else {
  249. // Note in unchecked mode we produce invalid output for invalid inputs.
  250. // This test just documents our behavior in those cases.
  251. // These values might change at any point and are not considered
  252. // what the implementation should be doing here.
  253. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
  254. }
  255. });
  256. it('fail when adding unpacked bool values with number value', () => {
  257. const accessor = Kernel.createEmpty();
  258. const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
  259. if (CHECK_CRITICAL_STATE) {
  260. expect(() => accessor.addUnpackedBoolIterable(1, [fakeBoolean]))
  261. .toThrowError('Must be a boolean, but got: 2');
  262. } else {
  263. // Note in unchecked mode we produce invalid output for invalid inputs.
  264. // This test just documents our behavior in those cases.
  265. // These values might change at any point and are not considered
  266. // what the implementation should be doing here.
  267. accessor.addUnpackedBoolIterable(1, [fakeBoolean]);
  268. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
  269. }
  270. });
  271. it('fail when adding single unpacked bool value with number value', () => {
  272. const accessor = Kernel.createEmpty();
  273. const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
  274. if (CHECK_CRITICAL_STATE) {
  275. expect(() => accessor.addUnpackedBoolElement(1, fakeBoolean))
  276. .toThrowError('Must be a boolean, but got: 2');
  277. } else {
  278. // Note in unchecked mode we produce invalid output for invalid inputs.
  279. // This test just documents our behavior in those cases.
  280. // These values might change at any point and are not considered
  281. // what the implementation should be doing here.
  282. accessor.addUnpackedBoolElement(1, fakeBoolean);
  283. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
  284. }
  285. });
  286. it('fail when setting unpacked bool values with number value', () => {
  287. const accessor = Kernel.createEmpty();
  288. const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
  289. if (CHECK_CRITICAL_STATE) {
  290. expect(() => accessor.setUnpackedBoolIterable(1, [fakeBoolean]))
  291. .toThrowError('Must be a boolean, but got: 2');
  292. } else {
  293. // Note in unchecked mode we produce invalid output for invalid inputs.
  294. // This test just documents our behavior in those cases.
  295. // These values might change at any point and are not considered
  296. // what the implementation should be doing here.
  297. accessor.setUnpackedBoolIterable(1, [fakeBoolean]);
  298. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
  299. }
  300. });
  301. it('fail when setting single unpacked bool value with number value', () => {
  302. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  303. const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
  304. if (CHECK_CRITICAL_STATE) {
  305. expect(() => accessor.setUnpackedBoolElement(1, 0, fakeBoolean))
  306. .toThrowError('Must be a boolean, but got: 2');
  307. } else {
  308. // Note in unchecked mode we produce invalid output for invalid inputs.
  309. // This test just documents our behavior in those cases.
  310. // These values might change at any point and are not considered
  311. // what the implementation should be doing here.
  312. accessor.setUnpackedBoolElement(1, 0, fakeBoolean);
  313. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
  314. }
  315. });
  316. it('fail when adding packed bool values with number value', () => {
  317. const accessor = Kernel.createEmpty();
  318. const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
  319. if (CHECK_CRITICAL_STATE) {
  320. expect(() => accessor.addPackedBoolIterable(1, [fakeBoolean]))
  321. .toThrowError('Must be a boolean, but got: 2');
  322. } else {
  323. // Note in unchecked mode we produce invalid output for invalid inputs.
  324. // This test just documents our behavior in those cases.
  325. // These values might change at any point and are not considered
  326. // what the implementation should be doing here.
  327. accessor.addPackedBoolIterable(1, [fakeBoolean]);
  328. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
  329. }
  330. });
  331. it('fail when adding single packed bool value with number value', () => {
  332. const accessor = Kernel.createEmpty();
  333. const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
  334. if (CHECK_CRITICAL_STATE) {
  335. expect(() => accessor.addPackedBoolElement(1, fakeBoolean))
  336. .toThrowError('Must be a boolean, but got: 2');
  337. } else {
  338. // Note in unchecked mode we produce invalid output for invalid inputs.
  339. // This test just documents our behavior in those cases.
  340. // These values might change at any point and are not considered
  341. // what the implementation should be doing here.
  342. accessor.addPackedBoolElement(1, fakeBoolean);
  343. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
  344. }
  345. });
  346. it('fail when setting packed bool values with number value', () => {
  347. const accessor = Kernel.createEmpty();
  348. const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
  349. if (CHECK_CRITICAL_STATE) {
  350. expect(() => accessor.setPackedBoolIterable(1, [fakeBoolean]))
  351. .toThrowError('Must be a boolean, but got: 2');
  352. } else {
  353. // Note in unchecked mode we produce invalid output for invalid inputs.
  354. // This test just documents our behavior in those cases.
  355. // These values might change at any point and are not considered
  356. // what the implementation should be doing here.
  357. accessor.setPackedBoolIterable(1, [fakeBoolean]);
  358. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
  359. }
  360. });
  361. it('fail when setting single packed bool value with number value', () => {
  362. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  363. const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
  364. if (CHECK_CRITICAL_STATE) {
  365. expect(() => accessor.setPackedBoolElement(1, 0, fakeBoolean))
  366. .toThrowError('Must be a boolean, but got: 2');
  367. } else {
  368. // Note in unchecked mode we produce invalid output for invalid inputs.
  369. // This test just documents our behavior in those cases.
  370. // These values might change at any point and are not considered
  371. // what the implementation should be doing here.
  372. accessor.setPackedBoolElement(1, 0, fakeBoolean);
  373. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
  374. }
  375. });
  376. it('fail when setting single unpacked with out-of-bound index', () => {
  377. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  378. if (CHECK_CRITICAL_STATE) {
  379. expect(() => accessor.setUnpackedBoolElement(1, 1, true))
  380. .toThrowError('Index out of bounds: index: 1 size: 1');
  381. } else {
  382. // Note in unchecked mode we produce invalid output for invalid inputs.
  383. // This test just documents our behavior in those cases.
  384. // These values might change at any point and are not considered
  385. // what the implementation should be doing here.
  386. accessor.setUnpackedBoolElement(1, 1, true);
  387. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [false, true]);
  388. }
  389. });
  390. it('fail when setting single packed with out-of-bound index', () => {
  391. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  392. if (CHECK_CRITICAL_STATE) {
  393. expect(() => accessor.setPackedBoolElement(1, 1, true))
  394. .toThrowError('Index out of bounds: index: 1 size: 1');
  395. } else {
  396. // Note in unchecked mode we produce invalid output for invalid inputs.
  397. // This test just documents our behavior in those cases.
  398. // These values might change at any point and are not considered
  399. // what the implementation should be doing here.
  400. accessor.setPackedBoolElement(1, 1, true);
  401. expectEqualToArray(accessor.getRepeatedBoolIterable(1), [false, true]);
  402. }
  403. });
  404. it('fail when getting element with out-of-range index', () => {
  405. const accessor = Kernel.createEmpty();
  406. if (CHECK_CRITICAL_STATE) {
  407. expect(() => {
  408. accessor.getRepeatedBoolElement(
  409. /* fieldNumber= */ 1, /* index= */ 0);
  410. }).toThrowError('Index out of bounds: index: 0 size: 0');
  411. } else {
  412. // Note in unchecked mode we produce invalid output for invalid inputs.
  413. // This test just documents our behavior in those cases.
  414. // These values might change at any point and are not considered
  415. // what the implementation should be doing here.
  416. expect(accessor.getRepeatedBoolElement(
  417. /* fieldNumber= */ 1, /* index= */ 0))
  418. .toBe(undefined);
  419. }
  420. });
  421. });
  422. describe('Kernel for repeated double does', () => {
  423. const value1 = 1;
  424. const value2 = 0;
  425. const unpackedValue1Value2 = createArrayBuffer(
  426. 0x09,
  427. 0x00,
  428. 0x00,
  429. 0x00,
  430. 0x00,
  431. 0x00,
  432. 0x00,
  433. 0xF0,
  434. 0x3F, // value1
  435. 0x09,
  436. 0x00,
  437. 0x00,
  438. 0x00,
  439. 0x00,
  440. 0x00,
  441. 0x00,
  442. 0x00,
  443. 0x00, // value2
  444. );
  445. const unpackedValue2Value1 = createArrayBuffer(
  446. 0x09,
  447. 0x00,
  448. 0x00,
  449. 0x00,
  450. 0x00,
  451. 0x00,
  452. 0x00,
  453. 0x00,
  454. 0x00, // value1
  455. 0x09,
  456. 0x00,
  457. 0x00,
  458. 0x00,
  459. 0x00,
  460. 0x00,
  461. 0x00,
  462. 0xF0,
  463. 0x3F, // value2
  464. );
  465. const packedValue1Value2 = createArrayBuffer(
  466. 0x0A,
  467. 0x10, // tag
  468. 0x00,
  469. 0x00,
  470. 0x00,
  471. 0x00,
  472. 0x00,
  473. 0x00,
  474. 0xF0,
  475. 0x3F, // value1
  476. 0x00,
  477. 0x00,
  478. 0x00,
  479. 0x00,
  480. 0x00,
  481. 0x00,
  482. 0x00,
  483. 0x00, // value2
  484. );
  485. const packedValue2Value1 = createArrayBuffer(
  486. 0x0A,
  487. 0x10, // tag
  488. 0x00,
  489. 0x00,
  490. 0x00,
  491. 0x00,
  492. 0x00,
  493. 0x00,
  494. 0x00,
  495. 0x00, // value1
  496. 0x00,
  497. 0x00,
  498. 0x00,
  499. 0x00,
  500. 0x00,
  501. 0x00,
  502. 0xF0,
  503. 0x3F, // value2
  504. );
  505. it('return empty array for the empty input', () => {
  506. const accessor = Kernel.createEmpty();
  507. const list = accessor.getRepeatedDoubleIterable(1);
  508. expectEqualToArray(list, []);
  509. });
  510. it('ensure not the same instance returned for the empty input', () => {
  511. const accessor = Kernel.createEmpty();
  512. const list1 = accessor.getRepeatedDoubleIterable(1);
  513. const list2 = accessor.getRepeatedDoubleIterable(1);
  514. expect(list1).not.toBe(list2);
  515. });
  516. it('return size for the empty input', () => {
  517. const accessor = Kernel.createEmpty();
  518. const size = accessor.getRepeatedDoubleSize(1);
  519. expect(size).toEqual(0);
  520. });
  521. it('return unpacked values from the input', () => {
  522. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  523. const list = accessor.getRepeatedDoubleIterable(1);
  524. expectEqualToArray(list, [value1, value2]);
  525. });
  526. it('ensure not the same instance returned for unpacked values', () => {
  527. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  528. const list1 = accessor.getRepeatedDoubleIterable(1);
  529. const list2 = accessor.getRepeatedDoubleIterable(1);
  530. expect(list1).not.toBe(list2);
  531. });
  532. it('add single unpacked value', () => {
  533. const accessor = Kernel.createEmpty();
  534. accessor.addUnpackedDoubleElement(1, value1);
  535. const list1 = accessor.getRepeatedDoubleIterable(1);
  536. accessor.addUnpackedDoubleElement(1, value2);
  537. const list2 = accessor.getRepeatedDoubleIterable(1);
  538. expectEqualToArray(list1, [value1]);
  539. expectEqualToArray(list2, [value1, value2]);
  540. });
  541. it('add unpacked values', () => {
  542. const accessor = Kernel.createEmpty();
  543. accessor.addUnpackedDoubleIterable(1, [value1]);
  544. const list1 = accessor.getRepeatedDoubleIterable(1);
  545. accessor.addUnpackedDoubleIterable(1, [value2]);
  546. const list2 = accessor.getRepeatedDoubleIterable(1);
  547. expectEqualToArray(list1, [value1]);
  548. expectEqualToArray(list2, [value1, value2]);
  549. });
  550. it('set a single unpacked value', () => {
  551. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  552. accessor.setUnpackedDoubleElement(1, 1, value1);
  553. const list = accessor.getRepeatedDoubleIterable(1);
  554. expectEqualToArray(list, [value1, value1]);
  555. });
  556. it('set unpacked values', () => {
  557. const accessor = Kernel.createEmpty();
  558. accessor.setUnpackedDoubleIterable(1, [value1]);
  559. const list = accessor.getRepeatedDoubleIterable(1);
  560. expectEqualToArray(list, [value1]);
  561. });
  562. it('encode for adding single unpacked value', () => {
  563. const accessor = Kernel.createEmpty();
  564. accessor.addUnpackedDoubleElement(1, value1);
  565. accessor.addUnpackedDoubleElement(1, value2);
  566. const serialized = accessor.serialize();
  567. expect(serialized).toEqual(unpackedValue1Value2);
  568. });
  569. it('encode for adding unpacked values', () => {
  570. const accessor = Kernel.createEmpty();
  571. accessor.addUnpackedDoubleIterable(1, [value1]);
  572. accessor.addUnpackedDoubleIterable(1, [value2]);
  573. const serialized = accessor.serialize();
  574. expect(serialized).toEqual(unpackedValue1Value2);
  575. });
  576. it('encode for setting single unpacked value', () => {
  577. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  578. accessor.setUnpackedDoubleElement(1, 0, value2);
  579. accessor.setUnpackedDoubleElement(1, 1, value1);
  580. const serialized = accessor.serialize();
  581. expect(serialized).toEqual(unpackedValue2Value1);
  582. });
  583. it('encode for setting unpacked values', () => {
  584. const accessor = Kernel.createEmpty();
  585. accessor.setUnpackedDoubleIterable(1, [value1, value2]);
  586. const serialized = accessor.serialize();
  587. expect(serialized).toEqual(unpackedValue1Value2);
  588. });
  589. it('return packed values from the input', () => {
  590. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  591. const list = accessor.getRepeatedDoubleIterable(1);
  592. expectEqualToArray(list, [value1, value2]);
  593. });
  594. it('ensure not the same instance returned for packed values', () => {
  595. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  596. const list1 = accessor.getRepeatedDoubleIterable(1);
  597. const list2 = accessor.getRepeatedDoubleIterable(1);
  598. expect(list1).not.toBe(list2);
  599. });
  600. it('add single packed value', () => {
  601. const accessor = Kernel.createEmpty();
  602. accessor.addPackedDoubleElement(1, value1);
  603. const list1 = accessor.getRepeatedDoubleIterable(1);
  604. accessor.addPackedDoubleElement(1, value2);
  605. const list2 = accessor.getRepeatedDoubleIterable(1);
  606. expectEqualToArray(list1, [value1]);
  607. expectEqualToArray(list2, [value1, value2]);
  608. });
  609. it('add packed values', () => {
  610. const accessor = Kernel.createEmpty();
  611. accessor.addPackedDoubleIterable(1, [value1]);
  612. const list1 = accessor.getRepeatedDoubleIterable(1);
  613. accessor.addPackedDoubleIterable(1, [value2]);
  614. const list2 = accessor.getRepeatedDoubleIterable(1);
  615. expectEqualToArray(list1, [value1]);
  616. expectEqualToArray(list2, [value1, value2]);
  617. });
  618. it('set a single packed value', () => {
  619. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  620. accessor.setPackedDoubleElement(1, 1, value1);
  621. const list = accessor.getRepeatedDoubleIterable(1);
  622. expectEqualToArray(list, [value1, value1]);
  623. });
  624. it('set packed values', () => {
  625. const accessor = Kernel.createEmpty();
  626. accessor.setPackedDoubleIterable(1, [value1]);
  627. const list1 = accessor.getRepeatedDoubleIterable(1);
  628. accessor.setPackedDoubleIterable(1, [value2]);
  629. const list2 = accessor.getRepeatedDoubleIterable(1);
  630. expectEqualToArray(list1, [value1]);
  631. expectEqualToArray(list2, [value2]);
  632. });
  633. it('encode for adding single packed value', () => {
  634. const accessor = Kernel.createEmpty();
  635. accessor.addPackedDoubleElement(1, value1);
  636. accessor.addPackedDoubleElement(1, value2);
  637. const serialized = accessor.serialize();
  638. expect(serialized).toEqual(packedValue1Value2);
  639. });
  640. it('encode for adding packed values', () => {
  641. const accessor = Kernel.createEmpty();
  642. accessor.addPackedDoubleIterable(1, [value1, value2]);
  643. const serialized = accessor.serialize();
  644. expect(serialized).toEqual(packedValue1Value2);
  645. });
  646. it('encode for setting single packed value', () => {
  647. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  648. accessor.setPackedDoubleElement(1, 0, value2);
  649. accessor.setPackedDoubleElement(1, 1, value1);
  650. const serialized = accessor.serialize();
  651. expect(serialized).toEqual(packedValue2Value1);
  652. });
  653. it('encode for setting packed values', () => {
  654. const accessor = Kernel.createEmpty();
  655. accessor.setPackedDoubleIterable(1, [value1, value2]);
  656. const serialized = accessor.serialize();
  657. expect(serialized).toEqual(packedValue1Value2);
  658. });
  659. it('return combined values from the input', () => {
  660. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  661. 0x09,
  662. 0x00,
  663. 0x00,
  664. 0x00,
  665. 0x00,
  666. 0x00,
  667. 0x00,
  668. 0xF0,
  669. 0x3F, // value1
  670. 0x0A,
  671. 0x10, // tag
  672. 0x00,
  673. 0x00,
  674. 0x00,
  675. 0x00,
  676. 0x00,
  677. 0x00,
  678. 0xF0,
  679. 0x3F, // value1
  680. 0x00,
  681. 0x00,
  682. 0x00,
  683. 0x00,
  684. 0x00,
  685. 0x00,
  686. 0x00,
  687. 0x00, // value2
  688. 0x09,
  689. 0x00,
  690. 0x00,
  691. 0x00,
  692. 0x00,
  693. 0x00,
  694. 0x00,
  695. 0x00,
  696. 0x00, // value2
  697. ));
  698. const list = accessor.getRepeatedDoubleIterable(1);
  699. expectEqualToArray(list, [value1, value1, value2, value2]);
  700. });
  701. it('return the repeated field element from the input', () => {
  702. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  703. const result1 = accessor.getRepeatedDoubleElement(
  704. /* fieldNumber= */ 1, /* index= */ 0);
  705. const result2 = accessor.getRepeatedDoubleElement(
  706. /* fieldNumber= */ 1, /* index= */ 1);
  707. expect(result1).toEqual(value1);
  708. expect(result2).toEqual(value2);
  709. });
  710. it('return the size from the input', () => {
  711. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  712. const size = accessor.getRepeatedDoubleSize(1);
  713. expect(size).toEqual(2);
  714. });
  715. it('fail when getting unpacked double value with other wire types', () => {
  716. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  717. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  718. if (CHECK_CRITICAL_STATE) {
  719. expect(() => {
  720. accessor.getRepeatedDoubleIterable(1);
  721. }).toThrowError('Expected wire type: 1 but found: 0');
  722. } else {
  723. // Note in unchecked mode we produce invalid output for invalid inputs.
  724. // This test just documents our behavior in those cases.
  725. // These values might change at any point and are not considered
  726. // what the implementation should be doing here.
  727. expectEqualToArray(
  728. accessor.getRepeatedDoubleIterable(1), [2.937446524422997e-306]);
  729. }
  730. });
  731. it('fail when adding unpacked double values with null value', () => {
  732. const accessor = Kernel.createEmpty();
  733. const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
  734. if (CHECK_CRITICAL_STATE) {
  735. expect(() => accessor.addUnpackedDoubleIterable(1, [fakeDouble]))
  736. .toThrowError('Must be a number, but got: null');
  737. } else {
  738. // Note in unchecked mode we produce invalid output for invalid inputs.
  739. // This test just documents our behavior in those cases.
  740. // These values might change at any point and are not considered
  741. // what the implementation should be doing here.
  742. accessor.addUnpackedDoubleIterable(1, [fakeDouble]);
  743. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
  744. }
  745. });
  746. it('fail when adding single unpacked double value with null value', () => {
  747. const accessor = Kernel.createEmpty();
  748. const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
  749. if (CHECK_CRITICAL_STATE) {
  750. expect(() => accessor.addUnpackedDoubleElement(1, fakeDouble))
  751. .toThrowError('Must be a number, but got: null');
  752. } else {
  753. // Note in unchecked mode we produce invalid output for invalid inputs.
  754. // This test just documents our behavior in those cases.
  755. // These values might change at any point and are not considered
  756. // what the implementation should be doing here.
  757. accessor.addUnpackedDoubleElement(1, fakeDouble);
  758. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
  759. }
  760. });
  761. it('fail when setting unpacked double values with null value', () => {
  762. const accessor = Kernel.createEmpty();
  763. const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
  764. if (CHECK_CRITICAL_STATE) {
  765. expect(() => accessor.setUnpackedDoubleIterable(1, [fakeDouble]))
  766. .toThrowError('Must be a number, but got: null');
  767. } else {
  768. // Note in unchecked mode we produce invalid output for invalid inputs.
  769. // This test just documents our behavior in those cases.
  770. // These values might change at any point and are not considered
  771. // what the implementation should be doing here.
  772. accessor.setUnpackedDoubleIterable(1, [fakeDouble]);
  773. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
  774. }
  775. });
  776. it('fail when setting single unpacked double value with null value', () => {
  777. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  778. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  779. const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
  780. if (CHECK_CRITICAL_STATE) {
  781. expect(() => accessor.setUnpackedDoubleElement(1, 0, fakeDouble))
  782. .toThrowError('Must be a number, but got: null');
  783. } else {
  784. // Note in unchecked mode we produce invalid output for invalid inputs.
  785. // This test just documents our behavior in those cases.
  786. // These values might change at any point and are not considered
  787. // what the implementation should be doing here.
  788. accessor.setUnpackedDoubleElement(1, 0, fakeDouble);
  789. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
  790. }
  791. });
  792. it('fail when adding packed double values with null value', () => {
  793. const accessor = Kernel.createEmpty();
  794. const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
  795. if (CHECK_CRITICAL_STATE) {
  796. expect(() => accessor.addPackedDoubleIterable(1, [fakeDouble]))
  797. .toThrowError('Must be a number, but got: null');
  798. } else {
  799. // Note in unchecked mode we produce invalid output for invalid inputs.
  800. // This test just documents our behavior in those cases.
  801. // These values might change at any point and are not considered
  802. // what the implementation should be doing here.
  803. accessor.addPackedDoubleIterable(1, [fakeDouble]);
  804. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
  805. }
  806. });
  807. it('fail when adding single packed double value with null value', () => {
  808. const accessor = Kernel.createEmpty();
  809. const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
  810. if (CHECK_CRITICAL_STATE) {
  811. expect(() => accessor.addPackedDoubleElement(1, fakeDouble))
  812. .toThrowError('Must be a number, but got: null');
  813. } else {
  814. // Note in unchecked mode we produce invalid output for invalid inputs.
  815. // This test just documents our behavior in those cases.
  816. // These values might change at any point and are not considered
  817. // what the implementation should be doing here.
  818. accessor.addPackedDoubleElement(1, fakeDouble);
  819. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
  820. }
  821. });
  822. it('fail when setting packed double values with null value', () => {
  823. const accessor = Kernel.createEmpty();
  824. const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
  825. if (CHECK_CRITICAL_STATE) {
  826. expect(() => accessor.setPackedDoubleIterable(1, [fakeDouble]))
  827. .toThrowError('Must be a number, but got: null');
  828. } else {
  829. // Note in unchecked mode we produce invalid output for invalid inputs.
  830. // This test just documents our behavior in those cases.
  831. // These values might change at any point and are not considered
  832. // what the implementation should be doing here.
  833. accessor.setPackedDoubleIterable(1, [fakeDouble]);
  834. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
  835. }
  836. });
  837. it('fail when setting single packed double value with null value', () => {
  838. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  839. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  840. const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
  841. if (CHECK_CRITICAL_STATE) {
  842. expect(() => accessor.setPackedDoubleElement(1, 0, fakeDouble))
  843. .toThrowError('Must be a number, but got: null');
  844. } else {
  845. // Note in unchecked mode we produce invalid output for invalid inputs.
  846. // This test just documents our behavior in those cases.
  847. // These values might change at any point and are not considered
  848. // what the implementation should be doing here.
  849. accessor.setPackedDoubleElement(1, 0, fakeDouble);
  850. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
  851. }
  852. });
  853. it('fail when setting single unpacked with out-of-bound index', () => {
  854. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  855. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  856. if (CHECK_CRITICAL_STATE) {
  857. expect(() => accessor.setUnpackedDoubleElement(1, 1, 1))
  858. .toThrowError('Index out of bounds: index: 1 size: 1');
  859. } else {
  860. // Note in unchecked mode we produce invalid output for invalid inputs.
  861. // This test just documents our behavior in those cases.
  862. // These values might change at any point and are not considered
  863. // what the implementation should be doing here.
  864. accessor.setUnpackedDoubleElement(1, 1, 1);
  865. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [0, 1]);
  866. }
  867. });
  868. it('fail when setting single packed with out-of-bound index', () => {
  869. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  870. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  871. if (CHECK_CRITICAL_STATE) {
  872. expect(() => accessor.setPackedDoubleElement(1, 1, 1))
  873. .toThrowError('Index out of bounds: index: 1 size: 1');
  874. } else {
  875. // Note in unchecked mode we produce invalid output for invalid inputs.
  876. // This test just documents our behavior in those cases.
  877. // These values might change at any point and are not considered
  878. // what the implementation should be doing here.
  879. accessor.setPackedDoubleElement(1, 1, 1);
  880. expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [0, 1]);
  881. }
  882. });
  883. it('fail when getting element with out-of-range index', () => {
  884. const accessor = Kernel.createEmpty();
  885. if (CHECK_CRITICAL_STATE) {
  886. expect(() => {
  887. accessor.getRepeatedDoubleElement(
  888. /* fieldNumber= */ 1, /* index= */ 0);
  889. }).toThrowError('Index out of bounds: index: 0 size: 0');
  890. } else {
  891. // Note in unchecked mode we produce invalid output for invalid inputs.
  892. // This test just documents our behavior in those cases.
  893. // These values might change at any point and are not considered
  894. // what the implementation should be doing here.
  895. expect(accessor.getRepeatedDoubleElement(
  896. /* fieldNumber= */ 1, /* index= */ 0))
  897. .toBe(undefined);
  898. }
  899. });
  900. });
  901. describe('Kernel for repeated fixed32 does', () => {
  902. const value1 = 1;
  903. const value2 = 0;
  904. const unpackedValue1Value2 = createArrayBuffer(
  905. 0x0D, 0x01, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00);
  906. const unpackedValue2Value1 = createArrayBuffer(
  907. 0x0D, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x01, 0x00, 0x00, 0x00);
  908. const packedValue1Value2 = createArrayBuffer(
  909. 0x0A, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
  910. const packedValue2Value1 = createArrayBuffer(
  911. 0x0A, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00);
  912. it('return empty array for the empty input', () => {
  913. const accessor = Kernel.createEmpty();
  914. const list = accessor.getRepeatedFixed32Iterable(1);
  915. expectEqualToArray(list, []);
  916. });
  917. it('ensure not the same instance returned for the empty input', () => {
  918. const accessor = Kernel.createEmpty();
  919. const list1 = accessor.getRepeatedFixed32Iterable(1);
  920. const list2 = accessor.getRepeatedFixed32Iterable(1);
  921. expect(list1).not.toBe(list2);
  922. });
  923. it('return size for the empty input', () => {
  924. const accessor = Kernel.createEmpty();
  925. const size = accessor.getRepeatedFixed32Size(1);
  926. expect(size).toEqual(0);
  927. });
  928. it('return unpacked values from the input', () => {
  929. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  930. const list = accessor.getRepeatedFixed32Iterable(1);
  931. expectEqualToArray(list, [value1, value2]);
  932. });
  933. it('ensure not the same instance returned for unpacked values', () => {
  934. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  935. const list1 = accessor.getRepeatedFixed32Iterable(1);
  936. const list2 = accessor.getRepeatedFixed32Iterable(1);
  937. expect(list1).not.toBe(list2);
  938. });
  939. it('add single unpacked value', () => {
  940. const accessor = Kernel.createEmpty();
  941. accessor.addUnpackedFixed32Element(1, value1);
  942. const list1 = accessor.getRepeatedFixed32Iterable(1);
  943. accessor.addUnpackedFixed32Element(1, value2);
  944. const list2 = accessor.getRepeatedFixed32Iterable(1);
  945. expectEqualToArray(list1, [value1]);
  946. expectEqualToArray(list2, [value1, value2]);
  947. });
  948. it('add unpacked values', () => {
  949. const accessor = Kernel.createEmpty();
  950. accessor.addUnpackedFixed32Iterable(1, [value1]);
  951. const list1 = accessor.getRepeatedFixed32Iterable(1);
  952. accessor.addUnpackedFixed32Iterable(1, [value2]);
  953. const list2 = accessor.getRepeatedFixed32Iterable(1);
  954. expectEqualToArray(list1, [value1]);
  955. expectEqualToArray(list2, [value1, value2]);
  956. });
  957. it('set a single unpacked value', () => {
  958. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  959. accessor.setUnpackedFixed32Element(1, 1, value1);
  960. const list = accessor.getRepeatedFixed32Iterable(1);
  961. expectEqualToArray(list, [value1, value1]);
  962. });
  963. it('set unpacked values', () => {
  964. const accessor = Kernel.createEmpty();
  965. accessor.setUnpackedFixed32Iterable(1, [value1]);
  966. const list = accessor.getRepeatedFixed32Iterable(1);
  967. expectEqualToArray(list, [value1]);
  968. });
  969. it('encode for adding single unpacked value', () => {
  970. const accessor = Kernel.createEmpty();
  971. accessor.addUnpackedFixed32Element(1, value1);
  972. accessor.addUnpackedFixed32Element(1, value2);
  973. const serialized = accessor.serialize();
  974. expect(serialized).toEqual(unpackedValue1Value2);
  975. });
  976. it('encode for adding unpacked values', () => {
  977. const accessor = Kernel.createEmpty();
  978. accessor.addUnpackedFixed32Iterable(1, [value1]);
  979. accessor.addUnpackedFixed32Iterable(1, [value2]);
  980. const serialized = accessor.serialize();
  981. expect(serialized).toEqual(unpackedValue1Value2);
  982. });
  983. it('encode for setting single unpacked value', () => {
  984. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  985. accessor.setUnpackedFixed32Element(1, 0, value2);
  986. accessor.setUnpackedFixed32Element(1, 1, value1);
  987. const serialized = accessor.serialize();
  988. expect(serialized).toEqual(unpackedValue2Value1);
  989. });
  990. it('encode for setting unpacked values', () => {
  991. const accessor = Kernel.createEmpty();
  992. accessor.setUnpackedFixed32Iterable(1, [value1, value2]);
  993. const serialized = accessor.serialize();
  994. expect(serialized).toEqual(unpackedValue1Value2);
  995. });
  996. it('return packed values from the input', () => {
  997. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  998. const list = accessor.getRepeatedFixed32Iterable(1);
  999. expectEqualToArray(list, [value1, value2]);
  1000. });
  1001. it('ensure not the same instance returned for packed values', () => {
  1002. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  1003. const list1 = accessor.getRepeatedFixed32Iterable(1);
  1004. const list2 = accessor.getRepeatedFixed32Iterable(1);
  1005. expect(list1).not.toBe(list2);
  1006. });
  1007. it('add single packed value', () => {
  1008. const accessor = Kernel.createEmpty();
  1009. accessor.addPackedFixed32Element(1, value1);
  1010. const list1 = accessor.getRepeatedFixed32Iterable(1);
  1011. accessor.addPackedFixed32Element(1, value2);
  1012. const list2 = accessor.getRepeatedFixed32Iterable(1);
  1013. expectEqualToArray(list1, [value1]);
  1014. expectEqualToArray(list2, [value1, value2]);
  1015. });
  1016. it('add packed values', () => {
  1017. const accessor = Kernel.createEmpty();
  1018. accessor.addPackedFixed32Iterable(1, [value1]);
  1019. const list1 = accessor.getRepeatedFixed32Iterable(1);
  1020. accessor.addPackedFixed32Iterable(1, [value2]);
  1021. const list2 = accessor.getRepeatedFixed32Iterable(1);
  1022. expectEqualToArray(list1, [value1]);
  1023. expectEqualToArray(list2, [value1, value2]);
  1024. });
  1025. it('set a single packed value', () => {
  1026. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1027. accessor.setPackedFixed32Element(1, 1, value1);
  1028. const list = accessor.getRepeatedFixed32Iterable(1);
  1029. expectEqualToArray(list, [value1, value1]);
  1030. });
  1031. it('set packed values', () => {
  1032. const accessor = Kernel.createEmpty();
  1033. accessor.setPackedFixed32Iterable(1, [value1]);
  1034. const list1 = accessor.getRepeatedFixed32Iterable(1);
  1035. accessor.setPackedFixed32Iterable(1, [value2]);
  1036. const list2 = accessor.getRepeatedFixed32Iterable(1);
  1037. expectEqualToArray(list1, [value1]);
  1038. expectEqualToArray(list2, [value2]);
  1039. });
  1040. it('encode for adding single packed value', () => {
  1041. const accessor = Kernel.createEmpty();
  1042. accessor.addPackedFixed32Element(1, value1);
  1043. accessor.addPackedFixed32Element(1, value2);
  1044. const serialized = accessor.serialize();
  1045. expect(serialized).toEqual(packedValue1Value2);
  1046. });
  1047. it('encode for adding packed values', () => {
  1048. const accessor = Kernel.createEmpty();
  1049. accessor.addPackedFixed32Iterable(1, [value1, value2]);
  1050. const serialized = accessor.serialize();
  1051. expect(serialized).toEqual(packedValue1Value2);
  1052. });
  1053. it('encode for setting single packed value', () => {
  1054. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1055. accessor.setPackedFixed32Element(1, 0, value2);
  1056. accessor.setPackedFixed32Element(1, 1, value1);
  1057. const serialized = accessor.serialize();
  1058. expect(serialized).toEqual(packedValue2Value1);
  1059. });
  1060. it('encode for setting packed values', () => {
  1061. const accessor = Kernel.createEmpty();
  1062. accessor.setPackedFixed32Iterable(1, [value1, value2]);
  1063. const serialized = accessor.serialize();
  1064. expect(serialized).toEqual(packedValue1Value2);
  1065. });
  1066. it('return combined values from the input', () => {
  1067. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  1068. 0x0D,
  1069. 0x01,
  1070. 0x00,
  1071. 0x00,
  1072. 0x00, // value1
  1073. 0x0A,
  1074. 0x08, // tag
  1075. 0x01,
  1076. 0x00,
  1077. 0x00,
  1078. 0x00, // value1
  1079. 0x00,
  1080. 0x00,
  1081. 0x00,
  1082. 0x00, // value2
  1083. 0x0D,
  1084. 0x00,
  1085. 0x00,
  1086. 0x00,
  1087. 0x00, // value2
  1088. ));
  1089. const list = accessor.getRepeatedFixed32Iterable(1);
  1090. expectEqualToArray(list, [value1, value1, value2, value2]);
  1091. });
  1092. it('return the repeated field element from the input', () => {
  1093. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1094. const result1 = accessor.getRepeatedFixed32Element(
  1095. /* fieldNumber= */ 1, /* index= */ 0);
  1096. const result2 = accessor.getRepeatedFixed32Element(
  1097. /* fieldNumber= */ 1, /* index= */ 1);
  1098. expect(result1).toEqual(value1);
  1099. expect(result2).toEqual(value2);
  1100. });
  1101. it('return the size from the input', () => {
  1102. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1103. const size = accessor.getRepeatedFixed32Size(1);
  1104. expect(size).toEqual(2);
  1105. });
  1106. it('fail when getting unpacked fixed32 value with other wire types', () => {
  1107. const accessor =
  1108. Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
  1109. if (CHECK_CRITICAL_STATE) {
  1110. expect(() => {
  1111. accessor.getRepeatedFixed32Iterable(1);
  1112. }).toThrowError('Expected wire type: 5 but found: 0');
  1113. } else {
  1114. // Note in unchecked mode we produce invalid output for invalid inputs.
  1115. // This test just documents our behavior in those cases.
  1116. // These values might change at any point and are not considered
  1117. // what the implementation should be doing here.
  1118. expectQualifiedIterable(
  1119. accessor.getRepeatedFixed32Iterable(1),
  1120. (value) => Number.isInteger(value));
  1121. }
  1122. });
  1123. it('fail when adding unpacked fixed32 values with null value', () => {
  1124. const accessor = Kernel.createEmpty();
  1125. const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
  1126. if (CHECK_CRITICAL_STATE) {
  1127. expect(() => accessor.addUnpackedFixed32Iterable(1, [fakeFixed32]))
  1128. .toThrowError('Must be a number, but got: null');
  1129. } else {
  1130. // Note in unchecked mode we produce invalid output for invalid inputs.
  1131. // This test just documents our behavior in those cases.
  1132. // These values might change at any point and are not considered
  1133. // what the implementation should be doing here.
  1134. accessor.addUnpackedFixed32Iterable(1, [fakeFixed32]);
  1135. expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
  1136. }
  1137. });
  1138. it('fail when adding single unpacked fixed32 value with null value', () => {
  1139. const accessor = Kernel.createEmpty();
  1140. const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
  1141. if (CHECK_CRITICAL_STATE) {
  1142. expect(() => accessor.addUnpackedFixed32Element(1, fakeFixed32))
  1143. .toThrowError('Must be a number, but got: null');
  1144. } else {
  1145. // Note in unchecked mode we produce invalid output for invalid inputs.
  1146. // This test just documents our behavior in those cases.
  1147. // These values might change at any point and are not considered
  1148. // what the implementation should be doing here.
  1149. accessor.addUnpackedFixed32Element(1, fakeFixed32);
  1150. expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
  1151. }
  1152. });
  1153. it('fail when setting unpacked fixed32 values with null value', () => {
  1154. const accessor = Kernel.createEmpty();
  1155. const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
  1156. if (CHECK_CRITICAL_STATE) {
  1157. expect(() => accessor.setUnpackedFixed32Iterable(1, [fakeFixed32]))
  1158. .toThrowError('Must be a number, but got: null');
  1159. } else {
  1160. // Note in unchecked mode we produce invalid output for invalid inputs.
  1161. // This test just documents our behavior in those cases.
  1162. // These values might change at any point and are not considered
  1163. // what the implementation should be doing here.
  1164. accessor.setUnpackedFixed32Iterable(1, [fakeFixed32]);
  1165. expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
  1166. }
  1167. });
  1168. it('fail when setting single unpacked fixed32 value with null value', () => {
  1169. const accessor =
  1170. Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
  1171. const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
  1172. if (CHECK_CRITICAL_STATE) {
  1173. expect(() => accessor.setUnpackedFixed32Element(1, 0, fakeFixed32))
  1174. .toThrowError('Must be a number, but got: null');
  1175. } else {
  1176. // Note in unchecked mode we produce invalid output for invalid inputs.
  1177. // This test just documents our behavior in those cases.
  1178. // These values might change at any point and are not considered
  1179. // what the implementation should be doing here.
  1180. accessor.setUnpackedFixed32Element(1, 0, fakeFixed32);
  1181. expectQualifiedIterable(
  1182. accessor.getRepeatedFixed32Iterable(1),
  1183. );
  1184. }
  1185. });
  1186. it('fail when adding packed fixed32 values with null value', () => {
  1187. const accessor = Kernel.createEmpty();
  1188. const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
  1189. if (CHECK_CRITICAL_STATE) {
  1190. expect(() => accessor.addPackedFixed32Iterable(1, [fakeFixed32]))
  1191. .toThrowError('Must be a number, but got: null');
  1192. } else {
  1193. // Note in unchecked mode we produce invalid output for invalid inputs.
  1194. // This test just documents our behavior in those cases.
  1195. // These values might change at any point and are not considered
  1196. // what the implementation should be doing here.
  1197. accessor.addPackedFixed32Iterable(1, [fakeFixed32]);
  1198. expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
  1199. }
  1200. });
  1201. it('fail when adding single packed fixed32 value with null value', () => {
  1202. const accessor = Kernel.createEmpty();
  1203. const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
  1204. if (CHECK_CRITICAL_STATE) {
  1205. expect(() => accessor.addPackedFixed32Element(1, fakeFixed32))
  1206. .toThrowError('Must be a number, but got: null');
  1207. } else {
  1208. // Note in unchecked mode we produce invalid output for invalid inputs.
  1209. // This test just documents our behavior in those cases.
  1210. // These values might change at any point and are not considered
  1211. // what the implementation should be doing here.
  1212. accessor.addPackedFixed32Element(1, fakeFixed32);
  1213. expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
  1214. }
  1215. });
  1216. it('fail when setting packed fixed32 values with null value', () => {
  1217. const accessor = Kernel.createEmpty();
  1218. const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
  1219. if (CHECK_CRITICAL_STATE) {
  1220. expect(() => accessor.setPackedFixed32Iterable(1, [fakeFixed32]))
  1221. .toThrowError('Must be a number, but got: null');
  1222. } else {
  1223. // Note in unchecked mode we produce invalid output for invalid inputs.
  1224. // This test just documents our behavior in those cases.
  1225. // These values might change at any point and are not considered
  1226. // what the implementation should be doing here.
  1227. accessor.setPackedFixed32Iterable(1, [fakeFixed32]);
  1228. expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
  1229. }
  1230. });
  1231. it('fail when setting single packed fixed32 value with null value', () => {
  1232. const accessor =
  1233. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
  1234. const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
  1235. if (CHECK_CRITICAL_STATE) {
  1236. expect(() => accessor.setPackedFixed32Element(1, 0, fakeFixed32))
  1237. .toThrowError('Must be a number, but got: null');
  1238. } else {
  1239. // Note in unchecked mode we produce invalid output for invalid inputs.
  1240. // This test just documents our behavior in those cases.
  1241. // These values might change at any point and are not considered
  1242. // what the implementation should be doing here.
  1243. accessor.setPackedFixed32Element(1, 0, fakeFixed32);
  1244. expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
  1245. }
  1246. });
  1247. it('fail when setting single unpacked with out-of-bound index', () => {
  1248. const accessor = Kernel.fromArrayBuffer(
  1249. createArrayBuffer(0x0A, 0x04, 0x00, 0x00, 0x00, 0x00));
  1250. if (CHECK_CRITICAL_STATE) {
  1251. expect(() => accessor.setUnpackedFixed32Element(1, 1, 1))
  1252. .toThrowError('Index out of bounds: index: 1 size: 1');
  1253. } else {
  1254. // Note in unchecked mode we produce invalid output for invalid inputs.
  1255. // This test just documents our behavior in those cases.
  1256. // These values might change at any point and are not considered
  1257. // what the implementation should be doing here.
  1258. accessor.setUnpackedFixed32Element(1, 1, 1);
  1259. expectQualifiedIterable(
  1260. accessor.getRepeatedFixed32Iterable(1),
  1261. (value) => Number.isInteger(value));
  1262. }
  1263. });
  1264. it('fail when setting single packed with out-of-bound index', () => {
  1265. const accessor =
  1266. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
  1267. if (CHECK_CRITICAL_STATE) {
  1268. expect(() => accessor.setPackedFixed32Element(1, 1, 1))
  1269. .toThrowError('Index out of bounds: index: 1 size: 1');
  1270. } else {
  1271. // Note in unchecked mode we produce invalid output for invalid inputs.
  1272. // This test just documents our behavior in those cases.
  1273. // These values might change at any point and are not considered
  1274. // what the implementation should be doing here.
  1275. accessor.setPackedFixed32Element(1, 1, 1);
  1276. expectQualifiedIterable(
  1277. accessor.getRepeatedFixed32Iterable(1),
  1278. (value) => Number.isInteger(value));
  1279. }
  1280. });
  1281. it('fail when getting element with out-of-range index', () => {
  1282. const accessor = Kernel.createEmpty();
  1283. if (CHECK_CRITICAL_STATE) {
  1284. expect(() => {
  1285. accessor.getRepeatedFixed32Element(
  1286. /* fieldNumber= */ 1, /* index= */ 0);
  1287. }).toThrowError('Index out of bounds: index: 0 size: 0');
  1288. } else {
  1289. // Note in unchecked mode we produce invalid output for invalid inputs.
  1290. // This test just documents our behavior in those cases.
  1291. // These values might change at any point and are not considered
  1292. // what the implementation should be doing here.
  1293. expect(accessor.getRepeatedFixed32Element(
  1294. /* fieldNumber= */ 1, /* index= */ 0))
  1295. .toBe(undefined);
  1296. }
  1297. });
  1298. });
  1299. describe('Kernel for repeated fixed64 does', () => {
  1300. const value1 = Int64.fromInt(1);
  1301. const value2 = Int64.fromInt(0);
  1302. const unpackedValue1Value2 = createArrayBuffer(
  1303. 0x09,
  1304. 0x01,
  1305. 0x00,
  1306. 0x00,
  1307. 0x00,
  1308. 0x00,
  1309. 0x00,
  1310. 0x00,
  1311. 0x00, // value1
  1312. 0x09,
  1313. 0x00,
  1314. 0x00,
  1315. 0x00,
  1316. 0x00,
  1317. 0x00,
  1318. 0x00,
  1319. 0x00,
  1320. 0x00, // value2
  1321. );
  1322. const unpackedValue2Value1 = createArrayBuffer(
  1323. 0x09,
  1324. 0x00,
  1325. 0x00,
  1326. 0x00,
  1327. 0x00,
  1328. 0x00,
  1329. 0x00,
  1330. 0x00,
  1331. 0x00, // value1
  1332. 0x09,
  1333. 0x01,
  1334. 0x00,
  1335. 0x00,
  1336. 0x00,
  1337. 0x00,
  1338. 0x00,
  1339. 0x00,
  1340. 0x00, // value2
  1341. );
  1342. const packedValue1Value2 = createArrayBuffer(
  1343. 0x0A,
  1344. 0x10, // tag
  1345. 0x01,
  1346. 0x00,
  1347. 0x00,
  1348. 0x00,
  1349. 0x00,
  1350. 0x00,
  1351. 0x00,
  1352. 0x00, // value1
  1353. 0x00,
  1354. 0x00,
  1355. 0x00,
  1356. 0x00,
  1357. 0x00,
  1358. 0x00,
  1359. 0x00,
  1360. 0x00, // value2
  1361. );
  1362. const packedValue2Value1 = createArrayBuffer(
  1363. 0x0A,
  1364. 0x10, // tag
  1365. 0x00,
  1366. 0x00,
  1367. 0x00,
  1368. 0x00,
  1369. 0x00,
  1370. 0x00,
  1371. 0x00,
  1372. 0x00, // value2
  1373. 0x01,
  1374. 0x00,
  1375. 0x00,
  1376. 0x00,
  1377. 0x00,
  1378. 0x00,
  1379. 0x00,
  1380. 0x00, // value1
  1381. );
  1382. it('return empty array for the empty input', () => {
  1383. const accessor = Kernel.createEmpty();
  1384. const list = accessor.getRepeatedFixed64Iterable(1);
  1385. expectEqualToArray(list, []);
  1386. });
  1387. it('ensure not the same instance returned for the empty input', () => {
  1388. const accessor = Kernel.createEmpty();
  1389. const list1 = accessor.getRepeatedFixed64Iterable(1);
  1390. const list2 = accessor.getRepeatedFixed64Iterable(1);
  1391. expect(list1).not.toBe(list2);
  1392. });
  1393. it('return size for the empty input', () => {
  1394. const accessor = Kernel.createEmpty();
  1395. const size = accessor.getRepeatedFixed64Size(1);
  1396. expect(size).toEqual(0);
  1397. });
  1398. it('return unpacked values from the input', () => {
  1399. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1400. const list = accessor.getRepeatedFixed64Iterable(1);
  1401. expectEqualToArray(list, [value1, value2]);
  1402. });
  1403. it('ensure not the same instance returned for unpacked values', () => {
  1404. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1405. const list1 = accessor.getRepeatedFixed64Iterable(1);
  1406. const list2 = accessor.getRepeatedFixed64Iterable(1);
  1407. expect(list1).not.toBe(list2);
  1408. });
  1409. it('add single unpacked value', () => {
  1410. const accessor = Kernel.createEmpty();
  1411. accessor.addUnpackedFixed64Element(1, value1);
  1412. const list1 = accessor.getRepeatedFixed64Iterable(1);
  1413. accessor.addUnpackedFixed64Element(1, value2);
  1414. const list2 = accessor.getRepeatedFixed64Iterable(1);
  1415. expectEqualToArray(list1, [value1]);
  1416. expectEqualToArray(list2, [value1, value2]);
  1417. });
  1418. it('add unpacked values', () => {
  1419. const accessor = Kernel.createEmpty();
  1420. accessor.addUnpackedFixed64Iterable(1, [value1]);
  1421. const list1 = accessor.getRepeatedFixed64Iterable(1);
  1422. accessor.addUnpackedFixed64Iterable(1, [value2]);
  1423. const list2 = accessor.getRepeatedFixed64Iterable(1);
  1424. expectEqualToArray(list1, [value1]);
  1425. expectEqualToArray(list2, [value1, value2]);
  1426. });
  1427. it('set a single unpacked value', () => {
  1428. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  1429. accessor.setUnpackedFixed64Element(1, 1, value1);
  1430. const list = accessor.getRepeatedFixed64Iterable(1);
  1431. expectEqualToArray(list, [value1, value1]);
  1432. });
  1433. it('set unpacked values', () => {
  1434. const accessor = Kernel.createEmpty();
  1435. accessor.setUnpackedFixed64Iterable(1, [value1]);
  1436. const list = accessor.getRepeatedFixed64Iterable(1);
  1437. expectEqualToArray(list, [value1]);
  1438. });
  1439. it('encode for adding single unpacked value', () => {
  1440. const accessor = Kernel.createEmpty();
  1441. accessor.addUnpackedFixed64Element(1, value1);
  1442. accessor.addUnpackedFixed64Element(1, value2);
  1443. const serialized = accessor.serialize();
  1444. expect(serialized).toEqual(unpackedValue1Value2);
  1445. });
  1446. it('encode for adding unpacked values', () => {
  1447. const accessor = Kernel.createEmpty();
  1448. accessor.addUnpackedFixed64Iterable(1, [value1]);
  1449. accessor.addUnpackedFixed64Iterable(1, [value2]);
  1450. const serialized = accessor.serialize();
  1451. expect(serialized).toEqual(unpackedValue1Value2);
  1452. });
  1453. it('encode for setting single unpacked value', () => {
  1454. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1455. accessor.setUnpackedFixed64Element(1, 0, value2);
  1456. accessor.setUnpackedFixed64Element(1, 1, value1);
  1457. const serialized = accessor.serialize();
  1458. expect(serialized).toEqual(unpackedValue2Value1);
  1459. });
  1460. it('encode for setting unpacked values', () => {
  1461. const accessor = Kernel.createEmpty();
  1462. accessor.setUnpackedFixed64Iterable(1, [value1, value2]);
  1463. const serialized = accessor.serialize();
  1464. expect(serialized).toEqual(unpackedValue1Value2);
  1465. });
  1466. it('return packed values from the input', () => {
  1467. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  1468. const list = accessor.getRepeatedFixed64Iterable(1);
  1469. expectEqualToArray(list, [value1, value2]);
  1470. });
  1471. it('ensure not the same instance returned for packed values', () => {
  1472. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  1473. const list1 = accessor.getRepeatedFixed64Iterable(1);
  1474. const list2 = accessor.getRepeatedFixed64Iterable(1);
  1475. expect(list1).not.toBe(list2);
  1476. });
  1477. it('add single packed value', () => {
  1478. const accessor = Kernel.createEmpty();
  1479. accessor.addPackedFixed64Element(1, value1);
  1480. const list1 = accessor.getRepeatedFixed64Iterable(1);
  1481. accessor.addPackedFixed64Element(1, value2);
  1482. const list2 = accessor.getRepeatedFixed64Iterable(1);
  1483. expectEqualToArray(list1, [value1]);
  1484. expectEqualToArray(list2, [value1, value2]);
  1485. });
  1486. it('add packed values', () => {
  1487. const accessor = Kernel.createEmpty();
  1488. accessor.addPackedFixed64Iterable(1, [value1]);
  1489. const list1 = accessor.getRepeatedFixed64Iterable(1);
  1490. accessor.addPackedFixed64Iterable(1, [value2]);
  1491. const list2 = accessor.getRepeatedFixed64Iterable(1);
  1492. expectEqualToArray(list1, [value1]);
  1493. expectEqualToArray(list2, [value1, value2]);
  1494. });
  1495. it('set a single packed value', () => {
  1496. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1497. accessor.setPackedFixed64Element(1, 1, value1);
  1498. const list = accessor.getRepeatedFixed64Iterable(1);
  1499. expectEqualToArray(list, [value1, value1]);
  1500. });
  1501. it('set packed values', () => {
  1502. const accessor = Kernel.createEmpty();
  1503. accessor.setPackedFixed64Iterable(1, [value1]);
  1504. const list1 = accessor.getRepeatedFixed64Iterable(1);
  1505. accessor.setPackedFixed64Iterable(1, [value2]);
  1506. const list2 = accessor.getRepeatedFixed64Iterable(1);
  1507. expectEqualToArray(list1, [value1]);
  1508. expectEqualToArray(list2, [value2]);
  1509. });
  1510. it('encode for adding single packed value', () => {
  1511. const accessor = Kernel.createEmpty();
  1512. accessor.addPackedFixed64Element(1, value1);
  1513. accessor.addPackedFixed64Element(1, value2);
  1514. const serialized = accessor.serialize();
  1515. expect(serialized).toEqual(packedValue1Value2);
  1516. });
  1517. it('encode for adding packed values', () => {
  1518. const accessor = Kernel.createEmpty();
  1519. accessor.addPackedFixed64Iterable(1, [value1, value2]);
  1520. const serialized = accessor.serialize();
  1521. expect(serialized).toEqual(packedValue1Value2);
  1522. });
  1523. it('encode for setting single packed value', () => {
  1524. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1525. accessor.setPackedFixed64Element(1, 0, value2);
  1526. accessor.setPackedFixed64Element(1, 1, value1);
  1527. const serialized = accessor.serialize();
  1528. expect(serialized).toEqual(packedValue2Value1);
  1529. });
  1530. it('encode for setting packed values', () => {
  1531. const accessor = Kernel.createEmpty();
  1532. accessor.setPackedFixed64Iterable(1, [value1, value2]);
  1533. const serialized = accessor.serialize();
  1534. expect(serialized).toEqual(packedValue1Value2);
  1535. });
  1536. it('return combined values from the input', () => {
  1537. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  1538. 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // value1
  1539. 0x0A, 0x10, // tag
  1540. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // value1
  1541. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // value2
  1542. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // value2
  1543. ));
  1544. const list = accessor.getRepeatedFixed64Iterable(1);
  1545. expectEqualToArray(list, [value1, value1, value2, value2]);
  1546. });
  1547. it('return the repeated field element from the input', () => {
  1548. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1549. const result1 = accessor.getRepeatedFixed64Element(
  1550. /* fieldNumber= */ 1, /* index= */ 0);
  1551. const result2 = accessor.getRepeatedFixed64Element(
  1552. /* fieldNumber= */ 1, /* index= */ 1);
  1553. expect(result1).toEqual(value1);
  1554. expect(result2).toEqual(value2);
  1555. });
  1556. it('return the size from the input', () => {
  1557. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1558. const size = accessor.getRepeatedFixed64Size(1);
  1559. expect(size).toEqual(2);
  1560. });
  1561. it('fail when getting unpacked fixed64 value with other wire types', () => {
  1562. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  1563. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  1564. if (CHECK_CRITICAL_STATE) {
  1565. expect(() => {
  1566. accessor.getRepeatedFixed64Iterable(1);
  1567. }).toThrowError('Expected wire type: 1 but found: 0');
  1568. } else {
  1569. // Note in unchecked mode we produce invalid output for invalid inputs.
  1570. // This test just documents our behavior in those cases.
  1571. // These values might change at any point and are not considered
  1572. // what the implementation should be doing here.
  1573. expectQualifiedIterable(
  1574. accessor.getRepeatedFixed64Iterable(1),
  1575. (value) => value instanceof Int64);
  1576. }
  1577. });
  1578. it('fail when adding unpacked fixed64 values with null value', () => {
  1579. const accessor = Kernel.createEmpty();
  1580. const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  1581. if (CHECK_CRITICAL_STATE) {
  1582. expect(() => accessor.addUnpackedFixed64Iterable(1, [fakeFixed64]))
  1583. .toThrowError('Must be Int64 instance, but got: null');
  1584. } else {
  1585. // Note in unchecked mode we produce invalid output for invalid inputs.
  1586. // This test just documents our behavior in those cases.
  1587. // These values might change at any point and are not considered
  1588. // what the implementation should be doing here.
  1589. accessor.addUnpackedFixed64Iterable(1, [fakeFixed64]);
  1590. expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
  1591. }
  1592. });
  1593. it('fail when adding single unpacked fixed64 value with null value', () => {
  1594. const accessor = Kernel.createEmpty();
  1595. const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  1596. if (CHECK_CRITICAL_STATE) {
  1597. expect(() => accessor.addUnpackedFixed64Element(1, fakeFixed64))
  1598. .toThrowError('Must be Int64 instance, but got: null');
  1599. } else {
  1600. // Note in unchecked mode we produce invalid output for invalid inputs.
  1601. // This test just documents our behavior in those cases.
  1602. // These values might change at any point and are not considered
  1603. // what the implementation should be doing here.
  1604. accessor.addUnpackedFixed64Element(1, fakeFixed64);
  1605. expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
  1606. }
  1607. });
  1608. it('fail when setting unpacked fixed64 values with null value', () => {
  1609. const accessor = Kernel.createEmpty();
  1610. const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  1611. if (CHECK_CRITICAL_STATE) {
  1612. expect(() => accessor.setUnpackedFixed64Iterable(1, [fakeFixed64]))
  1613. .toThrowError('Must be Int64 instance, but got: null');
  1614. } else {
  1615. // Note in unchecked mode we produce invalid output for invalid inputs.
  1616. // This test just documents our behavior in those cases.
  1617. // These values might change at any point and are not considered
  1618. // what the implementation should be doing here.
  1619. accessor.setUnpackedFixed64Iterable(1, [fakeFixed64]);
  1620. expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
  1621. }
  1622. });
  1623. it('fail when setting single unpacked fixed64 value with null value', () => {
  1624. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  1625. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  1626. const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  1627. if (CHECK_CRITICAL_STATE) {
  1628. expect(() => accessor.setUnpackedFixed64Element(1, 0, fakeFixed64))
  1629. .toThrowError('Must be Int64 instance, but got: null');
  1630. } else {
  1631. // Note in unchecked mode we produce invalid output for invalid inputs.
  1632. // This test just documents our behavior in those cases.
  1633. // These values might change at any point and are not considered
  1634. // what the implementation should be doing here.
  1635. accessor.setUnpackedFixed64Element(1, 0, fakeFixed64);
  1636. expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
  1637. }
  1638. });
  1639. it('fail when adding packed fixed64 values with null value', () => {
  1640. const accessor = Kernel.createEmpty();
  1641. const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  1642. if (CHECK_CRITICAL_STATE) {
  1643. expect(() => accessor.addPackedFixed64Iterable(1, [fakeFixed64]))
  1644. .toThrowError('Must be Int64 instance, but got: null');
  1645. } else {
  1646. // Note in unchecked mode we produce invalid output for invalid inputs.
  1647. // This test just documents our behavior in those cases.
  1648. // These values might change at any point and are not considered
  1649. // what the implementation should be doing here.
  1650. accessor.addPackedFixed64Iterable(1, [fakeFixed64]);
  1651. expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
  1652. }
  1653. });
  1654. it('fail when adding single packed fixed64 value with null value', () => {
  1655. const accessor = Kernel.createEmpty();
  1656. const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  1657. if (CHECK_CRITICAL_STATE) {
  1658. expect(() => accessor.addPackedFixed64Element(1, fakeFixed64))
  1659. .toThrowError('Must be Int64 instance, but got: null');
  1660. } else {
  1661. // Note in unchecked mode we produce invalid output for invalid inputs.
  1662. // This test just documents our behavior in those cases.
  1663. // These values might change at any point and are not considered
  1664. // what the implementation should be doing here.
  1665. accessor.addPackedFixed64Element(1, fakeFixed64);
  1666. expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
  1667. }
  1668. });
  1669. it('fail when setting packed fixed64 values with null value', () => {
  1670. const accessor = Kernel.createEmpty();
  1671. const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  1672. if (CHECK_CRITICAL_STATE) {
  1673. expect(() => accessor.setPackedFixed64Iterable(1, [fakeFixed64]))
  1674. .toThrowError('Must be Int64 instance, but got: null');
  1675. } else {
  1676. // Note in unchecked mode we produce invalid output for invalid inputs.
  1677. // This test just documents our behavior in those cases.
  1678. // These values might change at any point and are not considered
  1679. // what the implementation should be doing here.
  1680. accessor.setPackedFixed64Iterable(1, [fakeFixed64]);
  1681. expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
  1682. }
  1683. });
  1684. it('fail when setting single packed fixed64 value with null value', () => {
  1685. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  1686. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  1687. const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  1688. if (CHECK_CRITICAL_STATE) {
  1689. expect(() => accessor.setPackedFixed64Element(1, 0, fakeFixed64))
  1690. .toThrowError('Must be Int64 instance, but got: null');
  1691. } else {
  1692. // Note in unchecked mode we produce invalid output for invalid inputs.
  1693. // This test just documents our behavior in those cases.
  1694. // These values might change at any point and are not considered
  1695. // what the implementation should be doing here.
  1696. accessor.setPackedFixed64Element(1, 0, fakeFixed64);
  1697. expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
  1698. }
  1699. });
  1700. it('fail when setting single unpacked with out-of-bound index', () => {
  1701. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  1702. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  1703. if (CHECK_CRITICAL_STATE) {
  1704. expect(() => accessor.setUnpackedFixed64Element(1, 1, Int64.fromInt(1)))
  1705. .toThrowError('Index out of bounds: index: 1 size: 1');
  1706. } else {
  1707. // Note in unchecked mode we produce invalid output for invalid inputs.
  1708. // This test just documents our behavior in those cases.
  1709. // These values might change at any point and are not considered
  1710. // what the implementation should be doing here.
  1711. accessor.setUnpackedFixed64Element(1, 1, Int64.fromInt(1));
  1712. expectQualifiedIterable(
  1713. accessor.getRepeatedFixed64Iterable(1),
  1714. (value) => value instanceof Int64);
  1715. }
  1716. });
  1717. it('fail when setting single packed with out-of-bound index', () => {
  1718. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  1719. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  1720. if (CHECK_CRITICAL_STATE) {
  1721. expect(() => accessor.setPackedFixed64Element(1, 1, Int64.fromInt(1)))
  1722. .toThrowError('Index out of bounds: index: 1 size: 1');
  1723. } else {
  1724. // Note in unchecked mode we produce invalid output for invalid inputs.
  1725. // This test just documents our behavior in those cases.
  1726. // These values might change at any point and are not considered
  1727. // what the implementation should be doing here.
  1728. accessor.setPackedFixed64Element(1, 1, Int64.fromInt(1));
  1729. expectQualifiedIterable(
  1730. accessor.getRepeatedFixed64Iterable(1),
  1731. (value) => value instanceof Int64);
  1732. }
  1733. });
  1734. it('fail when getting element with out-of-range index', () => {
  1735. const accessor = Kernel.createEmpty();
  1736. if (CHECK_CRITICAL_STATE) {
  1737. expect(() => {
  1738. accessor.getRepeatedFixed64Element(
  1739. /* fieldNumber= */ 1, /* index= */ 0);
  1740. }).toThrowError('Index out of bounds: index: 0 size: 0');
  1741. } else {
  1742. // Note in unchecked mode we produce invalid output for invalid inputs.
  1743. // This test just documents our behavior in those cases.
  1744. // These values might change at any point and are not considered
  1745. // what the implementation should be doing here.
  1746. expect(accessor.getRepeatedFixed64Element(
  1747. /* fieldNumber= */ 1, /* index= */ 0))
  1748. .toBe(undefined);
  1749. }
  1750. });
  1751. });
  1752. describe('Kernel for repeated float does', () => {
  1753. const value1 = 1.6;
  1754. const value1Float = Math.fround(1.6);
  1755. const value2 = 0;
  1756. const unpackedValue1Value2 = createArrayBuffer(
  1757. 0x0D, 0xCD, 0xCC, 0xCC, 0x3F, 0x0D, 0x00, 0x00, 0x00, 0x00);
  1758. const unpackedValue2Value1 = createArrayBuffer(
  1759. 0x0D, 0x00, 0x00, 0x00, 0x00, 0x0D, 0xCD, 0xCC, 0xCC, 0x3F);
  1760. const packedValue1Value2 = createArrayBuffer(
  1761. 0x0A, 0x08, 0xCD, 0xCC, 0xCC, 0x3F, 0x00, 0x00, 0x00, 0x00);
  1762. const packedValue2Value1 = createArrayBuffer(
  1763. 0x0A, 0x08, 0x00, 0x00, 0x00, 0x00, 0xCD, 0xCC, 0xCC, 0x3F);
  1764. it('return empty array for the empty input', () => {
  1765. const accessor = Kernel.createEmpty();
  1766. const list = accessor.getRepeatedFloatIterable(1);
  1767. expectEqualToArray(list, []);
  1768. });
  1769. it('ensure not the same instance returned for the empty input', () => {
  1770. const accessor = Kernel.createEmpty();
  1771. const list1 = accessor.getRepeatedFloatIterable(1);
  1772. const list2 = accessor.getRepeatedFloatIterable(1);
  1773. expect(list1).not.toBe(list2);
  1774. });
  1775. it('return size for the empty input', () => {
  1776. const accessor = Kernel.createEmpty();
  1777. const size = accessor.getRepeatedFloatSize(1);
  1778. expect(size).toEqual(0);
  1779. });
  1780. it('return unpacked values from the input', () => {
  1781. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1782. const list = accessor.getRepeatedFloatIterable(1);
  1783. expectEqualToArray(list, [value1Float, value2]);
  1784. });
  1785. it('ensure not the same instance returned for unpacked values', () => {
  1786. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1787. const list1 = accessor.getRepeatedFloatIterable(1);
  1788. const list2 = accessor.getRepeatedFloatIterable(1);
  1789. expect(list1).not.toBe(list2);
  1790. });
  1791. it('add single unpacked value', () => {
  1792. const accessor = Kernel.createEmpty();
  1793. accessor.addUnpackedFloatElement(1, value1);
  1794. const list1 = accessor.getRepeatedFloatIterable(1);
  1795. accessor.addUnpackedFloatElement(1, value2);
  1796. const list2 = accessor.getRepeatedFloatIterable(1);
  1797. expectEqualToArray(list1, [value1Float]);
  1798. expectEqualToArray(list2, [value1Float, value2]);
  1799. });
  1800. it('add unpacked values', () => {
  1801. const accessor = Kernel.createEmpty();
  1802. accessor.addUnpackedFloatIterable(1, [value1]);
  1803. const list1 = accessor.getRepeatedFloatIterable(1);
  1804. accessor.addUnpackedFloatIterable(1, [value2]);
  1805. const list2 = accessor.getRepeatedFloatIterable(1);
  1806. expectEqualToArray(list1, [value1Float]);
  1807. expectEqualToArray(list2, [value1Float, value2]);
  1808. });
  1809. it('set a single unpacked value', () => {
  1810. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  1811. accessor.setUnpackedFloatElement(1, 1, value1);
  1812. const list = accessor.getRepeatedFloatIterable(1);
  1813. expectEqualToArray(list, [value1Float, value1Float]);
  1814. });
  1815. it('set unpacked values', () => {
  1816. const accessor = Kernel.createEmpty();
  1817. accessor.setUnpackedFloatIterable(1, [value1]);
  1818. const list = accessor.getRepeatedFloatIterable(1);
  1819. expectEqualToArray(list, [value1Float]);
  1820. });
  1821. it('encode for adding single unpacked value', () => {
  1822. const accessor = Kernel.createEmpty();
  1823. accessor.addUnpackedFloatElement(1, value1);
  1824. accessor.addUnpackedFloatElement(1, value2);
  1825. const serialized = accessor.serialize();
  1826. expect(serialized).toEqual(unpackedValue1Value2);
  1827. });
  1828. it('encode for adding unpacked values', () => {
  1829. const accessor = Kernel.createEmpty();
  1830. accessor.addUnpackedFloatIterable(1, [value1]);
  1831. accessor.addUnpackedFloatIterable(1, [value2]);
  1832. const serialized = accessor.serialize();
  1833. expect(serialized).toEqual(unpackedValue1Value2);
  1834. });
  1835. it('encode for setting single unpacked value', () => {
  1836. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1837. accessor.setUnpackedFloatElement(1, 0, value2);
  1838. accessor.setUnpackedFloatElement(1, 1, value1);
  1839. const serialized = accessor.serialize();
  1840. expect(serialized).toEqual(unpackedValue2Value1);
  1841. });
  1842. it('encode for setting unpacked values', () => {
  1843. const accessor = Kernel.createEmpty();
  1844. accessor.setUnpackedFloatIterable(1, [value1, value2]);
  1845. const serialized = accessor.serialize();
  1846. expect(serialized).toEqual(unpackedValue1Value2);
  1847. });
  1848. it('return packed values from the input', () => {
  1849. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  1850. const list = accessor.getRepeatedFloatIterable(1);
  1851. expectEqualToArray(list, [value1Float, value2]);
  1852. });
  1853. it('ensure not the same instance returned for packed values', () => {
  1854. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  1855. const list1 = accessor.getRepeatedFloatIterable(1);
  1856. const list2 = accessor.getRepeatedFloatIterable(1);
  1857. expect(list1).not.toBe(list2);
  1858. });
  1859. it('add single packed value', () => {
  1860. const accessor = Kernel.createEmpty();
  1861. accessor.addPackedFloatElement(1, value1);
  1862. const list1 = accessor.getRepeatedFloatIterable(1);
  1863. accessor.addPackedFloatElement(1, value2);
  1864. const list2 = accessor.getRepeatedFloatIterable(1);
  1865. expectEqualToArray(list1, [value1Float]);
  1866. expectEqualToArray(list2, [value1Float, value2]);
  1867. });
  1868. it('add packed values', () => {
  1869. const accessor = Kernel.createEmpty();
  1870. accessor.addPackedFloatIterable(1, [value1]);
  1871. const list1 = accessor.getRepeatedFloatIterable(1);
  1872. accessor.addPackedFloatIterable(1, [value2]);
  1873. const list2 = accessor.getRepeatedFloatIterable(1);
  1874. expectEqualToArray(list1, [value1Float]);
  1875. expectEqualToArray(list2, [value1Float, value2]);
  1876. });
  1877. it('set a single packed value', () => {
  1878. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1879. accessor.setPackedFloatElement(1, 1, value1);
  1880. const list = accessor.getRepeatedFloatIterable(1);
  1881. expectEqualToArray(list, [value1Float, value1Float]);
  1882. });
  1883. it('set packed values', () => {
  1884. const accessor = Kernel.createEmpty();
  1885. accessor.setPackedFloatIterable(1, [value1]);
  1886. const list1 = accessor.getRepeatedFloatIterable(1);
  1887. accessor.setPackedFloatIterable(1, [value2]);
  1888. const list2 = accessor.getRepeatedFloatIterable(1);
  1889. expectEqualToArray(list1, [value1Float]);
  1890. expectEqualToArray(list2, [value2]);
  1891. });
  1892. it('encode for adding single packed value', () => {
  1893. const accessor = Kernel.createEmpty();
  1894. accessor.addPackedFloatElement(1, value1);
  1895. accessor.addPackedFloatElement(1, value2);
  1896. const serialized = accessor.serialize();
  1897. expect(serialized).toEqual(packedValue1Value2);
  1898. });
  1899. it('encode for adding packed values', () => {
  1900. const accessor = Kernel.createEmpty();
  1901. accessor.addPackedFloatIterable(1, [value1, value2]);
  1902. const serialized = accessor.serialize();
  1903. expect(serialized).toEqual(packedValue1Value2);
  1904. });
  1905. it('encode for setting single packed value', () => {
  1906. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1907. accessor.setPackedFloatElement(1, 0, value2);
  1908. accessor.setPackedFloatElement(1, 1, value1);
  1909. const serialized = accessor.serialize();
  1910. expect(serialized).toEqual(packedValue2Value1);
  1911. });
  1912. it('encode for setting packed values', () => {
  1913. const accessor = Kernel.createEmpty();
  1914. accessor.setPackedFloatIterable(1, [value1, value2]);
  1915. const serialized = accessor.serialize();
  1916. expect(serialized).toEqual(packedValue1Value2);
  1917. });
  1918. it('return combined values from the input', () => {
  1919. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  1920. 0x0D,
  1921. 0xCD,
  1922. 0xCC,
  1923. 0xCC,
  1924. 0x3F, // value1
  1925. 0x0A,
  1926. 0x08, // tag
  1927. 0xCD,
  1928. 0xCC,
  1929. 0xCC,
  1930. 0x3F, // value1
  1931. 0x00,
  1932. 0x00,
  1933. 0x00,
  1934. 0x00, // value2
  1935. 0x0D,
  1936. 0x00,
  1937. 0x00,
  1938. 0x00,
  1939. 0x00, // value2
  1940. ));
  1941. const list = accessor.getRepeatedFloatIterable(1);
  1942. expectEqualToArray(list, [value1Float, value1Float, value2, value2]);
  1943. });
  1944. it('return the repeated field element from the input', () => {
  1945. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1946. const result1 = accessor.getRepeatedFloatElement(
  1947. /* fieldNumber= */ 1, /* index= */ 0);
  1948. const result2 = accessor.getRepeatedFloatElement(
  1949. /* fieldNumber= */ 1, /* index= */ 1);
  1950. expect(result1).toEqual(value1Float);
  1951. expect(result2).toEqual(value2);
  1952. });
  1953. it('return the size from the input', () => {
  1954. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  1955. const size = accessor.getRepeatedFloatSize(1);
  1956. expect(size).toEqual(2);
  1957. });
  1958. it('fail when getting unpacked float value with other wire types', () => {
  1959. const accessor =
  1960. Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
  1961. if (CHECK_CRITICAL_STATE) {
  1962. expect(() => {
  1963. accessor.getRepeatedFloatIterable(1);
  1964. }).toThrowError('Expected wire type: 5 but found: 0');
  1965. } else {
  1966. // Note in unchecked mode we produce invalid output for invalid inputs.
  1967. // This test just documents our behavior in those cases.
  1968. // These values might change at any point and are not considered
  1969. // what the implementation should be doing here.
  1970. expectQualifiedIterable(
  1971. accessor.getRepeatedFloatIterable(1),
  1972. (value) => typeof value === 'number');
  1973. }
  1974. });
  1975. it('fail when adding unpacked float values with null value', () => {
  1976. const accessor = Kernel.createEmpty();
  1977. const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
  1978. if (CHECK_CRITICAL_STATE) {
  1979. expect(() => accessor.addUnpackedFloatIterable(1, [fakeFloat]))
  1980. .toThrowError('Must be a number, but got: null');
  1981. } else {
  1982. // Note in unchecked mode we produce invalid output for invalid inputs.
  1983. // This test just documents our behavior in those cases.
  1984. // These values might change at any point and are not considered
  1985. // what the implementation should be doing here.
  1986. accessor.addUnpackedFloatIterable(1, [fakeFloat]);
  1987. expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
  1988. }
  1989. });
  1990. it('fail when adding single unpacked float value with null value', () => {
  1991. const accessor = Kernel.createEmpty();
  1992. const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
  1993. if (CHECK_CRITICAL_STATE) {
  1994. expect(() => accessor.addUnpackedFloatElement(1, fakeFloat))
  1995. .toThrowError('Must be a number, but got: null');
  1996. } else {
  1997. // Note in unchecked mode we produce invalid output for invalid inputs.
  1998. // This test just documents our behavior in those cases.
  1999. // These values might change at any point and are not considered
  2000. // what the implementation should be doing here.
  2001. accessor.addUnpackedFloatElement(1, fakeFloat);
  2002. expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
  2003. }
  2004. });
  2005. it('fail when setting unpacked float values with null value', () => {
  2006. const accessor = Kernel.createEmpty();
  2007. const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
  2008. if (CHECK_CRITICAL_STATE) {
  2009. expect(() => accessor.setUnpackedFloatIterable(1, [fakeFloat]))
  2010. .toThrowError('Must be a number, but got: null');
  2011. } else {
  2012. // Note in unchecked mode we produce invalid output for invalid inputs.
  2013. // This test just documents our behavior in those cases.
  2014. // These values might change at any point and are not considered
  2015. // what the implementation should be doing here.
  2016. accessor.setUnpackedFloatIterable(1, [fakeFloat]);
  2017. expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
  2018. }
  2019. });
  2020. it('fail when setting single unpacked float value with null value', () => {
  2021. const accessor =
  2022. Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
  2023. const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
  2024. if (CHECK_CRITICAL_STATE) {
  2025. expect(() => accessor.setUnpackedFloatElement(1, 0, fakeFloat))
  2026. .toThrowError('Must be a number, but got: null');
  2027. } else {
  2028. // Note in unchecked mode we produce invalid output for invalid inputs.
  2029. // This test just documents our behavior in those cases.
  2030. // These values might change at any point and are not considered
  2031. // what the implementation should be doing here.
  2032. accessor.setUnpackedFloatElement(1, 0, fakeFloat);
  2033. expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
  2034. }
  2035. });
  2036. it('fail when adding packed float values with null value', () => {
  2037. const accessor = Kernel.createEmpty();
  2038. const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
  2039. if (CHECK_CRITICAL_STATE) {
  2040. expect(() => accessor.addPackedFloatIterable(1, [fakeFloat]))
  2041. .toThrowError('Must be a number, but got: null');
  2042. } else {
  2043. // Note in unchecked mode we produce invalid output for invalid inputs.
  2044. // This test just documents our behavior in those cases.
  2045. // These values might change at any point and are not considered
  2046. // what the implementation should be doing here.
  2047. accessor.addPackedFloatIterable(1, [fakeFloat]);
  2048. expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
  2049. }
  2050. });
  2051. it('fail when adding single packed float value with null value', () => {
  2052. const accessor = Kernel.createEmpty();
  2053. const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
  2054. if (CHECK_CRITICAL_STATE) {
  2055. expect(() => accessor.addPackedFloatElement(1, fakeFloat))
  2056. .toThrowError('Must be a number, but got: null');
  2057. } else {
  2058. // Note in unchecked mode we produce invalid output for invalid inputs.
  2059. // This test just documents our behavior in those cases.
  2060. // These values might change at any point and are not considered
  2061. // what the implementation should be doing here.
  2062. accessor.addPackedFloatElement(1, fakeFloat);
  2063. expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
  2064. }
  2065. });
  2066. it('fail when setting packed float values with null value', () => {
  2067. const accessor = Kernel.createEmpty();
  2068. const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
  2069. if (CHECK_CRITICAL_STATE) {
  2070. expect(() => accessor.setPackedFloatIterable(1, [fakeFloat]))
  2071. .toThrowError('Must be a number, but got: null');
  2072. } else {
  2073. // Note in unchecked mode we produce invalid output for invalid inputs.
  2074. // This test just documents our behavior in those cases.
  2075. // These values might change at any point and are not considered
  2076. // what the implementation should be doing here.
  2077. accessor.setPackedFloatIterable(1, [fakeFloat]);
  2078. expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
  2079. }
  2080. });
  2081. it('fail when setting single packed float value with null value', () => {
  2082. const accessor =
  2083. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
  2084. const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
  2085. if (CHECK_CRITICAL_STATE) {
  2086. expect(() => accessor.setPackedFloatElement(1, 0, fakeFloat))
  2087. .toThrowError('Must be a number, but got: null');
  2088. } else {
  2089. // Note in unchecked mode we produce invalid output for invalid inputs.
  2090. // This test just documents our behavior in those cases.
  2091. // These values might change at any point and are not considered
  2092. // what the implementation should be doing here.
  2093. accessor.setPackedFloatElement(1, 0, fakeFloat);
  2094. expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
  2095. }
  2096. });
  2097. it('fail when setting single unpacked with out-of-bound index', () => {
  2098. const accessor =
  2099. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
  2100. if (CHECK_CRITICAL_STATE) {
  2101. expect(() => accessor.setUnpackedFloatElement(1, 1, 1))
  2102. .toThrowError('Index out of bounds: index: 1 size: 1');
  2103. } else {
  2104. // Note in unchecked mode we produce invalid output for invalid inputs.
  2105. // This test just documents our behavior in those cases.
  2106. // These values might change at any point and are not considered
  2107. // what the implementation should be doing here.
  2108. accessor.setUnpackedFloatElement(1, 1, 1);
  2109. expectQualifiedIterable(
  2110. accessor.getRepeatedFloatIterable(1),
  2111. (value) => typeof value === 'number');
  2112. }
  2113. });
  2114. it('fail when setting single packed with out-of-bound index', () => {
  2115. const accessor =
  2116. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
  2117. if (CHECK_CRITICAL_STATE) {
  2118. expect(() => accessor.setPackedFloatElement(1, 1, 1))
  2119. .toThrowError('Index out of bounds: index: 1 size: 1');
  2120. } else {
  2121. // Note in unchecked mode we produce invalid output for invalid inputs.
  2122. // This test just documents our behavior in those cases.
  2123. // These values might change at any point and are not considered
  2124. // what the implementation should be doing here.
  2125. accessor.setPackedFloatElement(1, 1, 1);
  2126. expectQualifiedIterable(
  2127. accessor.getRepeatedFloatIterable(1),
  2128. (value) => typeof value === 'number');
  2129. }
  2130. });
  2131. it('fail when getting element with out-of-range index', () => {
  2132. const accessor = Kernel.createEmpty();
  2133. if (CHECK_CRITICAL_STATE) {
  2134. expect(() => {
  2135. accessor.getRepeatedFloatElement(
  2136. /* fieldNumber= */ 1, /* index= */ 0);
  2137. }).toThrowError('Index out of bounds: index: 0 size: 0');
  2138. } else {
  2139. // Note in unchecked mode we produce invalid output for invalid inputs.
  2140. // This test just documents our behavior in those cases.
  2141. // These values might change at any point and are not considered
  2142. // what the implementation should be doing here.
  2143. expect(accessor.getRepeatedFloatElement(
  2144. /* fieldNumber= */ 1, /* index= */ 0))
  2145. .toBe(undefined);
  2146. }
  2147. });
  2148. });
  2149. describe('Kernel for repeated int32 does', () => {
  2150. const value1 = 1;
  2151. const value2 = 0;
  2152. const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  2153. const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
  2154. const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  2155. const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
  2156. it('return empty array for the empty input', () => {
  2157. const accessor = Kernel.createEmpty();
  2158. const list = accessor.getRepeatedInt32Iterable(1);
  2159. expectEqualToArray(list, []);
  2160. });
  2161. it('ensure not the same instance returned for the empty input', () => {
  2162. const accessor = Kernel.createEmpty();
  2163. const list1 = accessor.getRepeatedInt32Iterable(1);
  2164. const list2 = accessor.getRepeatedInt32Iterable(1);
  2165. expect(list1).not.toBe(list2);
  2166. });
  2167. it('return size for the empty input', () => {
  2168. const accessor = Kernel.createEmpty();
  2169. const size = accessor.getRepeatedInt32Size(1);
  2170. expect(size).toEqual(0);
  2171. });
  2172. it('return unpacked values from the input', () => {
  2173. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2174. const list = accessor.getRepeatedInt32Iterable(1);
  2175. expectEqualToArray(list, [value1, value2]);
  2176. });
  2177. it('ensure not the same instance returned for unpacked values', () => {
  2178. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2179. const list1 = accessor.getRepeatedInt32Iterable(1);
  2180. const list2 = accessor.getRepeatedInt32Iterable(1);
  2181. expect(list1).not.toBe(list2);
  2182. });
  2183. it('add single unpacked value', () => {
  2184. const accessor = Kernel.createEmpty();
  2185. accessor.addUnpackedInt32Element(1, value1);
  2186. const list1 = accessor.getRepeatedInt32Iterable(1);
  2187. accessor.addUnpackedInt32Element(1, value2);
  2188. const list2 = accessor.getRepeatedInt32Iterable(1);
  2189. expectEqualToArray(list1, [value1]);
  2190. expectEqualToArray(list2, [value1, value2]);
  2191. });
  2192. it('add unpacked values', () => {
  2193. const accessor = Kernel.createEmpty();
  2194. accessor.addUnpackedInt32Iterable(1, [value1]);
  2195. const list1 = accessor.getRepeatedInt32Iterable(1);
  2196. accessor.addUnpackedInt32Iterable(1, [value2]);
  2197. const list2 = accessor.getRepeatedInt32Iterable(1);
  2198. expectEqualToArray(list1, [value1]);
  2199. expectEqualToArray(list2, [value1, value2]);
  2200. });
  2201. it('set a single unpacked value', () => {
  2202. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  2203. accessor.setUnpackedInt32Element(1, 1, value1);
  2204. const list = accessor.getRepeatedInt32Iterable(1);
  2205. expectEqualToArray(list, [value1, value1]);
  2206. });
  2207. it('set unpacked values', () => {
  2208. const accessor = Kernel.createEmpty();
  2209. accessor.setUnpackedInt32Iterable(1, [value1]);
  2210. const list = accessor.getRepeatedInt32Iterable(1);
  2211. expectEqualToArray(list, [value1]);
  2212. });
  2213. it('encode for adding single unpacked value', () => {
  2214. const accessor = Kernel.createEmpty();
  2215. accessor.addUnpackedInt32Element(1, value1);
  2216. accessor.addUnpackedInt32Element(1, value2);
  2217. const serialized = accessor.serialize();
  2218. expect(serialized).toEqual(unpackedValue1Value2);
  2219. });
  2220. it('encode for adding unpacked values', () => {
  2221. const accessor = Kernel.createEmpty();
  2222. accessor.addUnpackedInt32Iterable(1, [value1]);
  2223. accessor.addUnpackedInt32Iterable(1, [value2]);
  2224. const serialized = accessor.serialize();
  2225. expect(serialized).toEqual(unpackedValue1Value2);
  2226. });
  2227. it('encode for setting single unpacked value', () => {
  2228. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2229. accessor.setUnpackedInt32Element(1, 0, value2);
  2230. accessor.setUnpackedInt32Element(1, 1, value1);
  2231. const serialized = accessor.serialize();
  2232. expect(serialized).toEqual(unpackedValue2Value1);
  2233. });
  2234. it('encode for setting unpacked values', () => {
  2235. const accessor = Kernel.createEmpty();
  2236. accessor.setUnpackedInt32Iterable(1, [value1, value2]);
  2237. const serialized = accessor.serialize();
  2238. expect(serialized).toEqual(unpackedValue1Value2);
  2239. });
  2240. it('return packed values from the input', () => {
  2241. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  2242. const list = accessor.getRepeatedInt32Iterable(1);
  2243. expectEqualToArray(list, [value1, value2]);
  2244. });
  2245. it('ensure not the same instance returned for packed values', () => {
  2246. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  2247. const list1 = accessor.getRepeatedInt32Iterable(1);
  2248. const list2 = accessor.getRepeatedInt32Iterable(1);
  2249. expect(list1).not.toBe(list2);
  2250. });
  2251. it('add single packed value', () => {
  2252. const accessor = Kernel.createEmpty();
  2253. accessor.addPackedInt32Element(1, value1);
  2254. const list1 = accessor.getRepeatedInt32Iterable(1);
  2255. accessor.addPackedInt32Element(1, value2);
  2256. const list2 = accessor.getRepeatedInt32Iterable(1);
  2257. expectEqualToArray(list1, [value1]);
  2258. expectEqualToArray(list2, [value1, value2]);
  2259. });
  2260. it('add packed values', () => {
  2261. const accessor = Kernel.createEmpty();
  2262. accessor.addPackedInt32Iterable(1, [value1]);
  2263. const list1 = accessor.getRepeatedInt32Iterable(1);
  2264. accessor.addPackedInt32Iterable(1, [value2]);
  2265. const list2 = accessor.getRepeatedInt32Iterable(1);
  2266. expectEqualToArray(list1, [value1]);
  2267. expectEqualToArray(list2, [value1, value2]);
  2268. });
  2269. it('set a single packed value', () => {
  2270. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2271. accessor.setPackedInt32Element(1, 1, value1);
  2272. const list = accessor.getRepeatedInt32Iterable(1);
  2273. expectEqualToArray(list, [value1, value1]);
  2274. });
  2275. it('set packed values', () => {
  2276. const accessor = Kernel.createEmpty();
  2277. accessor.setPackedInt32Iterable(1, [value1]);
  2278. const list1 = accessor.getRepeatedInt32Iterable(1);
  2279. accessor.setPackedInt32Iterable(1, [value2]);
  2280. const list2 = accessor.getRepeatedInt32Iterable(1);
  2281. expectEqualToArray(list1, [value1]);
  2282. expectEqualToArray(list2, [value2]);
  2283. });
  2284. it('encode for adding single packed value', () => {
  2285. const accessor = Kernel.createEmpty();
  2286. accessor.addPackedInt32Element(1, value1);
  2287. accessor.addPackedInt32Element(1, value2);
  2288. const serialized = accessor.serialize();
  2289. expect(serialized).toEqual(packedValue1Value2);
  2290. });
  2291. it('encode for adding packed values', () => {
  2292. const accessor = Kernel.createEmpty();
  2293. accessor.addPackedInt32Iterable(1, [value1, value2]);
  2294. const serialized = accessor.serialize();
  2295. expect(serialized).toEqual(packedValue1Value2);
  2296. });
  2297. it('encode for setting single packed value', () => {
  2298. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2299. accessor.setPackedInt32Element(1, 0, value2);
  2300. accessor.setPackedInt32Element(1, 1, value1);
  2301. const serialized = accessor.serialize();
  2302. expect(serialized).toEqual(packedValue2Value1);
  2303. });
  2304. it('encode for setting packed values', () => {
  2305. const accessor = Kernel.createEmpty();
  2306. accessor.setPackedInt32Iterable(1, [value1, value2]);
  2307. const serialized = accessor.serialize();
  2308. expect(serialized).toEqual(packedValue1Value2);
  2309. });
  2310. it('return combined values from the input', () => {
  2311. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  2312. 0x08,
  2313. 0x01, // unpacked value1
  2314. 0x0A,
  2315. 0x02,
  2316. 0x01,
  2317. 0x00, // packed value1 and value2
  2318. 0x08,
  2319. 0x00, // unpacked value2
  2320. ));
  2321. const list = accessor.getRepeatedInt32Iterable(1);
  2322. expectEqualToArray(list, [value1, value1, value2, value2]);
  2323. });
  2324. it('return the repeated field element from the input', () => {
  2325. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2326. const result1 = accessor.getRepeatedInt32Element(
  2327. /* fieldNumber= */ 1, /* index= */ 0);
  2328. const result2 = accessor.getRepeatedInt32Element(
  2329. /* fieldNumber= */ 1, /* index= */ 1);
  2330. expect(result1).toEqual(value1);
  2331. expect(result2).toEqual(value2);
  2332. });
  2333. it('return the size from the input', () => {
  2334. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2335. const size = accessor.getRepeatedInt32Size(1);
  2336. expect(size).toEqual(2);
  2337. });
  2338. it('fail when getting unpacked int32 value with other wire types', () => {
  2339. const accessor =
  2340. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  2341. if (CHECK_CRITICAL_STATE) {
  2342. expect(() => {
  2343. accessor.getRepeatedInt32Iterable(1);
  2344. }).toThrowError('Expected wire type: 0 but found: 5');
  2345. } else {
  2346. // Note in unchecked mode we produce invalid output for invalid inputs.
  2347. // This test just documents our behavior in those cases.
  2348. // These values might change at any point and are not considered
  2349. // what the implementation should be doing here.
  2350. expectQualifiedIterable(
  2351. accessor.getRepeatedInt32Iterable(1),
  2352. (value) => Number.isInteger(value));
  2353. }
  2354. });
  2355. it('fail when adding unpacked int32 values with null value', () => {
  2356. const accessor = Kernel.createEmpty();
  2357. const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
  2358. if (CHECK_CRITICAL_STATE) {
  2359. expect(() => accessor.addUnpackedInt32Iterable(1, [fakeInt32]))
  2360. .toThrowError('Must be a number, but got: null');
  2361. } else {
  2362. // Note in unchecked mode we produce invalid output for invalid inputs.
  2363. // This test just documents our behavior in those cases.
  2364. // These values might change at any point and are not considered
  2365. // what the implementation should be doing here.
  2366. accessor.addUnpackedInt32Iterable(1, [fakeInt32]);
  2367. expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
  2368. }
  2369. });
  2370. it('fail when adding single unpacked int32 value with null value', () => {
  2371. const accessor = Kernel.createEmpty();
  2372. const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
  2373. if (CHECK_CRITICAL_STATE) {
  2374. expect(() => accessor.addUnpackedInt32Element(1, fakeInt32))
  2375. .toThrowError('Must be a number, but got: null');
  2376. } else {
  2377. // Note in unchecked mode we produce invalid output for invalid inputs.
  2378. // This test just documents our behavior in those cases.
  2379. // These values might change at any point and are not considered
  2380. // what the implementation should be doing here.
  2381. accessor.addUnpackedInt32Element(1, fakeInt32);
  2382. expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
  2383. }
  2384. });
  2385. it('fail when setting unpacked int32 values with null value', () => {
  2386. const accessor = Kernel.createEmpty();
  2387. const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
  2388. if (CHECK_CRITICAL_STATE) {
  2389. expect(() => accessor.setUnpackedInt32Iterable(1, [fakeInt32]))
  2390. .toThrowError('Must be a number, but got: null');
  2391. } else {
  2392. // Note in unchecked mode we produce invalid output for invalid inputs.
  2393. // This test just documents our behavior in those cases.
  2394. // These values might change at any point and are not considered
  2395. // what the implementation should be doing here.
  2396. accessor.setUnpackedInt32Iterable(1, [fakeInt32]);
  2397. expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
  2398. }
  2399. });
  2400. it('fail when setting single unpacked int32 value with null value', () => {
  2401. const accessor =
  2402. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  2403. const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
  2404. if (CHECK_CRITICAL_STATE) {
  2405. expect(() => accessor.setUnpackedInt32Element(1, 0, fakeInt32))
  2406. .toThrowError('Must be a number, but got: null');
  2407. } else {
  2408. // Note in unchecked mode we produce invalid output for invalid inputs.
  2409. // This test just documents our behavior in those cases.
  2410. // These values might change at any point and are not considered
  2411. // what the implementation should be doing here.
  2412. accessor.setUnpackedInt32Element(1, 0, fakeInt32);
  2413. expectQualifiedIterable(
  2414. accessor.getRepeatedInt32Iterable(1),
  2415. );
  2416. }
  2417. });
  2418. it('fail when adding packed int32 values with null value', () => {
  2419. const accessor = Kernel.createEmpty();
  2420. const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
  2421. if (CHECK_CRITICAL_STATE) {
  2422. expect(() => accessor.addPackedInt32Iterable(1, [fakeInt32]))
  2423. .toThrowError('Must be a number, but got: null');
  2424. } else {
  2425. // Note in unchecked mode we produce invalid output for invalid inputs.
  2426. // This test just documents our behavior in those cases.
  2427. // These values might change at any point and are not considered
  2428. // what the implementation should be doing here.
  2429. accessor.addPackedInt32Iterable(1, [fakeInt32]);
  2430. expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
  2431. }
  2432. });
  2433. it('fail when adding single packed int32 value with null value', () => {
  2434. const accessor = Kernel.createEmpty();
  2435. const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
  2436. if (CHECK_CRITICAL_STATE) {
  2437. expect(() => accessor.addPackedInt32Element(1, fakeInt32))
  2438. .toThrowError('Must be a number, but got: null');
  2439. } else {
  2440. // Note in unchecked mode we produce invalid output for invalid inputs.
  2441. // This test just documents our behavior in those cases.
  2442. // These values might change at any point and are not considered
  2443. // what the implementation should be doing here.
  2444. accessor.addPackedInt32Element(1, fakeInt32);
  2445. expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
  2446. }
  2447. });
  2448. it('fail when setting packed int32 values with null value', () => {
  2449. const accessor = Kernel.createEmpty();
  2450. const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
  2451. if (CHECK_CRITICAL_STATE) {
  2452. expect(() => accessor.setPackedInt32Iterable(1, [fakeInt32]))
  2453. .toThrowError('Must be a number, but got: null');
  2454. } else {
  2455. // Note in unchecked mode we produce invalid output for invalid inputs.
  2456. // This test just documents our behavior in those cases.
  2457. // These values might change at any point and are not considered
  2458. // what the implementation should be doing here.
  2459. accessor.setPackedInt32Iterable(1, [fakeInt32]);
  2460. expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
  2461. }
  2462. });
  2463. it('fail when setting single packed int32 value with null value', () => {
  2464. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  2465. const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
  2466. if (CHECK_CRITICAL_STATE) {
  2467. expect(() => accessor.setPackedInt32Element(1, 0, fakeInt32))
  2468. .toThrowError('Must be a number, but got: null');
  2469. } else {
  2470. // Note in unchecked mode we produce invalid output for invalid inputs.
  2471. // This test just documents our behavior in those cases.
  2472. // These values might change at any point and are not considered
  2473. // what the implementation should be doing here.
  2474. accessor.setPackedInt32Element(1, 0, fakeInt32);
  2475. expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
  2476. }
  2477. });
  2478. it('fail when setting single unpacked with out-of-bound index', () => {
  2479. const accessor =
  2480. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
  2481. if (CHECK_CRITICAL_STATE) {
  2482. expect(() => accessor.setUnpackedInt32Element(1, 1, 1))
  2483. .toThrowError('Index out of bounds: index: 1 size: 1');
  2484. } else {
  2485. // Note in unchecked mode we produce invalid output for invalid inputs.
  2486. // This test just documents our behavior in those cases.
  2487. // These values might change at any point and are not considered
  2488. // what the implementation should be doing here.
  2489. accessor.setUnpackedInt32Element(1, 1, 1);
  2490. expectQualifiedIterable(
  2491. accessor.getRepeatedInt32Iterable(1),
  2492. (value) => Number.isInteger(value));
  2493. }
  2494. });
  2495. it('fail when setting single packed with out-of-bound index', () => {
  2496. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  2497. if (CHECK_CRITICAL_STATE) {
  2498. expect(() => accessor.setPackedInt32Element(1, 1, 1))
  2499. .toThrowError('Index out of bounds: index: 1 size: 1');
  2500. } else {
  2501. // Note in unchecked mode we produce invalid output for invalid inputs.
  2502. // This test just documents our behavior in those cases.
  2503. // These values might change at any point and are not considered
  2504. // what the implementation should be doing here.
  2505. accessor.setPackedInt32Element(1, 1, 1);
  2506. expectQualifiedIterable(
  2507. accessor.getRepeatedInt32Iterable(1),
  2508. (value) => Number.isInteger(value));
  2509. }
  2510. });
  2511. it('fail when getting element with out-of-range index', () => {
  2512. const accessor = Kernel.createEmpty();
  2513. if (CHECK_CRITICAL_STATE) {
  2514. expect(() => {
  2515. accessor.getRepeatedInt32Element(
  2516. /* fieldNumber= */ 1, /* index= */ 0);
  2517. }).toThrowError('Index out of bounds: index: 0 size: 0');
  2518. } else {
  2519. // Note in unchecked mode we produce invalid output for invalid inputs.
  2520. // This test just documents our behavior in those cases.
  2521. // These values might change at any point and are not considered
  2522. // what the implementation should be doing here.
  2523. expect(accessor.getRepeatedInt32Element(
  2524. /* fieldNumber= */ 1, /* index= */ 0))
  2525. .toBe(undefined);
  2526. }
  2527. });
  2528. });
  2529. describe('Kernel for repeated int64 does', () => {
  2530. const value1 = Int64.fromInt(1);
  2531. const value2 = Int64.fromInt(0);
  2532. const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  2533. const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
  2534. const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  2535. const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
  2536. it('return empty array for the empty input', () => {
  2537. const accessor = Kernel.createEmpty();
  2538. const list = accessor.getRepeatedInt64Iterable(1);
  2539. expectEqualToArray(list, []);
  2540. });
  2541. it('ensure not the same instance returned for the empty input', () => {
  2542. const accessor = Kernel.createEmpty();
  2543. const list1 = accessor.getRepeatedInt64Iterable(1);
  2544. const list2 = accessor.getRepeatedInt64Iterable(1);
  2545. expect(list1).not.toBe(list2);
  2546. });
  2547. it('return size for the empty input', () => {
  2548. const accessor = Kernel.createEmpty();
  2549. const size = accessor.getRepeatedInt64Size(1);
  2550. expect(size).toEqual(0);
  2551. });
  2552. it('return unpacked values from the input', () => {
  2553. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2554. const list = accessor.getRepeatedInt64Iterable(1);
  2555. expectEqualToArray(list, [value1, value2]);
  2556. });
  2557. it('ensure not the same instance returned for unpacked values', () => {
  2558. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2559. const list1 = accessor.getRepeatedInt64Iterable(1);
  2560. const list2 = accessor.getRepeatedInt64Iterable(1);
  2561. expect(list1).not.toBe(list2);
  2562. });
  2563. it('add single unpacked value', () => {
  2564. const accessor = Kernel.createEmpty();
  2565. accessor.addUnpackedInt64Element(1, value1);
  2566. const list1 = accessor.getRepeatedInt64Iterable(1);
  2567. accessor.addUnpackedInt64Element(1, value2);
  2568. const list2 = accessor.getRepeatedInt64Iterable(1);
  2569. expectEqualToArray(list1, [value1]);
  2570. expectEqualToArray(list2, [value1, value2]);
  2571. });
  2572. it('add unpacked values', () => {
  2573. const accessor = Kernel.createEmpty();
  2574. accessor.addUnpackedInt64Iterable(1, [value1]);
  2575. const list1 = accessor.getRepeatedInt64Iterable(1);
  2576. accessor.addUnpackedInt64Iterable(1, [value2]);
  2577. const list2 = accessor.getRepeatedInt64Iterable(1);
  2578. expectEqualToArray(list1, [value1]);
  2579. expectEqualToArray(list2, [value1, value2]);
  2580. });
  2581. it('set a single unpacked value', () => {
  2582. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  2583. accessor.setUnpackedInt64Element(1, 1, value1);
  2584. const list = accessor.getRepeatedInt64Iterable(1);
  2585. expectEqualToArray(list, [value1, value1]);
  2586. });
  2587. it('set unpacked values', () => {
  2588. const accessor = Kernel.createEmpty();
  2589. accessor.setUnpackedInt64Iterable(1, [value1]);
  2590. const list = accessor.getRepeatedInt64Iterable(1);
  2591. expectEqualToArray(list, [value1]);
  2592. });
  2593. it('encode for adding single unpacked value', () => {
  2594. const accessor = Kernel.createEmpty();
  2595. accessor.addUnpackedInt64Element(1, value1);
  2596. accessor.addUnpackedInt64Element(1, value2);
  2597. const serialized = accessor.serialize();
  2598. expect(serialized).toEqual(unpackedValue1Value2);
  2599. });
  2600. it('encode for adding unpacked values', () => {
  2601. const accessor = Kernel.createEmpty();
  2602. accessor.addUnpackedInt64Iterable(1, [value1]);
  2603. accessor.addUnpackedInt64Iterable(1, [value2]);
  2604. const serialized = accessor.serialize();
  2605. expect(serialized).toEqual(unpackedValue1Value2);
  2606. });
  2607. it('encode for setting single unpacked value', () => {
  2608. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2609. accessor.setUnpackedInt64Element(1, 0, value2);
  2610. accessor.setUnpackedInt64Element(1, 1, value1);
  2611. const serialized = accessor.serialize();
  2612. expect(serialized).toEqual(unpackedValue2Value1);
  2613. });
  2614. it('encode for setting unpacked values', () => {
  2615. const accessor = Kernel.createEmpty();
  2616. accessor.setUnpackedInt64Iterable(1, [value1, value2]);
  2617. const serialized = accessor.serialize();
  2618. expect(serialized).toEqual(unpackedValue1Value2);
  2619. });
  2620. it('return packed values from the input', () => {
  2621. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  2622. const list = accessor.getRepeatedInt64Iterable(1);
  2623. expectEqualToArray(list, [value1, value2]);
  2624. });
  2625. it('ensure not the same instance returned for packed values', () => {
  2626. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  2627. const list1 = accessor.getRepeatedInt64Iterable(1);
  2628. const list2 = accessor.getRepeatedInt64Iterable(1);
  2629. expect(list1).not.toBe(list2);
  2630. });
  2631. it('add single packed value', () => {
  2632. const accessor = Kernel.createEmpty();
  2633. accessor.addPackedInt64Element(1, value1);
  2634. const list1 = accessor.getRepeatedInt64Iterable(1);
  2635. accessor.addPackedInt64Element(1, value2);
  2636. const list2 = accessor.getRepeatedInt64Iterable(1);
  2637. expectEqualToArray(list1, [value1]);
  2638. expectEqualToArray(list2, [value1, value2]);
  2639. });
  2640. it('add packed values', () => {
  2641. const accessor = Kernel.createEmpty();
  2642. accessor.addPackedInt64Iterable(1, [value1]);
  2643. const list1 = accessor.getRepeatedInt64Iterable(1);
  2644. accessor.addPackedInt64Iterable(1, [value2]);
  2645. const list2 = accessor.getRepeatedInt64Iterable(1);
  2646. expectEqualToArray(list1, [value1]);
  2647. expectEqualToArray(list2, [value1, value2]);
  2648. });
  2649. it('set a single packed value', () => {
  2650. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2651. accessor.setPackedInt64Element(1, 1, value1);
  2652. const list = accessor.getRepeatedInt64Iterable(1);
  2653. expectEqualToArray(list, [value1, value1]);
  2654. });
  2655. it('set packed values', () => {
  2656. const accessor = Kernel.createEmpty();
  2657. accessor.setPackedInt64Iterable(1, [value1]);
  2658. const list1 = accessor.getRepeatedInt64Iterable(1);
  2659. accessor.setPackedInt64Iterable(1, [value2]);
  2660. const list2 = accessor.getRepeatedInt64Iterable(1);
  2661. expectEqualToArray(list1, [value1]);
  2662. expectEqualToArray(list2, [value2]);
  2663. });
  2664. it('encode for adding single packed value', () => {
  2665. const accessor = Kernel.createEmpty();
  2666. accessor.addPackedInt64Element(1, value1);
  2667. accessor.addPackedInt64Element(1, value2);
  2668. const serialized = accessor.serialize();
  2669. expect(serialized).toEqual(packedValue1Value2);
  2670. });
  2671. it('encode for adding packed values', () => {
  2672. const accessor = Kernel.createEmpty();
  2673. accessor.addPackedInt64Iterable(1, [value1, value2]);
  2674. const serialized = accessor.serialize();
  2675. expect(serialized).toEqual(packedValue1Value2);
  2676. });
  2677. it('encode for setting single packed value', () => {
  2678. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2679. accessor.setPackedInt64Element(1, 0, value2);
  2680. accessor.setPackedInt64Element(1, 1, value1);
  2681. const serialized = accessor.serialize();
  2682. expect(serialized).toEqual(packedValue2Value1);
  2683. });
  2684. it('encode for setting packed values', () => {
  2685. const accessor = Kernel.createEmpty();
  2686. accessor.setPackedInt64Iterable(1, [value1, value2]);
  2687. const serialized = accessor.serialize();
  2688. expect(serialized).toEqual(packedValue1Value2);
  2689. });
  2690. it('return combined values from the input', () => {
  2691. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  2692. 0x08,
  2693. 0x01, // unpacked value1
  2694. 0x0A,
  2695. 0x02,
  2696. 0x01,
  2697. 0x00, // packed value1 and value2
  2698. 0x08,
  2699. 0x00, // unpacked value2
  2700. ));
  2701. const list = accessor.getRepeatedInt64Iterable(1);
  2702. expectEqualToArray(list, [value1, value1, value2, value2]);
  2703. });
  2704. it('return the repeated field element from the input', () => {
  2705. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2706. const result1 = accessor.getRepeatedInt64Element(
  2707. /* fieldNumber= */ 1, /* index= */ 0);
  2708. const result2 = accessor.getRepeatedInt64Element(
  2709. /* fieldNumber= */ 1, /* index= */ 1);
  2710. expect(result1).toEqual(value1);
  2711. expect(result2).toEqual(value2);
  2712. });
  2713. it('return the size from the input', () => {
  2714. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2715. const size = accessor.getRepeatedInt64Size(1);
  2716. expect(size).toEqual(2);
  2717. });
  2718. it('fail when getting unpacked int64 value with other wire types', () => {
  2719. const accessor =
  2720. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  2721. if (CHECK_CRITICAL_STATE) {
  2722. expect(() => {
  2723. accessor.getRepeatedInt64Iterable(1);
  2724. }).toThrowError('Expected wire type: 0 but found: 5');
  2725. } else {
  2726. // Note in unchecked mode we produce invalid output for invalid inputs.
  2727. // This test just documents our behavior in those cases.
  2728. // These values might change at any point and are not considered
  2729. // what the implementation should be doing here.
  2730. expectQualifiedIterable(
  2731. accessor.getRepeatedInt64Iterable(1),
  2732. (value) => value instanceof Int64);
  2733. }
  2734. });
  2735. it('fail when adding unpacked int64 values with null value', () => {
  2736. const accessor = Kernel.createEmpty();
  2737. const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  2738. if (CHECK_CRITICAL_STATE) {
  2739. expect(() => accessor.addUnpackedInt64Iterable(1, [fakeInt64]))
  2740. .toThrowError('Must be Int64 instance, but got: null');
  2741. } else {
  2742. // Note in unchecked mode we produce invalid output for invalid inputs.
  2743. // This test just documents our behavior in those cases.
  2744. // These values might change at any point and are not considered
  2745. // what the implementation should be doing here.
  2746. accessor.addUnpackedInt64Iterable(1, [fakeInt64]);
  2747. expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
  2748. }
  2749. });
  2750. it('fail when adding single unpacked int64 value with null value', () => {
  2751. const accessor = Kernel.createEmpty();
  2752. const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  2753. if (CHECK_CRITICAL_STATE) {
  2754. expect(() => accessor.addUnpackedInt64Element(1, fakeInt64))
  2755. .toThrowError('Must be Int64 instance, but got: null');
  2756. } else {
  2757. // Note in unchecked mode we produce invalid output for invalid inputs.
  2758. // This test just documents our behavior in those cases.
  2759. // These values might change at any point and are not considered
  2760. // what the implementation should be doing here.
  2761. accessor.addUnpackedInt64Element(1, fakeInt64);
  2762. expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
  2763. }
  2764. });
  2765. it('fail when setting unpacked int64 values with null value', () => {
  2766. const accessor = Kernel.createEmpty();
  2767. const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  2768. if (CHECK_CRITICAL_STATE) {
  2769. expect(() => accessor.setUnpackedInt64Iterable(1, [fakeInt64]))
  2770. .toThrowError('Must be Int64 instance, but got: null');
  2771. } else {
  2772. // Note in unchecked mode we produce invalid output for invalid inputs.
  2773. // This test just documents our behavior in those cases.
  2774. // These values might change at any point and are not considered
  2775. // what the implementation should be doing here.
  2776. accessor.setUnpackedInt64Iterable(1, [fakeInt64]);
  2777. expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
  2778. }
  2779. });
  2780. it('fail when setting single unpacked int64 value with null value', () => {
  2781. const accessor =
  2782. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  2783. const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  2784. if (CHECK_CRITICAL_STATE) {
  2785. expect(() => accessor.setUnpackedInt64Element(1, 0, fakeInt64))
  2786. .toThrowError('Must be Int64 instance, but got: null');
  2787. } else {
  2788. // Note in unchecked mode we produce invalid output for invalid inputs.
  2789. // This test just documents our behavior in those cases.
  2790. // These values might change at any point and are not considered
  2791. // what the implementation should be doing here.
  2792. accessor.setUnpackedInt64Element(1, 0, fakeInt64);
  2793. expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
  2794. }
  2795. });
  2796. it('fail when adding packed int64 values with null value', () => {
  2797. const accessor = Kernel.createEmpty();
  2798. const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  2799. if (CHECK_CRITICAL_STATE) {
  2800. expect(() => accessor.addPackedInt64Iterable(1, [fakeInt64]))
  2801. .toThrowError('Must be Int64 instance, but got: null');
  2802. } else {
  2803. // Note in unchecked mode we produce invalid output for invalid inputs.
  2804. // This test just documents our behavior in those cases.
  2805. // These values might change at any point and are not considered
  2806. // what the implementation should be doing here.
  2807. accessor.addPackedInt64Iterable(1, [fakeInt64]);
  2808. expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
  2809. }
  2810. });
  2811. it('fail when adding single packed int64 value with null value', () => {
  2812. const accessor = Kernel.createEmpty();
  2813. const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  2814. if (CHECK_CRITICAL_STATE) {
  2815. expect(() => accessor.addPackedInt64Element(1, fakeInt64))
  2816. .toThrowError('Must be Int64 instance, but got: null');
  2817. } else {
  2818. // Note in unchecked mode we produce invalid output for invalid inputs.
  2819. // This test just documents our behavior in those cases.
  2820. // These values might change at any point and are not considered
  2821. // what the implementation should be doing here.
  2822. accessor.addPackedInt64Element(1, fakeInt64);
  2823. expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
  2824. }
  2825. });
  2826. it('fail when setting packed int64 values with null value', () => {
  2827. const accessor = Kernel.createEmpty();
  2828. const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  2829. if (CHECK_CRITICAL_STATE) {
  2830. expect(() => accessor.setPackedInt64Iterable(1, [fakeInt64]))
  2831. .toThrowError('Must be Int64 instance, but got: null');
  2832. } else {
  2833. // Note in unchecked mode we produce invalid output for invalid inputs.
  2834. // This test just documents our behavior in those cases.
  2835. // These values might change at any point and are not considered
  2836. // what the implementation should be doing here.
  2837. accessor.setPackedInt64Iterable(1, [fakeInt64]);
  2838. expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
  2839. }
  2840. });
  2841. it('fail when setting single packed int64 value with null value', () => {
  2842. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  2843. const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  2844. if (CHECK_CRITICAL_STATE) {
  2845. expect(() => accessor.setPackedInt64Element(1, 0, fakeInt64))
  2846. .toThrowError('Must be Int64 instance, but got: null');
  2847. } else {
  2848. // Note in unchecked mode we produce invalid output for invalid inputs.
  2849. // This test just documents our behavior in those cases.
  2850. // These values might change at any point and are not considered
  2851. // what the implementation should be doing here.
  2852. accessor.setPackedInt64Element(1, 0, fakeInt64);
  2853. expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
  2854. }
  2855. });
  2856. it('fail when setting single unpacked with out-of-bound index', () => {
  2857. const accessor =
  2858. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
  2859. if (CHECK_CRITICAL_STATE) {
  2860. expect(() => accessor.setUnpackedInt64Element(1, 1, Int64.fromInt(1)))
  2861. .toThrowError('Index out of bounds: index: 1 size: 1');
  2862. } else {
  2863. // Note in unchecked mode we produce invalid output for invalid inputs.
  2864. // This test just documents our behavior in those cases.
  2865. // These values might change at any point and are not considered
  2866. // what the implementation should be doing here.
  2867. accessor.setUnpackedInt64Element(1, 1, Int64.fromInt(1));
  2868. expectQualifiedIterable(
  2869. accessor.getRepeatedInt64Iterable(1),
  2870. (value) => value instanceof Int64);
  2871. }
  2872. });
  2873. it('fail when setting single packed with out-of-bound index', () => {
  2874. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  2875. if (CHECK_CRITICAL_STATE) {
  2876. expect(() => accessor.setPackedInt64Element(1, 1, Int64.fromInt(1)))
  2877. .toThrowError('Index out of bounds: index: 1 size: 1');
  2878. } else {
  2879. // Note in unchecked mode we produce invalid output for invalid inputs.
  2880. // This test just documents our behavior in those cases.
  2881. // These values might change at any point and are not considered
  2882. // what the implementation should be doing here.
  2883. accessor.setPackedInt64Element(1, 1, Int64.fromInt(1));
  2884. expectQualifiedIterable(
  2885. accessor.getRepeatedInt64Iterable(1),
  2886. (value) => value instanceof Int64);
  2887. }
  2888. });
  2889. it('fail when getting element with out-of-range index', () => {
  2890. const accessor = Kernel.createEmpty();
  2891. if (CHECK_CRITICAL_STATE) {
  2892. expect(() => {
  2893. accessor.getRepeatedInt64Element(
  2894. /* fieldNumber= */ 1, /* index= */ 0);
  2895. }).toThrowError('Index out of bounds: index: 0 size: 0');
  2896. } else {
  2897. // Note in unchecked mode we produce invalid output for invalid inputs.
  2898. // This test just documents our behavior in those cases.
  2899. // These values might change at any point and are not considered
  2900. // what the implementation should be doing here.
  2901. expect(accessor.getRepeatedInt64Element(
  2902. /* fieldNumber= */ 1, /* index= */ 0))
  2903. .toBe(undefined);
  2904. }
  2905. });
  2906. });
  2907. describe('Kernel for repeated sfixed32 does', () => {
  2908. const value1 = 1;
  2909. const value2 = 0;
  2910. const unpackedValue1Value2 = createArrayBuffer(
  2911. 0x0D, 0x01, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00);
  2912. const unpackedValue2Value1 = createArrayBuffer(
  2913. 0x0D, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x01, 0x00, 0x00, 0x00);
  2914. const packedValue1Value2 = createArrayBuffer(
  2915. 0x0A, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
  2916. const packedValue2Value1 = createArrayBuffer(
  2917. 0x0A, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00);
  2918. it('return empty array for the empty input', () => {
  2919. const accessor = Kernel.createEmpty();
  2920. const list = accessor.getRepeatedSfixed32Iterable(1);
  2921. expectEqualToArray(list, []);
  2922. });
  2923. it('ensure not the same instance returned for the empty input', () => {
  2924. const accessor = Kernel.createEmpty();
  2925. const list1 = accessor.getRepeatedSfixed32Iterable(1);
  2926. const list2 = accessor.getRepeatedSfixed32Iterable(1);
  2927. expect(list1).not.toBe(list2);
  2928. });
  2929. it('return size for the empty input', () => {
  2930. const accessor = Kernel.createEmpty();
  2931. const size = accessor.getRepeatedSfixed32Size(1);
  2932. expect(size).toEqual(0);
  2933. });
  2934. it('return unpacked values from the input', () => {
  2935. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2936. const list = accessor.getRepeatedSfixed32Iterable(1);
  2937. expectEqualToArray(list, [value1, value2]);
  2938. });
  2939. it('ensure not the same instance returned for unpacked values', () => {
  2940. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2941. const list1 = accessor.getRepeatedSfixed32Iterable(1);
  2942. const list2 = accessor.getRepeatedSfixed32Iterable(1);
  2943. expect(list1).not.toBe(list2);
  2944. });
  2945. it('add single unpacked value', () => {
  2946. const accessor = Kernel.createEmpty();
  2947. accessor.addUnpackedSfixed32Element(1, value1);
  2948. const list1 = accessor.getRepeatedSfixed32Iterable(1);
  2949. accessor.addUnpackedSfixed32Element(1, value2);
  2950. const list2 = accessor.getRepeatedSfixed32Iterable(1);
  2951. expectEqualToArray(list1, [value1]);
  2952. expectEqualToArray(list2, [value1, value2]);
  2953. });
  2954. it('add unpacked values', () => {
  2955. const accessor = Kernel.createEmpty();
  2956. accessor.addUnpackedSfixed32Iterable(1, [value1]);
  2957. const list1 = accessor.getRepeatedSfixed32Iterable(1);
  2958. accessor.addUnpackedSfixed32Iterable(1, [value2]);
  2959. const list2 = accessor.getRepeatedSfixed32Iterable(1);
  2960. expectEqualToArray(list1, [value1]);
  2961. expectEqualToArray(list2, [value1, value2]);
  2962. });
  2963. it('set a single unpacked value', () => {
  2964. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  2965. accessor.setUnpackedSfixed32Element(1, 1, value1);
  2966. const list = accessor.getRepeatedSfixed32Iterable(1);
  2967. expectEqualToArray(list, [value1, value1]);
  2968. });
  2969. it('set unpacked values', () => {
  2970. const accessor = Kernel.createEmpty();
  2971. accessor.setUnpackedSfixed32Iterable(1, [value1]);
  2972. const list = accessor.getRepeatedSfixed32Iterable(1);
  2973. expectEqualToArray(list, [value1]);
  2974. });
  2975. it('encode for adding single unpacked value', () => {
  2976. const accessor = Kernel.createEmpty();
  2977. accessor.addUnpackedSfixed32Element(1, value1);
  2978. accessor.addUnpackedSfixed32Element(1, value2);
  2979. const serialized = accessor.serialize();
  2980. expect(serialized).toEqual(unpackedValue1Value2);
  2981. });
  2982. it('encode for adding unpacked values', () => {
  2983. const accessor = Kernel.createEmpty();
  2984. accessor.addUnpackedSfixed32Iterable(1, [value1]);
  2985. accessor.addUnpackedSfixed32Iterable(1, [value2]);
  2986. const serialized = accessor.serialize();
  2987. expect(serialized).toEqual(unpackedValue1Value2);
  2988. });
  2989. it('encode for setting single unpacked value', () => {
  2990. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  2991. accessor.setUnpackedSfixed32Element(1, 0, value2);
  2992. accessor.setUnpackedSfixed32Element(1, 1, value1);
  2993. const serialized = accessor.serialize();
  2994. expect(serialized).toEqual(unpackedValue2Value1);
  2995. });
  2996. it('encode for setting unpacked values', () => {
  2997. const accessor = Kernel.createEmpty();
  2998. accessor.setUnpackedSfixed32Iterable(1, [value1, value2]);
  2999. const serialized = accessor.serialize();
  3000. expect(serialized).toEqual(unpackedValue1Value2);
  3001. });
  3002. it('return packed values from the input', () => {
  3003. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  3004. const list = accessor.getRepeatedSfixed32Iterable(1);
  3005. expectEqualToArray(list, [value1, value2]);
  3006. });
  3007. it('ensure not the same instance returned for packed values', () => {
  3008. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  3009. const list1 = accessor.getRepeatedSfixed32Iterable(1);
  3010. const list2 = accessor.getRepeatedSfixed32Iterable(1);
  3011. expect(list1).not.toBe(list2);
  3012. });
  3013. it('add single packed value', () => {
  3014. const accessor = Kernel.createEmpty();
  3015. accessor.addPackedSfixed32Element(1, value1);
  3016. const list1 = accessor.getRepeatedSfixed32Iterable(1);
  3017. accessor.addPackedSfixed32Element(1, value2);
  3018. const list2 = accessor.getRepeatedSfixed32Iterable(1);
  3019. expectEqualToArray(list1, [value1]);
  3020. expectEqualToArray(list2, [value1, value2]);
  3021. });
  3022. it('add packed values', () => {
  3023. const accessor = Kernel.createEmpty();
  3024. accessor.addPackedSfixed32Iterable(1, [value1]);
  3025. const list1 = accessor.getRepeatedSfixed32Iterable(1);
  3026. accessor.addPackedSfixed32Iterable(1, [value2]);
  3027. const list2 = accessor.getRepeatedSfixed32Iterable(1);
  3028. expectEqualToArray(list1, [value1]);
  3029. expectEqualToArray(list2, [value1, value2]);
  3030. });
  3031. it('set a single packed value', () => {
  3032. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3033. accessor.setPackedSfixed32Element(1, 1, value1);
  3034. const list = accessor.getRepeatedSfixed32Iterable(1);
  3035. expectEqualToArray(list, [value1, value1]);
  3036. });
  3037. it('set packed values', () => {
  3038. const accessor = Kernel.createEmpty();
  3039. accessor.setPackedSfixed32Iterable(1, [value1]);
  3040. const list1 = accessor.getRepeatedSfixed32Iterable(1);
  3041. accessor.setPackedSfixed32Iterable(1, [value2]);
  3042. const list2 = accessor.getRepeatedSfixed32Iterable(1);
  3043. expectEqualToArray(list1, [value1]);
  3044. expectEqualToArray(list2, [value2]);
  3045. });
  3046. it('encode for adding single packed value', () => {
  3047. const accessor = Kernel.createEmpty();
  3048. accessor.addPackedSfixed32Element(1, value1);
  3049. accessor.addPackedSfixed32Element(1, value2);
  3050. const serialized = accessor.serialize();
  3051. expect(serialized).toEqual(packedValue1Value2);
  3052. });
  3053. it('encode for adding packed values', () => {
  3054. const accessor = Kernel.createEmpty();
  3055. accessor.addPackedSfixed32Iterable(1, [value1, value2]);
  3056. const serialized = accessor.serialize();
  3057. expect(serialized).toEqual(packedValue1Value2);
  3058. });
  3059. it('encode for setting single packed value', () => {
  3060. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3061. accessor.setPackedSfixed32Element(1, 0, value2);
  3062. accessor.setPackedSfixed32Element(1, 1, value1);
  3063. const serialized = accessor.serialize();
  3064. expect(serialized).toEqual(packedValue2Value1);
  3065. });
  3066. it('encode for setting packed values', () => {
  3067. const accessor = Kernel.createEmpty();
  3068. accessor.setPackedSfixed32Iterable(1, [value1, value2]);
  3069. const serialized = accessor.serialize();
  3070. expect(serialized).toEqual(packedValue1Value2);
  3071. });
  3072. it('return combined values from the input', () => {
  3073. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  3074. 0x0D,
  3075. 0x01,
  3076. 0x00,
  3077. 0x00,
  3078. 0x00, // value1
  3079. 0x0A,
  3080. 0x08, // tag
  3081. 0x01,
  3082. 0x00,
  3083. 0x00,
  3084. 0x00, // value1
  3085. 0x00,
  3086. 0x00,
  3087. 0x00,
  3088. 0x00, // value2
  3089. 0x0D,
  3090. 0x00,
  3091. 0x00,
  3092. 0x00,
  3093. 0x00, // value2
  3094. ));
  3095. const list = accessor.getRepeatedSfixed32Iterable(1);
  3096. expectEqualToArray(list, [value1, value1, value2, value2]);
  3097. });
  3098. it('return the repeated field element from the input', () => {
  3099. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3100. const result1 = accessor.getRepeatedSfixed32Element(
  3101. /* fieldNumber= */ 1, /* index= */ 0);
  3102. const result2 = accessor.getRepeatedSfixed32Element(
  3103. /* fieldNumber= */ 1, /* index= */ 1);
  3104. expect(result1).toEqual(value1);
  3105. expect(result2).toEqual(value2);
  3106. });
  3107. it('return the size from the input', () => {
  3108. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3109. const size = accessor.getRepeatedSfixed32Size(1);
  3110. expect(size).toEqual(2);
  3111. });
  3112. it('fail when getting unpacked sfixed32 value with other wire types', () => {
  3113. const accessor =
  3114. Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
  3115. if (CHECK_CRITICAL_STATE) {
  3116. expect(() => {
  3117. accessor.getRepeatedSfixed32Iterable(1);
  3118. }).toThrowError('Expected wire type: 5 but found: 0');
  3119. } else {
  3120. // Note in unchecked mode we produce invalid output for invalid inputs.
  3121. // This test just documents our behavior in those cases.
  3122. // These values might change at any point and are not considered
  3123. // what the implementation should be doing here.
  3124. expectQualifiedIterable(
  3125. accessor.getRepeatedSfixed32Iterable(1),
  3126. (value) => typeof value === 'number');
  3127. }
  3128. });
  3129. it('fail when adding unpacked sfixed32 values with null value', () => {
  3130. const accessor = Kernel.createEmpty();
  3131. const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
  3132. if (CHECK_CRITICAL_STATE) {
  3133. expect(() => accessor.addUnpackedSfixed32Iterable(1, [fakeSfixed32]))
  3134. .toThrowError('Must be a number, but got: null');
  3135. } else {
  3136. // Note in unchecked mode we produce invalid output for invalid inputs.
  3137. // This test just documents our behavior in those cases.
  3138. // These values might change at any point and are not considered
  3139. // what the implementation should be doing here.
  3140. accessor.addUnpackedSfixed32Iterable(1, [fakeSfixed32]);
  3141. expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
  3142. }
  3143. });
  3144. it('fail when adding single unpacked sfixed32 value with null value', () => {
  3145. const accessor = Kernel.createEmpty();
  3146. const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
  3147. if (CHECK_CRITICAL_STATE) {
  3148. expect(() => accessor.addUnpackedSfixed32Element(1, fakeSfixed32))
  3149. .toThrowError('Must be a number, but got: null');
  3150. } else {
  3151. // Note in unchecked mode we produce invalid output for invalid inputs.
  3152. // This test just documents our behavior in those cases.
  3153. // These values might change at any point and are not considered
  3154. // what the implementation should be doing here.
  3155. accessor.addUnpackedSfixed32Element(1, fakeSfixed32);
  3156. expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
  3157. }
  3158. });
  3159. it('fail when setting unpacked sfixed32 values with null value', () => {
  3160. const accessor = Kernel.createEmpty();
  3161. const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
  3162. if (CHECK_CRITICAL_STATE) {
  3163. expect(() => accessor.setUnpackedSfixed32Iterable(1, [fakeSfixed32]))
  3164. .toThrowError('Must be a number, but got: null');
  3165. } else {
  3166. // Note in unchecked mode we produce invalid output for invalid inputs.
  3167. // This test just documents our behavior in those cases.
  3168. // These values might change at any point and are not considered
  3169. // what the implementation should be doing here.
  3170. accessor.setUnpackedSfixed32Iterable(1, [fakeSfixed32]);
  3171. expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
  3172. }
  3173. });
  3174. it('fail when setting single unpacked sfixed32 value with null value', () => {
  3175. const accessor =
  3176. Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
  3177. const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
  3178. if (CHECK_CRITICAL_STATE) {
  3179. expect(() => accessor.setUnpackedSfixed32Element(1, 0, fakeSfixed32))
  3180. .toThrowError('Must be a number, but got: null');
  3181. } else {
  3182. // Note in unchecked mode we produce invalid output for invalid inputs.
  3183. // This test just documents our behavior in those cases.
  3184. // These values might change at any point and are not considered
  3185. // what the implementation should be doing here.
  3186. accessor.setUnpackedSfixed32Element(1, 0, fakeSfixed32);
  3187. expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
  3188. }
  3189. });
  3190. it('fail when adding packed sfixed32 values with null value', () => {
  3191. const accessor = Kernel.createEmpty();
  3192. const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
  3193. if (CHECK_CRITICAL_STATE) {
  3194. expect(() => accessor.addPackedSfixed32Iterable(1, [fakeSfixed32]))
  3195. .toThrowError('Must be a number, but got: null');
  3196. } else {
  3197. // Note in unchecked mode we produce invalid output for invalid inputs.
  3198. // This test just documents our behavior in those cases.
  3199. // These values might change at any point and are not considered
  3200. // what the implementation should be doing here.
  3201. accessor.addPackedSfixed32Iterable(1, [fakeSfixed32]);
  3202. expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
  3203. }
  3204. });
  3205. it('fail when adding single packed sfixed32 value with null value', () => {
  3206. const accessor = Kernel.createEmpty();
  3207. const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
  3208. if (CHECK_CRITICAL_STATE) {
  3209. expect(() => accessor.addPackedSfixed32Element(1, fakeSfixed32))
  3210. .toThrowError('Must be a number, but got: null');
  3211. } else {
  3212. // Note in unchecked mode we produce invalid output for invalid inputs.
  3213. // This test just documents our behavior in those cases.
  3214. // These values might change at any point and are not considered
  3215. // what the implementation should be doing here.
  3216. accessor.addPackedSfixed32Element(1, fakeSfixed32);
  3217. expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
  3218. }
  3219. });
  3220. it('fail when setting packed sfixed32 values with null value', () => {
  3221. const accessor = Kernel.createEmpty();
  3222. const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
  3223. if (CHECK_CRITICAL_STATE) {
  3224. expect(() => accessor.setPackedSfixed32Iterable(1, [fakeSfixed32]))
  3225. .toThrowError('Must be a number, but got: null');
  3226. } else {
  3227. // Note in unchecked mode we produce invalid output for invalid inputs.
  3228. // This test just documents our behavior in those cases.
  3229. // These values might change at any point and are not considered
  3230. // what the implementation should be doing here.
  3231. accessor.setPackedSfixed32Iterable(1, [fakeSfixed32]);
  3232. expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
  3233. }
  3234. });
  3235. it('fail when setting single packed sfixed32 value with null value', () => {
  3236. const accessor =
  3237. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
  3238. const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
  3239. if (CHECK_CRITICAL_STATE) {
  3240. expect(() => accessor.setPackedSfixed32Element(1, 0, fakeSfixed32))
  3241. .toThrowError('Must be a number, but got: null');
  3242. } else {
  3243. // Note in unchecked mode we produce invalid output for invalid inputs.
  3244. // This test just documents our behavior in those cases.
  3245. // These values might change at any point and are not considered
  3246. // what the implementation should be doing here.
  3247. accessor.setPackedSfixed32Element(1, 0, fakeSfixed32);
  3248. expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
  3249. }
  3250. });
  3251. it('fail when setting single unpacked with out-of-bound index', () => {
  3252. const accessor =
  3253. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
  3254. if (CHECK_CRITICAL_STATE) {
  3255. expect(() => accessor.setUnpackedSfixed32Element(1, 1, 1))
  3256. .toThrowError('Index out of bounds: index: 1 size: 1');
  3257. } else {
  3258. // Note in unchecked mode we produce invalid output for invalid inputs.
  3259. // This test just documents our behavior in those cases.
  3260. // These values might change at any point and are not considered
  3261. // what the implementation should be doing here.
  3262. accessor.setUnpackedSfixed32Element(1, 1, 1);
  3263. expectQualifiedIterable(
  3264. accessor.getRepeatedSfixed32Iterable(1),
  3265. (value) => typeof value === 'number');
  3266. }
  3267. });
  3268. it('fail when setting single packed with out-of-bound index', () => {
  3269. const accessor =
  3270. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
  3271. if (CHECK_CRITICAL_STATE) {
  3272. expect(() => accessor.setPackedSfixed32Element(1, 1, 1))
  3273. .toThrowError('Index out of bounds: index: 1 size: 1');
  3274. } else {
  3275. // Note in unchecked mode we produce invalid output for invalid inputs.
  3276. // This test just documents our behavior in those cases.
  3277. // These values might change at any point and are not considered
  3278. // what the implementation should be doing here.
  3279. accessor.setPackedSfixed32Element(1, 1, 1);
  3280. expectQualifiedIterable(
  3281. accessor.getRepeatedSfixed32Iterable(1),
  3282. (value) => typeof value === 'number');
  3283. }
  3284. });
  3285. it('fail when getting element with out-of-range index', () => {
  3286. const accessor = Kernel.createEmpty();
  3287. if (CHECK_CRITICAL_STATE) {
  3288. expect(() => {
  3289. accessor.getRepeatedSfixed32Element(
  3290. /* fieldNumber= */ 1, /* index= */ 0);
  3291. }).toThrowError('Index out of bounds: index: 0 size: 0');
  3292. } else {
  3293. // Note in unchecked mode we produce invalid output for invalid inputs.
  3294. // This test just documents our behavior in those cases.
  3295. // These values might change at any point and are not considered
  3296. // what the implementation should be doing here.
  3297. expect(accessor.getRepeatedSfixed32Element(
  3298. /* fieldNumber= */ 1, /* index= */ 0))
  3299. .toBe(undefined);
  3300. }
  3301. });
  3302. });
  3303. describe('Kernel for repeated sfixed64 does', () => {
  3304. const value1 = Int64.fromInt(1);
  3305. const value2 = Int64.fromInt(0);
  3306. const unpackedValue1Value2 = createArrayBuffer(
  3307. 0x09,
  3308. 0x01,
  3309. 0x00,
  3310. 0x00,
  3311. 0x00,
  3312. 0x00,
  3313. 0x00,
  3314. 0x00,
  3315. 0x00, // value1
  3316. 0x09,
  3317. 0x00,
  3318. 0x00,
  3319. 0x00,
  3320. 0x00,
  3321. 0x00,
  3322. 0x00,
  3323. 0x00,
  3324. 0x00, // value2
  3325. );
  3326. const unpackedValue2Value1 = createArrayBuffer(
  3327. 0x09,
  3328. 0x00,
  3329. 0x00,
  3330. 0x00,
  3331. 0x00,
  3332. 0x00,
  3333. 0x00,
  3334. 0x00,
  3335. 0x00, // value1
  3336. 0x09,
  3337. 0x01,
  3338. 0x00,
  3339. 0x00,
  3340. 0x00,
  3341. 0x00,
  3342. 0x00,
  3343. 0x00,
  3344. 0x00, // value2
  3345. );
  3346. const packedValue1Value2 = createArrayBuffer(
  3347. 0x0A,
  3348. 0x10, // tag
  3349. 0x01,
  3350. 0x00,
  3351. 0x00,
  3352. 0x00,
  3353. 0x00,
  3354. 0x00,
  3355. 0x00,
  3356. 0x00, // value1
  3357. 0x00,
  3358. 0x00,
  3359. 0x00,
  3360. 0x00,
  3361. 0x00,
  3362. 0x00,
  3363. 0x00,
  3364. 0x00, // value2
  3365. );
  3366. const packedValue2Value1 = createArrayBuffer(
  3367. 0x0A,
  3368. 0x10, // tag
  3369. 0x00,
  3370. 0x00,
  3371. 0x00,
  3372. 0x00,
  3373. 0x00,
  3374. 0x00,
  3375. 0x00,
  3376. 0x00, // value2
  3377. 0x01,
  3378. 0x00,
  3379. 0x00,
  3380. 0x00,
  3381. 0x00,
  3382. 0x00,
  3383. 0x00,
  3384. 0x00, // value1
  3385. );
  3386. it('return empty array for the empty input', () => {
  3387. const accessor = Kernel.createEmpty();
  3388. const list = accessor.getRepeatedSfixed64Iterable(1);
  3389. expectEqualToArray(list, []);
  3390. });
  3391. it('ensure not the same instance returned for the empty input', () => {
  3392. const accessor = Kernel.createEmpty();
  3393. const list1 = accessor.getRepeatedSfixed64Iterable(1);
  3394. const list2 = accessor.getRepeatedSfixed64Iterable(1);
  3395. expect(list1).not.toBe(list2);
  3396. });
  3397. it('return size for the empty input', () => {
  3398. const accessor = Kernel.createEmpty();
  3399. const size = accessor.getRepeatedSfixed64Size(1);
  3400. expect(size).toEqual(0);
  3401. });
  3402. it('return unpacked values from the input', () => {
  3403. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3404. const list = accessor.getRepeatedSfixed64Iterable(1);
  3405. expectEqualToArray(list, [value1, value2]);
  3406. });
  3407. it('ensure not the same instance returned for unpacked values', () => {
  3408. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3409. const list1 = accessor.getRepeatedSfixed64Iterable(1);
  3410. const list2 = accessor.getRepeatedSfixed64Iterable(1);
  3411. expect(list1).not.toBe(list2);
  3412. });
  3413. it('add single unpacked value', () => {
  3414. const accessor = Kernel.createEmpty();
  3415. accessor.addUnpackedSfixed64Element(1, value1);
  3416. const list1 = accessor.getRepeatedSfixed64Iterable(1);
  3417. accessor.addUnpackedSfixed64Element(1, value2);
  3418. const list2 = accessor.getRepeatedSfixed64Iterable(1);
  3419. expectEqualToArray(list1, [value1]);
  3420. expectEqualToArray(list2, [value1, value2]);
  3421. });
  3422. it('add unpacked values', () => {
  3423. const accessor = Kernel.createEmpty();
  3424. accessor.addUnpackedSfixed64Iterable(1, [value1]);
  3425. const list1 = accessor.getRepeatedSfixed64Iterable(1);
  3426. accessor.addUnpackedSfixed64Iterable(1, [value2]);
  3427. const list2 = accessor.getRepeatedSfixed64Iterable(1);
  3428. expectEqualToArray(list1, [value1]);
  3429. expectEqualToArray(list2, [value1, value2]);
  3430. });
  3431. it('set a single unpacked value', () => {
  3432. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  3433. accessor.setUnpackedSfixed64Element(1, 1, value1);
  3434. const list = accessor.getRepeatedSfixed64Iterable(1);
  3435. expectEqualToArray(list, [value1, value1]);
  3436. });
  3437. it('set unpacked values', () => {
  3438. const accessor = Kernel.createEmpty();
  3439. accessor.setUnpackedSfixed64Iterable(1, [value1]);
  3440. const list = accessor.getRepeatedSfixed64Iterable(1);
  3441. expectEqualToArray(list, [value1]);
  3442. });
  3443. it('encode for adding single unpacked value', () => {
  3444. const accessor = Kernel.createEmpty();
  3445. accessor.addUnpackedSfixed64Element(1, value1);
  3446. accessor.addUnpackedSfixed64Element(1, value2);
  3447. const serialized = accessor.serialize();
  3448. expect(serialized).toEqual(unpackedValue1Value2);
  3449. });
  3450. it('encode for adding unpacked values', () => {
  3451. const accessor = Kernel.createEmpty();
  3452. accessor.addUnpackedSfixed64Iterable(1, [value1]);
  3453. accessor.addUnpackedSfixed64Iterable(1, [value2]);
  3454. const serialized = accessor.serialize();
  3455. expect(serialized).toEqual(unpackedValue1Value2);
  3456. });
  3457. it('encode for setting single unpacked value', () => {
  3458. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3459. accessor.setUnpackedSfixed64Element(1, 0, value2);
  3460. accessor.setUnpackedSfixed64Element(1, 1, value1);
  3461. const serialized = accessor.serialize();
  3462. expect(serialized).toEqual(unpackedValue2Value1);
  3463. });
  3464. it('encode for setting unpacked values', () => {
  3465. const accessor = Kernel.createEmpty();
  3466. accessor.setUnpackedSfixed64Iterable(1, [value1, value2]);
  3467. const serialized = accessor.serialize();
  3468. expect(serialized).toEqual(unpackedValue1Value2);
  3469. });
  3470. it('return packed values from the input', () => {
  3471. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  3472. const list = accessor.getRepeatedSfixed64Iterable(1);
  3473. expectEqualToArray(list, [value1, value2]);
  3474. });
  3475. it('ensure not the same instance returned for packed values', () => {
  3476. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  3477. const list1 = accessor.getRepeatedSfixed64Iterable(1);
  3478. const list2 = accessor.getRepeatedSfixed64Iterable(1);
  3479. expect(list1).not.toBe(list2);
  3480. });
  3481. it('add single packed value', () => {
  3482. const accessor = Kernel.createEmpty();
  3483. accessor.addPackedSfixed64Element(1, value1);
  3484. const list1 = accessor.getRepeatedSfixed64Iterable(1);
  3485. accessor.addPackedSfixed64Element(1, value2);
  3486. const list2 = accessor.getRepeatedSfixed64Iterable(1);
  3487. expectEqualToArray(list1, [value1]);
  3488. expectEqualToArray(list2, [value1, value2]);
  3489. });
  3490. it('add packed values', () => {
  3491. const accessor = Kernel.createEmpty();
  3492. accessor.addPackedSfixed64Iterable(1, [value1]);
  3493. const list1 = accessor.getRepeatedSfixed64Iterable(1);
  3494. accessor.addPackedSfixed64Iterable(1, [value2]);
  3495. const list2 = accessor.getRepeatedSfixed64Iterable(1);
  3496. expectEqualToArray(list1, [value1]);
  3497. expectEqualToArray(list2, [value1, value2]);
  3498. });
  3499. it('set a single packed value', () => {
  3500. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3501. accessor.setPackedSfixed64Element(1, 1, value1);
  3502. const list = accessor.getRepeatedSfixed64Iterable(1);
  3503. expectEqualToArray(list, [value1, value1]);
  3504. });
  3505. it('set packed values', () => {
  3506. const accessor = Kernel.createEmpty();
  3507. accessor.setPackedSfixed64Iterable(1, [value1]);
  3508. const list1 = accessor.getRepeatedSfixed64Iterable(1);
  3509. accessor.setPackedSfixed64Iterable(1, [value2]);
  3510. const list2 = accessor.getRepeatedSfixed64Iterable(1);
  3511. expectEqualToArray(list1, [value1]);
  3512. expectEqualToArray(list2, [value2]);
  3513. });
  3514. it('encode for adding single packed value', () => {
  3515. const accessor = Kernel.createEmpty();
  3516. accessor.addPackedSfixed64Element(1, value1);
  3517. accessor.addPackedSfixed64Element(1, value2);
  3518. const serialized = accessor.serialize();
  3519. expect(serialized).toEqual(packedValue1Value2);
  3520. });
  3521. it('encode for adding packed values', () => {
  3522. const accessor = Kernel.createEmpty();
  3523. accessor.addPackedSfixed64Iterable(1, [value1, value2]);
  3524. const serialized = accessor.serialize();
  3525. expect(serialized).toEqual(packedValue1Value2);
  3526. });
  3527. it('encode for setting single packed value', () => {
  3528. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3529. accessor.setPackedSfixed64Element(1, 0, value2);
  3530. accessor.setPackedSfixed64Element(1, 1, value1);
  3531. const serialized = accessor.serialize();
  3532. expect(serialized).toEqual(packedValue2Value1);
  3533. });
  3534. it('encode for setting packed values', () => {
  3535. const accessor = Kernel.createEmpty();
  3536. accessor.setPackedSfixed64Iterable(1, [value1, value2]);
  3537. const serialized = accessor.serialize();
  3538. expect(serialized).toEqual(packedValue1Value2);
  3539. });
  3540. it('return combined values from the input', () => {
  3541. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  3542. 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // value1
  3543. 0x0A, 0x10, // tag
  3544. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // value1
  3545. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // value2
  3546. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // value2
  3547. ));
  3548. const list = accessor.getRepeatedSfixed64Iterable(1);
  3549. expectEqualToArray(list, [value1, value1, value2, value2]);
  3550. });
  3551. it('return the repeated field element from the input', () => {
  3552. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3553. const result1 = accessor.getRepeatedSfixed64Element(
  3554. /* fieldNumber= */ 1, /* index= */ 0);
  3555. const result2 = accessor.getRepeatedSfixed64Element(
  3556. /* fieldNumber= */ 1, /* index= */ 1);
  3557. expect(result1).toEqual(value1);
  3558. expect(result2).toEqual(value2);
  3559. });
  3560. it('return the size from the input', () => {
  3561. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3562. const size = accessor.getRepeatedSfixed64Size(1);
  3563. expect(size).toEqual(2);
  3564. });
  3565. it('fail when getting unpacked sfixed64 value with other wire types', () => {
  3566. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  3567. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  3568. if (CHECK_CRITICAL_STATE) {
  3569. expect(() => {
  3570. accessor.getRepeatedSfixed64Iterable(1);
  3571. }).toThrowError('Expected wire type: 1 but found: 0');
  3572. } else {
  3573. // Note in unchecked mode we produce invalid output for invalid inputs.
  3574. // This test just documents our behavior in those cases.
  3575. // These values might change at any point and are not considered
  3576. // what the implementation should be doing here.
  3577. expectQualifiedIterable(
  3578. accessor.getRepeatedSfixed64Iterable(1),
  3579. (value) => value instanceof Int64);
  3580. }
  3581. });
  3582. it('fail when adding unpacked sfixed64 values with null value', () => {
  3583. const accessor = Kernel.createEmpty();
  3584. const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  3585. if (CHECK_CRITICAL_STATE) {
  3586. expect(() => accessor.addUnpackedSfixed64Iterable(1, [fakeSfixed64]))
  3587. .toThrowError('Must be Int64 instance, but got: null');
  3588. } else {
  3589. // Note in unchecked mode we produce invalid output for invalid inputs.
  3590. // This test just documents our behavior in those cases.
  3591. // These values might change at any point and are not considered
  3592. // what the implementation should be doing here.
  3593. accessor.addUnpackedSfixed64Iterable(1, [fakeSfixed64]);
  3594. expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
  3595. }
  3596. });
  3597. it('fail when adding single unpacked sfixed64 value with null value', () => {
  3598. const accessor = Kernel.createEmpty();
  3599. const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  3600. if (CHECK_CRITICAL_STATE) {
  3601. expect(() => accessor.addUnpackedSfixed64Element(1, fakeSfixed64))
  3602. .toThrowError('Must be Int64 instance, but got: null');
  3603. } else {
  3604. // Note in unchecked mode we produce invalid output for invalid inputs.
  3605. // This test just documents our behavior in those cases.
  3606. // These values might change at any point and are not considered
  3607. // what the implementation should be doing here.
  3608. accessor.addUnpackedSfixed64Element(1, fakeSfixed64);
  3609. expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
  3610. }
  3611. });
  3612. it('fail when setting unpacked sfixed64 values with null value', () => {
  3613. const accessor = Kernel.createEmpty();
  3614. const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  3615. if (CHECK_CRITICAL_STATE) {
  3616. expect(() => accessor.setUnpackedSfixed64Iterable(1, [fakeSfixed64]))
  3617. .toThrowError('Must be Int64 instance, but got: null');
  3618. } else {
  3619. // Note in unchecked mode we produce invalid output for invalid inputs.
  3620. // This test just documents our behavior in those cases.
  3621. // These values might change at any point and are not considered
  3622. // what the implementation should be doing here.
  3623. accessor.setUnpackedSfixed64Iterable(1, [fakeSfixed64]);
  3624. expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
  3625. }
  3626. });
  3627. it('fail when setting single unpacked sfixed64 value with null value', () => {
  3628. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  3629. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  3630. const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  3631. if (CHECK_CRITICAL_STATE) {
  3632. expect(() => accessor.setUnpackedSfixed64Element(1, 0, fakeSfixed64))
  3633. .toThrowError('Must be Int64 instance, but got: null');
  3634. } else {
  3635. // Note in unchecked mode we produce invalid output for invalid inputs.
  3636. // This test just documents our behavior in those cases.
  3637. // These values might change at any point and are not considered
  3638. // what the implementation should be doing here.
  3639. accessor.setUnpackedSfixed64Element(1, 0, fakeSfixed64);
  3640. expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
  3641. }
  3642. });
  3643. it('fail when adding packed sfixed64 values with null value', () => {
  3644. const accessor = Kernel.createEmpty();
  3645. const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  3646. if (CHECK_CRITICAL_STATE) {
  3647. expect(() => accessor.addPackedSfixed64Iterable(1, [fakeSfixed64]))
  3648. .toThrowError('Must be Int64 instance, but got: null');
  3649. } else {
  3650. // Note in unchecked mode we produce invalid output for invalid inputs.
  3651. // This test just documents our behavior in those cases.
  3652. // These values might change at any point and are not considered
  3653. // what the implementation should be doing here.
  3654. accessor.addPackedSfixed64Iterable(1, [fakeSfixed64]);
  3655. expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
  3656. }
  3657. });
  3658. it('fail when adding single packed sfixed64 value with null value', () => {
  3659. const accessor = Kernel.createEmpty();
  3660. const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  3661. if (CHECK_CRITICAL_STATE) {
  3662. expect(() => accessor.addPackedSfixed64Element(1, fakeSfixed64))
  3663. .toThrowError('Must be Int64 instance, but got: null');
  3664. } else {
  3665. // Note in unchecked mode we produce invalid output for invalid inputs.
  3666. // This test just documents our behavior in those cases.
  3667. // These values might change at any point and are not considered
  3668. // what the implementation should be doing here.
  3669. accessor.addPackedSfixed64Element(1, fakeSfixed64);
  3670. expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
  3671. }
  3672. });
  3673. it('fail when setting packed sfixed64 values with null value', () => {
  3674. const accessor = Kernel.createEmpty();
  3675. const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  3676. if (CHECK_CRITICAL_STATE) {
  3677. expect(() => accessor.setPackedSfixed64Iterable(1, [fakeSfixed64]))
  3678. .toThrowError('Must be Int64 instance, but got: null');
  3679. } else {
  3680. // Note in unchecked mode we produce invalid output for invalid inputs.
  3681. // This test just documents our behavior in those cases.
  3682. // These values might change at any point and are not considered
  3683. // what the implementation should be doing here.
  3684. accessor.setPackedSfixed64Iterable(1, [fakeSfixed64]);
  3685. expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
  3686. }
  3687. });
  3688. it('fail when setting single packed sfixed64 value with null value', () => {
  3689. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  3690. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  3691. const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  3692. if (CHECK_CRITICAL_STATE) {
  3693. expect(() => accessor.setPackedSfixed64Element(1, 0, fakeSfixed64))
  3694. .toThrowError('Must be Int64 instance, but got: null');
  3695. } else {
  3696. // Note in unchecked mode we produce invalid output for invalid inputs.
  3697. // This test just documents our behavior in those cases.
  3698. // These values might change at any point and are not considered
  3699. // what the implementation should be doing here.
  3700. accessor.setPackedSfixed64Element(1, 0, fakeSfixed64);
  3701. expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
  3702. }
  3703. });
  3704. it('fail when setting single unpacked with out-of-bound index', () => {
  3705. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  3706. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  3707. if (CHECK_CRITICAL_STATE) {
  3708. expect(() => accessor.setUnpackedSfixed64Element(1, 1, Int64.fromInt(1)))
  3709. .toThrowError('Index out of bounds: index: 1 size: 1');
  3710. } else {
  3711. // Note in unchecked mode we produce invalid output for invalid inputs.
  3712. // This test just documents our behavior in those cases.
  3713. // These values might change at any point and are not considered
  3714. // what the implementation should be doing here.
  3715. accessor.setUnpackedSfixed64Element(1, 1, Int64.fromInt(1));
  3716. expectQualifiedIterable(
  3717. accessor.getRepeatedSfixed64Iterable(1),
  3718. (value) => value instanceof Int64);
  3719. }
  3720. });
  3721. it('fail when setting single packed with out-of-bound index', () => {
  3722. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  3723. 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  3724. if (CHECK_CRITICAL_STATE) {
  3725. expect(() => accessor.setPackedSfixed64Element(1, 1, Int64.fromInt(1)))
  3726. .toThrowError('Index out of bounds: index: 1 size: 1');
  3727. } else {
  3728. // Note in unchecked mode we produce invalid output for invalid inputs.
  3729. // This test just documents our behavior in those cases.
  3730. // These values might change at any point and are not considered
  3731. // what the implementation should be doing here.
  3732. accessor.setPackedSfixed64Element(1, 1, Int64.fromInt(1));
  3733. expectQualifiedIterable(
  3734. accessor.getRepeatedSfixed64Iterable(1),
  3735. (value) => value instanceof Int64);
  3736. }
  3737. });
  3738. it('fail when getting element with out-of-range index', () => {
  3739. const accessor = Kernel.createEmpty();
  3740. if (CHECK_CRITICAL_STATE) {
  3741. expect(() => {
  3742. accessor.getRepeatedSfixed64Element(
  3743. /* fieldNumber= */ 1, /* index= */ 0);
  3744. }).toThrowError('Index out of bounds: index: 0 size: 0');
  3745. } else {
  3746. // Note in unchecked mode we produce invalid output for invalid inputs.
  3747. // This test just documents our behavior in those cases.
  3748. // These values might change at any point and are not considered
  3749. // what the implementation should be doing here.
  3750. expect(accessor.getRepeatedSfixed64Element(
  3751. /* fieldNumber= */ 1, /* index= */ 0))
  3752. .toBe(undefined);
  3753. }
  3754. });
  3755. });
  3756. describe('Kernel for repeated sint32 does', () => {
  3757. const value1 = -1;
  3758. const value2 = 0;
  3759. const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  3760. const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
  3761. const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  3762. const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
  3763. it('return empty array for the empty input', () => {
  3764. const accessor = Kernel.createEmpty();
  3765. const list = accessor.getRepeatedSint32Iterable(1);
  3766. expectEqualToArray(list, []);
  3767. });
  3768. it('ensure not the same instance returned for the empty input', () => {
  3769. const accessor = Kernel.createEmpty();
  3770. const list1 = accessor.getRepeatedSint32Iterable(1);
  3771. const list2 = accessor.getRepeatedSint32Iterable(1);
  3772. expect(list1).not.toBe(list2);
  3773. });
  3774. it('return size for the empty input', () => {
  3775. const accessor = Kernel.createEmpty();
  3776. const size = accessor.getRepeatedSint32Size(1);
  3777. expect(size).toEqual(0);
  3778. });
  3779. it('return unpacked values from the input', () => {
  3780. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3781. const list = accessor.getRepeatedSint32Iterable(1);
  3782. expectEqualToArray(list, [value1, value2]);
  3783. });
  3784. it('ensure not the same instance returned for unpacked values', () => {
  3785. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3786. const list1 = accessor.getRepeatedSint32Iterable(1);
  3787. const list2 = accessor.getRepeatedSint32Iterable(1);
  3788. expect(list1).not.toBe(list2);
  3789. });
  3790. it('add single unpacked value', () => {
  3791. const accessor = Kernel.createEmpty();
  3792. accessor.addUnpackedSint32Element(1, value1);
  3793. const list1 = accessor.getRepeatedSint32Iterable(1);
  3794. accessor.addUnpackedSint32Element(1, value2);
  3795. const list2 = accessor.getRepeatedSint32Iterable(1);
  3796. expectEqualToArray(list1, [value1]);
  3797. expectEqualToArray(list2, [value1, value2]);
  3798. });
  3799. it('add unpacked values', () => {
  3800. const accessor = Kernel.createEmpty();
  3801. accessor.addUnpackedSint32Iterable(1, [value1]);
  3802. const list1 = accessor.getRepeatedSint32Iterable(1);
  3803. accessor.addUnpackedSint32Iterable(1, [value2]);
  3804. const list2 = accessor.getRepeatedSint32Iterable(1);
  3805. expectEqualToArray(list1, [value1]);
  3806. expectEqualToArray(list2, [value1, value2]);
  3807. });
  3808. it('set a single unpacked value', () => {
  3809. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  3810. accessor.setUnpackedSint32Element(1, 1, value1);
  3811. const list = accessor.getRepeatedSint32Iterable(1);
  3812. expectEqualToArray(list, [value1, value1]);
  3813. });
  3814. it('set unpacked values', () => {
  3815. const accessor = Kernel.createEmpty();
  3816. accessor.setUnpackedSint32Iterable(1, [value1]);
  3817. const list = accessor.getRepeatedSint32Iterable(1);
  3818. expectEqualToArray(list, [value1]);
  3819. });
  3820. it('encode for adding single unpacked value', () => {
  3821. const accessor = Kernel.createEmpty();
  3822. accessor.addUnpackedSint32Element(1, value1);
  3823. accessor.addUnpackedSint32Element(1, value2);
  3824. const serialized = accessor.serialize();
  3825. expect(serialized).toEqual(unpackedValue1Value2);
  3826. });
  3827. it('encode for adding unpacked values', () => {
  3828. const accessor = Kernel.createEmpty();
  3829. accessor.addUnpackedSint32Iterable(1, [value1]);
  3830. accessor.addUnpackedSint32Iterable(1, [value2]);
  3831. const serialized = accessor.serialize();
  3832. expect(serialized).toEqual(unpackedValue1Value2);
  3833. });
  3834. it('encode for setting single unpacked value', () => {
  3835. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3836. accessor.setUnpackedSint32Element(1, 0, value2);
  3837. accessor.setUnpackedSint32Element(1, 1, value1);
  3838. const serialized = accessor.serialize();
  3839. expect(serialized).toEqual(unpackedValue2Value1);
  3840. });
  3841. it('encode for setting unpacked values', () => {
  3842. const accessor = Kernel.createEmpty();
  3843. accessor.setUnpackedSint32Iterable(1, [value1, value2]);
  3844. const serialized = accessor.serialize();
  3845. expect(serialized).toEqual(unpackedValue1Value2);
  3846. });
  3847. it('return packed values from the input', () => {
  3848. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  3849. const list = accessor.getRepeatedSint32Iterable(1);
  3850. expectEqualToArray(list, [value1, value2]);
  3851. });
  3852. it('ensure not the same instance returned for packed values', () => {
  3853. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  3854. const list1 = accessor.getRepeatedSint32Iterable(1);
  3855. const list2 = accessor.getRepeatedSint32Iterable(1);
  3856. expect(list1).not.toBe(list2);
  3857. });
  3858. it('add single packed value', () => {
  3859. const accessor = Kernel.createEmpty();
  3860. accessor.addPackedSint32Element(1, value1);
  3861. const list1 = accessor.getRepeatedSint32Iterable(1);
  3862. accessor.addPackedSint32Element(1, value2);
  3863. const list2 = accessor.getRepeatedSint32Iterable(1);
  3864. expectEqualToArray(list1, [value1]);
  3865. expectEqualToArray(list2, [value1, value2]);
  3866. });
  3867. it('add packed values', () => {
  3868. const accessor = Kernel.createEmpty();
  3869. accessor.addPackedSint32Iterable(1, [value1]);
  3870. const list1 = accessor.getRepeatedSint32Iterable(1);
  3871. accessor.addPackedSint32Iterable(1, [value2]);
  3872. const list2 = accessor.getRepeatedSint32Iterable(1);
  3873. expectEqualToArray(list1, [value1]);
  3874. expectEqualToArray(list2, [value1, value2]);
  3875. });
  3876. it('set a single packed value', () => {
  3877. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3878. accessor.setPackedSint32Element(1, 1, value1);
  3879. const list = accessor.getRepeatedSint32Iterable(1);
  3880. expectEqualToArray(list, [value1, value1]);
  3881. });
  3882. it('set packed values', () => {
  3883. const accessor = Kernel.createEmpty();
  3884. accessor.setPackedSint32Iterable(1, [value1]);
  3885. const list1 = accessor.getRepeatedSint32Iterable(1);
  3886. accessor.setPackedSint32Iterable(1, [value2]);
  3887. const list2 = accessor.getRepeatedSint32Iterable(1);
  3888. expectEqualToArray(list1, [value1]);
  3889. expectEqualToArray(list2, [value2]);
  3890. });
  3891. it('encode for adding single packed value', () => {
  3892. const accessor = Kernel.createEmpty();
  3893. accessor.addPackedSint32Element(1, value1);
  3894. accessor.addPackedSint32Element(1, value2);
  3895. const serialized = accessor.serialize();
  3896. expect(serialized).toEqual(packedValue1Value2);
  3897. });
  3898. it('encode for adding packed values', () => {
  3899. const accessor = Kernel.createEmpty();
  3900. accessor.addPackedSint32Iterable(1, [value1, value2]);
  3901. const serialized = accessor.serialize();
  3902. expect(serialized).toEqual(packedValue1Value2);
  3903. });
  3904. it('encode for setting single packed value', () => {
  3905. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3906. accessor.setPackedSint32Element(1, 0, value2);
  3907. accessor.setPackedSint32Element(1, 1, value1);
  3908. const serialized = accessor.serialize();
  3909. expect(serialized).toEqual(packedValue2Value1);
  3910. });
  3911. it('encode for setting packed values', () => {
  3912. const accessor = Kernel.createEmpty();
  3913. accessor.setPackedSint32Iterable(1, [value1, value2]);
  3914. const serialized = accessor.serialize();
  3915. expect(serialized).toEqual(packedValue1Value2);
  3916. });
  3917. it('return combined values from the input', () => {
  3918. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  3919. 0x08,
  3920. 0x01, // unpacked value1
  3921. 0x0A,
  3922. 0x02,
  3923. 0x01,
  3924. 0x00, // packed value1 and value2
  3925. 0x08,
  3926. 0x00, // unpacked value2
  3927. ));
  3928. const list = accessor.getRepeatedSint32Iterable(1);
  3929. expectEqualToArray(list, [value1, value1, value2, value2]);
  3930. });
  3931. it('return the repeated field element from the input', () => {
  3932. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3933. const result1 = accessor.getRepeatedSint32Element(
  3934. /* fieldNumber= */ 1, /* index= */ 0);
  3935. const result2 = accessor.getRepeatedSint32Element(
  3936. /* fieldNumber= */ 1, /* index= */ 1);
  3937. expect(result1).toEqual(value1);
  3938. expect(result2).toEqual(value2);
  3939. });
  3940. it('return the size from the input', () => {
  3941. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  3942. const size = accessor.getRepeatedSint32Size(1);
  3943. expect(size).toEqual(2);
  3944. });
  3945. it('fail when getting unpacked sint32 value with other wire types', () => {
  3946. const accessor =
  3947. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  3948. if (CHECK_CRITICAL_STATE) {
  3949. expect(() => {
  3950. accessor.getRepeatedSint32Iterable(1);
  3951. }).toThrowError('Expected wire type: 0 but found: 5');
  3952. } else {
  3953. // Note in unchecked mode we produce invalid output for invalid inputs.
  3954. // This test just documents our behavior in those cases.
  3955. // These values might change at any point and are not considered
  3956. // what the implementation should be doing here.
  3957. expectQualifiedIterable(
  3958. accessor.getRepeatedSint32Iterable(1),
  3959. (value) => Number.isInteger(value));
  3960. }
  3961. });
  3962. it('fail when adding unpacked sint32 values with null value', () => {
  3963. const accessor = Kernel.createEmpty();
  3964. const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
  3965. if (CHECK_CRITICAL_STATE) {
  3966. expect(() => accessor.addUnpackedSint32Iterable(1, [fakeSint32]))
  3967. .toThrowError('Must be a number, but got: null');
  3968. } else {
  3969. // Note in unchecked mode we produce invalid output for invalid inputs.
  3970. // This test just documents our behavior in those cases.
  3971. // These values might change at any point and are not considered
  3972. // what the implementation should be doing here.
  3973. accessor.addUnpackedSint32Iterable(1, [fakeSint32]);
  3974. expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
  3975. }
  3976. });
  3977. it('fail when adding single unpacked sint32 value with null value', () => {
  3978. const accessor = Kernel.createEmpty();
  3979. const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
  3980. if (CHECK_CRITICAL_STATE) {
  3981. expect(() => accessor.addUnpackedSint32Element(1, fakeSint32))
  3982. .toThrowError('Must be a number, but got: null');
  3983. } else {
  3984. // Note in unchecked mode we produce invalid output for invalid inputs.
  3985. // This test just documents our behavior in those cases.
  3986. // These values might change at any point and are not considered
  3987. // what the implementation should be doing here.
  3988. accessor.addUnpackedSint32Element(1, fakeSint32);
  3989. expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
  3990. }
  3991. });
  3992. it('fail when setting unpacked sint32 values with null value', () => {
  3993. const accessor = Kernel.createEmpty();
  3994. const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
  3995. if (CHECK_CRITICAL_STATE) {
  3996. expect(() => accessor.setUnpackedSint32Iterable(1, [fakeSint32]))
  3997. .toThrowError('Must be a number, but got: null');
  3998. } else {
  3999. // Note in unchecked mode we produce invalid output for invalid inputs.
  4000. // This test just documents our behavior in those cases.
  4001. // These values might change at any point and are not considered
  4002. // what the implementation should be doing here.
  4003. accessor.setUnpackedSint32Iterable(1, [fakeSint32]);
  4004. expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
  4005. }
  4006. });
  4007. it('fail when setting single unpacked sint32 value with null value', () => {
  4008. const accessor =
  4009. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  4010. const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
  4011. if (CHECK_CRITICAL_STATE) {
  4012. expect(() => accessor.setUnpackedSint32Element(1, 0, fakeSint32))
  4013. .toThrowError('Must be a number, but got: null');
  4014. } else {
  4015. // Note in unchecked mode we produce invalid output for invalid inputs.
  4016. // This test just documents our behavior in those cases.
  4017. // These values might change at any point and are not considered
  4018. // what the implementation should be doing here.
  4019. accessor.setUnpackedSint32Element(1, 0, fakeSint32);
  4020. expectQualifiedIterable(
  4021. accessor.getRepeatedSint32Iterable(1),
  4022. );
  4023. }
  4024. });
  4025. it('fail when adding packed sint32 values with null value', () => {
  4026. const accessor = Kernel.createEmpty();
  4027. const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
  4028. if (CHECK_CRITICAL_STATE) {
  4029. expect(() => accessor.addPackedSint32Iterable(1, [fakeSint32]))
  4030. .toThrowError('Must be a number, but got: null');
  4031. } else {
  4032. // Note in unchecked mode we produce invalid output for invalid inputs.
  4033. // This test just documents our behavior in those cases.
  4034. // These values might change at any point and are not considered
  4035. // what the implementation should be doing here.
  4036. accessor.addPackedSint32Iterable(1, [fakeSint32]);
  4037. expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
  4038. }
  4039. });
  4040. it('fail when adding single packed sint32 value with null value', () => {
  4041. const accessor = Kernel.createEmpty();
  4042. const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
  4043. if (CHECK_CRITICAL_STATE) {
  4044. expect(() => accessor.addPackedSint32Element(1, fakeSint32))
  4045. .toThrowError('Must be a number, but got: null');
  4046. } else {
  4047. // Note in unchecked mode we produce invalid output for invalid inputs.
  4048. // This test just documents our behavior in those cases.
  4049. // These values might change at any point and are not considered
  4050. // what the implementation should be doing here.
  4051. accessor.addPackedSint32Element(1, fakeSint32);
  4052. expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
  4053. }
  4054. });
  4055. it('fail when setting packed sint32 values with null value', () => {
  4056. const accessor = Kernel.createEmpty();
  4057. const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
  4058. if (CHECK_CRITICAL_STATE) {
  4059. expect(() => accessor.setPackedSint32Iterable(1, [fakeSint32]))
  4060. .toThrowError('Must be a number, but got: null');
  4061. } else {
  4062. // Note in unchecked mode we produce invalid output for invalid inputs.
  4063. // This test just documents our behavior in those cases.
  4064. // These values might change at any point and are not considered
  4065. // what the implementation should be doing here.
  4066. accessor.setPackedSint32Iterable(1, [fakeSint32]);
  4067. expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
  4068. }
  4069. });
  4070. it('fail when setting single packed sint32 value with null value', () => {
  4071. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  4072. const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
  4073. if (CHECK_CRITICAL_STATE) {
  4074. expect(() => accessor.setPackedSint32Element(1, 0, fakeSint32))
  4075. .toThrowError('Must be a number, but got: null');
  4076. } else {
  4077. // Note in unchecked mode we produce invalid output for invalid inputs.
  4078. // This test just documents our behavior in those cases.
  4079. // These values might change at any point and are not considered
  4080. // what the implementation should be doing here.
  4081. accessor.setPackedSint32Element(1, 0, fakeSint32);
  4082. expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
  4083. }
  4084. });
  4085. it('fail when setting single unpacked with out-of-bound index', () => {
  4086. const accessor =
  4087. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
  4088. if (CHECK_CRITICAL_STATE) {
  4089. expect(() => accessor.setUnpackedSint32Element(1, 1, 1))
  4090. .toThrowError('Index out of bounds: index: 1 size: 1');
  4091. } else {
  4092. // Note in unchecked mode we produce invalid output for invalid inputs.
  4093. // This test just documents our behavior in those cases.
  4094. // These values might change at any point and are not considered
  4095. // what the implementation should be doing here.
  4096. accessor.setUnpackedSint32Element(1, 1, 1);
  4097. expectQualifiedIterable(
  4098. accessor.getRepeatedSint32Iterable(1),
  4099. (value) => Number.isInteger(value));
  4100. }
  4101. });
  4102. it('fail when setting single packed with out-of-bound index', () => {
  4103. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  4104. if (CHECK_CRITICAL_STATE) {
  4105. expect(() => accessor.setPackedSint32Element(1, 1, 1))
  4106. .toThrowError('Index out of bounds: index: 1 size: 1');
  4107. } else {
  4108. // Note in unchecked mode we produce invalid output for invalid inputs.
  4109. // This test just documents our behavior in those cases.
  4110. // These values might change at any point and are not considered
  4111. // what the implementation should be doing here.
  4112. accessor.setPackedSint32Element(1, 1, 1);
  4113. expectQualifiedIterable(
  4114. accessor.getRepeatedSint32Iterable(1),
  4115. (value) => Number.isInteger(value));
  4116. }
  4117. });
  4118. it('fail when getting element with out-of-range index', () => {
  4119. const accessor = Kernel.createEmpty();
  4120. if (CHECK_CRITICAL_STATE) {
  4121. expect(() => {
  4122. accessor.getRepeatedSint32Element(
  4123. /* fieldNumber= */ 1, /* index= */ 0);
  4124. }).toThrowError('Index out of bounds: index: 0 size: 0');
  4125. } else {
  4126. // Note in unchecked mode we produce invalid output for invalid inputs.
  4127. // This test just documents our behavior in those cases.
  4128. // These values might change at any point and are not considered
  4129. // what the implementation should be doing here.
  4130. expect(accessor.getRepeatedSint32Element(
  4131. /* fieldNumber= */ 1, /* index= */ 0))
  4132. .toBe(undefined);
  4133. }
  4134. });
  4135. });
  4136. describe('Kernel for repeated sint64 does', () => {
  4137. const value1 = Int64.fromInt(-1);
  4138. const value2 = Int64.fromInt(0);
  4139. const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  4140. const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
  4141. const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  4142. const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
  4143. it('return empty array for the empty input', () => {
  4144. const accessor = Kernel.createEmpty();
  4145. const list = accessor.getRepeatedSint64Iterable(1);
  4146. expectEqualToArray(list, []);
  4147. });
  4148. it('ensure not the same instance returned for the empty input', () => {
  4149. const accessor = Kernel.createEmpty();
  4150. const list1 = accessor.getRepeatedSint64Iterable(1);
  4151. const list2 = accessor.getRepeatedSint64Iterable(1);
  4152. expect(list1).not.toBe(list2);
  4153. });
  4154. it('return size for the empty input', () => {
  4155. const accessor = Kernel.createEmpty();
  4156. const size = accessor.getRepeatedSint64Size(1);
  4157. expect(size).toEqual(0);
  4158. });
  4159. it('return unpacked values from the input', () => {
  4160. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4161. const list = accessor.getRepeatedSint64Iterable(1);
  4162. expectEqualToArray(list, [value1, value2]);
  4163. });
  4164. it('ensure not the same instance returned for unpacked values', () => {
  4165. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4166. const list1 = accessor.getRepeatedSint64Iterable(1);
  4167. const list2 = accessor.getRepeatedSint64Iterable(1);
  4168. expect(list1).not.toBe(list2);
  4169. });
  4170. it('add single unpacked value', () => {
  4171. const accessor = Kernel.createEmpty();
  4172. accessor.addUnpackedSint64Element(1, value1);
  4173. const list1 = accessor.getRepeatedSint64Iterable(1);
  4174. accessor.addUnpackedSint64Element(1, value2);
  4175. const list2 = accessor.getRepeatedSint64Iterable(1);
  4176. expectEqualToArray(list1, [value1]);
  4177. expectEqualToArray(list2, [value1, value2]);
  4178. });
  4179. it('add unpacked values', () => {
  4180. const accessor = Kernel.createEmpty();
  4181. accessor.addUnpackedSint64Iterable(1, [value1]);
  4182. const list1 = accessor.getRepeatedSint64Iterable(1);
  4183. accessor.addUnpackedSint64Iterable(1, [value2]);
  4184. const list2 = accessor.getRepeatedSint64Iterable(1);
  4185. expectEqualToArray(list1, [value1]);
  4186. expectEqualToArray(list2, [value1, value2]);
  4187. });
  4188. it('set a single unpacked value', () => {
  4189. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  4190. accessor.setUnpackedSint64Element(1, 1, value1);
  4191. const list = accessor.getRepeatedSint64Iterable(1);
  4192. expectEqualToArray(list, [value1, value1]);
  4193. });
  4194. it('set unpacked values', () => {
  4195. const accessor = Kernel.createEmpty();
  4196. accessor.setUnpackedSint64Iterable(1, [value1]);
  4197. const list = accessor.getRepeatedSint64Iterable(1);
  4198. expectEqualToArray(list, [value1]);
  4199. });
  4200. it('encode for adding single unpacked value', () => {
  4201. const accessor = Kernel.createEmpty();
  4202. accessor.addUnpackedSint64Element(1, value1);
  4203. accessor.addUnpackedSint64Element(1, value2);
  4204. const serialized = accessor.serialize();
  4205. expect(serialized).toEqual(unpackedValue1Value2);
  4206. });
  4207. it('encode for adding unpacked values', () => {
  4208. const accessor = Kernel.createEmpty();
  4209. accessor.addUnpackedSint64Iterable(1, [value1]);
  4210. accessor.addUnpackedSint64Iterable(1, [value2]);
  4211. const serialized = accessor.serialize();
  4212. expect(serialized).toEqual(unpackedValue1Value2);
  4213. });
  4214. it('encode for setting single unpacked value', () => {
  4215. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4216. accessor.setUnpackedSint64Element(1, 0, value2);
  4217. accessor.setUnpackedSint64Element(1, 1, value1);
  4218. const serialized = accessor.serialize();
  4219. expect(serialized).toEqual(unpackedValue2Value1);
  4220. });
  4221. it('encode for setting unpacked values', () => {
  4222. const accessor = Kernel.createEmpty();
  4223. accessor.setUnpackedSint64Iterable(1, [value1, value2]);
  4224. const serialized = accessor.serialize();
  4225. expect(serialized).toEqual(unpackedValue1Value2);
  4226. });
  4227. it('return packed values from the input', () => {
  4228. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  4229. const list = accessor.getRepeatedSint64Iterable(1);
  4230. expectEqualToArray(list, [value1, value2]);
  4231. });
  4232. it('ensure not the same instance returned for packed values', () => {
  4233. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  4234. const list1 = accessor.getRepeatedSint64Iterable(1);
  4235. const list2 = accessor.getRepeatedSint64Iterable(1);
  4236. expect(list1).not.toBe(list2);
  4237. });
  4238. it('add single packed value', () => {
  4239. const accessor = Kernel.createEmpty();
  4240. accessor.addPackedSint64Element(1, value1);
  4241. const list1 = accessor.getRepeatedSint64Iterable(1);
  4242. accessor.addPackedSint64Element(1, value2);
  4243. const list2 = accessor.getRepeatedSint64Iterable(1);
  4244. expectEqualToArray(list1, [value1]);
  4245. expectEqualToArray(list2, [value1, value2]);
  4246. });
  4247. it('add packed values', () => {
  4248. const accessor = Kernel.createEmpty();
  4249. accessor.addPackedSint64Iterable(1, [value1]);
  4250. const list1 = accessor.getRepeatedSint64Iterable(1);
  4251. accessor.addPackedSint64Iterable(1, [value2]);
  4252. const list2 = accessor.getRepeatedSint64Iterable(1);
  4253. expectEqualToArray(list1, [value1]);
  4254. expectEqualToArray(list2, [value1, value2]);
  4255. });
  4256. it('set a single packed value', () => {
  4257. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4258. accessor.setPackedSint64Element(1, 1, value1);
  4259. const list = accessor.getRepeatedSint64Iterable(1);
  4260. expectEqualToArray(list, [value1, value1]);
  4261. });
  4262. it('set packed values', () => {
  4263. const accessor = Kernel.createEmpty();
  4264. accessor.setPackedSint64Iterable(1, [value1]);
  4265. const list1 = accessor.getRepeatedSint64Iterable(1);
  4266. accessor.setPackedSint64Iterable(1, [value2]);
  4267. const list2 = accessor.getRepeatedSint64Iterable(1);
  4268. expectEqualToArray(list1, [value1]);
  4269. expectEqualToArray(list2, [value2]);
  4270. });
  4271. it('encode for adding single packed value', () => {
  4272. const accessor = Kernel.createEmpty();
  4273. accessor.addPackedSint64Element(1, value1);
  4274. accessor.addPackedSint64Element(1, value2);
  4275. const serialized = accessor.serialize();
  4276. expect(serialized).toEqual(packedValue1Value2);
  4277. });
  4278. it('encode for adding packed values', () => {
  4279. const accessor = Kernel.createEmpty();
  4280. accessor.addPackedSint64Iterable(1, [value1, value2]);
  4281. const serialized = accessor.serialize();
  4282. expect(serialized).toEqual(packedValue1Value2);
  4283. });
  4284. it('encode for setting single packed value', () => {
  4285. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4286. accessor.setPackedSint64Element(1, 0, value2);
  4287. accessor.setPackedSint64Element(1, 1, value1);
  4288. const serialized = accessor.serialize();
  4289. expect(serialized).toEqual(packedValue2Value1);
  4290. });
  4291. it('encode for setting packed values', () => {
  4292. const accessor = Kernel.createEmpty();
  4293. accessor.setPackedSint64Iterable(1, [value1, value2]);
  4294. const serialized = accessor.serialize();
  4295. expect(serialized).toEqual(packedValue1Value2);
  4296. });
  4297. it('return combined values from the input', () => {
  4298. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  4299. 0x08,
  4300. 0x01, // unpacked value1
  4301. 0x0A,
  4302. 0x02,
  4303. 0x01,
  4304. 0x00, // packed value1 and value2
  4305. 0x08,
  4306. 0x00, // unpacked value2
  4307. ));
  4308. const list = accessor.getRepeatedSint64Iterable(1);
  4309. expectEqualToArray(list, [value1, value1, value2, value2]);
  4310. });
  4311. it('return the repeated field element from the input', () => {
  4312. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4313. const result1 = accessor.getRepeatedSint64Element(
  4314. /* fieldNumber= */ 1, /* index= */ 0);
  4315. const result2 = accessor.getRepeatedSint64Element(
  4316. /* fieldNumber= */ 1, /* index= */ 1);
  4317. expect(result1).toEqual(value1);
  4318. expect(result2).toEqual(value2);
  4319. });
  4320. it('return the size from the input', () => {
  4321. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4322. const size = accessor.getRepeatedSint64Size(1);
  4323. expect(size).toEqual(2);
  4324. });
  4325. it('fail when getting unpacked sint64 value with other wire types', () => {
  4326. const accessor =
  4327. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  4328. if (CHECK_CRITICAL_STATE) {
  4329. expect(() => {
  4330. accessor.getRepeatedSint64Iterable(1);
  4331. }).toThrowError('Expected wire type: 0 but found: 5');
  4332. } else {
  4333. // Note in unchecked mode we produce invalid output for invalid inputs.
  4334. // This test just documents our behavior in those cases.
  4335. // These values might change at any point and are not considered
  4336. // what the implementation should be doing here.
  4337. expectQualifiedIterable(
  4338. accessor.getRepeatedSint64Iterable(1),
  4339. (value) => value instanceof Int64);
  4340. }
  4341. });
  4342. it('fail when adding unpacked sint64 values with null value', () => {
  4343. const accessor = Kernel.createEmpty();
  4344. const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  4345. if (CHECK_CRITICAL_STATE) {
  4346. expect(() => accessor.addUnpackedSint64Iterable(1, [fakeSint64]))
  4347. .toThrowError('Must be Int64 instance, but got: null');
  4348. } else {
  4349. // Note in unchecked mode we produce invalid output for invalid inputs.
  4350. // This test just documents our behavior in those cases.
  4351. // These values might change at any point and are not considered
  4352. // what the implementation should be doing here.
  4353. accessor.addUnpackedSint64Iterable(1, [fakeSint64]);
  4354. expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
  4355. }
  4356. });
  4357. it('fail when adding single unpacked sint64 value with null value', () => {
  4358. const accessor = Kernel.createEmpty();
  4359. const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  4360. if (CHECK_CRITICAL_STATE) {
  4361. expect(() => accessor.addUnpackedSint64Element(1, fakeSint64))
  4362. .toThrowError('Must be Int64 instance, but got: null');
  4363. } else {
  4364. // Note in unchecked mode we produce invalid output for invalid inputs.
  4365. // This test just documents our behavior in those cases.
  4366. // These values might change at any point and are not considered
  4367. // what the implementation should be doing here.
  4368. accessor.addUnpackedSint64Element(1, fakeSint64);
  4369. expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
  4370. }
  4371. });
  4372. it('fail when setting unpacked sint64 values with null value', () => {
  4373. const accessor = Kernel.createEmpty();
  4374. const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  4375. if (CHECK_CRITICAL_STATE) {
  4376. expect(() => accessor.setUnpackedSint64Iterable(1, [fakeSint64]))
  4377. .toThrowError('Must be Int64 instance, but got: null');
  4378. } else {
  4379. // Note in unchecked mode we produce invalid output for invalid inputs.
  4380. // This test just documents our behavior in those cases.
  4381. // These values might change at any point and are not considered
  4382. // what the implementation should be doing here.
  4383. accessor.setUnpackedSint64Iterable(1, [fakeSint64]);
  4384. expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
  4385. }
  4386. });
  4387. it('fail when setting single unpacked sint64 value with null value', () => {
  4388. const accessor =
  4389. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  4390. const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  4391. if (CHECK_CRITICAL_STATE) {
  4392. expect(() => accessor.setUnpackedSint64Element(1, 0, fakeSint64))
  4393. .toThrowError('Must be Int64 instance, but got: null');
  4394. } else {
  4395. // Note in unchecked mode we produce invalid output for invalid inputs.
  4396. // This test just documents our behavior in those cases.
  4397. // These values might change at any point and are not considered
  4398. // what the implementation should be doing here.
  4399. accessor.setUnpackedSint64Element(1, 0, fakeSint64);
  4400. expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
  4401. }
  4402. });
  4403. it('fail when adding packed sint64 values with null value', () => {
  4404. const accessor = Kernel.createEmpty();
  4405. const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  4406. if (CHECK_CRITICAL_STATE) {
  4407. expect(() => accessor.addPackedSint64Iterable(1, [fakeSint64]))
  4408. .toThrowError('Must be Int64 instance, but got: null');
  4409. } else {
  4410. // Note in unchecked mode we produce invalid output for invalid inputs.
  4411. // This test just documents our behavior in those cases.
  4412. // These values might change at any point and are not considered
  4413. // what the implementation should be doing here.
  4414. accessor.addPackedSint64Iterable(1, [fakeSint64]);
  4415. expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
  4416. }
  4417. });
  4418. it('fail when adding single packed sint64 value with null value', () => {
  4419. const accessor = Kernel.createEmpty();
  4420. const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  4421. if (CHECK_CRITICAL_STATE) {
  4422. expect(() => accessor.addPackedSint64Element(1, fakeSint64))
  4423. .toThrowError('Must be Int64 instance, but got: null');
  4424. } else {
  4425. // Note in unchecked mode we produce invalid output for invalid inputs.
  4426. // This test just documents our behavior in those cases.
  4427. // These values might change at any point and are not considered
  4428. // what the implementation should be doing here.
  4429. accessor.addPackedSint64Element(1, fakeSint64);
  4430. expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
  4431. }
  4432. });
  4433. it('fail when setting packed sint64 values with null value', () => {
  4434. const accessor = Kernel.createEmpty();
  4435. const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  4436. if (CHECK_CRITICAL_STATE) {
  4437. expect(() => accessor.setPackedSint64Iterable(1, [fakeSint64]))
  4438. .toThrowError('Must be Int64 instance, but got: null');
  4439. } else {
  4440. // Note in unchecked mode we produce invalid output for invalid inputs.
  4441. // This test just documents our behavior in those cases.
  4442. // These values might change at any point and are not considered
  4443. // what the implementation should be doing here.
  4444. accessor.setPackedSint64Iterable(1, [fakeSint64]);
  4445. expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
  4446. }
  4447. });
  4448. it('fail when setting single packed sint64 value with null value', () => {
  4449. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  4450. const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  4451. if (CHECK_CRITICAL_STATE) {
  4452. expect(() => accessor.setPackedSint64Element(1, 0, fakeSint64))
  4453. .toThrowError('Must be Int64 instance, but got: null');
  4454. } else {
  4455. // Note in unchecked mode we produce invalid output for invalid inputs.
  4456. // This test just documents our behavior in those cases.
  4457. // These values might change at any point and are not considered
  4458. // what the implementation should be doing here.
  4459. accessor.setPackedSint64Element(1, 0, fakeSint64);
  4460. expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
  4461. }
  4462. });
  4463. it('fail when setting single unpacked with out-of-bound index', () => {
  4464. const accessor =
  4465. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
  4466. if (CHECK_CRITICAL_STATE) {
  4467. expect(() => accessor.setUnpackedSint64Element(1, 1, Int64.fromInt(1)))
  4468. .toThrowError('Index out of bounds: index: 1 size: 1');
  4469. } else {
  4470. // Note in unchecked mode we produce invalid output for invalid inputs.
  4471. // This test just documents our behavior in those cases.
  4472. // These values might change at any point and are not considered
  4473. // what the implementation should be doing here.
  4474. accessor.setUnpackedSint64Element(1, 1, Int64.fromInt(1));
  4475. expectQualifiedIterable(
  4476. accessor.getRepeatedSint64Iterable(1),
  4477. (value) => value instanceof Int64);
  4478. }
  4479. });
  4480. it('fail when setting single packed with out-of-bound index', () => {
  4481. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  4482. if (CHECK_CRITICAL_STATE) {
  4483. expect(() => accessor.setPackedSint64Element(1, 1, Int64.fromInt(1)))
  4484. .toThrowError('Index out of bounds: index: 1 size: 1');
  4485. } else {
  4486. // Note in unchecked mode we produce invalid output for invalid inputs.
  4487. // This test just documents our behavior in those cases.
  4488. // These values might change at any point and are not considered
  4489. // what the implementation should be doing here.
  4490. accessor.setPackedSint64Element(1, 1, Int64.fromInt(1));
  4491. expectQualifiedIterable(
  4492. accessor.getRepeatedSint64Iterable(1),
  4493. (value) => value instanceof Int64);
  4494. }
  4495. });
  4496. it('fail when getting element with out-of-range index', () => {
  4497. const accessor = Kernel.createEmpty();
  4498. if (CHECK_CRITICAL_STATE) {
  4499. expect(() => {
  4500. accessor.getRepeatedSint64Element(
  4501. /* fieldNumber= */ 1, /* index= */ 0);
  4502. }).toThrowError('Index out of bounds: index: 0 size: 0');
  4503. } else {
  4504. // Note in unchecked mode we produce invalid output for invalid inputs.
  4505. // This test just documents our behavior in those cases.
  4506. // These values might change at any point and are not considered
  4507. // what the implementation should be doing here.
  4508. expect(accessor.getRepeatedSint64Element(
  4509. /* fieldNumber= */ 1, /* index= */ 0))
  4510. .toBe(undefined);
  4511. }
  4512. });
  4513. });
  4514. describe('Kernel for repeated uint32 does', () => {
  4515. const value1 = 1;
  4516. const value2 = 0;
  4517. const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  4518. const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
  4519. const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  4520. const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
  4521. it('return empty array for the empty input', () => {
  4522. const accessor = Kernel.createEmpty();
  4523. const list = accessor.getRepeatedUint32Iterable(1);
  4524. expectEqualToArray(list, []);
  4525. });
  4526. it('ensure not the same instance returned for the empty input', () => {
  4527. const accessor = Kernel.createEmpty();
  4528. const list1 = accessor.getRepeatedUint32Iterable(1);
  4529. const list2 = accessor.getRepeatedUint32Iterable(1);
  4530. expect(list1).not.toBe(list2);
  4531. });
  4532. it('return size for the empty input', () => {
  4533. const accessor = Kernel.createEmpty();
  4534. const size = accessor.getRepeatedUint32Size(1);
  4535. expect(size).toEqual(0);
  4536. });
  4537. it('return unpacked values from the input', () => {
  4538. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4539. const list = accessor.getRepeatedUint32Iterable(1);
  4540. expectEqualToArray(list, [value1, value2]);
  4541. });
  4542. it('ensure not the same instance returned for unpacked values', () => {
  4543. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4544. const list1 = accessor.getRepeatedUint32Iterable(1);
  4545. const list2 = accessor.getRepeatedUint32Iterable(1);
  4546. expect(list1).not.toBe(list2);
  4547. });
  4548. it('add single unpacked value', () => {
  4549. const accessor = Kernel.createEmpty();
  4550. accessor.addUnpackedUint32Element(1, value1);
  4551. const list1 = accessor.getRepeatedUint32Iterable(1);
  4552. accessor.addUnpackedUint32Element(1, value2);
  4553. const list2 = accessor.getRepeatedUint32Iterable(1);
  4554. expectEqualToArray(list1, [value1]);
  4555. expectEqualToArray(list2, [value1, value2]);
  4556. });
  4557. it('add unpacked values', () => {
  4558. const accessor = Kernel.createEmpty();
  4559. accessor.addUnpackedUint32Iterable(1, [value1]);
  4560. const list1 = accessor.getRepeatedUint32Iterable(1);
  4561. accessor.addUnpackedUint32Iterable(1, [value2]);
  4562. const list2 = accessor.getRepeatedUint32Iterable(1);
  4563. expectEqualToArray(list1, [value1]);
  4564. expectEqualToArray(list2, [value1, value2]);
  4565. });
  4566. it('set a single unpacked value', () => {
  4567. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  4568. accessor.setUnpackedUint32Element(1, 1, value1);
  4569. const list = accessor.getRepeatedUint32Iterable(1);
  4570. expectEqualToArray(list, [value1, value1]);
  4571. });
  4572. it('set unpacked values', () => {
  4573. const accessor = Kernel.createEmpty();
  4574. accessor.setUnpackedUint32Iterable(1, [value1]);
  4575. const list = accessor.getRepeatedUint32Iterable(1);
  4576. expectEqualToArray(list, [value1]);
  4577. });
  4578. it('encode for adding single unpacked value', () => {
  4579. const accessor = Kernel.createEmpty();
  4580. accessor.addUnpackedUint32Element(1, value1);
  4581. accessor.addUnpackedUint32Element(1, value2);
  4582. const serialized = accessor.serialize();
  4583. expect(serialized).toEqual(unpackedValue1Value2);
  4584. });
  4585. it('encode for adding unpacked values', () => {
  4586. const accessor = Kernel.createEmpty();
  4587. accessor.addUnpackedUint32Iterable(1, [value1]);
  4588. accessor.addUnpackedUint32Iterable(1, [value2]);
  4589. const serialized = accessor.serialize();
  4590. expect(serialized).toEqual(unpackedValue1Value2);
  4591. });
  4592. it('encode for setting single unpacked value', () => {
  4593. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4594. accessor.setUnpackedUint32Element(1, 0, value2);
  4595. accessor.setUnpackedUint32Element(1, 1, value1);
  4596. const serialized = accessor.serialize();
  4597. expect(serialized).toEqual(unpackedValue2Value1);
  4598. });
  4599. it('encode for setting unpacked values', () => {
  4600. const accessor = Kernel.createEmpty();
  4601. accessor.setUnpackedUint32Iterable(1, [value1, value2]);
  4602. const serialized = accessor.serialize();
  4603. expect(serialized).toEqual(unpackedValue1Value2);
  4604. });
  4605. it('return packed values from the input', () => {
  4606. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  4607. const list = accessor.getRepeatedUint32Iterable(1);
  4608. expectEqualToArray(list, [value1, value2]);
  4609. });
  4610. it('ensure not the same instance returned for packed values', () => {
  4611. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  4612. const list1 = accessor.getRepeatedUint32Iterable(1);
  4613. const list2 = accessor.getRepeatedUint32Iterable(1);
  4614. expect(list1).not.toBe(list2);
  4615. });
  4616. it('add single packed value', () => {
  4617. const accessor = Kernel.createEmpty();
  4618. accessor.addPackedUint32Element(1, value1);
  4619. const list1 = accessor.getRepeatedUint32Iterable(1);
  4620. accessor.addPackedUint32Element(1, value2);
  4621. const list2 = accessor.getRepeatedUint32Iterable(1);
  4622. expectEqualToArray(list1, [value1]);
  4623. expectEqualToArray(list2, [value1, value2]);
  4624. });
  4625. it('add packed values', () => {
  4626. const accessor = Kernel.createEmpty();
  4627. accessor.addPackedUint32Iterable(1, [value1]);
  4628. const list1 = accessor.getRepeatedUint32Iterable(1);
  4629. accessor.addPackedUint32Iterable(1, [value2]);
  4630. const list2 = accessor.getRepeatedUint32Iterable(1);
  4631. expectEqualToArray(list1, [value1]);
  4632. expectEqualToArray(list2, [value1, value2]);
  4633. });
  4634. it('set a single packed value', () => {
  4635. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4636. accessor.setPackedUint32Element(1, 1, value1);
  4637. const list = accessor.getRepeatedUint32Iterable(1);
  4638. expectEqualToArray(list, [value1, value1]);
  4639. });
  4640. it('set packed values', () => {
  4641. const accessor = Kernel.createEmpty();
  4642. accessor.setPackedUint32Iterable(1, [value1]);
  4643. const list1 = accessor.getRepeatedUint32Iterable(1);
  4644. accessor.setPackedUint32Iterable(1, [value2]);
  4645. const list2 = accessor.getRepeatedUint32Iterable(1);
  4646. expectEqualToArray(list1, [value1]);
  4647. expectEqualToArray(list2, [value2]);
  4648. });
  4649. it('encode for adding single packed value', () => {
  4650. const accessor = Kernel.createEmpty();
  4651. accessor.addPackedUint32Element(1, value1);
  4652. accessor.addPackedUint32Element(1, value2);
  4653. const serialized = accessor.serialize();
  4654. expect(serialized).toEqual(packedValue1Value2);
  4655. });
  4656. it('encode for adding packed values', () => {
  4657. const accessor = Kernel.createEmpty();
  4658. accessor.addPackedUint32Iterable(1, [value1, value2]);
  4659. const serialized = accessor.serialize();
  4660. expect(serialized).toEqual(packedValue1Value2);
  4661. });
  4662. it('encode for setting single packed value', () => {
  4663. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4664. accessor.setPackedUint32Element(1, 0, value2);
  4665. accessor.setPackedUint32Element(1, 1, value1);
  4666. const serialized = accessor.serialize();
  4667. expect(serialized).toEqual(packedValue2Value1);
  4668. });
  4669. it('encode for setting packed values', () => {
  4670. const accessor = Kernel.createEmpty();
  4671. accessor.setPackedUint32Iterable(1, [value1, value2]);
  4672. const serialized = accessor.serialize();
  4673. expect(serialized).toEqual(packedValue1Value2);
  4674. });
  4675. it('return combined values from the input', () => {
  4676. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  4677. 0x08,
  4678. 0x01, // unpacked value1
  4679. 0x0A,
  4680. 0x02,
  4681. 0x01,
  4682. 0x00, // packed value1 and value2
  4683. 0x08,
  4684. 0x00, // unpacked value2
  4685. ));
  4686. const list = accessor.getRepeatedUint32Iterable(1);
  4687. expectEqualToArray(list, [value1, value1, value2, value2]);
  4688. });
  4689. it('return the repeated field element from the input', () => {
  4690. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4691. const result1 = accessor.getRepeatedUint32Element(
  4692. /* fieldNumber= */ 1, /* index= */ 0);
  4693. const result2 = accessor.getRepeatedUint32Element(
  4694. /* fieldNumber= */ 1, /* index= */ 1);
  4695. expect(result1).toEqual(value1);
  4696. expect(result2).toEqual(value2);
  4697. });
  4698. it('return the size from the input', () => {
  4699. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4700. const size = accessor.getRepeatedUint32Size(1);
  4701. expect(size).toEqual(2);
  4702. });
  4703. it('fail when getting unpacked uint32 value with other wire types', () => {
  4704. const accessor =
  4705. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  4706. if (CHECK_CRITICAL_STATE) {
  4707. expect(() => {
  4708. accessor.getRepeatedUint32Iterable(1);
  4709. }).toThrowError('Expected wire type: 0 but found: 5');
  4710. } else {
  4711. // Note in unchecked mode we produce invalid output for invalid inputs.
  4712. // This test just documents our behavior in those cases.
  4713. // These values might change at any point and are not considered
  4714. // what the implementation should be doing here.
  4715. expectQualifiedIterable(
  4716. accessor.getRepeatedUint32Iterable(1),
  4717. (value) => Number.isInteger(value));
  4718. }
  4719. });
  4720. it('fail when adding unpacked uint32 values with null value', () => {
  4721. const accessor = Kernel.createEmpty();
  4722. const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
  4723. if (CHECK_CRITICAL_STATE) {
  4724. expect(() => accessor.addUnpackedUint32Iterable(1, [fakeUint32]))
  4725. .toThrowError('Must be a number, but got: null');
  4726. } else {
  4727. // Note in unchecked mode we produce invalid output for invalid inputs.
  4728. // This test just documents our behavior in those cases.
  4729. // These values might change at any point and are not considered
  4730. // what the implementation should be doing here.
  4731. accessor.addUnpackedUint32Iterable(1, [fakeUint32]);
  4732. expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
  4733. }
  4734. });
  4735. it('fail when adding single unpacked uint32 value with null value', () => {
  4736. const accessor = Kernel.createEmpty();
  4737. const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
  4738. if (CHECK_CRITICAL_STATE) {
  4739. expect(() => accessor.addUnpackedUint32Element(1, fakeUint32))
  4740. .toThrowError('Must be a number, but got: null');
  4741. } else {
  4742. // Note in unchecked mode we produce invalid output for invalid inputs.
  4743. // This test just documents our behavior in those cases.
  4744. // These values might change at any point and are not considered
  4745. // what the implementation should be doing here.
  4746. accessor.addUnpackedUint32Element(1, fakeUint32);
  4747. expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
  4748. }
  4749. });
  4750. it('fail when setting unpacked uint32 values with null value', () => {
  4751. const accessor = Kernel.createEmpty();
  4752. const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
  4753. if (CHECK_CRITICAL_STATE) {
  4754. expect(() => accessor.setUnpackedUint32Iterable(1, [fakeUint32]))
  4755. .toThrowError('Must be a number, but got: null');
  4756. } else {
  4757. // Note in unchecked mode we produce invalid output for invalid inputs.
  4758. // This test just documents our behavior in those cases.
  4759. // These values might change at any point and are not considered
  4760. // what the implementation should be doing here.
  4761. accessor.setUnpackedUint32Iterable(1, [fakeUint32]);
  4762. expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
  4763. }
  4764. });
  4765. it('fail when setting single unpacked uint32 value with null value', () => {
  4766. const accessor =
  4767. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  4768. const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
  4769. if (CHECK_CRITICAL_STATE) {
  4770. expect(() => accessor.setUnpackedUint32Element(1, 0, fakeUint32))
  4771. .toThrowError('Must be a number, but got: null');
  4772. } else {
  4773. // Note in unchecked mode we produce invalid output for invalid inputs.
  4774. // This test just documents our behavior in those cases.
  4775. // These values might change at any point and are not considered
  4776. // what the implementation should be doing here.
  4777. accessor.setUnpackedUint32Element(1, 0, fakeUint32);
  4778. expectQualifiedIterable(
  4779. accessor.getRepeatedUint32Iterable(1),
  4780. );
  4781. }
  4782. });
  4783. it('fail when adding packed uint32 values with null value', () => {
  4784. const accessor = Kernel.createEmpty();
  4785. const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
  4786. if (CHECK_CRITICAL_STATE) {
  4787. expect(() => accessor.addPackedUint32Iterable(1, [fakeUint32]))
  4788. .toThrowError('Must be a number, but got: null');
  4789. } else {
  4790. // Note in unchecked mode we produce invalid output for invalid inputs.
  4791. // This test just documents our behavior in those cases.
  4792. // These values might change at any point and are not considered
  4793. // what the implementation should be doing here.
  4794. accessor.addPackedUint32Iterable(1, [fakeUint32]);
  4795. expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
  4796. }
  4797. });
  4798. it('fail when adding single packed uint32 value with null value', () => {
  4799. const accessor = Kernel.createEmpty();
  4800. const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
  4801. if (CHECK_CRITICAL_STATE) {
  4802. expect(() => accessor.addPackedUint32Element(1, fakeUint32))
  4803. .toThrowError('Must be a number, but got: null');
  4804. } else {
  4805. // Note in unchecked mode we produce invalid output for invalid inputs.
  4806. // This test just documents our behavior in those cases.
  4807. // These values might change at any point and are not considered
  4808. // what the implementation should be doing here.
  4809. accessor.addPackedUint32Element(1, fakeUint32);
  4810. expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
  4811. }
  4812. });
  4813. it('fail when setting packed uint32 values with null value', () => {
  4814. const accessor = Kernel.createEmpty();
  4815. const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
  4816. if (CHECK_CRITICAL_STATE) {
  4817. expect(() => accessor.setPackedUint32Iterable(1, [fakeUint32]))
  4818. .toThrowError('Must be a number, but got: null');
  4819. } else {
  4820. // Note in unchecked mode we produce invalid output for invalid inputs.
  4821. // This test just documents our behavior in those cases.
  4822. // These values might change at any point and are not considered
  4823. // what the implementation should be doing here.
  4824. accessor.setPackedUint32Iterable(1, [fakeUint32]);
  4825. expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
  4826. }
  4827. });
  4828. it('fail when setting single packed uint32 value with null value', () => {
  4829. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  4830. const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
  4831. if (CHECK_CRITICAL_STATE) {
  4832. expect(() => accessor.setPackedUint32Element(1, 0, fakeUint32))
  4833. .toThrowError('Must be a number, but got: null');
  4834. } else {
  4835. // Note in unchecked mode we produce invalid output for invalid inputs.
  4836. // This test just documents our behavior in those cases.
  4837. // These values might change at any point and are not considered
  4838. // what the implementation should be doing here.
  4839. accessor.setPackedUint32Element(1, 0, fakeUint32);
  4840. expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
  4841. }
  4842. });
  4843. it('fail when setting single unpacked with out-of-bound index', () => {
  4844. const accessor =
  4845. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
  4846. if (CHECK_CRITICAL_STATE) {
  4847. expect(() => accessor.setUnpackedUint32Element(1, 1, 1))
  4848. .toThrowError('Index out of bounds: index: 1 size: 1');
  4849. } else {
  4850. // Note in unchecked mode we produce invalid output for invalid inputs.
  4851. // This test just documents our behavior in those cases.
  4852. // These values might change at any point and are not considered
  4853. // what the implementation should be doing here.
  4854. accessor.setUnpackedUint32Element(1, 1, 1);
  4855. expectQualifiedIterable(
  4856. accessor.getRepeatedUint32Iterable(1),
  4857. (value) => Number.isInteger(value));
  4858. }
  4859. });
  4860. it('fail when setting single packed with out-of-bound index', () => {
  4861. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  4862. if (CHECK_CRITICAL_STATE) {
  4863. expect(() => accessor.setPackedUint32Element(1, 1, 1))
  4864. .toThrowError('Index out of bounds: index: 1 size: 1');
  4865. } else {
  4866. // Note in unchecked mode we produce invalid output for invalid inputs.
  4867. // This test just documents our behavior in those cases.
  4868. // These values might change at any point and are not considered
  4869. // what the implementation should be doing here.
  4870. accessor.setPackedUint32Element(1, 1, 1);
  4871. expectQualifiedIterable(
  4872. accessor.getRepeatedUint32Iterable(1),
  4873. (value) => Number.isInteger(value));
  4874. }
  4875. });
  4876. it('fail when getting element with out-of-range index', () => {
  4877. const accessor = Kernel.createEmpty();
  4878. if (CHECK_CRITICAL_STATE) {
  4879. expect(() => {
  4880. accessor.getRepeatedUint32Element(
  4881. /* fieldNumber= */ 1, /* index= */ 0);
  4882. }).toThrowError('Index out of bounds: index: 0 size: 0');
  4883. } else {
  4884. // Note in unchecked mode we produce invalid output for invalid inputs.
  4885. // This test just documents our behavior in those cases.
  4886. // These values might change at any point and are not considered
  4887. // what the implementation should be doing here.
  4888. expect(accessor.getRepeatedUint32Element(
  4889. /* fieldNumber= */ 1, /* index= */ 0))
  4890. .toBe(undefined);
  4891. }
  4892. });
  4893. });
  4894. describe('Kernel for repeated uint64 does', () => {
  4895. const value1 = Int64.fromInt(1);
  4896. const value2 = Int64.fromInt(0);
  4897. const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
  4898. const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
  4899. const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
  4900. const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
  4901. it('return empty array for the empty input', () => {
  4902. const accessor = Kernel.createEmpty();
  4903. const list = accessor.getRepeatedUint64Iterable(1);
  4904. expectEqualToArray(list, []);
  4905. });
  4906. it('ensure not the same instance returned for the empty input', () => {
  4907. const accessor = Kernel.createEmpty();
  4908. const list1 = accessor.getRepeatedUint64Iterable(1);
  4909. const list2 = accessor.getRepeatedUint64Iterable(1);
  4910. expect(list1).not.toBe(list2);
  4911. });
  4912. it('return size for the empty input', () => {
  4913. const accessor = Kernel.createEmpty();
  4914. const size = accessor.getRepeatedUint64Size(1);
  4915. expect(size).toEqual(0);
  4916. });
  4917. it('return unpacked values from the input', () => {
  4918. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4919. const list = accessor.getRepeatedUint64Iterable(1);
  4920. expectEqualToArray(list, [value1, value2]);
  4921. });
  4922. it('ensure not the same instance returned for unpacked values', () => {
  4923. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4924. const list1 = accessor.getRepeatedUint64Iterable(1);
  4925. const list2 = accessor.getRepeatedUint64Iterable(1);
  4926. expect(list1).not.toBe(list2);
  4927. });
  4928. it('add single unpacked value', () => {
  4929. const accessor = Kernel.createEmpty();
  4930. accessor.addUnpackedUint64Element(1, value1);
  4931. const list1 = accessor.getRepeatedUint64Iterable(1);
  4932. accessor.addUnpackedUint64Element(1, value2);
  4933. const list2 = accessor.getRepeatedUint64Iterable(1);
  4934. expectEqualToArray(list1, [value1]);
  4935. expectEqualToArray(list2, [value1, value2]);
  4936. });
  4937. it('add unpacked values', () => {
  4938. const accessor = Kernel.createEmpty();
  4939. accessor.addUnpackedUint64Iterable(1, [value1]);
  4940. const list1 = accessor.getRepeatedUint64Iterable(1);
  4941. accessor.addUnpackedUint64Iterable(1, [value2]);
  4942. const list2 = accessor.getRepeatedUint64Iterable(1);
  4943. expectEqualToArray(list1, [value1]);
  4944. expectEqualToArray(list2, [value1, value2]);
  4945. });
  4946. it('set a single unpacked value', () => {
  4947. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  4948. accessor.setUnpackedUint64Element(1, 1, value1);
  4949. const list = accessor.getRepeatedUint64Iterable(1);
  4950. expectEqualToArray(list, [value1, value1]);
  4951. });
  4952. it('set unpacked values', () => {
  4953. const accessor = Kernel.createEmpty();
  4954. accessor.setUnpackedUint64Iterable(1, [value1]);
  4955. const list = accessor.getRepeatedUint64Iterable(1);
  4956. expectEqualToArray(list, [value1]);
  4957. });
  4958. it('encode for adding single unpacked value', () => {
  4959. const accessor = Kernel.createEmpty();
  4960. accessor.addUnpackedUint64Element(1, value1);
  4961. accessor.addUnpackedUint64Element(1, value2);
  4962. const serialized = accessor.serialize();
  4963. expect(serialized).toEqual(unpackedValue1Value2);
  4964. });
  4965. it('encode for adding unpacked values', () => {
  4966. const accessor = Kernel.createEmpty();
  4967. accessor.addUnpackedUint64Iterable(1, [value1]);
  4968. accessor.addUnpackedUint64Iterable(1, [value2]);
  4969. const serialized = accessor.serialize();
  4970. expect(serialized).toEqual(unpackedValue1Value2);
  4971. });
  4972. it('encode for setting single unpacked value', () => {
  4973. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  4974. accessor.setUnpackedUint64Element(1, 0, value2);
  4975. accessor.setUnpackedUint64Element(1, 1, value1);
  4976. const serialized = accessor.serialize();
  4977. expect(serialized).toEqual(unpackedValue2Value1);
  4978. });
  4979. it('encode for setting unpacked values', () => {
  4980. const accessor = Kernel.createEmpty();
  4981. accessor.setUnpackedUint64Iterable(1, [value1, value2]);
  4982. const serialized = accessor.serialize();
  4983. expect(serialized).toEqual(unpackedValue1Value2);
  4984. });
  4985. it('return packed values from the input', () => {
  4986. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  4987. const list = accessor.getRepeatedUint64Iterable(1);
  4988. expectEqualToArray(list, [value1, value2]);
  4989. });
  4990. it('ensure not the same instance returned for packed values', () => {
  4991. const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
  4992. const list1 = accessor.getRepeatedUint64Iterable(1);
  4993. const list2 = accessor.getRepeatedUint64Iterable(1);
  4994. expect(list1).not.toBe(list2);
  4995. });
  4996. it('add single packed value', () => {
  4997. const accessor = Kernel.createEmpty();
  4998. accessor.addPackedUint64Element(1, value1);
  4999. const list1 = accessor.getRepeatedUint64Iterable(1);
  5000. accessor.addPackedUint64Element(1, value2);
  5001. const list2 = accessor.getRepeatedUint64Iterable(1);
  5002. expectEqualToArray(list1, [value1]);
  5003. expectEqualToArray(list2, [value1, value2]);
  5004. });
  5005. it('add packed values', () => {
  5006. const accessor = Kernel.createEmpty();
  5007. accessor.addPackedUint64Iterable(1, [value1]);
  5008. const list1 = accessor.getRepeatedUint64Iterable(1);
  5009. accessor.addPackedUint64Iterable(1, [value2]);
  5010. const list2 = accessor.getRepeatedUint64Iterable(1);
  5011. expectEqualToArray(list1, [value1]);
  5012. expectEqualToArray(list2, [value1, value2]);
  5013. });
  5014. it('set a single packed value', () => {
  5015. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  5016. accessor.setPackedUint64Element(1, 1, value1);
  5017. const list = accessor.getRepeatedUint64Iterable(1);
  5018. expectEqualToArray(list, [value1, value1]);
  5019. });
  5020. it('set packed values', () => {
  5021. const accessor = Kernel.createEmpty();
  5022. accessor.setPackedUint64Iterable(1, [value1]);
  5023. const list1 = accessor.getRepeatedUint64Iterable(1);
  5024. accessor.setPackedUint64Iterable(1, [value2]);
  5025. const list2 = accessor.getRepeatedUint64Iterable(1);
  5026. expectEqualToArray(list1, [value1]);
  5027. expectEqualToArray(list2, [value2]);
  5028. });
  5029. it('encode for adding single packed value', () => {
  5030. const accessor = Kernel.createEmpty();
  5031. accessor.addPackedUint64Element(1, value1);
  5032. accessor.addPackedUint64Element(1, value2);
  5033. const serialized = accessor.serialize();
  5034. expect(serialized).toEqual(packedValue1Value2);
  5035. });
  5036. it('encode for adding packed values', () => {
  5037. const accessor = Kernel.createEmpty();
  5038. accessor.addPackedUint64Iterable(1, [value1, value2]);
  5039. const serialized = accessor.serialize();
  5040. expect(serialized).toEqual(packedValue1Value2);
  5041. });
  5042. it('encode for setting single packed value', () => {
  5043. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  5044. accessor.setPackedUint64Element(1, 0, value2);
  5045. accessor.setPackedUint64Element(1, 1, value1);
  5046. const serialized = accessor.serialize();
  5047. expect(serialized).toEqual(packedValue2Value1);
  5048. });
  5049. it('encode for setting packed values', () => {
  5050. const accessor = Kernel.createEmpty();
  5051. accessor.setPackedUint64Iterable(1, [value1, value2]);
  5052. const serialized = accessor.serialize();
  5053. expect(serialized).toEqual(packedValue1Value2);
  5054. });
  5055. it('return combined values from the input', () => {
  5056. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  5057. 0x08,
  5058. 0x01, // unpacked value1
  5059. 0x0A,
  5060. 0x02,
  5061. 0x01,
  5062. 0x00, // packed value1 and value2
  5063. 0x08,
  5064. 0x00, // unpacked value2
  5065. ));
  5066. const list = accessor.getRepeatedUint64Iterable(1);
  5067. expectEqualToArray(list, [value1, value1, value2, value2]);
  5068. });
  5069. it('return the repeated field element from the input', () => {
  5070. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  5071. const result1 = accessor.getRepeatedUint64Element(
  5072. /* fieldNumber= */ 1, /* index= */ 0);
  5073. const result2 = accessor.getRepeatedUint64Element(
  5074. /* fieldNumber= */ 1, /* index= */ 1);
  5075. expect(result1).toEqual(value1);
  5076. expect(result2).toEqual(value2);
  5077. });
  5078. it('return the size from the input', () => {
  5079. const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
  5080. const size = accessor.getRepeatedUint64Size(1);
  5081. expect(size).toEqual(2);
  5082. });
  5083. it('fail when getting unpacked uint64 value with other wire types', () => {
  5084. const accessor =
  5085. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  5086. if (CHECK_CRITICAL_STATE) {
  5087. expect(() => {
  5088. accessor.getRepeatedUint64Iterable(1);
  5089. }).toThrowError('Expected wire type: 0 but found: 5');
  5090. } else {
  5091. // Note in unchecked mode we produce invalid output for invalid inputs.
  5092. // This test just documents our behavior in those cases.
  5093. // These values might change at any point and are not considered
  5094. // what the implementation should be doing here.
  5095. expectQualifiedIterable(
  5096. accessor.getRepeatedUint64Iterable(1),
  5097. (value) => value instanceof Int64);
  5098. }
  5099. });
  5100. it('fail when adding unpacked uint64 values with null value', () => {
  5101. const accessor = Kernel.createEmpty();
  5102. const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  5103. if (CHECK_CRITICAL_STATE) {
  5104. expect(() => accessor.addUnpackedUint64Iterable(1, [fakeUint64]))
  5105. .toThrowError('Must be Int64 instance, but got: null');
  5106. } else {
  5107. // Note in unchecked mode we produce invalid output for invalid inputs.
  5108. // This test just documents our behavior in those cases.
  5109. // These values might change at any point and are not considered
  5110. // what the implementation should be doing here.
  5111. accessor.addUnpackedUint64Iterable(1, [fakeUint64]);
  5112. expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
  5113. }
  5114. });
  5115. it('fail when adding single unpacked uint64 value with null value', () => {
  5116. const accessor = Kernel.createEmpty();
  5117. const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  5118. if (CHECK_CRITICAL_STATE) {
  5119. expect(() => accessor.addUnpackedUint64Element(1, fakeUint64))
  5120. .toThrowError('Must be Int64 instance, but got: null');
  5121. } else {
  5122. // Note in unchecked mode we produce invalid output for invalid inputs.
  5123. // This test just documents our behavior in those cases.
  5124. // These values might change at any point and are not considered
  5125. // what the implementation should be doing here.
  5126. accessor.addUnpackedUint64Element(1, fakeUint64);
  5127. expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
  5128. }
  5129. });
  5130. it('fail when setting unpacked uint64 values with null value', () => {
  5131. const accessor = Kernel.createEmpty();
  5132. const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  5133. if (CHECK_CRITICAL_STATE) {
  5134. expect(() => accessor.setUnpackedUint64Iterable(1, [fakeUint64]))
  5135. .toThrowError('Must be Int64 instance, but got: null');
  5136. } else {
  5137. // Note in unchecked mode we produce invalid output for invalid inputs.
  5138. // This test just documents our behavior in those cases.
  5139. // These values might change at any point and are not considered
  5140. // what the implementation should be doing here.
  5141. accessor.setUnpackedUint64Iterable(1, [fakeUint64]);
  5142. expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
  5143. }
  5144. });
  5145. it('fail when setting single unpacked uint64 value with null value', () => {
  5146. const accessor =
  5147. Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
  5148. const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  5149. if (CHECK_CRITICAL_STATE) {
  5150. expect(() => accessor.setUnpackedUint64Element(1, 0, fakeUint64))
  5151. .toThrowError('Must be Int64 instance, but got: null');
  5152. } else {
  5153. // Note in unchecked mode we produce invalid output for invalid inputs.
  5154. // This test just documents our behavior in those cases.
  5155. // These values might change at any point and are not considered
  5156. // what the implementation should be doing here.
  5157. accessor.setUnpackedUint64Element(1, 0, fakeUint64);
  5158. expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
  5159. }
  5160. });
  5161. it('fail when adding packed uint64 values with null value', () => {
  5162. const accessor = Kernel.createEmpty();
  5163. const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  5164. if (CHECK_CRITICAL_STATE) {
  5165. expect(() => accessor.addPackedUint64Iterable(1, [fakeUint64]))
  5166. .toThrowError('Must be Int64 instance, but got: null');
  5167. } else {
  5168. // Note in unchecked mode we produce invalid output for invalid inputs.
  5169. // This test just documents our behavior in those cases.
  5170. // These values might change at any point and are not considered
  5171. // what the implementation should be doing here.
  5172. accessor.addPackedUint64Iterable(1, [fakeUint64]);
  5173. expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
  5174. }
  5175. });
  5176. it('fail when adding single packed uint64 value with null value', () => {
  5177. const accessor = Kernel.createEmpty();
  5178. const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  5179. if (CHECK_CRITICAL_STATE) {
  5180. expect(() => accessor.addPackedUint64Element(1, fakeUint64))
  5181. .toThrowError('Must be Int64 instance, but got: null');
  5182. } else {
  5183. // Note in unchecked mode we produce invalid output for invalid inputs.
  5184. // This test just documents our behavior in those cases.
  5185. // These values might change at any point and are not considered
  5186. // what the implementation should be doing here.
  5187. accessor.addPackedUint64Element(1, fakeUint64);
  5188. expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
  5189. }
  5190. });
  5191. it('fail when setting packed uint64 values with null value', () => {
  5192. const accessor = Kernel.createEmpty();
  5193. const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  5194. if (CHECK_CRITICAL_STATE) {
  5195. expect(() => accessor.setPackedUint64Iterable(1, [fakeUint64]))
  5196. .toThrowError('Must be Int64 instance, but got: null');
  5197. } else {
  5198. // Note in unchecked mode we produce invalid output for invalid inputs.
  5199. // This test just documents our behavior in those cases.
  5200. // These values might change at any point and are not considered
  5201. // what the implementation should be doing here.
  5202. accessor.setPackedUint64Iterable(1, [fakeUint64]);
  5203. expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
  5204. }
  5205. });
  5206. it('fail when setting single packed uint64 value with null value', () => {
  5207. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  5208. const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
  5209. if (CHECK_CRITICAL_STATE) {
  5210. expect(() => accessor.setPackedUint64Element(1, 0, fakeUint64))
  5211. .toThrowError('Must be Int64 instance, but got: null');
  5212. } else {
  5213. // Note in unchecked mode we produce invalid output for invalid inputs.
  5214. // This test just documents our behavior in those cases.
  5215. // These values might change at any point and are not considered
  5216. // what the implementation should be doing here.
  5217. accessor.setPackedUint64Element(1, 0, fakeUint64);
  5218. expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
  5219. }
  5220. });
  5221. it('fail when setting single unpacked with out-of-bound index', () => {
  5222. const accessor =
  5223. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
  5224. if (CHECK_CRITICAL_STATE) {
  5225. expect(() => accessor.setUnpackedUint64Element(1, 1, Int64.fromInt(1)))
  5226. .toThrowError('Index out of bounds: index: 1 size: 1');
  5227. } else {
  5228. // Note in unchecked mode we produce invalid output for invalid inputs.
  5229. // This test just documents our behavior in those cases.
  5230. // These values might change at any point and are not considered
  5231. // what the implementation should be doing here.
  5232. accessor.setUnpackedUint64Element(1, 1, Int64.fromInt(1));
  5233. expectQualifiedIterable(
  5234. accessor.getRepeatedUint64Iterable(1),
  5235. (value) => value instanceof Int64);
  5236. }
  5237. });
  5238. it('fail when setting single packed with out-of-bound index', () => {
  5239. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
  5240. if (CHECK_CRITICAL_STATE) {
  5241. expect(() => accessor.setPackedUint64Element(1, 1, Int64.fromInt(1)))
  5242. .toThrowError('Index out of bounds: index: 1 size: 1');
  5243. } else {
  5244. // Note in unchecked mode we produce invalid output for invalid inputs.
  5245. // This test just documents our behavior in those cases.
  5246. // These values might change at any point and are not considered
  5247. // what the implementation should be doing here.
  5248. accessor.setPackedUint64Element(1, 1, Int64.fromInt(1));
  5249. expectQualifiedIterable(
  5250. accessor.getRepeatedUint64Iterable(1),
  5251. (value) => value instanceof Int64);
  5252. }
  5253. });
  5254. it('fail when getting element with out-of-range index', () => {
  5255. const accessor = Kernel.createEmpty();
  5256. if (CHECK_CRITICAL_STATE) {
  5257. expect(() => {
  5258. accessor.getRepeatedUint64Element(
  5259. /* fieldNumber= */ 1, /* index= */ 0);
  5260. }).toThrowError('Index out of bounds: index: 0 size: 0');
  5261. } else {
  5262. // Note in unchecked mode we produce invalid output for invalid inputs.
  5263. // This test just documents our behavior in those cases.
  5264. // These values might change at any point and are not considered
  5265. // what the implementation should be doing here.
  5266. expect(accessor.getRepeatedUint64Element(
  5267. /* fieldNumber= */ 1, /* index= */ 0))
  5268. .toBe(undefined);
  5269. }
  5270. });
  5271. });
  5272. describe('Kernel for repeated bytes does', () => {
  5273. const value1 = ByteString.fromArrayBuffer((createArrayBuffer(0x61)));
  5274. const value2 = ByteString.fromArrayBuffer((createArrayBuffer(0x62)));
  5275. const repeatedValue1Value2 = createArrayBuffer(
  5276. 0x0A,
  5277. 0x01,
  5278. 0x61, // value1
  5279. 0x0A,
  5280. 0x01,
  5281. 0x62, // value2
  5282. );
  5283. const repeatedValue2Value1 = createArrayBuffer(
  5284. 0x0A,
  5285. 0x01,
  5286. 0x62, // value2
  5287. 0x0A,
  5288. 0x01,
  5289. 0x61, // value1
  5290. );
  5291. it('return empty array for the empty input', () => {
  5292. const accessor = Kernel.createEmpty();
  5293. const list = accessor.getRepeatedBytesIterable(1);
  5294. expectEqualToArray(list, []);
  5295. });
  5296. it('ensure not the same instance returned for the empty input', () => {
  5297. const accessor = Kernel.createEmpty();
  5298. const list1 = accessor.getRepeatedBytesIterable(1);
  5299. const list2 = accessor.getRepeatedBytesIterable(1);
  5300. expect(list1).not.toBe(list2);
  5301. });
  5302. it('return size for the empty input', () => {
  5303. const accessor = Kernel.createEmpty();
  5304. const size = accessor.getRepeatedBytesSize(1);
  5305. expect(size).toEqual(0);
  5306. });
  5307. it('return values from the input', () => {
  5308. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5309. const list = accessor.getRepeatedBytesIterable(1);
  5310. expectEqualToArray(list, [value1, value2]);
  5311. });
  5312. it('ensure not the same instance returned for values', () => {
  5313. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5314. const list1 = accessor.getRepeatedBytesIterable(1);
  5315. const list2 = accessor.getRepeatedBytesIterable(1);
  5316. expect(list1).not.toBe(list2);
  5317. });
  5318. it('add single value', () => {
  5319. const accessor = Kernel.createEmpty();
  5320. accessor.addRepeatedBytesElement(1, value1);
  5321. const list1 = accessor.getRepeatedBytesIterable(1);
  5322. accessor.addRepeatedBytesElement(1, value2);
  5323. const list2 = accessor.getRepeatedBytesIterable(1);
  5324. expectEqualToArray(list1, [value1]);
  5325. expectEqualToArray(list2, [value1, value2]);
  5326. });
  5327. it('add values', () => {
  5328. const accessor = Kernel.createEmpty();
  5329. accessor.addRepeatedBytesIterable(1, [value1]);
  5330. const list1 = accessor.getRepeatedBytesIterable(1);
  5331. accessor.addRepeatedBytesIterable(1, [value2]);
  5332. const list2 = accessor.getRepeatedBytesIterable(1);
  5333. expectEqualToArray(list1, [value1]);
  5334. expectEqualToArray(list2, [value1, value2]);
  5335. });
  5336. it('set a single value', () => {
  5337. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5338. accessor.setRepeatedBytesElement(1, 1, value1);
  5339. const list = accessor.getRepeatedBytesIterable(1);
  5340. expectEqualToArray(list, [value1, value1]);
  5341. });
  5342. it('set values', () => {
  5343. const accessor = Kernel.createEmpty();
  5344. accessor.setRepeatedBytesIterable(1, [value1]);
  5345. const list = accessor.getRepeatedBytesIterable(1);
  5346. expectEqualToArray(list, [value1]);
  5347. });
  5348. it('encode for adding single value', () => {
  5349. const accessor = Kernel.createEmpty();
  5350. accessor.addRepeatedBytesElement(1, value1);
  5351. accessor.addRepeatedBytesElement(1, value2);
  5352. const serialized = accessor.serialize();
  5353. expect(serialized).toEqual(repeatedValue1Value2);
  5354. });
  5355. it('encode for adding values', () => {
  5356. const accessor = Kernel.createEmpty();
  5357. accessor.addRepeatedBytesIterable(1, [value1]);
  5358. accessor.addRepeatedBytesIterable(1, [value2]);
  5359. const serialized = accessor.serialize();
  5360. expect(serialized).toEqual(repeatedValue1Value2);
  5361. });
  5362. it('encode for setting single value', () => {
  5363. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5364. accessor.setRepeatedBytesElement(1, 0, value2);
  5365. accessor.setRepeatedBytesElement(1, 1, value1);
  5366. const serialized = accessor.serialize();
  5367. expect(serialized).toEqual(repeatedValue2Value1);
  5368. });
  5369. it('encode for setting values', () => {
  5370. const accessor = Kernel.createEmpty();
  5371. accessor.setRepeatedBytesIterable(1, [value1, value2]);
  5372. const serialized = accessor.serialize();
  5373. expect(serialized).toEqual(repeatedValue1Value2);
  5374. });
  5375. it('return the repeated field element from the input', () => {
  5376. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5377. const result1 = accessor.getRepeatedBytesElement(
  5378. /* fieldNumber= */ 1, /* index= */ 0);
  5379. const result2 = accessor.getRepeatedBytesElement(
  5380. /* fieldNumber= */ 1, /* index= */ 1);
  5381. expect(result1).toEqual(value1);
  5382. expect(result2).toEqual(value2);
  5383. });
  5384. it('return the size from the input', () => {
  5385. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5386. const size = accessor.getRepeatedBytesSize(1);
  5387. expect(size).toEqual(2);
  5388. });
  5389. it('fail when getting bytes value with other wire types', () => {
  5390. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  5391. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  5392. if (CHECK_CRITICAL_STATE) {
  5393. expect(() => {
  5394. accessor.getRepeatedBytesIterable(1);
  5395. }).toThrowError('Expected wire type: 2 but found: 0');
  5396. } else {
  5397. // Note in unchecked mode we produce invalid output for invalid inputs.
  5398. // This test just documents our behavior in those cases.
  5399. // These values might change at any point and are not considered
  5400. // what the implementation should be doing here.
  5401. expectQualifiedIterable(
  5402. accessor.getRepeatedBytesIterable(1),
  5403. (value) => value instanceof ByteString);
  5404. }
  5405. });
  5406. it('fail when adding bytes values with null value', () => {
  5407. const accessor = Kernel.createEmpty();
  5408. const fakeBytes = /** @type {!ByteString} */ (/** @type {*} */ (null));
  5409. if (CHECK_CRITICAL_STATE) {
  5410. expect(() => accessor.addRepeatedBytesIterable(1, [fakeBytes]))
  5411. .toThrowError('Must be a ByteString, but got: null');
  5412. } else {
  5413. // Note in unchecked mode we produce invalid output for invalid inputs.
  5414. // This test just documents our behavior in those cases.
  5415. // These values might change at any point and are not considered
  5416. // what the implementation should be doing here.
  5417. accessor.addRepeatedBytesIterable(1, [fakeBytes]);
  5418. expectQualifiedIterable(accessor.getRepeatedBytesIterable(1));
  5419. }
  5420. });
  5421. it('fail when adding single bytes value with null value', () => {
  5422. const accessor = Kernel.createEmpty();
  5423. const fakeBytes = /** @type {!ByteString} */ (/** @type {*} */ (null));
  5424. if (CHECK_CRITICAL_STATE) {
  5425. expect(() => accessor.addRepeatedBytesElement(1, fakeBytes))
  5426. .toThrowError('Must be a ByteString, but got: null');
  5427. } else {
  5428. // Note in unchecked mode we produce invalid output for invalid inputs.
  5429. // This test just documents our behavior in those cases.
  5430. // These values might change at any point and are not considered
  5431. // what the implementation should be doing here.
  5432. accessor.addRepeatedBytesElement(1, fakeBytes);
  5433. expectQualifiedIterable(accessor.getRepeatedBytesIterable(1));
  5434. }
  5435. });
  5436. it('fail when setting bytes values with null value', () => {
  5437. const accessor = Kernel.createEmpty();
  5438. const fakeBytes = /** @type {!ByteString} */ (/** @type {*} */ (null));
  5439. if (CHECK_CRITICAL_STATE) {
  5440. expect(() => accessor.setRepeatedBytesIterable(1, [fakeBytes]))
  5441. .toThrowError('Must be a ByteString, but got: null');
  5442. } else {
  5443. // Note in unchecked mode we produce invalid output for invalid inputs.
  5444. // This test just documents our behavior in those cases.
  5445. // These values might change at any point and are not considered
  5446. // what the implementation should be doing here.
  5447. accessor.setRepeatedBytesIterable(1, [fakeBytes]);
  5448. expectQualifiedIterable(accessor.getRepeatedBytesIterable(1));
  5449. }
  5450. });
  5451. it('fail when setting single bytes value with null value', () => {
  5452. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  5453. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  5454. const fakeBytes = /** @type {!ByteString} */ (/** @type {*} */ (null));
  5455. if (CHECK_CRITICAL_STATE) {
  5456. expect(() => accessor.setRepeatedBytesElement(1, 0, fakeBytes))
  5457. .toThrowError('Must be a ByteString, but got: null');
  5458. } else {
  5459. // Note in unchecked mode we produce invalid output for invalid inputs.
  5460. // This test just documents our behavior in those cases.
  5461. // These values might change at any point and are not considered
  5462. // what the implementation should be doing here.
  5463. accessor.setRepeatedBytesElement(1, 0, fakeBytes);
  5464. expectQualifiedIterable(accessor.getRepeatedBytesIterable(1));
  5465. }
  5466. });
  5467. it('fail when setting single with out-of-bound index', () => {
  5468. const accessor =
  5469. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x61));
  5470. if (CHECK_CRITICAL_STATE) {
  5471. expect(() => accessor.setRepeatedBytesElement(1, 1, value1))
  5472. .toThrowError('Index out of bounds: index: 1 size: 1');
  5473. } else {
  5474. // Note in unchecked mode we produce invalid output for invalid inputs.
  5475. // This test just documents our behavior in those cases.
  5476. // These values might change at any point and are not considered
  5477. // what the implementation should be doing here.
  5478. accessor.setRepeatedBytesElement(1, 1, value1);
  5479. expectQualifiedIterable(
  5480. accessor.getRepeatedBytesIterable(1),
  5481. (value) => value instanceof ByteString);
  5482. }
  5483. });
  5484. it('fail when getting element with out-of-range index', () => {
  5485. const accessor = Kernel.createEmpty();
  5486. if (CHECK_CRITICAL_STATE) {
  5487. expect(() => {
  5488. accessor.getRepeatedBytesElement(
  5489. /* fieldNumber= */ 1, /* index= */ 0);
  5490. }).toThrowError('Index out of bounds: index: 0 size: 0');
  5491. } else {
  5492. // Note in unchecked mode we produce invalid output for invalid inputs.
  5493. // This test just documents our behavior in those cases.
  5494. // These values might change at any point and are not considered
  5495. // what the implementation should be doing here.
  5496. expect(accessor.getRepeatedBytesElement(
  5497. /* fieldNumber= */ 1, /* index= */ 0))
  5498. .toBe(undefined);
  5499. }
  5500. });
  5501. });
  5502. describe('Kernel for repeated string does', () => {
  5503. const value1 = 'a';
  5504. const value2 = 'b';
  5505. const repeatedValue1Value2 = createArrayBuffer(
  5506. 0x0A,
  5507. 0x01,
  5508. 0x61, // value1
  5509. 0x0A,
  5510. 0x01,
  5511. 0x62, // value2
  5512. );
  5513. const repeatedValue2Value1 = createArrayBuffer(
  5514. 0x0A,
  5515. 0x01,
  5516. 0x62, // value2
  5517. 0x0A,
  5518. 0x01,
  5519. 0x61, // value1
  5520. );
  5521. it('return empty array for the empty input', () => {
  5522. const accessor = Kernel.createEmpty();
  5523. const list = accessor.getRepeatedStringIterable(1);
  5524. expectEqualToArray(list, []);
  5525. });
  5526. it('ensure not the same instance returned for the empty input', () => {
  5527. const accessor = Kernel.createEmpty();
  5528. const list1 = accessor.getRepeatedStringIterable(1);
  5529. const list2 = accessor.getRepeatedStringIterable(1);
  5530. expect(list1).not.toBe(list2);
  5531. });
  5532. it('return size for the empty input', () => {
  5533. const accessor = Kernel.createEmpty();
  5534. const size = accessor.getRepeatedStringSize(1);
  5535. expect(size).toEqual(0);
  5536. });
  5537. it('return values from the input', () => {
  5538. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5539. const list = accessor.getRepeatedStringIterable(1);
  5540. expectEqualToArray(list, [value1, value2]);
  5541. });
  5542. it('ensure not the same instance returned for values', () => {
  5543. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5544. const list1 = accessor.getRepeatedStringIterable(1);
  5545. const list2 = accessor.getRepeatedStringIterable(1);
  5546. expect(list1).not.toBe(list2);
  5547. });
  5548. it('add single value', () => {
  5549. const accessor = Kernel.createEmpty();
  5550. accessor.addRepeatedStringElement(1, value1);
  5551. const list1 = accessor.getRepeatedStringIterable(1);
  5552. accessor.addRepeatedStringElement(1, value2);
  5553. const list2 = accessor.getRepeatedStringIterable(1);
  5554. expectEqualToArray(list1, [value1]);
  5555. expectEqualToArray(list2, [value1, value2]);
  5556. });
  5557. it('add values', () => {
  5558. const accessor = Kernel.createEmpty();
  5559. accessor.addRepeatedStringIterable(1, [value1]);
  5560. const list1 = accessor.getRepeatedStringIterable(1);
  5561. accessor.addRepeatedStringIterable(1, [value2]);
  5562. const list2 = accessor.getRepeatedStringIterable(1);
  5563. expectEqualToArray(list1, [value1]);
  5564. expectEqualToArray(list2, [value1, value2]);
  5565. });
  5566. it('set a single value', () => {
  5567. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5568. accessor.setRepeatedStringElement(1, 1, value1);
  5569. const list = accessor.getRepeatedStringIterable(1);
  5570. expectEqualToArray(list, [value1, value1]);
  5571. });
  5572. it('set values', () => {
  5573. const accessor = Kernel.createEmpty();
  5574. accessor.setRepeatedStringIterable(1, [value1]);
  5575. const list = accessor.getRepeatedStringIterable(1);
  5576. expectEqualToArray(list, [value1]);
  5577. });
  5578. it('encode for adding single value', () => {
  5579. const accessor = Kernel.createEmpty();
  5580. accessor.addRepeatedStringElement(1, value1);
  5581. accessor.addRepeatedStringElement(1, value2);
  5582. const serialized = accessor.serialize();
  5583. expect(serialized).toEqual(repeatedValue1Value2);
  5584. });
  5585. it('encode for adding values', () => {
  5586. const accessor = Kernel.createEmpty();
  5587. accessor.addRepeatedStringIterable(1, [value1]);
  5588. accessor.addRepeatedStringIterable(1, [value2]);
  5589. const serialized = accessor.serialize();
  5590. expect(serialized).toEqual(repeatedValue1Value2);
  5591. });
  5592. it('encode for setting single value', () => {
  5593. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5594. accessor.setRepeatedStringElement(1, 0, value2);
  5595. accessor.setRepeatedStringElement(1, 1, value1);
  5596. const serialized = accessor.serialize();
  5597. expect(serialized).toEqual(repeatedValue2Value1);
  5598. });
  5599. it('encode for setting values', () => {
  5600. const accessor = Kernel.createEmpty();
  5601. accessor.setRepeatedStringIterable(1, [value1, value2]);
  5602. const serialized = accessor.serialize();
  5603. expect(serialized).toEqual(repeatedValue1Value2);
  5604. });
  5605. it('return the repeated field element from the input', () => {
  5606. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5607. const result1 = accessor.getRepeatedStringElement(
  5608. /* fieldNumber= */ 1, /* index= */ 0);
  5609. const result2 = accessor.getRepeatedStringElement(
  5610. /* fieldNumber= */ 1, /* index= */ 1);
  5611. expect(result1).toEqual(value1);
  5612. expect(result2).toEqual(value2);
  5613. });
  5614. it('return the size from the input', () => {
  5615. const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
  5616. const size = accessor.getRepeatedStringSize(1);
  5617. expect(size).toEqual(2);
  5618. });
  5619. it('fail when getting string value with other wire types', () => {
  5620. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  5621. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  5622. if (CHECK_CRITICAL_STATE) {
  5623. expect(() => {
  5624. accessor.getRepeatedStringIterable(1);
  5625. }).toThrowError('Expected wire type: 2 but found: 0');
  5626. } else {
  5627. // Note in unchecked mode we produce invalid output for invalid inputs.
  5628. // This test just documents our behavior in those cases.
  5629. // These values might change at any point and are not considered
  5630. // what the implementation should be doing here.
  5631. expectQualifiedIterable(
  5632. accessor.getRepeatedStringIterable(1),
  5633. (value) => typeof value === 'string');
  5634. }
  5635. });
  5636. it('fail when adding string values with null value', () => {
  5637. const accessor = Kernel.createEmpty();
  5638. const fakeString = /** @type {string} */ (/** @type {*} */ (null));
  5639. if (CHECK_CRITICAL_STATE) {
  5640. expect(() => accessor.addRepeatedStringIterable(1, [fakeString]))
  5641. .toThrowError('Must be string, but got: null');
  5642. } else {
  5643. // Note in unchecked mode we produce invalid output for invalid inputs.
  5644. // This test just documents our behavior in those cases.
  5645. // These values might change at any point and are not considered
  5646. // what the implementation should be doing here.
  5647. accessor.addRepeatedStringIterable(1, [fakeString]);
  5648. expectQualifiedIterable(accessor.getRepeatedStringIterable(1));
  5649. }
  5650. });
  5651. it('fail when adding single string value with null value', () => {
  5652. const accessor = Kernel.createEmpty();
  5653. const fakeString = /** @type {string} */ (/** @type {*} */ (null));
  5654. if (CHECK_CRITICAL_STATE) {
  5655. expect(() => accessor.addRepeatedStringElement(1, fakeString))
  5656. .toThrowError('Must be string, but got: null');
  5657. } else {
  5658. // Note in unchecked mode we produce invalid output for invalid inputs.
  5659. // This test just documents our behavior in those cases.
  5660. // These values might change at any point and are not considered
  5661. // what the implementation should be doing here.
  5662. accessor.addRepeatedStringElement(1, fakeString);
  5663. expectQualifiedIterable(accessor.getRepeatedStringIterable(1));
  5664. }
  5665. });
  5666. it('fail when setting string values with null value', () => {
  5667. const accessor = Kernel.createEmpty();
  5668. const fakeString = /** @type {string} */ (/** @type {*} */ (null));
  5669. if (CHECK_CRITICAL_STATE) {
  5670. expect(() => accessor.setRepeatedStringIterable(1, [fakeString]))
  5671. .toThrowError('Must be string, but got: null');
  5672. } else {
  5673. // Note in unchecked mode we produce invalid output for invalid inputs.
  5674. // This test just documents our behavior in those cases.
  5675. // These values might change at any point and are not considered
  5676. // what the implementation should be doing here.
  5677. accessor.setRepeatedStringIterable(1, [fakeString]);
  5678. expectQualifiedIterable(accessor.getRepeatedStringIterable(1));
  5679. }
  5680. });
  5681. it('fail when setting single string value with null value', () => {
  5682. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  5683. 0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
  5684. const fakeString = /** @type {string} */ (/** @type {*} */ (null));
  5685. if (CHECK_CRITICAL_STATE) {
  5686. expect(() => accessor.setRepeatedStringElement(1, 0, fakeString))
  5687. .toThrowError('Must be string, but got: null');
  5688. } else {
  5689. // Note in unchecked mode we produce invalid output for invalid inputs.
  5690. // This test just documents our behavior in those cases.
  5691. // These values might change at any point and are not considered
  5692. // what the implementation should be doing here.
  5693. accessor.setRepeatedStringElement(1, 0, fakeString);
  5694. expectQualifiedIterable(accessor.getRepeatedStringIterable(1));
  5695. }
  5696. });
  5697. it('fail when setting single with out-of-bound index', () => {
  5698. const accessor =
  5699. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x61));
  5700. if (CHECK_CRITICAL_STATE) {
  5701. expect(() => accessor.setRepeatedStringElement(1, 1, value1))
  5702. .toThrowError('Index out of bounds: index: 1 size: 1');
  5703. } else {
  5704. // Note in unchecked mode we produce invalid output for invalid inputs.
  5705. // This test just documents our behavior in those cases.
  5706. // These values might change at any point and are not considered
  5707. // what the implementation should be doing here.
  5708. accessor.setRepeatedStringElement(1, 1, value1);
  5709. expectQualifiedIterable(
  5710. accessor.getRepeatedStringIterable(1),
  5711. (value) => typeof value === 'string');
  5712. }
  5713. });
  5714. it('fail when getting element with out-of-range index', () => {
  5715. const accessor = Kernel.createEmpty();
  5716. if (CHECK_CRITICAL_STATE) {
  5717. expect(() => {
  5718. accessor.getRepeatedStringElement(
  5719. /* fieldNumber= */ 1, /* index= */ 0);
  5720. }).toThrowError('Index out of bounds: index: 0 size: 0');
  5721. } else {
  5722. // Note in unchecked mode we produce invalid output for invalid inputs.
  5723. // This test just documents our behavior in those cases.
  5724. // These values might change at any point and are not considered
  5725. // what the implementation should be doing here.
  5726. expect(accessor.getRepeatedStringElement(
  5727. /* fieldNumber= */ 1, /* index= */ 0))
  5728. .toBe(undefined);
  5729. }
  5730. });
  5731. });
  5732. describe('Kernel for repeated message does', () => {
  5733. it('return empty array for the empty input', () => {
  5734. const accessor = Kernel.createEmpty();
  5735. expectEqualToArray(
  5736. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator),
  5737. []);
  5738. });
  5739. it('return empty accessor array for the empty input', () => {
  5740. const accessor = Kernel.createEmpty();
  5741. expectEqualToArray(accessor.getRepeatedMessageAccessorIterable(1), []);
  5742. });
  5743. it('ensure not the same instance returned for the empty input', () => {
  5744. const accessor = Kernel.createEmpty();
  5745. const list1 =
  5746. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5747. const list2 =
  5748. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5749. expect(list1).not.toBe(list2);
  5750. });
  5751. it('return size for the empty input', () => {
  5752. const accessor = Kernel.createEmpty();
  5753. expect(accessor.getRepeatedMessageSize(1, TestMessage.instanceCreator))
  5754. .toEqual(0);
  5755. });
  5756. it('return values from the input', () => {
  5757. const bytes1 = createArrayBuffer(0x08, 0x01);
  5758. const bytes2 = createArrayBuffer(0x08, 0x00);
  5759. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  5760. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  5761. const bytes =
  5762. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5763. const accessor = Kernel.fromArrayBuffer(bytes);
  5764. expectEqualToMessageArray(
  5765. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator),
  5766. [msg1, msg2]);
  5767. });
  5768. it('ensure not the same array instance returned', () => {
  5769. const bytes =
  5770. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5771. const accessor = Kernel.fromArrayBuffer(bytes);
  5772. const list1 =
  5773. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5774. const list2 =
  5775. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5776. expect(list1).not.toBe(list2);
  5777. });
  5778. it('ensure the same array element returned for get iterable', () => {
  5779. const bytes =
  5780. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5781. const accessor = Kernel.fromArrayBuffer(bytes);
  5782. const list1 =
  5783. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5784. const list2 = accessor.getRepeatedMessageIterable(
  5785. 1, TestMessage.instanceCreator, /* pivot= */ 0);
  5786. const array1 = Array.from(list1);
  5787. const array2 = Array.from(list2);
  5788. for (let i = 0; i < array1.length; i++) {
  5789. expect(array1[i]).toBe(array2[i]);
  5790. }
  5791. });
  5792. it('return accessors from the input', () => {
  5793. const bytes =
  5794. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5795. const accessor = Kernel.fromArrayBuffer(bytes);
  5796. const [accessor1, accessor2] =
  5797. [...accessor.getRepeatedMessageAccessorIterable(1)];
  5798. expect(accessor1.getInt32WithDefault(1)).toEqual(1);
  5799. expect(accessor2.getInt32WithDefault(1)).toEqual(0);
  5800. });
  5801. it('return accessors from the input when pivot is set', () => {
  5802. const bytes =
  5803. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5804. const accessor = Kernel.fromArrayBuffer(bytes);
  5805. const [accessor1, accessor2] =
  5806. [...accessor.getRepeatedMessageAccessorIterable(1, /* pivot= */ 0)];
  5807. expect(accessor1.getInt32WithDefault(1)).toEqual(1);
  5808. expect(accessor2.getInt32WithDefault(1)).toEqual(0);
  5809. });
  5810. it('return the repeated field element from the input', () => {
  5811. const bytes =
  5812. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5813. const accessor = Kernel.fromArrayBuffer(bytes);
  5814. const msg1 = accessor.getRepeatedMessageElement(
  5815. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  5816. /* index= */ 0);
  5817. const msg2 = accessor.getRepeatedMessageElement(
  5818. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  5819. /* index= */ 1, /* pivot= */ 0);
  5820. expect(msg1.getBoolWithDefault(
  5821. /* fieldNumber= */ 1, /* default= */ false))
  5822. .toEqual(true);
  5823. expect(msg2.getBoolWithDefault(
  5824. /* fieldNumber= */ 1, /* default= */ false))
  5825. .toEqual(false);
  5826. });
  5827. it('ensure the same array element returned', () => {
  5828. const bytes = createArrayBuffer(0x0A, 0x02, 0x08, 0x01);
  5829. const accessor = Kernel.fromArrayBuffer(bytes);
  5830. const msg1 = accessor.getRepeatedMessageElement(
  5831. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  5832. /* index= */ 0);
  5833. const msg2 = accessor.getRepeatedMessageElement(
  5834. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  5835. /* index= */ 0);
  5836. expect(msg1).toBe(msg2);
  5837. });
  5838. it('return the size from the input', () => {
  5839. const bytes =
  5840. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5841. const accessor = Kernel.fromArrayBuffer(bytes);
  5842. expect(accessor.getRepeatedMessageSize(1, TestMessage.instanceCreator))
  5843. .toEqual(2);
  5844. });
  5845. it('encode repeated message from the input', () => {
  5846. const bytes =
  5847. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5848. const accessor = Kernel.fromArrayBuffer(bytes);
  5849. expect(accessor.serialize()).toEqual(bytes);
  5850. });
  5851. it('add a single value', () => {
  5852. const accessor = Kernel.createEmpty();
  5853. const bytes1 = createArrayBuffer(0x08, 0x01);
  5854. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  5855. const bytes2 = createArrayBuffer(0x08, 0x00);
  5856. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  5857. accessor.addRepeatedMessageElement(1, msg1, TestMessage.instanceCreator);
  5858. accessor.addRepeatedMessageElement(1, msg2, TestMessage.instanceCreator);
  5859. const result =
  5860. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5861. expect(Array.from(result)).toEqual([msg1, msg2]);
  5862. });
  5863. it('add values', () => {
  5864. const accessor = Kernel.createEmpty();
  5865. const bytes1 = createArrayBuffer(0x08, 0x01);
  5866. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  5867. const bytes2 = createArrayBuffer(0x08, 0x00);
  5868. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  5869. accessor.addRepeatedMessageIterable(1, [msg1], TestMessage.instanceCreator);
  5870. accessor.addRepeatedMessageIterable(1, [msg2], TestMessage.instanceCreator);
  5871. const result =
  5872. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5873. expect(Array.from(result)).toEqual([msg1, msg2]);
  5874. });
  5875. it('set a single value', () => {
  5876. const bytes = createArrayBuffer(0x0A, 0x02, 0x08, 0x00);
  5877. const accessor = Kernel.fromArrayBuffer(bytes);
  5878. const subbytes = createArrayBuffer(0x08, 0x01);
  5879. const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
  5880. accessor.setRepeatedMessageElement(
  5881. /* fieldNumber= */ 1, submsg, TestMessage.instanceCreator,
  5882. /* index= */ 0);
  5883. const result =
  5884. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5885. expect(Array.from(result)).toEqual([submsg]);
  5886. });
  5887. it('write submessage changes made via getRepeatedMessagElement', () => {
  5888. const bytes = createArrayBuffer(0x0A, 0x02, 0x08, 0x05);
  5889. const expected = createArrayBuffer(0x0A, 0x02, 0x08, 0x00);
  5890. const accessor = Kernel.fromArrayBuffer(bytes);
  5891. const submsg = accessor.getRepeatedMessageElement(
  5892. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  5893. /* index= */ 0);
  5894. expect(submsg.getInt32WithDefault(1, 0)).toEqual(5);
  5895. submsg.setInt32(1, 0);
  5896. expect(accessor.serialize()).toEqual(expected);
  5897. });
  5898. it('set values', () => {
  5899. const accessor = Kernel.createEmpty();
  5900. const subbytes = createArrayBuffer(0x08, 0x01);
  5901. const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
  5902. accessor.setRepeatedMessageIterable(1, [submsg]);
  5903. const result =
  5904. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5905. expect(Array.from(result)).toEqual([submsg]);
  5906. });
  5907. it('encode for adding single value', () => {
  5908. const accessor = Kernel.createEmpty();
  5909. const bytes1 = createArrayBuffer(0x08, 0x01);
  5910. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  5911. const bytes2 = createArrayBuffer(0x08, 0x00);
  5912. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  5913. const expected =
  5914. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5915. accessor.addRepeatedMessageElement(1, msg1, TestMessage.instanceCreator);
  5916. accessor.addRepeatedMessageElement(1, msg2, TestMessage.instanceCreator);
  5917. const result = accessor.serialize();
  5918. expect(result).toEqual(expected);
  5919. });
  5920. it('encode for adding values', () => {
  5921. const accessor = Kernel.createEmpty();
  5922. const bytes1 = createArrayBuffer(0x08, 0x01);
  5923. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  5924. const bytes2 = createArrayBuffer(0x08, 0x00);
  5925. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  5926. const expected =
  5927. createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
  5928. accessor.addRepeatedMessageIterable(
  5929. 1, [msg1, msg2], TestMessage.instanceCreator);
  5930. const result = accessor.serialize();
  5931. expect(result).toEqual(expected);
  5932. });
  5933. it('encode for setting single value', () => {
  5934. const bytes = createArrayBuffer(0x0A, 0x02, 0x08, 0x00);
  5935. const accessor = Kernel.fromArrayBuffer(bytes);
  5936. const subbytes = createArrayBuffer(0x08, 0x01);
  5937. const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
  5938. const expected = createArrayBuffer(0x0A, 0x02, 0x08, 0x01);
  5939. accessor.setRepeatedMessageElement(
  5940. /* fieldNumber= */ 1, submsg, TestMessage.instanceCreator,
  5941. /* index= */ 0);
  5942. const result = accessor.serialize();
  5943. expect(result).toEqual(expected);
  5944. });
  5945. it('encode for setting values', () => {
  5946. const accessor = Kernel.createEmpty();
  5947. const subbytes = createArrayBuffer(0x08, 0x01);
  5948. const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
  5949. const expected = createArrayBuffer(0x0A, 0x02, 0x08, 0x01);
  5950. accessor.setRepeatedMessageIterable(1, [submsg]);
  5951. const result = accessor.serialize();
  5952. expect(result).toEqual(expected);
  5953. });
  5954. it('get accessors from set values.', () => {
  5955. const accessor = Kernel.createEmpty();
  5956. const bytes1 = createArrayBuffer(0x08, 0x01);
  5957. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  5958. const bytes2 = createArrayBuffer(0x08, 0x00);
  5959. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  5960. accessor.addRepeatedMessageIterable(
  5961. 1, [msg1, msg2], TestMessage.instanceCreator);
  5962. const [accessor1, accessor2] =
  5963. [...accessor.getRepeatedMessageAccessorIterable(1)];
  5964. expect(accessor1.getInt32WithDefault(1)).toEqual(1);
  5965. expect(accessor2.getInt32WithDefault(1)).toEqual(0);
  5966. // Retrieved accessors are the exact same accessors as the added messages.
  5967. expect(accessor1).toBe(
  5968. (/** @type {!InternalMessage} */ (msg1)).internalGetKernel());
  5969. expect(accessor2).toBe(
  5970. (/** @type {!InternalMessage} */ (msg2)).internalGetKernel());
  5971. });
  5972. it('fail when getting message value with other wire types', () => {
  5973. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  5974. 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  5975. if (CHECK_CRITICAL_STATE) {
  5976. expect(() => {
  5977. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5978. }).toThrow();
  5979. } else {
  5980. // Note in unchecked mode we produce invalid output for invalid inputs.
  5981. // This test just documents our behavior in those cases.
  5982. // These values might change at any point and are not considered
  5983. // what the implementation should be doing here.
  5984. const [msg1] =
  5985. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  5986. expect(msg1.serialize()).toEqual(createArrayBuffer());
  5987. }
  5988. });
  5989. it('fail when adding message values with wrong type value', () => {
  5990. const accessor = Kernel.createEmpty();
  5991. const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
  5992. if (CHECK_CRITICAL_STATE) {
  5993. expect(
  5994. () => accessor.addRepeatedMessageIterable(
  5995. 1, [fakeValue], TestMessage.instanceCreator))
  5996. .toThrowError('Given value is not a message instance: null');
  5997. } else {
  5998. // Note in unchecked mode we produce invalid output for invalid inputs.
  5999. // This test just documents our behavior in those cases.
  6000. // These values might change at any point and are not considered
  6001. // what the implementation should be doing here.
  6002. accessor.addRepeatedMessageIterable(
  6003. 1, [fakeValue], TestMessage.instanceCreator);
  6004. const list =
  6005. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  6006. expect(Array.from(list)).toEqual([null]);
  6007. }
  6008. });
  6009. it('fail when adding single message value with wrong type value', () => {
  6010. const accessor = Kernel.createEmpty();
  6011. const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
  6012. if (CHECK_CRITICAL_STATE) {
  6013. expect(
  6014. () => accessor.addRepeatedMessageElement(
  6015. 1, fakeValue, TestMessage.instanceCreator))
  6016. .toThrowError('Given value is not a message instance: null');
  6017. } else {
  6018. // Note in unchecked mode we produce invalid output for invalid inputs.
  6019. // This test just documents our behavior in those cases.
  6020. // These values might change at any point and are not considered
  6021. // what the implementation should be doing here.
  6022. accessor.addRepeatedMessageElement(
  6023. 1, fakeValue, TestMessage.instanceCreator);
  6024. const list =
  6025. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  6026. expect(Array.from(list)).toEqual([null]);
  6027. }
  6028. });
  6029. it('fail when setting message values with wrong type value', () => {
  6030. const accessor = Kernel.createEmpty();
  6031. const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
  6032. if (CHECK_CRITICAL_STATE) {
  6033. expect(() => accessor.setRepeatedMessageIterable(1, [fakeValue]))
  6034. .toThrowError('Given value is not a message instance: null');
  6035. } else {
  6036. // Note in unchecked mode we produce invalid output for invalid inputs.
  6037. // This test just documents our behavior in those cases.
  6038. // These values might change at any point and are not considered
  6039. // what the implementation should be doing here.
  6040. accessor.setRepeatedMessageIterable(1, [fakeValue]);
  6041. const list =
  6042. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  6043. expect(Array.from(list)).toEqual([null]);
  6044. }
  6045. });
  6046. it('fail when setting single value with wrong type value', () => {
  6047. const accessor =
  6048. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x02, 0x08, 0x00));
  6049. const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
  6050. if (CHECK_CRITICAL_STATE) {
  6051. expect(
  6052. () => accessor.setRepeatedMessageElement(
  6053. /* fieldNumber= */ 1, fakeValue, TestMessage.instanceCreator,
  6054. /* index= */ 0))
  6055. .toThrowError('Given value is not a message instance: null');
  6056. } else {
  6057. // Note in unchecked mode we produce invalid output for invalid inputs.
  6058. // This test just documents our behavior in those cases.
  6059. // These values might change at any point and are not considered
  6060. // what the implementation should be doing here.
  6061. accessor.setRepeatedMessageElement(
  6062. /* fieldNumber= */ 1, fakeValue, TestMessage.instanceCreator,
  6063. /* index= */ 0);
  6064. const list =
  6065. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
  6066. expect(Array.from(list).length).toEqual(1);
  6067. }
  6068. });
  6069. it('fail when setting single value with out-of-bound index', () => {
  6070. const accessor =
  6071. Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x02, 0x08, 0x00));
  6072. const msg1 =
  6073. accessor.getRepeatedMessageElement(1, TestMessage.instanceCreator, 0);
  6074. const bytes2 = createArrayBuffer(0x08, 0x01);
  6075. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  6076. if (CHECK_CRITICAL_STATE) {
  6077. expect(
  6078. () => accessor.setRepeatedMessageElement(
  6079. /* fieldNumber= */ 1, msg2, TestMessage.instanceCreator,
  6080. /* index= */ 1))
  6081. .toThrowError('Index out of bounds: index: 1 size: 1');
  6082. } else {
  6083. // Note in unchecked mode we produce invalid output for invalid inputs.
  6084. // This test just documents our behavior in those cases.
  6085. // These values might change at any point and are not considered
  6086. // what the implementation should be doing here.
  6087. accessor.setRepeatedMessageElement(
  6088. /* fieldNumber= */ 1, msg2, TestMessage.instanceCreator,
  6089. /* index= */ 1);
  6090. expectEqualToArray(
  6091. accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator),
  6092. [msg1, msg2]);
  6093. }
  6094. });
  6095. });
  6096. describe('Kernel for repeated groups does', () => {
  6097. it('return empty array for the empty input', () => {
  6098. const accessor = Kernel.createEmpty();
  6099. expectEqualToArray(
  6100. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator), []);
  6101. });
  6102. it('ensure not the same instance returned for the empty input', () => {
  6103. const accessor = Kernel.createEmpty();
  6104. const list1 =
  6105. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6106. const list2 =
  6107. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6108. expect(list1).not.toBe(list2);
  6109. });
  6110. it('return size for the empty input', () => {
  6111. const accessor = Kernel.createEmpty();
  6112. expect(accessor.getRepeatedGroupSize(1, TestMessage.instanceCreator))
  6113. .toEqual(0);
  6114. });
  6115. it('return values from the input', () => {
  6116. const bytes1 = createArrayBuffer(0x08, 0x01);
  6117. const bytes2 = createArrayBuffer(0x08, 0x02);
  6118. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  6119. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  6120. const bytes =
  6121. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
  6122. const accessor = Kernel.fromArrayBuffer(bytes);
  6123. expectEqualToMessageArray(
  6124. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator),
  6125. [msg1, msg2]);
  6126. });
  6127. it('ensure not the same array instance returned', () => {
  6128. const bytes =
  6129. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
  6130. const accessor = Kernel.fromArrayBuffer(bytes);
  6131. const list1 =
  6132. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6133. const list2 =
  6134. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6135. expect(list1).not.toBe(list2);
  6136. });
  6137. it('ensure the same array element returned for get iterable', () => {
  6138. const bytes =
  6139. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
  6140. const accessor = Kernel.fromArrayBuffer(bytes);
  6141. const list1 =
  6142. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6143. const list2 = accessor.getRepeatedGroupIterable(
  6144. 1, TestMessage.instanceCreator, /* pivot= */ 0);
  6145. const array1 = Array.from(list1);
  6146. const array2 = Array.from(list2);
  6147. for (let i = 0; i < array1.length; i++) {
  6148. expect(array1[i]).toBe(array2[i]);
  6149. }
  6150. });
  6151. it('return accessors from the input', () => {
  6152. const bytes =
  6153. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
  6154. const accessor = Kernel.fromArrayBuffer(bytes);
  6155. const [accessor1, accessor2] =
  6156. [...accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator)];
  6157. expect(accessor1.getInt32WithDefault(1)).toEqual(1);
  6158. expect(accessor2.getInt32WithDefault(1)).toEqual(2);
  6159. });
  6160. it('return accessors from the input when pivot is set', () => {
  6161. const bytes =
  6162. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
  6163. const accessor = Kernel.fromArrayBuffer(bytes);
  6164. const [accessor1, accessor2] = [...accessor.getRepeatedGroupIterable(
  6165. 1, TestMessage.instanceCreator, /* pivot= */ 0)];
  6166. expect(accessor1.getInt32WithDefault(1)).toEqual(1);
  6167. expect(accessor2.getInt32WithDefault(1)).toEqual(2);
  6168. });
  6169. it('return the repeated field element from the input', () => {
  6170. const bytes =
  6171. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
  6172. const accessor = Kernel.fromArrayBuffer(bytes);
  6173. const msg1 = accessor.getRepeatedGroupElement(
  6174. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  6175. /* index= */ 0);
  6176. const msg2 = accessor.getRepeatedGroupElement(
  6177. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  6178. /* index= */ 1, /* pivot= */ 0);
  6179. expect(msg1.getInt32WithDefault(
  6180. /* fieldNumber= */ 1, /* default= */ 0))
  6181. .toEqual(1);
  6182. expect(msg2.getInt32WithDefault(
  6183. /* fieldNumber= */ 1, /* default= */ 0))
  6184. .toEqual(2);
  6185. });
  6186. it('ensure the same array element returned', () => {
  6187. const bytes =
  6188. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
  6189. const accessor = Kernel.fromArrayBuffer(bytes);
  6190. const msg1 = accessor.getRepeatedGroupElement(
  6191. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  6192. /* index= */ 0);
  6193. const msg2 = accessor.getRepeatedGroupElement(
  6194. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  6195. /* index= */ 0);
  6196. expect(msg1).toBe(msg2);
  6197. });
  6198. it('return the size from the input', () => {
  6199. const bytes =
  6200. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
  6201. const accessor = Kernel.fromArrayBuffer(bytes);
  6202. expect(accessor.getRepeatedGroupSize(1, TestMessage.instanceCreator))
  6203. .toEqual(2);
  6204. });
  6205. it('encode repeated message from the input', () => {
  6206. const bytes =
  6207. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
  6208. const accessor = Kernel.fromArrayBuffer(bytes);
  6209. expect(accessor.serialize()).toEqual(bytes);
  6210. });
  6211. it('add a single value', () => {
  6212. const accessor = Kernel.createEmpty();
  6213. const bytes1 = createArrayBuffer(0x08, 0x01);
  6214. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  6215. const bytes2 = createArrayBuffer(0x08, 0x02);
  6216. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  6217. accessor.addRepeatedGroupElement(1, msg1, TestMessage.instanceCreator);
  6218. accessor.addRepeatedGroupElement(1, msg2, TestMessage.instanceCreator);
  6219. const result =
  6220. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6221. expect(Array.from(result)).toEqual([msg1, msg2]);
  6222. });
  6223. it('add values', () => {
  6224. const accessor = Kernel.createEmpty();
  6225. const bytes1 = createArrayBuffer(0x08, 0x01);
  6226. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  6227. const bytes2 = createArrayBuffer(0x08, 0x02);
  6228. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  6229. accessor.addRepeatedGroupIterable(1, [msg1], TestMessage.instanceCreator);
  6230. accessor.addRepeatedGroupIterable(1, [msg2], TestMessage.instanceCreator);
  6231. const result =
  6232. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6233. expect(Array.from(result)).toEqual([msg1, msg2]);
  6234. });
  6235. it('set a single value', () => {
  6236. const bytes = createArrayBuffer(0x0B, 0x08, 0x01, 0x0C);
  6237. const accessor = Kernel.fromArrayBuffer(bytes);
  6238. const subbytes = createArrayBuffer(0x08, 0x01);
  6239. const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
  6240. accessor.setRepeatedGroupElement(
  6241. /* fieldNumber= */ 1, submsg, TestMessage.instanceCreator,
  6242. /* index= */ 0);
  6243. const result =
  6244. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6245. expect(Array.from(result)).toEqual([submsg]);
  6246. });
  6247. it('write submessage changes made via getRepeatedGroupElement', () => {
  6248. const bytes = createArrayBuffer(0x0B, 0x08, 0x05, 0x0C);
  6249. const expected = createArrayBuffer(0x0B, 0x08, 0x00, 0x0C);
  6250. const accessor = Kernel.fromArrayBuffer(bytes);
  6251. const submsg = accessor.getRepeatedGroupElement(
  6252. /* fieldNumber= */ 1, TestMessage.instanceCreator,
  6253. /* index= */ 0);
  6254. expect(submsg.getInt32WithDefault(1, 0)).toEqual(5);
  6255. submsg.setInt32(1, 0);
  6256. expect(accessor.serialize()).toEqual(expected);
  6257. });
  6258. it('set values', () => {
  6259. const accessor = Kernel.createEmpty();
  6260. const subbytes = createArrayBuffer(0x08, 0x01);
  6261. const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
  6262. accessor.setRepeatedGroupIterable(1, [submsg]);
  6263. const result =
  6264. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6265. expect(Array.from(result)).toEqual([submsg]);
  6266. });
  6267. it('encode for adding single value', () => {
  6268. const accessor = Kernel.createEmpty();
  6269. const bytes1 = createArrayBuffer(0x08, 0x01);
  6270. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  6271. const bytes2 = createArrayBuffer(0x08, 0x00);
  6272. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  6273. const expected =
  6274. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x00, 0x0C);
  6275. accessor.addRepeatedGroupElement(1, msg1, TestMessage.instanceCreator);
  6276. accessor.addRepeatedGroupElement(1, msg2, TestMessage.instanceCreator);
  6277. const result = accessor.serialize();
  6278. expect(result).toEqual(expected);
  6279. });
  6280. it('encode for adding values', () => {
  6281. const accessor = Kernel.createEmpty();
  6282. const bytes1 = createArrayBuffer(0x08, 0x01);
  6283. const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
  6284. const bytes2 = createArrayBuffer(0x08, 0x00);
  6285. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  6286. const expected =
  6287. createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x00, 0x0C);
  6288. accessor.addRepeatedGroupIterable(
  6289. 1, [msg1, msg2], TestMessage.instanceCreator);
  6290. const result = accessor.serialize();
  6291. expect(result).toEqual(expected);
  6292. });
  6293. it('encode for setting single value', () => {
  6294. const bytes = createArrayBuffer(0x0B, 0x08, 0x00, 0x0C);
  6295. const accessor = Kernel.fromArrayBuffer(bytes);
  6296. const subbytes = createArrayBuffer(0x08, 0x01);
  6297. const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
  6298. const expected = createArrayBuffer(0x0B, 0x08, 0x01, 0x0C);
  6299. accessor.setRepeatedGroupElement(
  6300. /* fieldNumber= */ 1, submsg, TestMessage.instanceCreator,
  6301. /* index= */ 0);
  6302. const result = accessor.serialize();
  6303. expect(result).toEqual(expected);
  6304. });
  6305. it('encode for setting values', () => {
  6306. const accessor = Kernel.createEmpty();
  6307. const subbytes = createArrayBuffer(0x08, 0x01);
  6308. const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
  6309. const expected = createArrayBuffer(0x0B, 0x08, 0x01, 0x0C);
  6310. accessor.setRepeatedGroupIterable(1, [submsg]);
  6311. const result = accessor.serialize();
  6312. expect(result).toEqual(expected);
  6313. });
  6314. it('fail when getting groups value with other wire types', () => {
  6315. const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
  6316. 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  6317. if (CHECK_CRITICAL_STATE) {
  6318. expect(() => {
  6319. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6320. }).toThrow();
  6321. }
  6322. });
  6323. it('fail when adding group values with wrong type value', () => {
  6324. const accessor = Kernel.createEmpty();
  6325. const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
  6326. if (CHECK_CRITICAL_STATE) {
  6327. expect(
  6328. () => accessor.addRepeatedGroupIterable(
  6329. 1, [fakeValue], TestMessage.instanceCreator))
  6330. .toThrowError('Given value is not a message instance: null');
  6331. } else {
  6332. // Note in unchecked mode we produce invalid output for invalid inputs.
  6333. // This test just documents our behavior in those cases.
  6334. // These values might change at any point and are not considered
  6335. // what the implementation should be doing here.
  6336. accessor.addRepeatedGroupIterable(
  6337. 1, [fakeValue], TestMessage.instanceCreator);
  6338. const list =
  6339. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6340. expect(Array.from(list)).toEqual([null]);
  6341. }
  6342. });
  6343. it('fail when adding single group value with wrong type value', () => {
  6344. const accessor = Kernel.createEmpty();
  6345. const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
  6346. if (CHECK_CRITICAL_STATE) {
  6347. expect(
  6348. () => accessor.addRepeatedGroupElement(
  6349. 1, fakeValue, TestMessage.instanceCreator))
  6350. .toThrowError('Given value is not a message instance: null');
  6351. } else {
  6352. // Note in unchecked mode we produce invalid output for invalid inputs.
  6353. // This test just documents our behavior in those cases.
  6354. // These values might change at any point and are not considered
  6355. // what the implementation should be doing here.
  6356. accessor.addRepeatedGroupElement(
  6357. 1, fakeValue, TestMessage.instanceCreator);
  6358. const list =
  6359. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6360. expect(Array.from(list)).toEqual([null]);
  6361. }
  6362. });
  6363. it('fail when setting message values with wrong type value', () => {
  6364. const accessor = Kernel.createEmpty();
  6365. const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
  6366. if (CHECK_CRITICAL_STATE) {
  6367. expect(() => accessor.setRepeatedGroupIterable(1, [fakeValue]))
  6368. .toThrowError('Given value is not a message instance: null');
  6369. } else {
  6370. // Note in unchecked mode we produce invalid output for invalid inputs.
  6371. // This test just documents our behavior in those cases.
  6372. // These values might change at any point and are not considered
  6373. // what the implementation should be doing here.
  6374. accessor.setRepeatedGroupIterable(1, [fakeValue]);
  6375. const list =
  6376. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6377. expect(Array.from(list)).toEqual([null]);
  6378. }
  6379. });
  6380. it('fail when setting single value with wrong type value', () => {
  6381. const accessor =
  6382. Kernel.fromArrayBuffer(createArrayBuffer(0x0B, 0x08, 0x00, 0x0C));
  6383. const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
  6384. if (CHECK_CRITICAL_STATE) {
  6385. expect(
  6386. () => accessor.setRepeatedGroupElement(
  6387. /* fieldNumber= */ 1, fakeValue, TestMessage.instanceCreator,
  6388. /* index= */ 0))
  6389. .toThrowError('Given value is not a message instance: null');
  6390. } else {
  6391. // Note in unchecked mode we produce invalid output for invalid inputs.
  6392. // This test just documents our behavior in those cases.
  6393. // These values might change at any point and are not considered
  6394. // what the implementation should be doing here.
  6395. accessor.setRepeatedGroupElement(
  6396. /* fieldNumber= */ 1, fakeValue, TestMessage.instanceCreator,
  6397. /* index= */ 0);
  6398. const list =
  6399. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
  6400. expect(Array.from(list).length).toEqual(1);
  6401. }
  6402. });
  6403. it('fail when setting single value with out-of-bound index', () => {
  6404. const accessor =
  6405. Kernel.fromArrayBuffer(createArrayBuffer(0x0B, 0x08, 0x00, 0x0C));
  6406. const msg1 =
  6407. accessor.getRepeatedGroupElement(1, TestMessage.instanceCreator, 0);
  6408. const bytes2 = createArrayBuffer(0x08, 0x01);
  6409. const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
  6410. if (CHECK_CRITICAL_STATE) {
  6411. expect(
  6412. () => accessor.setRepeatedGroupElement(
  6413. /* fieldNumber= */ 1, msg2, TestMessage.instanceCreator,
  6414. /* index= */ 1))
  6415. .toThrowError('Index out of bounds: index: 1 size: 1');
  6416. } else {
  6417. // Note in unchecked mode we produce invalid output for invalid inputs.
  6418. // This test just documents our behavior in those cases.
  6419. // These values might change at any point and are not considered
  6420. // what the implementation should be doing here.
  6421. accessor.setRepeatedGroupElement(
  6422. /* fieldNumber= */ 1, msg2, TestMessage.instanceCreator,
  6423. /* index= */ 1);
  6424. expectEqualToArray(
  6425. accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator),
  6426. [msg1, msg2]);
  6427. }
  6428. });
  6429. });