kernel_repeated_test.js 268 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427
  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. });