| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556 |
- ;(function() {
- /** Used as a safe reference for `undefined` in pre-ES5 environments. */
- var undefined;
- /** Used to detect when a function becomes hot. */
- var HOT_COUNT = 150;
- /** Used as the size to cover large array optimizations. */
- var LARGE_ARRAY_SIZE = 200;
- /** Used as the `TypeError` message for "Functions" methods. */
- var FUNC_ERROR_TEXT = 'Expected a function';
- /** Used as references for various `Number` constants. */
- var MAX_SAFE_INTEGER = 9007199254740991,
- MAX_INTEGER = 1.7976931348623157e+308;
- /** Used as references for the maximum length and index of an array. */
- var MAX_ARRAY_LENGTH = 4294967295,
- MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
- /** `Object#toString` result references. */
- var funcTag = '[object Function]',
- numberTag = '[object Number]',
- objectTag = '[object Object]';
- /** Used as a reference to the global object. */
- var root = (typeof global == 'object' && global) || this;
- /** Used to store lodash to test for bad extensions/shims. */
- var lodashBizarro = root.lodashBizarro;
- /** Used for native method references. */
- var arrayProto = Array.prototype,
- funcProto = Function.prototype,
- objectProto = Object.prototype,
- numberProto = Number.prototype,
- stringProto = String.prototype;
- /** Method and object shortcuts. */
- var phantom = root.phantom,
- process = root.process,
- amd = root.define && define.amd,
- argv = process && process.argv,
- defineProperty = Object.defineProperty,
- document = !phantom && root.document,
- body = root.document && root.document.body,
- create = Object.create,
- fnToString = funcProto.toString,
- freeze = Object.freeze,
- getSymbols = Object.getOwnPropertySymbols,
- identity = function(value) { return value; },
- JSON = root.JSON,
- noop = function() {},
- objToString = objectProto.toString,
- params = argv,
- push = arrayProto.push,
- realm = {},
- slice = arrayProto.slice;
- var ArrayBuffer = root.ArrayBuffer,
- Buffer = root.Buffer,
- Promise = root.Promise,
- Map = root.Map,
- Set = root.Set,
- Symbol = root.Symbol,
- Uint8Array = root.Uint8Array,
- WeakMap = root.WeakMap,
- WeakSet = root.WeakSet;
- var arrayBuffer = ArrayBuffer ? new ArrayBuffer(2) : undefined,
- map = Map ? new Map : undefined,
- promise = Promise ? Promise.resolve(1) : undefined,
- set = Set ? new Set : undefined,
- symbol = Symbol ? Symbol('a') : undefined,
- weakMap = WeakMap ? new WeakMap : undefined,
- weakSet = WeakSet ? new WeakSet : undefined;
- /** Math helpers. */
- var add = function(x, y) { return x + y; },
- doubled = function(n) { return n * 2; },
- isEven = function(n) { return n % 2 == 0; },
- square = function(n) { return n * n; };
- /** Stub functions. */
- var stubA = function() { return 'a'; },
- stubB = function() { return 'b'; },
- stubC = function() { return 'c'; };
- var stubTrue = function() { return true; },
- stubFalse = function() { return false; };
- var stubNaN = function() { return NaN; },
- stubNull = function() { return null; };
- var stubZero = function() { return 0; },
- stubOne = function() { return 1; },
- stubTwo = function() { return 2; },
- stubThree = function() { return 3; },
- stubFour = function() { return 4; };
- var stubArray = function() { return []; },
- stubObject = function() { return {}; },
- stubString = function() { return ''; };
- /** List of Latin Unicode letters. */
- var burredLetters = [
- // Latin-1 Supplement letters.
- '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf',
- '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf',
- '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef',
- '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff',
- // Latin Extended-A letters.
- '\u0100', '\u0101', '\u0102', '\u0103', '\u0104', '\u0105', '\u0106', '\u0107', '\u0108', '\u0109', '\u010a', '\u010b', '\u010c', '\u010d', '\u010e', '\u010f',
- '\u0110', '\u0111', '\u0112', '\u0113', '\u0114', '\u0115', '\u0116', '\u0117', '\u0118', '\u0119', '\u011a', '\u011b', '\u011c', '\u011d', '\u011e', '\u011f',
- '\u0120', '\u0121', '\u0122', '\u0123', '\u0124', '\u0125', '\u0126', '\u0127', '\u0128', '\u0129', '\u012a', '\u012b', '\u012c', '\u012d', '\u012e', '\u012f',
- '\u0130', '\u0131', '\u0132', '\u0133', '\u0134', '\u0135', '\u0136', '\u0137', '\u0138', '\u0139', '\u013a', '\u013b', '\u013c', '\u013d', '\u013e', '\u013f',
- '\u0140', '\u0141', '\u0142', '\u0143', '\u0144', '\u0145', '\u0146', '\u0147', '\u0148', '\u0149', '\u014a', '\u014b', '\u014c', '\u014d', '\u014e', '\u014f',
- '\u0150', '\u0151', '\u0152', '\u0153', '\u0154', '\u0155', '\u0156', '\u0157', '\u0158', '\u0159', '\u015a', '\u015b', '\u015c', '\u015d', '\u015e', '\u015f',
- '\u0160', '\u0161', '\u0162', '\u0163', '\u0164', '\u0165', '\u0166', '\u0167', '\u0168', '\u0169', '\u016a', '\u016b', '\u016c', '\u016d', '\u016e', '\u016f',
- '\u0170', '\u0171', '\u0172', '\u0173', '\u0174', '\u0175', '\u0176', '\u0177', '\u0178', '\u0179', '\u017a', '\u017b', '\u017c', '\u017d', '\u017e', '\u017f'
- ];
- /** List of combining diacritical marks. */
- var comboMarks = [
- '\u0300', '\u0301', '\u0302', '\u0303', '\u0304', '\u0305', '\u0306', '\u0307', '\u0308', '\u0309', '\u030a', '\u030b', '\u030c', '\u030d', '\u030e', '\u030f',
- '\u0310', '\u0311', '\u0312', '\u0313', '\u0314', '\u0315', '\u0316', '\u0317', '\u0318', '\u0319', '\u031a', '\u031b', '\u031c', '\u031d', '\u031e', '\u031f',
- '\u0320', '\u0321', '\u0322', '\u0323', '\u0324', '\u0325', '\u0326', '\u0327', '\u0328', '\u0329', '\u032a', '\u032b', '\u032c', '\u032d', '\u032e', '\u032f',
- '\u0330', '\u0331', '\u0332', '\u0333', '\u0334', '\u0335', '\u0336', '\u0337', '\u0338', '\u0339', '\u033a', '\u033b', '\u033c', '\u033d', '\u033e', '\u033f',
- '\u0340', '\u0341', '\u0342', '\u0343', '\u0344', '\u0345', '\u0346', '\u0347', '\u0348', '\u0349', '\u034a', '\u034b', '\u034c', '\u034d', '\u034e', '\u034f',
- '\u0350', '\u0351', '\u0352', '\u0353', '\u0354', '\u0355', '\u0356', '\u0357', '\u0358', '\u0359', '\u035a', '\u035b', '\u035c', '\u035d', '\u035e', '\u035f',
- '\u0360', '\u0361', '\u0362', '\u0363', '\u0364', '\u0365', '\u0366', '\u0367', '\u0368', '\u0369', '\u036a', '\u036b', '\u036c', '\u036d', '\u036e', '\u036f',
- '\ufe20', '\ufe21', '\ufe22', '\ufe23'
- ];
- /** List of converted Latin Unicode letters. */
- var deburredLetters = [
- // Converted Latin-1 Supplement letters.
- 'A', 'A', 'A', 'A', 'A', 'A', 'Ae', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I',
- 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'Th',
- 'ss', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i',
- 'i', 'd', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'th', 'y',
- // Converted Latin Extended-A letters.
- 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c',
- 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e',
- 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h',
- 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j',
- 'K', 'k', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l',
- 'N', 'n', 'N', 'n', 'N', 'n', "'n", 'N', 'n',
- 'O', 'o', 'O', 'o', 'O', 'o', 'Oe', 'oe',
- 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's',
- 'T', 't', 'T', 't', 'T', 't',
- 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u',
- 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 'ss'
- ];
- /** Used to provide falsey values to methods. */
- var falsey = [, null, undefined, false, 0, NaN, ''];
- /** Used to specify the emoji style glyph variant of characters. */
- var emojiVar = '\ufe0f';
- /** Used to provide empty values to methods. */
- var empties = [[], {}].concat(falsey.slice(1));
- /** Used to test error objects. */
- var errors = [
- new Error,
- new EvalError,
- new RangeError,
- new ReferenceError,
- new SyntaxError,
- new TypeError,
- new URIError
- ];
- /** List of fitzpatrick modifiers. */
- var fitzModifiers = [
- '\ud83c\udffb',
- '\ud83c\udffc',
- '\ud83c\udffd',
- '\ud83c\udffe',
- '\ud83c\udfff'
- ];
- /** Used to provide primitive values to methods. */
- var primitives = [null, undefined, false, true, 1, NaN, 'a'];
- /** Used to check whether methods support typed arrays. */
- var typedArrays = [
- 'Float32Array',
- 'Float64Array',
- 'Int8Array',
- 'Int16Array',
- 'Int32Array',
- 'Uint8Array',
- 'Uint8ClampedArray',
- 'Uint16Array',
- 'Uint32Array'
- ];
- /** Used to check whether methods support array views. */
- var arrayViews = typedArrays.concat('DataView');
- /** The file path of the lodash file to test. */
- var filePath = (function() {
- var min = 2,
- result = params || [];
- if (phantom) {
- min = 0;
- result = params = phantom.args || require('system').args;
- }
- var last = result[result.length - 1];
- result = (result.length > min && !/test(?:\.js)?$/.test(last)) ? last : '../lodash.js';
- if (!amd) {
- try {
- result = require('fs').realpathSync(result);
- } catch (e) {}
- try {
- result = require.resolve(result);
- } catch (e) {}
- }
- return result;
- }());
- /** The `ui` object. */
- var ui = root.ui || (root.ui = {
- 'buildPath': filePath,
- 'loaderPath': '',
- 'isModularize': /\b(?:amd|commonjs|es|node|npm|(index|main)\.js)\b/.test(filePath),
- 'isStrict': /\bes\b/.test(filePath) || 'default' in require(filePath),
- 'urlParams': {}
- });
- /** The basename of the lodash file to test. */
- var basename = /[\w.-]+$/.exec(filePath)[0];
- /** Used to indicate testing a modularized build. */
- var isModularize = ui.isModularize;
- /** Detect if testing `npm` modules. */
- var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
- /** Detect if running in PhantomJS. */
- var isPhantom = phantom || (typeof callPhantom == 'function');
- /** Detect if lodash is in strict mode. */
- var isStrict = ui.isStrict;
- /*--------------------------------------------------------------------------*/
- // Leak to avoid sporadic `noglobals` fails on Edge in Sauce Labs.
- root.msWDfn = undefined;
- // Assign `setTimeout` to itself to avoid being flagged as a leak.
- setProperty(root, 'setTimeout', setTimeout);
- // Exit early if going to run tests in a PhantomJS web page.
- if (phantom && isModularize) {
- var page = require('webpage').create();
- page.onCallback = function(details) {
- var coverage = details.coverage;
- if (coverage) {
- var fs = require('fs'),
- cwd = fs.workingDirectory,
- sep = fs.separator;
- fs.write([cwd, 'coverage', 'coverage.json'].join(sep), JSON.stringify(coverage));
- }
- phantom.exit(details.failed ? 1 : 0);
- };
- page.onConsoleMessage = function(message) {
- console.log(message);
- };
- page.onInitialized = function() {
- page.evaluate(function() {
- document.addEventListener('DOMContentLoaded', function() {
- QUnit.done(function(details) {
- details.coverage = window.__coverage__;
- callPhantom(details);
- });
- });
- });
- };
- page.open(filePath, function(status) {
- if (status != 'success') {
- console.log('PhantomJS failed to load page: ' + filePath);
- phantom.exit(1);
- }
- });
- console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
- return;
- }
- /*--------------------------------------------------------------------------*/
- /** Used to test Web Workers. */
- var Worker = !(ui.isForeign || ui.isSauceLabs || isModularize) &&
- (document && document.origin != 'null') && root.Worker;
- /** Used to test host objects in IE. */
- try {
- var xml = new ActiveXObject('Microsoft.XMLDOM');
- } catch (e) {}
- /** Poison the free variable `root` in Node.js */
- try {
- defineProperty(global.root, 'root', {
- 'configurable': false,
- 'enumerable': false,
- 'get': function() { throw new ReferenceError; }
- });
- } catch (e) {}
- /** Load QUnit and extras. */
- var QUnit = root.QUnit || require('qunit-extras');
- /** Load stable Lodash. */
- var lodashStable = root.lodashStable;
- if (!lodashStable) {
- try {
- lodashStable = interopRequire('../node_modules/lodash/lodash.js');
- } catch (e) {
- console.log('Error: The stable lodash dev dependency should be at least a version behind master branch.');
- return;
- }
- lodashStable = lodashStable.noConflict();
- }
- /** The `lodash` function to test. */
- var _ = root._ || (root._ = interopRequire(filePath));
- /** Used to test pseudo private map caches. */
- var mapCaches = (function() {
- var MapCache = _.memoize.Cache;
- var result = {
- 'Hash': new MapCache().__data__.hash.constructor,
- 'MapCache': MapCache
- };
- _.isMatchWith({ 'a': 1 }, { 'a': 1 }, function() {
- var stack = lodashStable.last(arguments);
- result.ListCache = stack.__data__.constructor;
- result.Stack = stack.constructor;
- });
- return result;
- }());
- /** Used to detect instrumented istanbul code coverage runs. */
- var coverage = root.__coverage__ || root[lodashStable.find(lodashStable.keys(root), function(key) {
- return /^(?:\$\$cov_\d+\$\$)$/.test(key);
- })];
- /** Used to test generator functions. */
- var generator = lodashStable.attempt(function() {
- return Function('return function*(){}');
- });
- /** Used to restore the `_` reference. */
- var oldDash = root._;
- /**
- * Used to check for problems removing whitespace. For a whitespace reference,
- * see [V8's unit test](https://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/whitespaces.js).
- */
- var whitespace = lodashStable.filter([
- // Basic whitespace characters.
- ' ', '\t', '\x0b', '\f', '\xa0', '\ufeff',
- // Line terminators.
- '\n', '\r', '\u2028', '\u2029',
- // Unicode category "Zs" space separators.
- '\u1680', '\u180e', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005',
- '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u202f', '\u205f', '\u3000'
- ],
- function(chr) { return /\s/.exec(chr); })
- .join('');
- /**
- * Creates a custom error object.
- *
- * @private
- * @constructor
- * @param {string} message The error message.
- */
- function CustomError(message) {
- this.name = 'CustomError';
- this.message = message;
- }
- CustomError.prototype = lodashStable.create(Error.prototype, {
- 'constructor': CustomError
- });
- /**
- * Removes all own enumerable string keyed properties from a given object.
- *
- * @private
- * @param {Object} object The object to empty.
- */
- function emptyObject(object) {
- lodashStable.forOwn(object, function(value, key, object) {
- delete object[key];
- });
- }
- /**
- * Extracts the unwrapped value from its wrapper.
- *
- * @private
- * @param {Object} wrapper The wrapper to unwrap.
- * @returns {*} Returns the unwrapped value.
- */
- function getUnwrappedValue(wrapper) {
- var index = -1,
- actions = wrapper.__actions__,
- length = actions.length,
- result = wrapper.__wrapped__;
- while (++index < length) {
- var args = [result],
- action = actions[index];
- push.apply(args, action.args);
- result = action.func.apply(action.thisArg, args);
- }
- return result;
- }
- /**
- * Loads the module of `id`. If the module has an `exports.default`, the
- * exported default value is returned as the resolved module.
- *
- * @private
- * @param {string} id The identifier of the module to resolve.
- * @returns {*} Returns the resolved module.
- */
- function interopRequire(id) {
- var result = require(id);
- return 'default' in result ? result['default'] : result;
- }
- /**
- * Sets a non-enumerable property value on `object`.
- *
- * Note: This function is used to avoid a bug in older versions of V8 where
- * overwriting non-enumerable built-ins makes them enumerable.
- * See https://code.google.com/p/v8/issues/detail?id=1623
- *
- * @private
- * @param {Object} object The object modify.
- * @param {string} key The name of the property to set.
- * @param {*} value The property value.
- */
- function setProperty(object, key, value) {
- try {
- defineProperty(object, key, {
- 'configurable': true,
- 'enumerable': false,
- 'writable': true,
- 'value': value
- });
- } catch (e) {
- object[key] = value;
- }
- return object;
- }
- /**
- * Skips a given number of tests with a passing result.
- *
- * @private
- * @param {Object} assert The QUnit assert object.
- * @param {number} [count=1] The number of tests to skip.
- */
- function skipAssert(assert, count) {
- count || (count = 1);
- while (count--) {
- assert.ok(true, 'test skipped');
- }
- }
- /*--------------------------------------------------------------------------*/
- // Add bizarro values.
- (function() {
- if (document || (typeof require != 'function')) {
- return;
- }
- var nativeString = fnToString.call(toString),
- reToString = /toString/g;
- function createToString(funcName) {
- return lodashStable.constant(nativeString.replace(reToString, funcName));
- }
- // Allow bypassing native checks.
- setProperty(funcProto, 'toString', function wrapper() {
- setProperty(funcProto, 'toString', fnToString);
- var result = lodashStable.has(this, 'toString') ? this.toString() : fnToString.call(this);
- setProperty(funcProto, 'toString', wrapper);
- return result;
- });
- // Add prototype extensions.
- funcProto._method = noop;
- // Set bad shims.
- setProperty(Object, 'create', (function() {
- function object() {}
- return function(prototype) {
- if (lodashStable.isObject(prototype)) {
- object.prototype = prototype;
- var result = new object;
- object.prototype = undefined;
- }
- return result || {};
- };
- }()));
- setProperty(Object, 'getOwnPropertySymbols', undefined);
- var _propertyIsEnumerable = objectProto.propertyIsEnumerable;
- setProperty(objectProto, 'propertyIsEnumerable', function(key) {
- return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
- });
- if (Buffer) {
- defineProperty(root, 'Buffer', {
- 'configurable': true,
- 'enumerable': true,
- 'get': function get() {
- var caller = get.caller,
- name = caller ? caller.name : '';
- if (!(name == 'runInContext' || name.length == 1 || /\b_\.isBuffer\b/.test(caller))) {
- return Buffer;
- }
- }
- });
- }
- if (Map) {
- setProperty(root, 'Map', (function() {
- var count = 0;
- return function() {
- if (count++) {
- return new Map;
- }
- setProperty(root, 'Map', Map);
- return {};
- };
- }()));
- setProperty(root.Map, 'toString', createToString('Map'));
- }
- setProperty(root, 'Promise', noop);
- setProperty(root, 'Set', noop);
- setProperty(root, 'Symbol', undefined);
- setProperty(root, 'WeakMap', noop);
- // Fake `WinRTError`.
- setProperty(root, 'WinRTError', Error);
- // Clear cache so lodash can be reloaded.
- emptyObject(require.cache);
- // Load lodash and expose it to the bad extensions/shims.
- lodashBizarro = interopRequire(filePath);
- root._ = oldDash;
- // Restore built-in methods.
- setProperty(Object, 'create', create);
- setProperty(objectProto, 'propertyIsEnumerable', _propertyIsEnumerable);
- setProperty(root, 'Buffer', Buffer);
- if (getSymbols) {
- Object.getOwnPropertySymbols = getSymbols;
- } else {
- delete Object.getOwnPropertySymbols;
- }
- if (Map) {
- setProperty(root, 'Map', Map);
- } else {
- delete root.Map;
- }
- if (Promise) {
- setProperty(root, 'Promise', Promise);
- } else {
- delete root.Promise;
- }
- if (Set) {
- setProperty(root, 'Set', Set);
- } else {
- delete root.Set;
- }
- if (Symbol) {
- setProperty(root, 'Symbol', Symbol);
- } else {
- delete root.Symbol;
- }
- if (WeakMap) {
- setProperty(root, 'WeakMap', WeakMap);
- } else {
- delete root.WeakMap;
- }
- delete root.WinRTError;
- delete funcProto._method;
- }());
- // Add other realm values from the `vm` module.
- lodashStable.attempt(function() {
- lodashStable.assign(realm, require('vm').runInNewContext([
- '(function() {',
- ' var noop = function() {},',
- ' root = this;',
- '',
- ' var object = {',
- " 'ArrayBuffer': root.ArrayBuffer,",
- " 'arguments': (function() { return arguments; }(1, 2, 3)),",
- " 'array': [1],",
- " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
- " 'boolean': Object(false),",
- " 'date': new Date,",
- " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
- " 'function': noop,",
- " 'map': root.Map ? new root.Map : undefined,",
- " 'nan': NaN,",
- " 'null': null,",
- " 'number': Object(0),",
- " 'object': { 'a': 1 },",
- " 'promise': root.Promise ? Promise.resolve(1) : undefined,",
- " 'regexp': /x/,",
- " 'set': root.Set ? new root.Set : undefined,",
- " 'string': Object('a'),",
- " 'symbol': root.Symbol ? root.Symbol() : undefined,",
- " 'undefined': undefined,",
- " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
- " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
- ' };',
- '',
- " ['" + arrayViews.join("', '") + "'].forEach(function(type) {",
- ' var Ctor = root[type]',
- ' object[type] = Ctor;',
- ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
- ' });',
- '',
- ' return object;',
- '}())'
- ].join('\n')));
- });
- // Add other realm values from an iframe.
- lodashStable.attempt(function() {
- _._realm = realm;
- var iframe = document.createElement('iframe');
- iframe.frameBorder = iframe.height = iframe.width = 0;
- body.appendChild(iframe);
- var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc;
- idoc.write([
- '<script>',
- 'var _ = parent._;',
- '',
- ' var noop = function() {},',
- ' root = this;',
- '',
- 'var object = {',
- " 'ArrayBuffer': root.ArrayBuffer,",
- " 'arguments': (function() { return arguments; }(1, 2, 3)),",
- " 'array': [1],",
- " 'arrayBuffer': root.ArrayBuffer ? new root.ArrayBuffer : undefined,",
- " 'boolean': Object(false),",
- " 'date': new Date,",
- " 'errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],",
- " 'function': noop,",
- " 'map': root.Map ? new root.Map : undefined,",
- " 'nan': NaN,",
- " 'null': null,",
- " 'number': Object(0),",
- " 'object': { 'a': 1 },",
- " 'promise': root.Promise ? Promise.resolve(1) : undefined,",
- " 'regexp': /x/,",
- " 'set': root.Set ? new root.Set : undefined,",
- " 'string': Object('a'),",
- " 'symbol': root.Symbol ? root.Symbol() : undefined,",
- " 'undefined': undefined,",
- " 'weakMap': root.WeakMap ? new root.WeakMap : undefined,",
- " 'weakSet': root.WeakSet ? new root.WeakSet : undefined",
- '};',
- '',
- "_.each(['" + arrayViews.join("', '") + "'], function(type) {",
- ' var Ctor = root[type];',
- ' object[type] = Ctor;',
- ' object[type.toLowerCase()] = Ctor ? new Ctor(new ArrayBuffer(24)) : undefined;',
- '});',
- '',
- '_.assign(_._realm, object);',
- '<\/script>'
- ].join('\n'));
- idoc.close();
- delete _._realm;
- });
- // Add a web worker.
- lodashStable.attempt(function() {
- var worker = new Worker('./asset/worker.js?t=' + (+new Date));
- worker.addEventListener('message', function(e) {
- _._VERSION = e.data || '';
- }, false);
- worker.postMessage(ui.buildPath);
- });
- // Expose internal modules for better code coverage.
- lodashStable.attempt(function() {
- var path = require('path'),
- basePath = path.dirname(filePath);
- if (isModularize && !(amd || isNpm)) {
- lodashStable.each([
- 'baseEach',
- 'isIndex',
- 'isIterateeCall'
- ], function(funcName) {
- _['_' + funcName] = interopRequire(path.join(basePath, '_' + funcName));
- });
- }
- });
- /*--------------------------------------------------------------------------*/
- if (params) {
- console.log('Running lodash tests.');
- console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
- }
- QUnit.module(basename);
- (function() {
- QUnit.test('should support loading ' + basename + ' as the "lodash" module', function(assert) {
- assert.expect(1);
- if (amd) {
- assert.strictEqual((lodashModule || {}).moduleName, 'lodash');
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should support loading ' + basename + ' with the Require.js "shim" configuration option', function(assert) {
- assert.expect(1);
- if (amd && lodashStable.includes(ui.loaderPath, 'requirejs')) {
- assert.strictEqual((shimmedModule || {}).moduleName, 'shimmed');
- } else {
- skipAssert(assert);
- }
- });
- QUnit.test('should support loading ' + basename + ' as the "underscore" module', function(assert) {
- assert.expect(1);
- if (amd) {
- assert.strictEqual((underscoreModule || {}).moduleName, 'underscore');
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should support loading ' + basename + ' in a web worker', function(assert) {
- assert.expect(1);
- var done = assert.async();
- if (Worker) {
- var limit = 30000 / QUnit.config.asyncRetries,
- start = +new Date;
- var attempt = function() {
- var actual = _._VERSION;
- if ((new Date - start) < limit && typeof actual != 'string') {
- setTimeout(attempt, 16);
- return;
- }
- assert.strictEqual(actual, _.VERSION);
- done();
- };
- attempt();
- }
- else {
- skipAssert(assert);
- done();
- }
- });
- QUnit.test('should not add `Function.prototype` extensions to lodash', function(assert) {
- assert.expect(1);
- if (lodashBizarro) {
- assert.notOk('_method' in lodashBizarro);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should avoid non-native built-ins', function(assert) {
- assert.expect(7);
- function message(lodashMethod, nativeMethod) {
- return '`' + lodashMethod + '` should avoid overwritten native `' + nativeMethod + '`';
- }
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var object = { 'a': 1 },
- otherObject = { 'b': 2 },
- largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
- if (lodashBizarro) {
- try {
- var actual = lodashBizarro.keysIn(new Foo).sort();
- } catch (e) {
- actual = null;
- }
- var label = message('_.keysIn', 'Object#propertyIsEnumerable');
- assert.deepEqual(actual, ['a', 'b'], label);
- try {
- var actual = lodashBizarro.isEmpty({});
- } catch (e) {
- actual = null;
- }
- var label = message('_.isEmpty', 'Object#propertyIsEnumerable');
- assert.strictEqual(actual, true, label);
- try {
- actual = [
- lodashBizarro.difference([object, otherObject], largeArray),
- lodashBizarro.intersection(largeArray, [object]),
- lodashBizarro.uniq(largeArray)
- ];
- } catch (e) {
- actual = null;
- }
- label = message('_.difference`, `_.intersection`, and `_.uniq', 'Object.create` and `Map');
- assert.deepEqual(actual, [[otherObject], [object], [object]], label);
- try {
- if (Symbol) {
- object[symbol] = {};
- }
- actual = [
- lodashBizarro.clone(object),
- lodashBizarro.cloneDeep(object)
- ];
- } catch (e) {
- actual = null;
- }
- label = message('_.clone` and `_.cloneDeep', 'Object.getOwnPropertySymbols');
- assert.deepEqual(actual, [object, object], label);
- try {
- var symObject = Object(symbol);
- // Avoid symbol detection in Babel's `typeof` helper.
- symObject.constructor = Object;
- actual = [
- Symbol ? lodashBizarro.clone(symObject) : { 'constructor': Object },
- Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
- Symbol ? lodashBizarro.toString(symObject) : ''
- ];
- } catch (e) {
- actual = null;
- }
- label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
- assert.deepEqual(actual, [{ 'constructor': Object }, false, ''], label);
- try {
- var map = new lodashBizarro.memoize.Cache;
- actual = map.set('a', 1).get('a');
- } catch (e) {
- actual = null;
- }
- label = message('_.memoize.Cache', 'Map');
- assert.deepEqual(actual, 1, label);
- try {
- map = new (Map || Object);
- if (Symbol && Symbol.iterator) {
- map[Symbol.iterator] = null;
- }
- actual = lodashBizarro.toArray(map);
- } catch (e) {
- actual = null;
- }
- label = message('_.toArray', 'Map');
- assert.deepEqual(actual, [], label);
- }
- else {
- skipAssert(assert, 7);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('isIndex');
- (function() {
- var func = _._isIndex;
- QUnit.test('should return `true` for indexes', function(assert) {
- assert.expect(1);
- if (func) {
- var values = [[0], ['0'], ['1'], [3, 4], [MAX_SAFE_INTEGER - 1]],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(args) {
- return func.apply(undefined, args);
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for non-indexes', function(assert) {
- assert.expect(1);
- if (func) {
- var values = [['1abc'], ['07'], ['0001'], [-1], [3, 3], [1.1], [MAX_SAFE_INTEGER]],
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(args) {
- return func.apply(undefined, args);
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('isIterateeCall');
- (function() {
- var array = [1],
- func = _._isIterateeCall,
- object = { 'a': 1 };
- QUnit.test('should return `true` for iteratee calls', function(assert) {
- assert.expect(3);
- function Foo() {}
- Foo.prototype.a = 1;
- if (func) {
- assert.strictEqual(func(1, 0, array), true);
- assert.strictEqual(func(1, 'a', object), true);
- assert.strictEqual(func(1, 'a', new Foo), true);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('should return `false` for non-iteratee calls', function(assert) {
- assert.expect(4);
- if (func) {
- assert.strictEqual(func(2, 0, array), false);
- assert.strictEqual(func(1, 1.1, array), false);
- assert.strictEqual(func(1, 0, { 'length': MAX_SAFE_INTEGER + 1 }), false);
- assert.strictEqual(func(1, 'b', object), false);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should work with `NaN` values', function(assert) {
- assert.expect(2);
- if (func) {
- assert.strictEqual(func(NaN, 0, [NaN]), true);
- assert.strictEqual(func(NaN, 'a', { 'a': NaN }), true);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should not error when `index` is an object without a `toString` method', function(assert) {
- assert.expect(1);
- if (func) {
- try {
- var actual = func(1, { 'toString': null }, [1]);
- } catch (e) {
- var message = e.message;
- }
- assert.strictEqual(actual, false, message || '');
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('map caches');
- (function() {
- var keys = [null, undefined, false, true, 1, -Infinity, NaN, {}, 'a', symbol || noop];
- var pairs = lodashStable.map(keys, function(key, index) {
- var lastIndex = keys.length - 1;
- return [key, keys[lastIndex - index]];
- });
- function createCaches(pairs) {
- var largeStack = new mapCaches.Stack(pairs),
- length = pairs ? pairs.length : 0;
- lodashStable.times(LARGE_ARRAY_SIZE - length, function() {
- largeStack.set({}, {});
- });
- return {
- 'hashes': new mapCaches.Hash(pairs),
- 'list caches': new mapCaches.ListCache(pairs),
- 'map caches': new mapCaches.MapCache(pairs),
- 'stack caches': new mapCaches.Stack(pairs),
- 'large stacks': largeStack
- };
- }
- lodashStable.forOwn(createCaches(pairs), function(cache, kind) {
- QUnit.test('should implement a `Map` interface for ' + kind, function(assert) {
- assert.expect(82);
- lodashStable.each(keys, function(key, index) {
- var value = pairs[index][1];
- assert.deepEqual(cache.get(key), value);
- assert.strictEqual(cache.has(key), true);
- assert.strictEqual(cache['delete'](key), true);
- assert.strictEqual(cache.has(key), false);
- assert.strictEqual(cache.get(key), undefined);
- assert.strictEqual(cache['delete'](key), false);
- assert.strictEqual(cache.set(key, value), cache);
- assert.strictEqual(cache.has(key), true);
- });
- assert.strictEqual(cache.clear(), undefined);
- assert.ok(lodashStable.every(keys, function(key) {
- return !cache.has(key);
- }));
- });
- });
- lodashStable.forOwn(createCaches(), function(cache, kind) {
- QUnit.test('should support changing values of ' + kind, function(assert) {
- assert.expect(10);
- lodashStable.each(keys, function(key) {
- cache.set(key, 1);
- cache.set(key, 2);
- assert.strictEqual(cache.get(key), 2);
- });
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash constructor');
- (function() {
- var values = empties.concat(true, 1, 'a'),
- expected = lodashStable.map(values, stubTrue);
- QUnit.test('should create a new instance when called without the `new` operator', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = lodashStable.map(values, function(value) {
- return _(value) instanceof _;
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return the given `lodash` instances', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = lodashStable.map(values, function(value) {
- var wrapped = _(value);
- return _(wrapped) === wrapped;
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should convert foreign wrapped values to `lodash` instances', function(assert) {
- assert.expect(1);
- if (!isNpm && lodashBizarro) {
- var actual = lodashStable.map(values, function(value) {
- var wrapped = _(lodashBizarro(value)),
- unwrapped = wrapped.value();
- return wrapped instanceof _ &&
- ((unwrapped === value) || (unwrapped !== unwrapped && value !== value));
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.add');
- (function() {
- QUnit.test('should add two numbers', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.add(6, 4), 10);
- assert.strictEqual(_.add(-6, 4), -2);
- assert.strictEqual(_.add(-6, -4), -10);
- });
- QUnit.test('should not coerce arguments to numbers', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.add('6', '4'), '64');
- assert.strictEqual(_.add('x', 'y'), 'xy');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.after');
- (function() {
- function after(n, times) {
- var count = 0;
- lodashStable.times(times, _.after(n, function() { count++; }));
- return count;
- }
- QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
- assert.expect(4);
- assert.strictEqual(after(5, 5), 1, 'after(n) should invoke `func` after being called `n` times');
- assert.strictEqual(after(5, 4), 0, 'after(n) should not invoke `func` before being called `n` times');
- assert.strictEqual(after(0, 0), 0, 'after(0) should not invoke `func` immediately');
- assert.strictEqual(after(0, 1), 1, 'after(0) should invoke `func` when called once');
- });
- QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
- assert.expect(1);
- assert.strictEqual(after(NaN, 1), 1);
- });
- QUnit.test('should use `this` binding of function', function(assert) {
- assert.expect(2);
- var after = _.after(1, function(assert) { return ++this.count; }),
- object = { 'after': after, 'count': 0 };
- object.after();
- assert.strictEqual(object.after(), 2);
- assert.strictEqual(object.count, 2);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.ary');
- (function() {
- function fn(a, b, c) {
- return slice.call(arguments);
- }
- QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
- assert.expect(2);
- var actual = lodashStable.map(['6', '8', '10'], _.ary(parseInt, 1));
- assert.deepEqual(actual, [6, 8, 10]);
- var capped = _.ary(fn, 2);
- assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b']);
- });
- QUnit.test('should use `func.length` if `n` is not given', function(assert) {
- assert.expect(1);
- var capped = _.ary(fn);
- assert.deepEqual(capped('a', 'b', 'c', 'd'), ['a', 'b', 'c']);
- });
- QUnit.test('should treat a negative `n` as `0`', function(assert) {
- assert.expect(1);
- var capped = _.ary(fn, -1);
- try {
- var actual = capped('a');
- } catch (e) {}
- assert.deepEqual(actual, []);
- });
- QUnit.test('should coerce `n` to an integer', function(assert) {
- assert.expect(1);
- var values = ['1', 1.6, 'xyz'],
- expected = [['a'], ['a'], []];
- var actual = lodashStable.map(values, function(n) {
- var capped = _.ary(fn, n);
- return capped('a', 'b');
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should not force a minimum argument count', function(assert) {
- assert.expect(1);
- var capped = _.ary(fn, 3),
- args = ['a', 'b', 'c'];
- var expected = lodashStable.map(args, function(arg, index) {
- return args.slice(0, index);
- });
- var actual = lodashStable.map(expected, function(array) {
- return capped.apply(undefined, array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should use `this` binding of function', function(assert) {
- assert.expect(1);
- var capped = _.ary(function(a, b) { return this; }, 1),
- object = { 'capped': capped };
- assert.strictEqual(object.capped(), object);
- });
- QUnit.test('should use the existing `ary` if smaller', function(assert) {
- assert.expect(1);
- var capped = _.ary(_.ary(fn, 1), 2);
- assert.deepEqual(capped('a', 'b', 'c'), ['a']);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var funcs = lodashStable.map([fn], _.ary),
- actual = funcs[0]('a', 'b', 'c');
- assert.deepEqual(actual, ['a', 'b', 'c']);
- });
- QUnit.test('should work when combined with other methods that use metadata', function(assert) {
- assert.expect(2);
- var array = ['a', 'b', 'c'],
- includes = _.curry(_.rearg(_.ary(_.includes, 2), 1, 0), 2);
- assert.strictEqual(includes('b')(array, 2), true);
- if (!isNpm) {
- includes = _(_.includes).ary(2).rearg(1, 0).curry(2).value();
- assert.strictEqual(includes('b')(array, 2), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.assignIn');
- (function() {
- QUnit.test('should be aliased', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.extend, _.assignIn);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.assign and lodash.assignIn');
- lodashStable.each(['assign', 'assignIn'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should assign source properties to `object`', function(assert) {
- assert.expect(1);
- assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }), { 'a': 1, 'b': 2 });
- });
- QUnit.test('`_.' + methodName + '` should accept multiple sources', function(assert) {
- assert.expect(2);
- var expected = { 'a': 1, 'b': 2, 'c': 3 };
- assert.deepEqual(func({ 'a': 1 }, { 'b': 2 }, { 'c': 3 }), expected);
- assert.deepEqual(func({ 'a': 1 }, { 'b': 2, 'c': 2 }, { 'c': 3 }), expected);
- });
- QUnit.test('`_.' + methodName + '` should overwrite destination properties', function(assert) {
- assert.expect(1);
- var expected = { 'a': 3, 'b': 2, 'c': 1 };
- assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
- });
- QUnit.test('`_.' + methodName + '` should assign source properties with nullish values', function(assert) {
- assert.expect(1);
- var expected = { 'a': null, 'b': undefined, 'c': null };
- assert.deepEqual(func({ 'a': 1, 'b': 2 }, expected), expected);
- });
- QUnit.test('`_.' + methodName + '` should skip assignments if values are the same', function(assert) {
- assert.expect(1);
- var object = {};
- var descriptor = {
- 'configurable': true,
- 'enumerable': true,
- 'set': function() { throw new Error; }
- };
- var source = {
- 'a': 1,
- 'b': undefined,
- 'c': NaN,
- 'd': undefined,
- 'constructor': Object,
- 'toString': lodashStable.constant('source')
- };
- defineProperty(object, 'a', lodashStable.assign({}, descriptor, {
- 'get': stubOne
- }));
- defineProperty(object, 'b', lodashStable.assign({}, descriptor, {
- 'get': noop
- }));
- defineProperty(object, 'c', lodashStable.assign({}, descriptor, {
- 'get': stubNaN
- }));
- defineProperty(object, 'constructor', lodashStable.assign({}, descriptor, {
- 'get': lodashStable.constant(Object)
- }));
- try {
- var actual = func(object, source);
- } catch (e) {}
- assert.deepEqual(actual, source);
- });
- QUnit.test('`_.' + methodName + '` should treat sparse array sources as dense', function(assert) {
- assert.expect(1);
- var array = [1];
- array[2] = 3;
- assert.deepEqual(func({}, array), { '0': 1, '1': undefined, '2': 3 });
- });
- QUnit.test('`_.' + methodName + '` should assign values of prototype objects', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.prototype.a = 1;
- assert.deepEqual(func({}, Foo.prototype), { 'a': 1 });
- });
- QUnit.test('`_.' + methodName + '` should coerce string sources to objects', function(assert) {
- assert.expect(1);
- assert.deepEqual(func({}, 'a'), { '0': 'a' });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.assignInWith');
- (function() {
- QUnit.test('should be aliased', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.extendWith, _.assignInWith);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.assignWith and lodash.assignInWith');
- lodashStable.each(['assignWith', 'assignInWith'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should work with a `customizer` callback', function(assert) {
- assert.expect(1);
- var actual = func({ 'a': 1, 'b': 2 }, { 'a': 3, 'c': 3 }, function(a, b) {
- return a === undefined ? b : a;
- });
- assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
- });
- QUnit.test('`_.' + methodName + '` should work with a `customizer` that returns `undefined`', function(assert) {
- assert.expect(1);
- var expected = { 'a': 1 };
- assert.deepEqual(func({}, expected, noop), expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.at');
- (function() {
- var args = arguments,
- array = ['a', 'b', 'c'],
- object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
- QUnit.test('should return the elements corresponding to the specified keys', function(assert) {
- assert.expect(1);
- var actual = _.at(array, [0, 2]);
- assert.deepEqual(actual, ['a', 'c']);
- });
- QUnit.test('should return `undefined` for nonexistent keys', function(assert) {
- assert.expect(1);
- var actual = _.at(array, [2, 4, 0]);
- assert.deepEqual(actual, ['c', undefined, 'a']);
- });
- QUnit.test('should work with non-index keys on array values', function(assert) {
- assert.expect(1);
- var values = lodashStable.reject(empties, function(value) {
- return (value === 0) || lodashStable.isArray(value);
- }).concat(-1, 1.1);
- var array = lodashStable.transform(values, function(result, value) {
- result[value] = 1;
- }, []);
- var expected = lodashStable.map(values, stubOne),
- actual = _.at(array, values);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return an empty array when no keys are given', function(assert) {
- assert.expect(2);
- assert.deepEqual(_.at(array), []);
- assert.deepEqual(_.at(array, [], []), []);
- });
- QUnit.test('should accept multiple key arguments', function(assert) {
- assert.expect(1);
- var actual = _.at(['a', 'b', 'c', 'd'], 3, 0, 2);
- assert.deepEqual(actual, ['d', 'a', 'c']);
- });
- QUnit.test('should work with a falsey `object` argument when keys are given', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, lodashStable.constant(Array(4)));
- var actual = lodashStable.map(falsey, function(object) {
- try {
- return _.at(object, 0, 1, 'pop', 'push');
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with an `arguments` object for `object`', function(assert) {
- assert.expect(1);
- var actual = _.at(args, [2, 0]);
- assert.deepEqual(actual, [3, 1]);
- });
- QUnit.test('should work with `arguments` object as secondary arguments', function(assert) {
- assert.expect(1);
- var actual = _.at([1, 2, 3, 4, 5], args);
- assert.deepEqual(actual, [2, 3, 4]);
- });
- QUnit.test('should work with an object for `object`', function(assert) {
- assert.expect(1);
- var actual = _.at(object, ['a[0].b.c', 'a[1]']);
- assert.deepEqual(actual, [3, 4]);
- });
- QUnit.test('should pluck inherited property values', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var actual = _.at(new Foo, 'b');
- assert.deepEqual(actual, [2]);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
- smallArray = array;
- lodashStable.each([[2], ['2'], [2, 1]], function(paths) {
- lodashStable.times(2, function(index) {
- var array = index ? largeArray : smallArray,
- wrapped = _(array).map(identity).at(paths);
- assert.deepEqual(wrapped.value(), _.at(_.map(array, identity), paths));
- });
- });
- }
- else {
- skipAssert(assert, 6);
- }
- });
- QUnit.test('should support shortcut fusion', function(assert) {
- assert.expect(8);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE),
- count = 0,
- iteratee = function(value) { count++; return square(value); },
- lastIndex = LARGE_ARRAY_SIZE - 1;
- lodashStable.each([lastIndex, lastIndex + '', LARGE_ARRAY_SIZE, []], function(n, index) {
- count = 0;
- var actual = _(array).map(iteratee).at(n).value(),
- expected = index < 2 ? 1 : 0;
- assert.strictEqual(count, expected);
- expected = index == 3 ? [] : [index == 2 ? undefined : square(lastIndex)];
- assert.deepEqual(actual, expected);
- });
- }
- else {
- skipAssert(assert, 8);
- }
- });
- QUnit.test('work with an object for `object` when chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var paths = ['a[0].b.c', 'a[1]'],
- actual = _(object).map(identity).at(paths).value();
- assert.deepEqual(actual, _.at(_.map(object, identity), paths));
- var indexObject = { '0': 1 };
- actual = _(indexObject).at(0).value();
- assert.deepEqual(actual, _.at(indexObject, 0));
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.attempt');
- (function() {
- QUnit.test('should return the result of `func`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.attempt(lodashStable.constant('x')), 'x');
- });
- QUnit.test('should provide additional arguments to `func`', function(assert) {
- assert.expect(1);
- var actual = _.attempt(function() { return slice.call(arguments); }, 1, 2);
- assert.deepEqual(actual, [1, 2]);
- });
- QUnit.test('should return the caught error', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(errors, stubTrue);
- var actual = lodashStable.map(errors, function(error) {
- return _.attempt(function() { throw error; }) === error;
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should coerce errors to error objects', function(assert) {
- assert.expect(1);
- var actual = _.attempt(function() { throw 'x'; });
- assert.ok(lodashStable.isEqual(actual, Error('x')));
- });
- QUnit.test('should preserve custom errors', function(assert) {
- assert.expect(1);
- var actual = _.attempt(function() { throw new CustomError('x'); });
- assert.ok(actual instanceof CustomError);
- });
- QUnit.test('should work with an error object from another realm', function(assert) {
- assert.expect(1);
- if (realm.errors) {
- var expected = lodashStable.map(realm.errors, stubTrue);
- var actual = lodashStable.map(realm.errors, function(error) {
- return _.attempt(function() { throw error; }) === error;
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.strictEqual(_(lodashStable.constant('x')).attempt(), 'x');
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_(lodashStable.constant('x')).chain().attempt() instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.before');
- (function() {
- function before(n, times) {
- var count = 0;
- lodashStable.times(times, _.before(n, function() { count++; }));
- return count;
- }
- QUnit.test('should create a function that invokes `func` after `n` calls', function(assert) {
- assert.expect(4);
- assert.strictEqual(before(5, 4), 4, 'before(n) should invoke `func` before being called `n` times');
- assert.strictEqual(before(5, 6), 4, 'before(n) should not invoke `func` after being called `n - 1` times');
- assert.strictEqual(before(0, 0), 0, 'before(0) should not invoke `func` immediately');
- assert.strictEqual(before(0, 1), 0, 'before(0) should not invoke `func` when called');
- });
- QUnit.test('should coerce `n` values of `NaN` to `0`', function(assert) {
- assert.expect(1);
- assert.strictEqual(before(NaN, 1), 0);
- });
- QUnit.test('should use `this` binding of function', function(assert) {
- assert.expect(2);
- var before = _.before(2, function(assert) { return ++this.count; }),
- object = { 'before': before, 'count': 0 };
- object.before();
- assert.strictEqual(object.before(), 1);
- assert.strictEqual(object.count, 1);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.bind');
- (function() {
- function fn() {
- var result = [this];
- push.apply(result, arguments);
- return result;
- }
- QUnit.test('should bind a function to an object', function(assert) {
- assert.expect(1);
- var object = {},
- bound = _.bind(fn, object);
- assert.deepEqual(bound('a'), [object, 'a']);
- });
- QUnit.test('should accept a falsey `thisArg` argument', function(assert) {
- assert.expect(1);
- var values = lodashStable.reject(falsey.slice(1), function(value) { return value == null; }),
- expected = lodashStable.map(values, function(value) { return [value]; });
- var actual = lodashStable.map(values, function(value) {
- try {
- var bound = _.bind(fn, value);
- return bound();
- } catch (e) {}
- });
- assert.ok(lodashStable.every(actual, function(value, index) {
- return lodashStable.isEqual(value, expected[index]);
- }));
- });
- QUnit.test('should bind a function to nullish values', function(assert) {
- assert.expect(6);
- var bound = _.bind(fn, null),
- actual = bound('a');
- assert.ok((actual[0] === null) || (actual[0] && actual[0].Array));
- assert.strictEqual(actual[1], 'a');
- lodashStable.times(2, function(index) {
- bound = index ? _.bind(fn, undefined) : _.bind(fn);
- actual = bound('b');
- assert.ok((actual[0] === undefined) || (actual[0] && actual[0].Array));
- assert.strictEqual(actual[1], 'b');
- });
- });
- QUnit.test('should partially apply arguments ', function(assert) {
- assert.expect(4);
- var object = {},
- bound = _.bind(fn, object, 'a');
- assert.deepEqual(bound(), [object, 'a']);
- bound = _.bind(fn, object, 'a');
- assert.deepEqual(bound('b'), [object, 'a', 'b']);
- bound = _.bind(fn, object, 'a', 'b');
- assert.deepEqual(bound(), [object, 'a', 'b']);
- assert.deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']);
- });
- QUnit.test('should support placeholders', function(assert) {
- assert.expect(4);
- var object = {},
- ph = _.bind.placeholder,
- bound = _.bind(fn, object, ph, 'b', ph);
- assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', 'c']);
- assert.deepEqual(bound('a'), [object, 'a', 'b', undefined]);
- assert.deepEqual(bound('a', 'c', 'd'), [object, 'a', 'b', 'c', 'd']);
- assert.deepEqual(bound(), [object, undefined, 'b', undefined]);
- });
- QUnit.test('should use `_.placeholder` when set', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var _ph = _.placeholder = {},
- ph = _.bind.placeholder,
- object = {},
- bound = _.bind(fn, object, _ph, 'b', ph);
- assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', ph, 'c']);
- delete _.placeholder;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should create a function with a `length` of `0`', function(assert) {
- assert.expect(2);
- var fn = function(a, b, c) {},
- bound = _.bind(fn, {});
- assert.strictEqual(bound.length, 0);
- bound = _.bind(fn, {}, 1);
- assert.strictEqual(bound.length, 0);
- });
- QUnit.test('should ignore binding when called with the `new` operator', function(assert) {
- assert.expect(3);
- function Foo() {
- return this;
- }
- var bound = _.bind(Foo, { 'a': 1 }),
- newBound = new bound;
- assert.strictEqual(bound().a, 1);
- assert.strictEqual(newBound.a, undefined);
- assert.ok(newBound instanceof Foo);
- });
- QUnit.test('should handle a number of arguments when called with the `new` operator', function(assert) {
- assert.expect(1);
- function Foo() {
- return this;
- }
- function Bar() {}
- var thisArg = { 'a': 1 },
- boundFoo = _.bind(Foo, thisArg),
- boundBar = _.bind(Bar, thisArg),
- count = 9,
- expected = lodashStable.times(count, lodashStable.constant([undefined, undefined]));
- var actual = lodashStable.times(count, function(index) {
- try {
- switch (index) {
- case 0: return [new boundFoo().a, new boundBar().a];
- case 1: return [new boundFoo(1).a, new boundBar(1).a];
- case 2: return [new boundFoo(1, 2).a, new boundBar(1, 2).a];
- case 3: return [new boundFoo(1, 2, 3).a, new boundBar(1, 2, 3).a];
- case 4: return [new boundFoo(1, 2, 3, 4).a, new boundBar(1, 2, 3, 4).a];
- case 5: return [new boundFoo(1, 2, 3, 4, 5).a, new boundBar(1, 2, 3, 4, 5).a];
- case 6: return [new boundFoo(1, 2, 3, 4, 5, 6).a, new boundBar(1, 2, 3, 4, 5, 6).a];
- case 7: return [new boundFoo(1, 2, 3, 4, 5, 6, 7).a, new boundBar(1, 2, 3, 4, 5, 6, 7).a];
- case 8: return [new boundFoo(1, 2, 3, 4, 5, 6, 7, 8).a, new boundBar(1, 2, 3, 4, 5, 6, 7, 8).a];
- }
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should ensure `new bound` is an instance of `func`', function(assert) {
- assert.expect(2);
- function Foo(value) {
- return value && object;
- }
- var bound = _.bind(Foo),
- object = {};
- assert.ok(new bound instanceof Foo);
- assert.strictEqual(new bound(true), object);
- });
- QUnit.test('should append array arguments to partially applied arguments', function(assert) {
- assert.expect(1);
- var object = {},
- bound = _.bind(fn, object, 'a');
- assert.deepEqual(bound(['b'], 'c'), [object, 'a', ['b'], 'c']);
- });
- QUnit.test('should not rebind functions', function(assert) {
- assert.expect(3);
- var object1 = {},
- object2 = {},
- object3 = {};
- var bound1 = _.bind(fn, object1),
- bound2 = _.bind(bound1, object2, 'a'),
- bound3 = _.bind(bound1, object3, 'b');
- assert.deepEqual(bound1(), [object1]);
- assert.deepEqual(bound2(), [object1, 'a']);
- assert.deepEqual(bound3(), [object1, 'b']);
- });
- QUnit.test('should not error when instantiating bound built-ins', function(assert) {
- assert.expect(2);
- var Ctor = _.bind(Date, null),
- expected = new Date(2012, 4, 23, 0, 0, 0, 0);
- try {
- var actual = new Ctor(2012, 4, 23, 0, 0, 0, 0);
- } catch (e) {}
- assert.deepEqual(actual, expected);
- Ctor = _.bind(Date, null, 2012, 4, 23);
- try {
- actual = new Ctor(0, 0, 0, 0);
- } catch (e) {}
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should not error when calling bound class constructors with the `new` operator', function(assert) {
- assert.expect(1);
- var createCtor = lodashStable.attempt(Function, '"use strict";return class A{}');
- if (typeof createCtor == 'function') {
- var bound = _.bind(createCtor()),
- count = 8,
- expected = lodashStable.times(count, stubTrue);
- var actual = lodashStable.times(count, function(index) {
- try {
- switch (index) {
- case 0: return !!(new bound);
- case 1: return !!(new bound(1));
- case 2: return !!(new bound(1, 2));
- case 3: return !!(new bound(1, 2, 3));
- case 4: return !!(new bound(1, 2, 3, 4));
- case 5: return !!(new bound(1, 2, 3, 4, 5));
- case 6: return !!(new bound(1, 2, 3, 4, 5, 6));
- case 7: return !!(new bound(1, 2, 3, 4, 5, 6, 7));
- }
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return a wrapped value when chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var object = {},
- bound = _(fn).bind({}, 'a', 'b');
- assert.ok(bound instanceof _);
- var actual = bound.value()('c');
- assert.deepEqual(actual, [object, 'a', 'b', 'c']);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.bindAll');
- (function() {
- var args = arguments;
- var source = {
- '_n0': -2,
- '_p0': -1,
- '_a': 1,
- '_b': 2,
- '_c': 3,
- '_d': 4,
- '-0': function() { return this._n0; },
- '0': function() { return this._p0; },
- 'a': function() { return this._a; },
- 'b': function() { return this._b; },
- 'c': function() { return this._c; },
- 'd': function() { return this._d; }
- };
- QUnit.test('should accept individual method names', function(assert) {
- assert.expect(1);
- var object = lodashStable.cloneDeep(source);
- _.bindAll(object, 'a', 'b');
- var actual = lodashStable.map(['a', 'b', 'c'], function(key) {
- return object[key].call({});
- });
- assert.deepEqual(actual, [1, 2, undefined]);
- });
- QUnit.test('should accept arrays of method names', function(assert) {
- assert.expect(1);
- var object = lodashStable.cloneDeep(source);
- _.bindAll(object, ['a', 'b'], ['c']);
- var actual = lodashStable.map(['a', 'b', 'c', 'd'], function(key) {
- return object[key].call({});
- });
- assert.deepEqual(actual, [1, 2, 3, undefined]);
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var props = [-0, Object(-0), 0, Object(0)];
- var actual = lodashStable.map(props, function(key) {
- var object = lodashStable.cloneDeep(source);
- _.bindAll(object, key);
- return object[lodashStable.toString(key)].call({});
- });
- assert.deepEqual(actual, [-2, -2, -1, -1]);
- });
- QUnit.test('should work with an array `object` argument', function(assert) {
- assert.expect(1);
- var array = ['push', 'pop'];
- _.bindAll(array);
- assert.strictEqual(array.pop, arrayProto.pop);
- });
- QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
- assert.expect(1);
- var object = lodashStable.cloneDeep(source);
- _.bindAll(object, args);
- var actual = lodashStable.map(args, function(key) {
- return object[key].call({});
- });
- assert.deepEqual(actual, [1]);
- });
- }('a'));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.bindKey');
- (function() {
- QUnit.test('should work when the target function is overwritten', function(assert) {
- assert.expect(2);
- var object = {
- 'user': 'fred',
- 'greet': function(greeting) {
- return this.user + ' says: ' + greeting;
- }
- };
- var bound = _.bindKey(object, 'greet', 'hi');
- assert.strictEqual(bound(), 'fred says: hi');
- object.greet = function(greeting) {
- return this.user + ' says: ' + greeting + '!';
- };
- assert.strictEqual(bound(), 'fred says: hi!');
- });
- QUnit.test('should support placeholders', function(assert) {
- assert.expect(4);
- var object = {
- 'fn': function() {
- return slice.call(arguments);
- }
- };
- var ph = _.bindKey.placeholder,
- bound = _.bindKey(object, 'fn', ph, 'b', ph);
- assert.deepEqual(bound('a', 'c'), ['a', 'b', 'c']);
- assert.deepEqual(bound('a'), ['a', 'b', undefined]);
- assert.deepEqual(bound('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
- assert.deepEqual(bound(), [undefined, 'b', undefined]);
- });
- QUnit.test('should use `_.placeholder` when set', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var object = {
- 'fn': function() {
- return slice.call(arguments);
- }
- };
- var _ph = _.placeholder = {},
- ph = _.bindKey.placeholder,
- bound = _.bindKey(object, 'fn', _ph, 'b', ph);
- assert.deepEqual(bound('a', 'c'), ['a', 'b', ph, 'c']);
- delete _.placeholder;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should ensure `new bound` is an instance of `object[key]`', function(assert) {
- assert.expect(2);
- function Foo(value) {
- return value && object;
- }
- var object = { 'Foo': Foo },
- bound = _.bindKey(object, 'Foo');
- assert.ok(new bound instanceof Foo);
- assert.strictEqual(new bound(true), object);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('case methods');
- lodashStable.each(['camel', 'kebab', 'lower', 'snake', 'start', 'upper'], function(caseName) {
- var methodName = caseName + 'Case',
- func = _[methodName];
- var strings = [
- 'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar',
- 'FOO BAR', 'fooBar', '--foo-bar--', '__foo_bar__'
- ];
- var converted = (function() {
- switch (caseName) {
- case 'camel': return 'fooBar';
- case 'kebab': return 'foo-bar';
- case 'lower': return 'foo bar';
- case 'snake': return 'foo_bar';
- case 'start': return 'Foo Bar';
- case 'upper': return 'FOO BAR';
- }
- }());
- QUnit.test('`_.' + methodName + '` should convert `string` to ' + caseName + ' case', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(strings, function(string) {
- var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
- return func(string) === expected;
- });
- assert.deepEqual(actual, lodashStable.map(strings, stubTrue));
- });
- QUnit.test('`_.' + methodName + '` should handle double-converting strings', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(strings, function(string) {
- var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
- return func(func(string)) === expected;
- });
- assert.deepEqual(actual, lodashStable.map(strings, stubTrue));
- });
- QUnit.test('`_.' + methodName + '` should deburr letters', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(burredLetters, function(burred, index) {
- var letter = deburredLetters[index].replace(/['\u2019]/g, '');
- if (caseName == 'start') {
- letter = letter == 'IJ' ? letter : lodashStable.capitalize(letter);
- } else if (caseName == 'upper') {
- letter = letter.toUpperCase();
- } else {
- letter = letter.toLowerCase();
- }
- return func(burred) === letter;
- });
- assert.deepEqual(actual, lodashStable.map(burredLetters, stubTrue));
- });
- QUnit.test('`_.' + methodName + '` should remove contraction apostrophes', function(assert) {
- assert.expect(2);
- var postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
- lodashStable.each(["'", '\u2019'], function(apos) {
- var actual = lodashStable.map(postfixes, function(postfix) {
- return func('a b' + apos + postfix + ' c');
- });
- var expected = lodashStable.map(postfixes, function(postfix) {
- switch (caseName) {
- case 'camel': return 'aB' + postfix + 'C';
- case 'kebab': return 'a-b' + postfix + '-c';
- case 'lower': return 'a b' + postfix + ' c';
- case 'snake': return 'a_b' + postfix + '_c';
- case 'start': return 'A B' + postfix + ' C';
- case 'upper': return 'A B' + postfix.toUpperCase() + ' C';
- }
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('`_.' + methodName + '` should remove Latin mathematical operators', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(['\xd7', '\xf7'], func);
- assert.deepEqual(actual, ['', '']);
- });
- QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
- assert.expect(2);
- var string = 'foo bar';
- assert.strictEqual(func(Object(string)), converted);
- assert.strictEqual(func({ 'toString': lodashStable.constant(string) }), converted);
- });
- QUnit.test('`_.' + methodName + '` should return an unwrapped value implicitly when chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.strictEqual(_('foo bar')[methodName](), converted);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_('foo bar').chain()[methodName]() instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- (function() {
- QUnit.test('should get the original value after cycling through all case methods', function(assert) {
- assert.expect(1);
- var funcs = [_.camelCase, _.kebabCase, _.lowerCase, _.snakeCase, _.startCase, _.lowerCase, _.camelCase];
- var actual = lodashStable.reduce(funcs, function(result, func) {
- return func(result);
- }, 'enable 6h format');
- assert.strictEqual(actual, 'enable6HFormat');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.camelCase');
- (function() {
- QUnit.test('should work with numbers', function(assert) {
- assert.expect(6);
- assert.strictEqual(_.camelCase('12 feet'), '12Feet');
- assert.strictEqual(_.camelCase('enable 6h format'), 'enable6HFormat');
- assert.strictEqual(_.camelCase('enable 24H format'), 'enable24HFormat');
- assert.strictEqual(_.camelCase('too legit 2 quit'), 'tooLegit2Quit');
- assert.strictEqual(_.camelCase('walk 500 miles'), 'walk500Miles');
- assert.strictEqual(_.camelCase('xhr2 request'), 'xhr2Request');
- });
- QUnit.test('should handle acronyms', function(assert) {
- assert.expect(6);
- lodashStable.each(['safe HTML', 'safeHTML'], function(string) {
- assert.strictEqual(_.camelCase(string), 'safeHtml');
- });
- lodashStable.each(['escape HTML entities', 'escapeHTMLEntities'], function(string) {
- assert.strictEqual(_.camelCase(string), 'escapeHtmlEntities');
- });
- lodashStable.each(['XMLHttpRequest', 'XmlHTTPRequest'], function(string) {
- assert.strictEqual(_.camelCase(string), 'xmlHttpRequest');
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.capitalize');
- (function() {
- QUnit.test('should capitalize the first character of a string', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.capitalize('fred'), 'Fred');
- assert.strictEqual(_.capitalize('Fred'), 'Fred');
- assert.strictEqual(_.capitalize(' fred'), ' fred');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.castArray');
- (function() {
- QUnit.test('should wrap non-array items in an array', function(assert) {
- assert.expect(1);
- var values = falsey.concat(true, 1, 'a', { 'a': 1 }),
- expected = lodashStable.map(values, function(value) { return [value]; }),
- actual = lodashStable.map(values, _.castArray);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return array values by reference', function(assert) {
- assert.expect(1);
- var array = [1];
- assert.strictEqual(_.castArray(array), array);
- });
- QUnit.test('should return an empty array when no arguments are given', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.castArray(), []);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.chain');
- (function() {
- QUnit.test('should return a wrapped value', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = _.chain({ 'a': 0 });
- assert.ok(actual instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return existing wrapped values', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _({ 'a': 0 });
- assert.strictEqual(_.chain(wrapped), wrapped);
- assert.strictEqual(wrapped.chain(), wrapped);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should enable chaining for methods that return unwrapped values', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- var array = ['c', 'b', 'a'];
- assert.ok(_.chain(array).head() instanceof _);
- assert.ok(_(array).chain().head() instanceof _);
- assert.ok(_.chain(array).isArray() instanceof _);
- assert.ok(_(array).chain().isArray() instanceof _);
- assert.ok(_.chain(array).sortBy().head() instanceof _);
- assert.ok(_(array).chain().sortBy().head() instanceof _);
- }
- else {
- skipAssert(assert, 6);
- }
- });
- QUnit.test('should chain multiple methods', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- lodashStable.times(2, function(index) {
- var array = ['one two three four', 'five six seven eight', 'nine ten eleven twelve'],
- expected = { ' ': 9, 'e': 14, 'f': 2, 'g': 1, 'h': 2, 'i': 4, 'l': 2, 'n': 6, 'o': 3, 'r': 2, 's': 2, 't': 5, 'u': 1, 'v': 4, 'w': 2, 'x': 1 },
- wrapped = index ? _(array).chain() : _.chain(array);
- var actual = wrapped
- .chain()
- .map(function(value) { return value.split(''); })
- .flatten()
- .reduce(function(object, chr) {
- object[chr] || (object[chr] = 0);
- object[chr]++;
- return object;
- }, {})
- .value();
- assert.deepEqual(actual, expected);
- array = [1, 2, 3, 4, 5, 6];
- wrapped = index ? _(array).chain() : _.chain(array);
- actual = wrapped
- .chain()
- .filter(function(n) { return n % 2 != 0; })
- .reject(function(n) { return n % 3 == 0; })
- .sortBy(function(n) { return -n; })
- .value();
- assert.deepEqual(actual, [5, 1]);
- array = [3, 4];
- wrapped = index ? _(array).chain() : _.chain(array);
- actual = wrapped
- .reverse()
- .concat([2, 1])
- .unshift(5)
- .tap(function(value) { value.pop(); })
- .map(square)
- .value();
- assert.deepEqual(actual, [25, 16, 9, 4]);
- });
- }
- else {
- skipAssert(assert, 6);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.chunk');
- (function() {
- var array = [0, 1, 2, 3, 4, 5];
- QUnit.test('should return chunked arrays', function(assert) {
- assert.expect(1);
- var actual = _.chunk(array, 3);
- assert.deepEqual(actual, [[0, 1, 2], [3, 4, 5]]);
- });
- QUnit.test('should return the last chunk as remaining elements', function(assert) {
- assert.expect(1);
- var actual = _.chunk(array, 4);
- assert.deepEqual(actual, [[0, 1, 2, 3], [4, 5]]);
- });
- QUnit.test('should treat falsey `size` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? [[0], [1], [2], [3], [4], [5]] : [];
- });
- var actual = lodashStable.map(falsey, function(size, index) {
- return index ? _.chunk(array, size) : _.chunk(array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should ensure the minimum `size` is `0`', function(assert) {
- assert.expect(1);
- var values = lodashStable.reject(falsey, lodashStable.isUndefined).concat(-1, -Infinity),
- expected = lodashStable.map(values, stubArray);
- var actual = lodashStable.map(values, function(n) {
- return _.chunk(array, n);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should coerce `size` to an integer', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map([[1, 2], [3, 4]], _.chunk);
- assert.deepEqual(actual, [[[1], [2]], [[3], [4]]]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.clamp');
- (function() {
- QUnit.test('should work with a `max` argument', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.clamp(5, 3), 3);
- assert.strictEqual(_.clamp(1, 3), 1);
- });
- QUnit.test('should clamp negative numbers', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.clamp(-10, -5, 5), -5);
- assert.strictEqual(_.clamp(-10.2, -5.5, 5.5), -5.5);
- assert.strictEqual(_.clamp(-Infinity, -5, 5), -5);
- });
- QUnit.test('should clamp positive numbers', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.clamp(10, -5, 5), 5);
- assert.strictEqual(_.clamp(10.6, -5.6, 5.4), 5.4);
- assert.strictEqual(_.clamp(Infinity, -5, 5), 5);
- });
- QUnit.test('should not alter negative numbers in range', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.clamp(-4, -5, 5), -4);
- assert.strictEqual(_.clamp(-5, -5, 5), -5);
- assert.strictEqual(_.clamp(-5.5, -5.6, 5.6), -5.5);
- });
- QUnit.test('should not alter positive numbers in range', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.clamp(4, -5, 5), 4);
- assert.strictEqual(_.clamp(5, -5, 5), 5);
- assert.strictEqual(_.clamp(4.5, -5.1, 5.2), 4.5);
- });
- QUnit.test('should not alter `0` in range', function(assert) {
- assert.expect(1);
- assert.strictEqual(1 / _.clamp(0, -5, 5), Infinity);
- });
- QUnit.test('should clamp to `0`', function(assert) {
- assert.expect(1);
- assert.strictEqual(1 / _.clamp(-10, 0, 5), Infinity);
- });
- QUnit.test('should not alter `-0` in range', function(assert) {
- assert.expect(1);
- assert.strictEqual(1 / _.clamp(-0, -5, 5), -Infinity);
- });
- QUnit.test('should clamp to `-0`', function(assert) {
- assert.expect(1);
- assert.strictEqual(1 / _.clamp(-10, -0, 5), -Infinity);
- });
- QUnit.test('should return `NaN` when `number` is `NaN`', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.clamp(NaN, -5, 5), NaN);
- });
- QUnit.test('should coerce `min` and `max` of `NaN` to `0`', function(assert) {
- assert.expect(2);
- assert.deepEqual(_.clamp(1, -5, NaN), 0);
- assert.deepEqual(_.clamp(-1, NaN, 5), 0);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('clone methods');
- (function() {
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 1;
- Foo.c = function() {};
- if (Map) {
- var map = new Map;
- map.set('a', 1);
- map.set('b', 2);
- }
- if (Set) {
- var set = new Set;
- set.add(1);
- set.add(2);
- }
- var objects = {
- '`arguments` objects': arguments,
- 'arrays': ['a', ''],
- 'array-like objects': { '0': 'a', 'length': 1 },
- 'booleans': false,
- 'boolean objects': Object(false),
- 'date objects': new Date,
- 'Foo instances': new Foo,
- 'objects': { 'a': 0, 'b': 1, 'c': 2 },
- 'objects with object values': { 'a': /a/, 'b': ['B'], 'c': { 'C': 1 } },
- 'objects from another document': realm.object || {},
- 'maps': map,
- 'null values': null,
- 'numbers': 0,
- 'number objects': Object(0),
- 'regexes': /a/gim,
- 'sets': set,
- 'strings': 'a',
- 'string objects': Object('a'),
- 'undefined values': undefined
- };
- objects.arrays.length = 3;
- var uncloneable = {
- 'DOM elements': body,
- 'functions': Foo,
- 'generators': generator
- };
- lodashStable.each(errors, function(error) {
- uncloneable[error.name + 's'] = error;
- });
- QUnit.test('`_.clone` should perform a shallow clone', function(assert) {
- assert.expect(2);
- var array = [{ 'a': 0 }, { 'b': 1 }],
- actual = _.clone(array);
- assert.deepEqual(actual, array);
- assert.ok(actual !== array && actual[0] === array[0]);
- });
- QUnit.test('`_.cloneDeep` should deep clone objects with circular references', function(assert) {
- assert.expect(1);
- var object = {
- 'foo': { 'b': { 'c': { 'd': {} } } },
- 'bar': {}
- };
- object.foo.b.c.d = object;
- object.bar.b = object.foo.b;
- var actual = _.cloneDeep(object);
- assert.ok(actual.bar.b === actual.foo.b && actual === actual.foo.b.c.d && actual !== object);
- });
- QUnit.test('`_.cloneDeep` should deep clone objects with lots of circular references', function(assert) {
- assert.expect(2);
- var cyclical = {};
- lodashStable.times(LARGE_ARRAY_SIZE + 1, function(index) {
- cyclical['v' + index] = [index ? cyclical['v' + (index - 1)] : cyclical];
- });
- var clone = _.cloneDeep(cyclical),
- actual = clone['v' + LARGE_ARRAY_SIZE][0];
- assert.strictEqual(actual, clone['v' + (LARGE_ARRAY_SIZE - 1)]);
- assert.notStrictEqual(actual, cyclical['v' + (LARGE_ARRAY_SIZE - 1)]);
- });
- QUnit.test('`_.cloneDeepWith` should provide `stack` to `customizer`', function(assert) {
- assert.expect(1);
- var actual;
- _.cloneDeepWith({ 'a': 1 }, function() {
- actual = _.last(arguments);
- });
- assert.ok(isNpm
- ? actual.constructor.name == 'Stack'
- : actual instanceof mapCaches.Stack
- );
- });
- lodashStable.each(['clone', 'cloneDeep'], function(methodName) {
- var func = _[methodName],
- isDeep = methodName == 'cloneDeep';
- lodashStable.forOwn(objects, function(object, kind) {
- QUnit.test('`_.' + methodName + '` should clone ' + kind, function(assert) {
- assert.expect(2);
- var actual = func(object);
- assert.ok(lodashStable.isEqual(actual, object));
- if (lodashStable.isObject(object)) {
- assert.notStrictEqual(actual, object);
- } else {
- assert.strictEqual(actual, object);
- }
- });
- });
- QUnit.test('`_.' + methodName + '` should clone array buffers', function(assert) {
- assert.expect(2);
- if (ArrayBuffer) {
- var actual = func(arrayBuffer);
- assert.strictEqual(actual.byteLength, arrayBuffer.byteLength);
- assert.notStrictEqual(actual, arrayBuffer);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('`_.' + methodName + '` should clone buffers', function(assert) {
- assert.expect(4);
- if (Buffer) {
- var buffer = new Buffer([1, 2]),
- actual = func(buffer);
- assert.strictEqual(actual.byteLength, buffer.byteLength);
- assert.strictEqual(actual.inspect(), buffer.inspect());
- assert.notStrictEqual(actual, buffer);
- buffer[0] = 2;
- assert.strictEqual(actual[0], isDeep ? 2 : 1);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('`_.' + methodName + '` should clone `index` and `input` array properties', function(assert) {
- assert.expect(2);
- var array = /c/.exec('abcde'),
- actual = func(array);
- assert.strictEqual(actual.index, 2);
- assert.strictEqual(actual.input, 'abcde');
- });
- QUnit.test('`_.' + methodName + '` should clone `lastIndex` regexp property', function(assert) {
- assert.expect(1);
- var regexp = /c/g;
- regexp.exec('abcde');
- assert.strictEqual(func(regexp).lastIndex, 3);
- });
- QUnit.test('`_.' + methodName + '` should clone expando properties', function(assert) {
- assert.expect(1);
- var values = lodashStable.map([false, true, 1, 'a'], function(value) {
- var object = Object(value);
- object.a = 1;
- return object;
- });
- var expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value) {
- return func(value).a === 1;
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should clone prototype objects', function(assert) {
- assert.expect(2);
- var actual = func(Foo.prototype);
- assert.notOk(actual instanceof Foo);
- assert.deepEqual(actual, { 'b': 1 });
- });
- QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone', function(assert) {
- assert.expect(1);
- assert.ok(func(new Foo) instanceof Foo);
- });
- QUnit.test('`_.' + methodName + '` should set the `[[Prototype]]` of a clone even when the `constructor` is incorrect', function(assert) {
- assert.expect(1);
- Foo.prototype.constructor = Object;
- assert.ok(func(new Foo) instanceof Foo);
- Foo.prototype.constructor = Foo;
- });
- QUnit.test('`_.' + methodName + '` should ensure `value` constructor is a function before using its `[[Prototype]]`', function(assert) {
- assert.expect(1);
- Foo.prototype.constructor = null;
- assert.notOk(func(new Foo) instanceof Foo);
- Foo.prototype.constructor = Foo;
- });
- QUnit.test('`_.' + methodName + '` should clone properties that shadow those on `Object.prototype`', function(assert) {
- assert.expect(2);
- var object = {
- 'constructor': objectProto.constructor,
- 'hasOwnProperty': objectProto.hasOwnProperty,
- 'isPrototypeOf': objectProto.isPrototypeOf,
- 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
- 'toLocaleString': objectProto.toLocaleString,
- 'toString': objectProto.toString,
- 'valueOf': objectProto.valueOf
- };
- var actual = func(object);
- assert.deepEqual(actual, object);
- assert.notStrictEqual(actual, object);
- });
- QUnit.test('`_.' + methodName + '` should clone symbol properties', function(assert) {
- assert.expect(3);
- function Foo() {
- this[symbol] = { 'c': 1 };
- }
- if (Symbol) {
- var symbol2 = Symbol('b');
- Foo.prototype[symbol2] = 2;
- var object = { 'a': { 'b': new Foo } };
- object[symbol] = { 'b': 1 };
- var actual = func(object);
- assert.deepEqual(getSymbols(actual.a.b), [symbol]);
- if (isDeep) {
- assert.deepEqual(actual[symbol], object[symbol]);
- assert.deepEqual(actual.a.b[symbol], object.a.b[symbol]);
- }
- else {
- assert.strictEqual(actual[symbol], object[symbol]);
- assert.strictEqual(actual.a, object.a);
- }
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('`_.' + methodName + '` should clone symbol objects', function(assert) {
- assert.expect(4);
- if (Symbol) {
- assert.strictEqual(func(symbol), symbol);
- var object = Object(symbol),
- actual = func(object);
- assert.strictEqual(typeof actual, 'object');
- assert.strictEqual(typeof actual.valueOf(), 'symbol');
- assert.notStrictEqual(actual, object);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('`_.' + methodName + '` should not clone symbol primitives', function(assert) {
- assert.expect(1);
- if (Symbol) {
- assert.strictEqual(func(symbol), symbol);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should not error on DOM elements', function(assert) {
- assert.expect(1);
- if (document) {
- var element = document.createElement('div');
- try {
- assert.deepEqual(func(element), {});
- } catch (e) {
- assert.ok(false, e.message);
- }
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should create an object from the same realm as `value`', function(assert) {
- assert.expect(1);
- var props = [];
- var objects = lodashStable.transform(_, function(result, value, key) {
- if (lodashStable.startsWith(key, '_') && lodashStable.isObject(value) &&
- !lodashStable.isArguments(value) && !lodashStable.isElement(value) &&
- !lodashStable.isFunction(value)) {
- props.push(lodashStable.capitalize(lodashStable.camelCase(key)));
- result.push(value);
- }
- }, []);
- var expected = lodashStable.map(objects, stubTrue);
- var actual = lodashStable.map(objects, function(object) {
- var Ctor = object.constructor,
- result = func(object);
- return result !== object && ((result instanceof Ctor) || !(new Ctor instanceof Ctor));
- });
- assert.deepEqual(actual, expected, props.join(', '));
- });
- QUnit.test('`_.' + methodName + '` should perform a ' + (isDeep ? 'deep' : 'shallow') + ' clone when used as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(2);
- var expected = [{ 'a': [0] }, { 'b': [1] }],
- actual = lodashStable.map(expected, func);
- assert.deepEqual(actual, expected);
- if (isDeep) {
- assert.ok(actual[0] !== expected[0] && actual[0].a !== expected[0].a && actual[1].b !== expected[1].b);
- } else {
- assert.ok(actual[0] !== expected[0] && actual[0].a === expected[0].a && actual[1].b === expected[1].b);
- }
- });
- QUnit.test('`_.' + methodName + '` should return a unwrapped value when chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var object = objects.objects,
- actual = _(object)[methodName]();
- assert.deepEqual(actual, object);
- assert.notStrictEqual(actual, object);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- lodashStable.each(arrayViews, function(type) {
- QUnit.test('`_.' + methodName + '` should clone ' + type + ' values', function(assert) {
- assert.expect(10);
- var Ctor = root[type];
- lodashStable.times(2, function(index) {
- if (Ctor) {
- var buffer = new ArrayBuffer(24),
- view = index ? new Ctor(buffer, 8, 1) : new Ctor(buffer),
- actual = func(view);
- assert.deepEqual(actual, view);
- assert.notStrictEqual(actual, view);
- assert.strictEqual(actual.buffer === view.buffer, !isDeep);
- assert.strictEqual(actual.byteOffset, view.byteOffset);
- assert.strictEqual(actual.length, view.length);
- }
- else {
- skipAssert(assert, 5);
- }
- });
- });
- });
- lodashStable.forOwn(uncloneable, function(value, key) {
- QUnit.test('`_.' + methodName + '` should not clone ' + key, function(assert) {
- assert.expect(3);
- if (value) {
- var object = { 'a': value, 'b': { 'c': value } },
- actual = func(object),
- expected = (typeof value == 'function' && !!value.c) ? { 'c': Foo.c } : {};
- assert.deepEqual(actual, object);
- assert.notStrictEqual(actual, object);
- assert.deepEqual(func(value), expected);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- });
- });
- lodashStable.each(['cloneWith', 'cloneDeepWith'], function(methodName) {
- var func = _[methodName],
- isDeep = methodName == 'cloneDeepWith';
- QUnit.test('`_.' + methodName + '` should provide correct `customizer` arguments', function(assert) {
- assert.expect(1);
- var argsList = [],
- object = new Foo;
- func(object, function() {
- var length = arguments.length,
- args = slice.call(arguments, 0, length - (length > 1 ? 1 : 0));
- argsList.push(args);
- });
- assert.deepEqual(argsList, isDeep ? [[object], [1, 'a', object]] : [[object]]);
- });
- QUnit.test('`_.' + methodName + '` should handle cloning when `customizer` returns `undefined`', function(assert) {
- assert.expect(1);
- var actual = func({ 'a': { 'b': 'c' } }, noop);
- assert.deepEqual(actual, { 'a': { 'b': 'c' } });
- });
- lodashStable.forOwn(uncloneable, function(value, key) {
- QUnit.test('`_.' + methodName + '` should work with a `customizer` callback and ' + key, function(assert) {
- assert.expect(3);
- var customizer = function(value) {
- return lodashStable.isPlainObject(value) ? undefined : value;
- };
- var actual = func(value, customizer);
- assert.strictEqual(actual, value);
- var object = { 'a': value, 'b': { 'c': value } };
- actual = func(object, customizer);
- assert.deepEqual(actual, object);
- assert.notStrictEqual(actual, object);
- });
- });
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.compact');
- (function() {
- var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null);
- QUnit.test('should filter falsey values', function(assert) {
- assert.expect(1);
- var array = ['0', '1', '2'];
- assert.deepEqual(_.compact(falsey.concat(array)), array);
- });
- QUnit.test('should work when in-between lazy operators', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var actual = _(falsey).thru(_.slice).compact().thru(_.slice).value();
- assert.deepEqual(actual, []);
- actual = _(falsey).thru(_.slice).push(true, 1).compact().push('a').value();
- assert.deepEqual(actual, [true, 1, 'a']);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = _(largeArray).slice(1).compact().reverse().take().value();
- assert.deepEqual(actual, _.take(_.compact(_.slice(largeArray, 1)).reverse()));
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should work in a lazy sequence with a custom `_.iteratee`', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var iteratee = _.iteratee,
- pass = false;
- _.iteratee = identity;
- try {
- var actual = _(largeArray).slice(1).compact().value();
- pass = lodashStable.isEqual(actual, _.compact(_.slice(largeArray, 1)));
- } catch (e) {console.log(e);}
- assert.ok(pass);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.concat');
- (function() {
- QUnit.test('should shallow clone `array`', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3],
- actual = _.concat(array);
- assert.deepEqual(actual, array);
- assert.notStrictEqual(actual, array);
- });
- QUnit.test('should concat arrays and values', function(assert) {
- assert.expect(2);
- var array = [1],
- actual = _.concat(array, 2, [3], [[4]]);
- assert.deepEqual(actual, [1, 2, 3, [4]]);
- assert.deepEqual(array, [1]);
- });
- QUnit.test('should cast non-array `array` values to arrays', function(assert) {
- assert.expect(2);
- var values = [, null, undefined, false, true, 1, NaN, 'a'];
- var expected = lodashStable.map(values, function(value, index) {
- return index ? [value] : [];
- });
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.concat(value) : _.concat();
- });
- assert.deepEqual(actual, expected);
- expected = lodashStable.map(values, function(value) {
- return [value, 2, [3]];
- });
- actual = lodashStable.map(values, function(value) {
- return _.concat(value, [2], [[3]]);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should treat sparse arrays as dense', function(assert) {
- assert.expect(3);
- var expected = [],
- actual = _.concat(Array(1), Array(1));
- expected.push(undefined, undefined);
- assert.ok('0'in actual);
- assert.ok('1' in actual);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return a new wrapped array', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var array = [1],
- wrapped = _(array).concat([2, 3]),
- actual = wrapped.value();
- assert.deepEqual(array, [1]);
- assert.deepEqual(actual, [1, 2, 3]);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.cond');
- (function() {
- QUnit.test('should create a conditional function', function(assert) {
- assert.expect(3);
- var cond = _.cond([
- [lodashStable.matches({ 'a': 1 }), stubA],
- [lodashStable.matchesProperty('b', 1), stubB],
- [lodashStable.property('c'), stubC]
- ]);
- assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
- assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
- assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
- });
- QUnit.test('should provide arguments to functions', function(assert) {
- assert.expect(2);
- var args1,
- args2,
- expected = ['a', 'b', 'c'];
- var cond = _.cond([[
- function() { args1 || (args1 = slice.call(arguments)); return true; },
- function() { args2 || (args2 = slice.call(arguments)); }
- ]]);
- cond('a', 'b', 'c');
- assert.deepEqual(args1, expected);
- assert.deepEqual(args2, expected);
- });
- QUnit.test('should work with predicate shorthands', function(assert) {
- assert.expect(3);
- var cond = _.cond([
- [{ 'a': 1 }, stubA],
- [['b', 1], stubB],
- ['c', stubC]
- ]);
- assert.strictEqual(cond({ 'a': 1, 'b': 2, 'c': 3 }), 'a');
- assert.strictEqual(cond({ 'a': 0, 'b': 1, 'c': 2 }), 'b');
- assert.strictEqual(cond({ 'a': -1, 'b': 0, 'c': 1 }), 'c');
- });
- QUnit.test('should return `undefined` when no condition is met', function(assert) {
- assert.expect(1);
- var cond = _.cond([[stubFalse, stubA]]);
- assert.strictEqual(cond({ 'a': 1 }), undefined);
- });
- QUnit.test('should throw a TypeError if `pairs` is not composed of functions', function(assert) {
- assert.expect(2);
- lodashStable.each([false, true], function(value) {
- assert.raises(function() { _.cond([[stubTrue, value]])(); }, TypeError);
- });
- });
- QUnit.test('should use `this` binding of function for `pairs`', function(assert) {
- assert.expect(1);
- var cond = _.cond([
- [function(a) { return this[a]; }, function(a, b) { return this[b]; }]
- ]);
- var object = { 'cond': cond, 'a': 1, 'b': 2 };
- assert.strictEqual(object.cond('a', 'b'), 2);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.conforms');
- (function() {
- QUnit.test('should not change behavior if `source` is modified', function(assert) {
- assert.expect(2);
- var object = { 'a': 2 },
- source = { 'a': function(value) { return value > 1; } },
- par = _.conforms(source);
- assert.strictEqual(par(object), true);
- source.a = function(value) { return value < 2; };
- assert.strictEqual(par(object), true);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('conforms methods');
- lodashStable.each(['conforms', 'conformsTo'], function(methodName) {
- var isConforms = methodName == 'conforms';
- function conforms(source) {
- return isConforms ? _.conforms(source) : function(object) {
- return _.conformsTo(object, source);
- };
- }
- QUnit.test('`_.' + methodName + '` should check if `object` conforms to `source`', function(assert) {
- assert.expect(2);
- var objects = [
- { 'a': 1, 'b': 8 },
- { 'a': 2, 'b': 4 },
- { 'a': 3, 'b': 16 }
- ];
- var par = conforms({
- 'b': function(value) { return value > 4; }
- });
- var actual = lodashStable.filter(objects, par);
- assert.deepEqual(actual, [objects[0], objects[2]]);
- par = conforms({
- 'b': function(value) { return value > 8; },
- 'a': function(value) { return value > 1; }
- });
- actual = lodashStable.filter(objects, par);
- assert.deepEqual(actual, [objects[2]]);
- });
- QUnit.test('`_.' + methodName + '` should not match by inherited `source` properties', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = function(value) {
- return value > 1;
- };
- }
- Foo.prototype.b = function(value) {
- return value > 8;
- };
- var objects = [
- { 'a': 1, 'b': 8 },
- { 'a': 2, 'b': 4 },
- { 'a': 3, 'b': 16 }
- ];
- var par = conforms(new Foo),
- actual = lodashStable.filter(objects, par);
- assert.deepEqual(actual, [objects[1], objects[2]]);
- });
- QUnit.test('`_.' + methodName + '` should not invoke `source` predicates for missing `object` properties', function(assert) {
- assert.expect(2);
- var count = 0;
- var par = conforms({
- 'a': function() { count++; return true; }
- });
- assert.strictEqual(par({}), false);
- assert.strictEqual(count, 0);
- });
- QUnit.test('`_.' + methodName + '` should work with a function for `object`', function(assert) {
- assert.expect(2);
- function Foo() {}
- Foo.a = 1;
- function Bar() {}
- Bar.a = 2;
- var par = conforms({
- 'a': function(value) { return value > 1; }
- });
- assert.strictEqual(par(Foo), false);
- assert.strictEqual(par(Bar), true);
- });
- QUnit.test('`_.' + methodName + '` should work with a function for `source`', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.a = function(value) { return value > 1; };
- var objects = [{ 'a': 1 }, { 'a': 2 }],
- actual = lodashStable.filter(objects, conforms(Foo));
- assert.deepEqual(actual, [objects[1]]);
- });
- QUnit.test('`_.' + methodName + '` should work with a non-plain `object`', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var par = conforms({
- 'b': function(value) { return value > 1; }
- });
- assert.strictEqual(par(new Foo), true);
- });
- QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubFalse);
- var par = conforms({
- 'a': function(value) { return value > 1; }
- });
- var actual = lodashStable.map(values, function(value, index) {
- try {
- return index ? par(value) : par();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubTrue),
- par = conforms({});
- var actual = lodashStable.map(values, function(value, index) {
- try {
- return index ? par(value) : par();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should return `true` when comparing an empty `source`', function(assert) {
- assert.expect(1);
- var object = { 'a': 1 },
- expected = lodashStable.map(empties, stubTrue);
- var actual = lodashStable.map(empties, function(value) {
- var par = conforms(value);
- return par(object);
- });
- assert.deepEqual(actual, expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.constant');
- (function() {
- QUnit.test('should create a function that returns `value`', function(assert) {
- assert.expect(1);
- var object = { 'a': 1 },
- values = Array(2).concat(empties, true, 1, 'a'),
- constant = _.constant(object);
- var results = lodashStable.map(values, function(value, index) {
- if (index < 2) {
- return index ? constant.call({}) : constant();
- }
- return constant(value);
- });
- assert.ok(lodashStable.every(results, function(result) {
- return result === object;
- }));
- });
- QUnit.test('should work with falsey values', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(value, index) {
- var constant = index ? _.constant(value) : _.constant(),
- result = constant();
- return (result === value) || (result !== result && value !== value);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return a wrapped value when chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var wrapped = _(true).constant();
- assert.ok(wrapped instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.countBy');
- (function() {
- var array = [6.1, 4.2, 6.3];
- QUnit.test('should transform keys by `iteratee`', function(assert) {
- assert.expect(1);
- var actual = _.countBy(array, Math.floor);
- assert.deepEqual(actual, { '4': 1, '6': 2 });
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var array = [4, 6, 6],
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant({ '4': 1, '6': 2 }));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.countBy(array, value) : _.countBy(array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var actual = _.countBy(['one', 'two', 'three'], 'length');
- assert.deepEqual(actual, { '3': 2, '5': 1 });
- });
- QUnit.test('should only add values to own, not inherited, properties', function(assert) {
- assert.expect(2);
- var actual = _.countBy(array, function(n) {
- return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
- });
- assert.deepEqual(actual.constructor, 1);
- assert.deepEqual(actual.hasOwnProperty, 2);
- });
- QUnit.test('should work with a number for `iteratee`', function(assert) {
- assert.expect(2);
- var array = [
- [1, 'a'],
- [2, 'a'],
- [2, 'b']
- ];
- assert.deepEqual(_.countBy(array, 0), { '1': 1, '2': 2 });
- assert.deepEqual(_.countBy(array, 1), { 'a': 2, 'b': 1 });
- });
- QUnit.test('should work with an object for `collection`', function(assert) {
- assert.expect(1);
- var actual = _.countBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
- assert.deepEqual(actual, { '4': 1, '6': 2 });
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
- lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
- lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
- );
- var actual = _(array).countBy().map(square).filter(isEven).take().value();
- assert.deepEqual(actual, _.take(_.filter(_.map(_.countBy(array), square), isEven)));
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.create');
- (function() {
- function Shape() {
- this.x = 0;
- this.y = 0;
- }
- function Circle() {
- Shape.call(this);
- }
- QUnit.test('should create an object that inherits from the given `prototype` object', function(assert) {
- assert.expect(3);
- Circle.prototype = _.create(Shape.prototype);
- Circle.prototype.constructor = Circle;
- var actual = new Circle;
- assert.ok(actual instanceof Circle);
- assert.ok(actual instanceof Shape);
- assert.notStrictEqual(Circle.prototype, Shape.prototype);
- });
- QUnit.test('should assign `properties` to the created object', function(assert) {
- assert.expect(3);
- var expected = { 'constructor': Circle, 'radius': 0 };
- Circle.prototype = _.create(Shape.prototype, expected);
- var actual = new Circle;
- assert.ok(actual instanceof Circle);
- assert.ok(actual instanceof Shape);
- assert.deepEqual(Circle.prototype, expected);
- });
- QUnit.test('should assign own properties', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- this.c = 3;
- }
- Foo.prototype.b = 2;
- assert.deepEqual(_.create({}, new Foo), { 'a': 1, 'c': 3 });
- });
- QUnit.test('should assign properties that shadow those of `prototype`', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- var object = _.create(new Foo, { 'a': 1 });
- assert.deepEqual(lodashStable.keys(object), ['a']);
- });
- QUnit.test('should accept a falsey `prototype` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubObject);
- var actual = lodashStable.map(falsey, function(prototype, index) {
- return index ? _.create(prototype) : _.create();
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should ignore primitive `prototype` arguments and use an empty object instead', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(primitives, stubTrue);
- var actual = lodashStable.map(primitives, function(value, index) {
- return lodashStable.isPlainObject(index ? _.create(value) : _.create());
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [{ 'a': 1 }, { 'a': 1 }, { 'a': 1 }],
- expected = lodashStable.map(array, stubTrue),
- objects = lodashStable.map(array, _.create);
- var actual = lodashStable.map(objects, function(object) {
- return object.a === 1 && !_.keys(object).length;
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.curry');
- (function() {
- function fn(a, b, c, d) {
- return slice.call(arguments);
- }
- QUnit.test('should curry based on the number of arguments given', function(assert) {
- assert.expect(3);
- var curried = _.curry(fn),
- expected = [1, 2, 3, 4];
- assert.deepEqual(curried(1)(2)(3)(4), expected);
- assert.deepEqual(curried(1, 2)(3, 4), expected);
- assert.deepEqual(curried(1, 2, 3, 4), expected);
- });
- QUnit.test('should allow specifying `arity`', function(assert) {
- assert.expect(3);
- var curried = _.curry(fn, 3),
- expected = [1, 2, 3];
- assert.deepEqual(curried(1)(2, 3), expected);
- assert.deepEqual(curried(1, 2)(3), expected);
- assert.deepEqual(curried(1, 2, 3), expected);
- });
- QUnit.test('should coerce `arity` to an integer', function(assert) {
- assert.expect(2);
- var values = ['0', 0.6, 'xyz'],
- expected = lodashStable.map(values, stubArray);
- var actual = lodashStable.map(values, function(arity) {
- return _.curry(fn, arity)();
- });
- assert.deepEqual(actual, expected);
- assert.deepEqual(_.curry(fn, '2')(1)(2), [1, 2]);
- });
- QUnit.test('should support placeholders', function(assert) {
- assert.expect(4);
- var curried = _.curry(fn),
- ph = curried.placeholder;
- assert.deepEqual(curried(1)(ph, 3)(ph, 4)(2), [1, 2, 3, 4]);
- assert.deepEqual(curried(ph, 2)(1)(ph, 4)(3), [1, 2, 3, 4]);
- assert.deepEqual(curried(ph, ph, 3)(ph, 2)(ph, 4)(1), [1, 2, 3, 4]);
- assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), [1, 2, 3, 4]);
- });
- QUnit.test('should persist placeholders', function(assert) {
- assert.expect(1);
- var curried = _.curry(fn),
- ph = curried.placeholder,
- actual = curried(ph, ph, ph, 'd')('a')(ph)('b')('c');
- assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
- });
- QUnit.test('should use `_.placeholder` when set', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var curried = _.curry(fn),
- _ph = _.placeholder = {},
- ph = curried.placeholder;
- assert.deepEqual(curried(1)(_ph, 3)(ph, 4), [1, ph, 3, 4]);
- delete _.placeholder;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
- assert.expect(3);
- var curried = _.curry(fn, 3);
- assert.deepEqual(curried(1)(2, 3, 4), [1, 2, 3, 4]);
- assert.deepEqual(curried(1, 2)(3, 4, 5), [1, 2, 3, 4, 5]);
- assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
- });
- QUnit.test('should create a function with a `length` of `0`', function(assert) {
- assert.expect(6);
- lodashStable.times(2, function(index) {
- var curried = index ? _.curry(fn, 4) : _.curry(fn);
- assert.strictEqual(curried.length, 0);
- assert.strictEqual(curried(1).length, 0);
- assert.strictEqual(curried(1, 2).length, 0);
- });
- });
- QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
- assert.expect(2);
- function Foo(value) {
- return value && object;
- }
- var curried = _.curry(Foo),
- object = {};
- assert.ok(new curried(false) instanceof Foo);
- assert.strictEqual(new curried(true), object);
- });
- QUnit.test('should use `this` binding of function', function(assert) {
- assert.expect(9);
- var fn = function(a, b, c) {
- var value = this || {};
- return [value[a], value[b], value[c]];
- };
- var object = { 'a': 1, 'b': 2, 'c': 3 },
- expected = [1, 2, 3];
- assert.deepEqual(_.curry(_.bind(fn, object), 3)('a')('b')('c'), expected);
- assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b')('c'), expected);
- assert.deepEqual(_.curry(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
- assert.deepEqual(_.bind(_.curry(fn), object)('a')('b')('c'), Array(3));
- assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b')('c'), Array(3));
- assert.deepEqual(_.bind(_.curry(fn), object)('a', 'b', 'c'), expected);
- object.curried = _.curry(fn);
- assert.deepEqual(object.curried('a')('b')('c'), Array(3));
- assert.deepEqual(object.curried('a', 'b')('c'), Array(3));
- assert.deepEqual(object.curried('a', 'b', 'c'), expected);
- });
- QUnit.test('should work with partialed methods', function(assert) {
- assert.expect(2);
- var curried = _.curry(fn),
- expected = [1, 2, 3, 4];
- var a = _.partial(curried, 1),
- b = _.bind(a, null, 2),
- c = _.partialRight(b, 4),
- d = _.partialRight(b(3), 4);
- assert.deepEqual(c(3), expected);
- assert.deepEqual(d(), expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.curryRight');
- (function() {
- function fn(a, b, c, d) {
- return slice.call(arguments);
- }
- QUnit.test('should curry based on the number of arguments given', function(assert) {
- assert.expect(3);
- var curried = _.curryRight(fn),
- expected = [1, 2, 3, 4];
- assert.deepEqual(curried(4)(3)(2)(1), expected);
- assert.deepEqual(curried(3, 4)(1, 2), expected);
- assert.deepEqual(curried(1, 2, 3, 4), expected);
- });
- QUnit.test('should allow specifying `arity`', function(assert) {
- assert.expect(3);
- var curried = _.curryRight(fn, 3),
- expected = [1, 2, 3];
- assert.deepEqual(curried(3)(1, 2), expected);
- assert.deepEqual(curried(2, 3)(1), expected);
- assert.deepEqual(curried(1, 2, 3), expected);
- });
- QUnit.test('should coerce `arity` to an integer', function(assert) {
- assert.expect(2);
- var values = ['0', 0.6, 'xyz'],
- expected = lodashStable.map(values, stubArray);
- var actual = lodashStable.map(values, function(arity) {
- return _.curryRight(fn, arity)();
- });
- assert.deepEqual(actual, expected);
- assert.deepEqual(_.curryRight(fn, '2')(1)(2), [2, 1]);
- });
- QUnit.test('should support placeholders', function(assert) {
- assert.expect(4);
- var curried = _.curryRight(fn),
- expected = [1, 2, 3, 4],
- ph = curried.placeholder;
- assert.deepEqual(curried(4)(2, ph)(1, ph)(3), expected);
- assert.deepEqual(curried(3, ph)(4)(1, ph)(2), expected);
- assert.deepEqual(curried(ph, ph, 4)(ph, 3)(ph, 2)(1), expected);
- assert.deepEqual(curried(ph, ph, ph, 4)(ph, ph, 3)(ph, 2)(1), expected);
- });
- QUnit.test('should persist placeholders', function(assert) {
- assert.expect(1);
- var curried = _.curryRight(fn),
- ph = curried.placeholder,
- actual = curried('a', ph, ph, ph)('b')(ph)('c')('d');
- assert.deepEqual(actual, ['a', 'b', 'c', 'd']);
- });
- QUnit.test('should use `_.placeholder` when set', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var curried = _.curryRight(fn),
- _ph = _.placeholder = {},
- ph = curried.placeholder;
- assert.deepEqual(curried(4)(2, _ph)(1, ph), [1, 2, ph, 4]);
- delete _.placeholder;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should provide additional arguments after reaching the target arity', function(assert) {
- assert.expect(3);
- var curried = _.curryRight(fn, 3);
- assert.deepEqual(curried(4)(1, 2, 3), [1, 2, 3, 4]);
- assert.deepEqual(curried(4, 5)(1, 2, 3), [1, 2, 3, 4, 5]);
- assert.deepEqual(curried(1, 2, 3, 4, 5, 6), [1, 2, 3, 4, 5, 6]);
- });
- QUnit.test('should create a function with a `length` of `0`', function(assert) {
- assert.expect(6);
- lodashStable.times(2, function(index) {
- var curried = index ? _.curryRight(fn, 4) : _.curryRight(fn);
- assert.strictEqual(curried.length, 0);
- assert.strictEqual(curried(4).length, 0);
- assert.strictEqual(curried(3, 4).length, 0);
- });
- });
- QUnit.test('should ensure `new curried` is an instance of `func`', function(assert) {
- assert.expect(2);
- function Foo(value) {
- return value && object;
- }
- var curried = _.curryRight(Foo),
- object = {};
- assert.ok(new curried(false) instanceof Foo);
- assert.strictEqual(new curried(true), object);
- });
- QUnit.test('should use `this` binding of function', function(assert) {
- assert.expect(9);
- var fn = function(a, b, c) {
- var value = this || {};
- return [value[a], value[b], value[c]];
- };
- var object = { 'a': 1, 'b': 2, 'c': 3 },
- expected = [1, 2, 3];
- assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('c')('b')('a'), expected);
- assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('b', 'c')('a'), expected);
- assert.deepEqual(_.curryRight(_.bind(fn, object), 3)('a', 'b', 'c'), expected);
- assert.deepEqual(_.bind(_.curryRight(fn), object)('c')('b')('a'), Array(3));
- assert.deepEqual(_.bind(_.curryRight(fn), object)('b', 'c')('a'), Array(3));
- assert.deepEqual(_.bind(_.curryRight(fn), object)('a', 'b', 'c'), expected);
- object.curried = _.curryRight(fn);
- assert.deepEqual(object.curried('c')('b')('a'), Array(3));
- assert.deepEqual(object.curried('b', 'c')('a'), Array(3));
- assert.deepEqual(object.curried('a', 'b', 'c'), expected);
- });
- QUnit.test('should work with partialed methods', function(assert) {
- assert.expect(2);
- var curried = _.curryRight(fn),
- expected = [1, 2, 3, 4];
- var a = _.partialRight(curried, 4),
- b = _.partialRight(a, 3),
- c = _.bind(b, null, 1),
- d = _.partial(b(2), 1);
- assert.deepEqual(c(2), expected);
- assert.deepEqual(d(), expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('curry methods');
- lodashStable.each(['curry', 'curryRight'], function(methodName) {
- var func = _[methodName],
- fn = function(a, b) { return slice.call(arguments); },
- isCurry = methodName == 'curry';
- QUnit.test('`_.' + methodName + '` should not error on functions with the same name as lodash methods', function(assert) {
- assert.expect(1);
- function run(a, b) {
- return a + b;
- }
- var curried = func(run);
- try {
- var actual = curried(1)(2);
- } catch (e) {}
- assert.strictEqual(actual, 3);
- });
- QUnit.test('`_.' + methodName + '` should work for function names that shadow those on `Object.prototype`', function(assert) {
- assert.expect(1);
- var curried = _.curry(function hasOwnProperty(a, b, c) {
- return [a, b, c];
- });
- var expected = [1, 2, 3];
- assert.deepEqual(curried(1)(2)(3), expected);
- });
- QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(2);
- var array = [fn, fn, fn],
- object = { 'a': fn, 'b': fn, 'c': fn };
- lodashStable.each([array, object], function(collection) {
- var curries = lodashStable.map(collection, func),
- expected = lodashStable.map(collection, lodashStable.constant(isCurry ? ['a', 'b'] : ['b', 'a']));
- var actual = lodashStable.map(curries, function(curried) {
- return curried('a')('b');
- });
- assert.deepEqual(actual, expected);
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.debounce');
- (function() {
- QUnit.test('should debounce a function', function(assert) {
- assert.expect(6);
- var done = assert.async();
- var callCount = 0;
- var debounced = _.debounce(function(value) {
- ++callCount;
- return value;
- }, 32);
- var results = [debounced('a'), debounced('b'), debounced('c')];
- assert.deepEqual(results, [undefined, undefined, undefined]);
- assert.strictEqual(callCount, 0);
- setTimeout(function() {
- assert.strictEqual(callCount, 1);
- var results = [debounced('d'), debounced('e'), debounced('f')];
- assert.deepEqual(results, ['c', 'c', 'c']);
- assert.strictEqual(callCount, 1);
- }, 128);
- setTimeout(function() {
- assert.strictEqual(callCount, 2);
- done();
- }, 256);
- });
- QUnit.test('subsequent debounced calls return the last `func` result', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var debounced = _.debounce(identity, 32);
- debounced('a');
- setTimeout(function() {
- assert.notEqual(debounced('b'), 'b');
- }, 64);
- setTimeout(function() {
- assert.notEqual(debounced('c'), 'c');
- done();
- }, 128);
- });
- QUnit.test('should not immediately call `func` when `wait` is `0`', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var callCount = 0,
- debounced = _.debounce(function() { ++callCount; }, 0);
- debounced();
- debounced();
- assert.strictEqual(callCount, 0);
- setTimeout(function() {
- assert.strictEqual(callCount, 1);
- done();
- }, 5);
- });
- QUnit.test('should apply default options', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var callCount = 0,
- debounced = _.debounce(function() { callCount++; }, 32, {});
- debounced();
- assert.strictEqual(callCount, 0);
- setTimeout(function() {
- assert.strictEqual(callCount, 1);
- done();
- }, 64);
- });
- QUnit.test('should support a `leading` option', function(assert) {
- assert.expect(4);
- var done = assert.async();
- var callCounts = [0, 0];
- var withLeading = _.debounce(function() {
- callCounts[0]++;
- }, 32, { 'leading': true });
- var withLeadingAndTrailing = _.debounce(function() {
- callCounts[1]++;
- }, 32, { 'leading': true });
- withLeading();
- assert.strictEqual(callCounts[0], 1);
- withLeadingAndTrailing();
- withLeadingAndTrailing();
- assert.strictEqual(callCounts[1], 1);
- setTimeout(function() {
- assert.deepEqual(callCounts, [1, 2]);
- withLeading();
- assert.strictEqual(callCounts[0], 2);
- done();
- }, 64);
- });
- QUnit.test('subsequent leading debounced calls return the last `func` result', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var debounced = _.debounce(identity, 32, { 'leading': true, 'trailing': false }),
- results = [debounced('a'), debounced('b')];
- assert.deepEqual(results, ['a', 'a']);
- setTimeout(function() {
- var results = [debounced('c'), debounced('d')];
- assert.deepEqual(results, ['c', 'c']);
- done();
- }, 64);
- });
- QUnit.test('should support a `trailing` option', function(assert) {
- assert.expect(4);
- var done = assert.async();
- var withCount = 0,
- withoutCount = 0;
- var withTrailing = _.debounce(function() {
- withCount++;
- }, 32, { 'trailing': true });
- var withoutTrailing = _.debounce(function() {
- withoutCount++;
- }, 32, { 'trailing': false });
- withTrailing();
- assert.strictEqual(withCount, 0);
- withoutTrailing();
- assert.strictEqual(withoutCount, 0);
- setTimeout(function() {
- assert.strictEqual(withCount, 1);
- assert.strictEqual(withoutCount, 0);
- done();
- }, 64);
- });
- QUnit.test('should support a `maxWait` option', function(assert) {
- assert.expect(4);
- var done = assert.async();
- var callCount = 0;
- var debounced = _.debounce(function(value) {
- ++callCount;
- return value;
- }, 32, { 'maxWait': 64 });
- debounced();
- debounced();
- assert.strictEqual(callCount, 0);
- setTimeout(function() {
- assert.strictEqual(callCount, 1);
- debounced();
- debounced();
- assert.strictEqual(callCount, 1);
- }, 128);
- setTimeout(function() {
- assert.strictEqual(callCount, 2);
- done();
- }, 256);
- });
- QUnit.test('should support `maxWait` in a tight loop', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var limit = (argv || isPhantom) ? 1000 : 320,
- withCount = 0,
- withoutCount = 0;
- var withMaxWait = _.debounce(function() {
- withCount++;
- }, 64, { 'maxWait': 128 });
- var withoutMaxWait = _.debounce(function() {
- withoutCount++;
- }, 96);
- var start = +new Date;
- while ((new Date - start) < limit) {
- withMaxWait();
- withoutMaxWait();
- }
- var actual = [Boolean(withoutCount), Boolean(withCount)];
- setTimeout(function() {
- assert.deepEqual(actual, [false, true]);
- done();
- }, 1);
- });
- QUnit.test('should queue a trailing call for subsequent debounced calls after `maxWait`', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var callCount = 0;
- var debounced = _.debounce(function() {
- ++callCount;
- }, 200, { 'maxWait': 200 });
- debounced();
- setTimeout(debounced, 190);
- setTimeout(debounced, 200);
- setTimeout(debounced, 210);
- setTimeout(function() {
- assert.strictEqual(callCount, 2);
- done();
- }, 500);
- });
- QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var callCount = 0;
- var debounced = _.debounce(function() {
- callCount++;
- }, 32, { 'maxWait': 64 });
- debounced();
- setTimeout(function() {
- debounced();
- assert.strictEqual(callCount, 1);
- }, 128);
- setTimeout(function() {
- assert.strictEqual(callCount, 2);
- done();
- }, 192);
- });
- QUnit.test('should invoke the trailing call with the correct arguments and `this` binding', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var actual,
- callCount = 0,
- object = {};
- var debounced = _.debounce(function(value) {
- actual = [this];
- push.apply(actual, arguments);
- return ++callCount != 2;
- }, 32, { 'leading': true, 'maxWait': 64 });
- while (true) {
- if (!debounced.call(object, 'a')) {
- break;
- }
- }
- setTimeout(function() {
- assert.strictEqual(callCount, 2);
- assert.deepEqual(actual, [object, 'a']);
- done();
- }, 64);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.deburr');
- (function() {
- QUnit.test('should convert Latin-1 Supplement letters to basic Latin', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(burredLetters, _.deburr);
- assert.deepEqual(actual, deburredLetters);
- });
- QUnit.test('should not deburr Latin mathematical operators', function(assert) {
- assert.expect(1);
- var operators = ['\xd7', '\xf7'],
- actual = lodashStable.map(operators, _.deburr);
- assert.deepEqual(actual, operators);
- });
- QUnit.test('should deburr combining diacritical marks', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(comboMarks, lodashStable.constant('ei'));
- var actual = lodashStable.map(comboMarks, function(chr) {
- return _.deburr('e' + chr + 'i');
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.defaults');
- (function() {
- QUnit.test('should assign source properties if missing on `object`', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.defaults({ 'a': 1 }, { 'a': 2, 'b': 2 }), { 'a': 1, 'b': 2 });
- });
- QUnit.test('should accept multiple sources', function(assert) {
- assert.expect(2);
- var expected = { 'a': 1, 'b': 2, 'c': 3 };
- assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3 }, { 'c': 3 }), expected);
- assert.deepEqual(_.defaults({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 3 }, { 'c': 2 }), expected);
- });
- QUnit.test('should not overwrite `null` values', function(assert) {
- assert.expect(1);
- var actual = _.defaults({ 'a': null }, { 'a': 1 });
- assert.strictEqual(actual.a, null);
- });
- QUnit.test('should overwrite `undefined` values', function(assert) {
- assert.expect(1);
- var actual = _.defaults({ 'a': undefined }, { 'a': 1 });
- assert.strictEqual(actual.a, 1);
- });
- QUnit.test('should assign properties that shadow those on `Object.prototype`', function(assert) {
- assert.expect(2);
- var object = {
- 'constructor': objectProto.constructor,
- 'hasOwnProperty': objectProto.hasOwnProperty,
- 'isPrototypeOf': objectProto.isPrototypeOf,
- 'propertyIsEnumerable': objectProto.propertyIsEnumerable,
- 'toLocaleString': objectProto.toLocaleString,
- 'toString': objectProto.toString,
- 'valueOf': objectProto.valueOf
- };
- var source = {
- 'constructor': 1,
- 'hasOwnProperty': 2,
- 'isPrototypeOf': 3,
- 'propertyIsEnumerable': 4,
- 'toLocaleString': 5,
- 'toString': 6,
- 'valueOf': 7
- };
- assert.deepEqual(_.defaults({}, source), source);
- assert.deepEqual(_.defaults({}, object, source), object);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.defaultsDeep');
- (function() {
- QUnit.test('should deep assign source properties if missing on `object`', function(assert) {
- assert.expect(1);
- var object = { 'a': { 'b': 2 }, 'd': 4 },
- source = { 'a': { 'b': 3, 'c': 3 }, 'e': 5 },
- expected = { 'a': { 'b': 2, 'c': 3 }, 'd': 4, 'e': 5 };
- assert.deepEqual(_.defaultsDeep(object, source), expected);
- });
- QUnit.test('should accept multiple sources', function(assert) {
- assert.expect(2);
- var source1 = { 'a': { 'b': 3 } },
- source2 = { 'a': { 'c': 3 } },
- source3 = { 'a': { 'b': 3, 'c': 3 } },
- source4 = { 'a': { 'c': 4 } },
- expected = { 'a': { 'b': 2, 'c': 3 } };
- assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source1, source2), expected);
- assert.deepEqual(_.defaultsDeep({ 'a': { 'b': 2 } }, source3, source4), expected);
- });
- QUnit.test('should not overwrite `null` values', function(assert) {
- assert.expect(1);
- var object = { 'a': { 'b': null } },
- source = { 'a': { 'b': 2 } },
- actual = _.defaultsDeep(object, source);
- assert.strictEqual(actual.a.b, null);
- });
- QUnit.test('should not overwrite regexp values', function(assert) {
- assert.expect(1);
- var object = { 'a': { 'b': /x/ } },
- source = { 'a': { 'b': /y/ } },
- actual = _.defaultsDeep(object, source);
- assert.deepEqual(actual.a.b, /x/);
- });
- QUnit.test('should not convert function properties to objects', function(assert) {
- assert.expect(2);
- var actual = _.defaultsDeep({}, { 'a': noop });
- assert.strictEqual(actual.a, noop);
- actual = _.defaultsDeep({}, { 'a': { 'b': noop } });
- assert.strictEqual(actual.a.b, noop);
- });
- QUnit.test('should overwrite `undefined` values', function(assert) {
- assert.expect(1);
- var object = { 'a': { 'b': undefined } },
- source = { 'a': { 'b': 2 } },
- actual = _.defaultsDeep(object, source);
- assert.strictEqual(actual.a.b, 2);
- });
- QUnit.test('should merge sources containing circular references', function(assert) {
- assert.expect(2);
- var object = {
- 'foo': { 'b': { 'c': { 'd': {} } } },
- 'bar': { 'a': 2 }
- };
- var source = {
- 'foo': { 'b': { 'c': { 'd': {} } } },
- 'bar': {}
- };
- object.foo.b.c.d = object;
- source.foo.b.c.d = source;
- source.bar.b = source.foo.b;
- var actual = _.defaultsDeep(object, source);
- assert.strictEqual(actual.bar.b, actual.foo.b);
- assert.strictEqual(actual.foo.b.c.d, actual.foo.b.c.d.foo.b.c.d);
- });
- QUnit.test('should not modify sources', function(assert) {
- assert.expect(3);
- var source1 = { 'a': 1, 'b': { 'c': 2 } },
- source2 = { 'b': { 'c': 3, 'd': 3 } },
- actual = _.defaultsDeep({}, source1, source2);
- assert.deepEqual(actual, { 'a': 1, 'b': { 'c': 2, 'd': 3 } });
- assert.deepEqual(source1, { 'a': 1, 'b': { 'c': 2 } });
- assert.deepEqual(source2, { 'b': { 'c': 3, 'd': 3 } });
- });
- QUnit.test('should not attempt a merge of a string into an array', function(assert) {
- assert.expect(1);
- var actual = _.defaultsDeep({ 'a': ['abc'] }, { 'a': 'abc' });
- assert.deepEqual(actual, { 'a': ['abc'] });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.defaultTo');
- (function() {
- QUnit.test('should return a default value if `value` is `NaN` or nullish', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return (value == null || value !== value) ? 1 : value;
- });
- var actual = lodashStable.map(falsey, function(value) {
- return _.defaultTo(value, 1);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.defer');
- (function() {
- QUnit.test('should defer `func` execution', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var pass = false;
- _.defer(function() { pass = true; });
- setTimeout(function() {
- assert.ok(pass);
- done();
- }, 32);
- });
- QUnit.test('should provide additional arguments to `func`', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var args;
- _.defer(function() {
- args = slice.call(arguments);
- }, 1, 2);
- setTimeout(function() {
- assert.deepEqual(args, [1, 2]);
- done();
- }, 32);
- });
- QUnit.test('should be cancelable', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var pass = true,
- timerId = _.defer(function() { pass = false; });
- clearTimeout(timerId);
- setTimeout(function() {
- assert.ok(pass);
- done();
- }, 32);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.delay');
- (function() {
- QUnit.test('should delay `func` execution', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var pass = false;
- _.delay(function() { pass = true; }, 32);
- setTimeout(function() {
- assert.notOk(pass);
- }, 1);
- setTimeout(function() {
- assert.ok(pass);
- done();
- }, 64);
- });
- QUnit.test('should provide additional arguments to `func`', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var args;
- _.delay(function() {
- args = slice.call(arguments);
- }, 32, 1, 2);
- setTimeout(function() {
- assert.deepEqual(args, [1, 2]);
- done();
- }, 64);
- });
- QUnit.test('should use a default `wait` of `0`', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var pass = false;
- _.delay(function() { pass = true; });
- assert.notOk(pass);
- setTimeout(function() {
- assert.ok(pass);
- done();
- }, 0);
- });
- QUnit.test('should be cancelable', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var pass = true,
- timerId = _.delay(function() { pass = false; }, 32);
- clearTimeout(timerId);
- setTimeout(function() {
- assert.ok(pass);
- done();
- }, 64);
- });
- QUnit.test('should work with mocked `setTimeout`', function(assert) {
- assert.expect(1);
- if (!isPhantom) {
- var pass = false,
- setTimeout = root.setTimeout;
- setProperty(root, 'setTimeout', function(func) { func(); });
- _.delay(function() { pass = true; }, 32);
- setProperty(root, 'setTimeout', setTimeout);
- assert.ok(pass);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('difference methods');
- lodashStable.each(['difference', 'differenceBy', 'differenceWith'], function(methodName) {
- var args = (function() { return arguments; }(1, 2, 3)),
- func = _[methodName];
- QUnit.test('`_.' + methodName + '` should return the difference of two arrays', function(assert) {
- assert.expect(1);
- var actual = func([2, 1], [2, 3]);
- assert.deepEqual(actual, [1]);
- });
- QUnit.test('`_.' + methodName + '` should return the difference of multiple arrays', function(assert) {
- assert.expect(1);
- var actual = func([2, 1, 2, 3], [3, 4], [3, 2]);
- assert.deepEqual(actual, [1]);
- });
- QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
- assert.expect(2);
- var array = [-0, 0];
- var actual = lodashStable.map(array, function(value) {
- return func(array, [value]);
- });
- assert.deepEqual(actual, [[], []]);
- actual = lodashStable.map(func([-0, 1], [1]), lodashStable.toString);
- assert.deepEqual(actual, ['0']);
- });
- QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
- assert.expect(1);
- assert.deepEqual(func([1, NaN, 3], [NaN, 5, NaN]), [1, 3]);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
- assert.expect(1);
- var array1 = lodashStable.range(LARGE_ARRAY_SIZE + 1),
- array2 = lodashStable.range(LARGE_ARRAY_SIZE),
- a = {},
- b = {},
- c = {};
- array1.push(a, b, c);
- array2.push(b, c, a);
- assert.deepEqual(func(array1, array2), [LARGE_ARRAY_SIZE]);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
- assert.expect(2);
- var array = [-0, 0];
- var actual = lodashStable.map(array, function(value) {
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(value));
- return func(array, largeArray);
- });
- assert.deepEqual(actual, [[], []]);
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubOne);
- actual = lodashStable.map(func([-0, 1], largeArray), lodashStable.toString);
- assert.deepEqual(actual, ['0']);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
- assert.expect(1);
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubNaN);
- assert.deepEqual(func([1, NaN, 3], largeArray), [1, 3]);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
- assert.expect(1);
- var object1 = {},
- object2 = {},
- largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object1));
- assert.deepEqual(func([object1, object2], largeArray), [object2]);
- });
- QUnit.test('`_.' + methodName + '` should ignore values that are not array-like', function(assert) {
- assert.expect(3);
- var array = [1, null, 3];
- assert.deepEqual(func(args, 3, { '0': 1 }), [1, 2, 3]);
- assert.deepEqual(func(null, array, 1), []);
- assert.deepEqual(func(array, args, null), [null]);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.differenceBy');
- (function() {
- QUnit.test('should accept an `iteratee` argument', function(assert) {
- assert.expect(2);
- var actual = _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
- assert.deepEqual(actual, [1.2]);
- actual = _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
- assert.deepEqual(actual, [{ 'x': 2 }]);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.differenceBy([2.1, 1.2], [2.3, 3.4], function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [2.3]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.differenceWith');
- (function() {
- QUnit.test('should work with a `comparator` argument', function(assert) {
- assert.expect(1);
- var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
- actual = _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], lodashStable.isEqual);
- assert.deepEqual(actual, [objects[1]]);
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var array = [-0, 1],
- largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubOne),
- others = [[1], largeArray],
- expected = lodashStable.map(others, lodashStable.constant(['-0']));
- var actual = lodashStable.map(others, function(other) {
- return lodashStable.map(_.differenceWith(array, other, lodashStable.eq), lodashStable.toString);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.divide');
- (function() {
- QUnit.test('should divide two numbers', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.divide(6, 4), 1.5);
- assert.strictEqual(_.divide(-6, 4), -1.5);
- assert.strictEqual(_.divide(-6, -4), 1.5);
- });
- QUnit.test('should coerce arguments to numbers', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.divide('6', '4'), 1.5);
- assert.deepEqual(_.divide('x', 'y'), NaN);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.drop');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should drop the first two elements', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.drop(array, 2), [3]);
- });
- QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? [2, 3] : array;
- });
- var actual = lodashStable.map(falsey, function(n) {
- return _.drop(array, n);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return all elements when `n` < `1`', function(assert) {
- assert.expect(3);
- lodashStable.each([0, -1, -Infinity], function(n) {
- assert.deepEqual(_.drop(array, n), array);
- });
- });
- QUnit.test('should return an empty array when `n` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
- assert.deepEqual(_.drop(array, n), []);
- });
- });
- QUnit.test('should coerce `n` to an integer', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.drop(array, 1.6), [2, 3]);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- actual = lodashStable.map(array, _.drop);
- assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
- predicate = function(value) { values.push(value); return isEven(value); },
- values = [],
- actual = _(array).drop(2).drop().value();
- assert.deepEqual(actual, array.slice(3));
- actual = _(array).filter(predicate).drop(2).drop().value();
- assert.deepEqual(values, array);
- assert.deepEqual(actual, _.drop(_.drop(_.filter(array, predicate), 2)));
- actual = _(array).drop(2).dropRight().drop().dropRight(2).value();
- assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(array, 2))), 2));
- values = [];
- actual = _(array).drop().filter(predicate).drop(2).dropRight().drop().dropRight(2).value();
- assert.deepEqual(values, array.slice(1));
- assert.deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(_.filter(_.drop(array), predicate), 2))), 2));
- }
- else {
- skipAssert(assert, 6);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.dropRight');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should drop the last two elements', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.dropRight(array, 2), [1]);
- });
- QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? [1, 2] : array;
- });
- var actual = lodashStable.map(falsey, function(n) {
- return _.dropRight(array, n);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return all elements when `n` < `1`', function(assert) {
- assert.expect(3);
- lodashStable.each([0, -1, -Infinity], function(n) {
- assert.deepEqual(_.dropRight(array, n), array);
- });
- });
- QUnit.test('should return an empty array when `n` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
- assert.deepEqual(_.dropRight(array, n), []);
- });
- });
- QUnit.test('should coerce `n` to an integer', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.dropRight(array, 1.6), [1, 2]);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- actual = lodashStable.map(array, _.dropRight);
- assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
- predicate = function(value) { values.push(value); return isEven(value); },
- values = [],
- actual = _(array).dropRight(2).dropRight().value();
- assert.deepEqual(actual, array.slice(0, -3));
- actual = _(array).filter(predicate).dropRight(2).dropRight().value();
- assert.deepEqual(values, array);
- assert.deepEqual(actual, _.dropRight(_.dropRight(_.filter(array, predicate), 2)));
- actual = _(array).dropRight(2).drop().dropRight().drop(2).value();
- assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(array, 2))), 2));
- values = [];
- actual = _(array).dropRight().filter(predicate).dropRight(2).drop().dropRight().drop(2).value();
- assert.deepEqual(values, array.slice(0, -1));
- assert.deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(_.filter(_.dropRight(array), predicate), 2))), 2));
- }
- else {
- skipAssert(assert, 6);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.dropRightWhile');
- (function() {
- var array = [1, 2, 3, 4];
- var objects = [
- { 'a': 0, 'b': 0 },
- { 'a': 1, 'b': 1 },
- { 'a': 2, 'b': 2 }
- ];
- QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
- assert.expect(1);
- var actual = _.dropRightWhile(array, function(n) {
- return n > 2;
- });
- assert.deepEqual(actual, [1, 2]);
- });
- QUnit.test('should provide correct `predicate` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.dropRightWhile(array, function() {
- args = slice.call(arguments);
- });
- assert.deepEqual(args, [4, 3, array]);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.dropRightWhile(objects, { 'b': 2 }), objects.slice(0, 2));
- });
- QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.dropRightWhile(objects, ['b', 2]), objects.slice(0, 2));
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.dropRightWhile(objects, 'b'), objects.slice(0, 1));
- });
- QUnit.test('should return a wrapped value when chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _(array).dropRightWhile(function(n) {
- return n > 2;
- });
- assert.ok(wrapped instanceof _);
- assert.deepEqual(wrapped.value(), [1, 2]);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.dropWhile');
- (function() {
- var array = [1, 2, 3, 4];
- var objects = [
- { 'a': 2, 'b': 2 },
- { 'a': 1, 'b': 1 },
- { 'a': 0, 'b': 0 }
- ];
- QUnit.test('should drop elements while `predicate` returns truthy', function(assert) {
- assert.expect(1);
- var actual = _.dropWhile(array, function(n) {
- return n < 3;
- });
- assert.deepEqual(actual, [3, 4]);
- });
- QUnit.test('should provide correct `predicate` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.dropWhile(array, function() {
- args = slice.call(arguments);
- });
- assert.deepEqual(args, [1, 0, array]);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.dropWhile(objects, { 'b': 2 }), objects.slice(1));
- });
- QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.dropWhile(objects, ['b', 2]), objects.slice(1));
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.dropWhile(objects, 'b'), objects.slice(2));
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(3);
- if (!isNpm) {
- var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3),
- predicate = function(n) { return n < 3; },
- expected = _.dropWhile(array, predicate),
- wrapped = _(array).dropWhile(predicate);
- assert.deepEqual(wrapped.value(), expected);
- assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
- assert.strictEqual(wrapped.last(), _.last(expected));
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('should work in a lazy sequence with `drop`', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 3);
- var actual = _(array)
- .dropWhile(function(n) { return n == 1; })
- .drop()
- .dropWhile(function(n) { return n == 3; })
- .value();
- assert.deepEqual(actual, array.slice(3));
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.endsWith');
- (function() {
- var string = 'abc';
- QUnit.test('should return `true` if a string ends with `target`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.endsWith(string, 'c'), true);
- });
- QUnit.test('should return `false` if a string does not end with `target`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.endsWith(string, 'b'), false);
- });
- QUnit.test('should work with a `position` argument', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.endsWith(string, 'b', 2), true);
- });
- QUnit.test('should work with `position` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
- assert.strictEqual(_.endsWith(string, 'c', position), true);
- });
- });
- QUnit.test('should treat falsey `position` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(position) {
- return _.endsWith(string, position === undefined ? 'c' : '', position);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should treat a negative `position` as `0`', function(assert) {
- assert.expect(6);
- lodashStable.each([-1, -3, -Infinity], function(position) {
- assert.ok(lodashStable.every(string, function(chr) {
- return !_.endsWith(string, chr, position);
- }));
- assert.strictEqual(_.endsWith(string, '', position), true);
- });
- });
- QUnit.test('should coerce `position` to an integer', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.endsWith(string, 'ab', 2.2), true);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.eq');
- (function() {
- QUnit.test('should perform a `SameValueZero` comparison of two values', function(assert) {
- assert.expect(11);
- assert.strictEqual(_.eq(), true);
- assert.strictEqual(_.eq(undefined), true);
- assert.strictEqual(_.eq(0, -0), true);
- assert.strictEqual(_.eq(NaN, NaN), true);
- assert.strictEqual(_.eq(1, 1), true);
- assert.strictEqual(_.eq(null, undefined), false);
- assert.strictEqual(_.eq(1, Object(1)), false);
- assert.strictEqual(_.eq(1, '1'), false);
- assert.strictEqual(_.eq(1, '1'), false);
- var object = { 'a': 1 };
- assert.strictEqual(_.eq(object, object), true);
- assert.strictEqual(_.eq(object, { 'a': 1 }), false);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.escape');
- (function() {
- var escaped = '&<>"'`\/',
- unescaped = '&<>"\'`\/';
- escaped += escaped;
- unescaped += unescaped;
- QUnit.test('should escape values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.escape(unescaped), escaped);
- });
- QUnit.test('should not escape the "/" character', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.escape('/'), '/');
- });
- QUnit.test('should handle strings with nothing to escape', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.escape('abc'), 'abc');
- });
- QUnit.test('should escape the same characters unescaped by `_.unescape`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.escape(_.unescape(escaped)), escaped);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.escapeRegExp');
- (function() {
- var escaped = '\\^\\$\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\',
- unescaped = '^$.*+?()[]{}|\\';
- QUnit.test('should escape values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.escapeRegExp(unescaped + unescaped), escaped + escaped);
- });
- QUnit.test('should handle strings with nothing to escape', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.escapeRegExp('abc'), 'abc');
- });
- QUnit.test('should return an empty string for empty values', function(assert) {
- assert.expect(1);
- var values = [, null, undefined, ''],
- expected = lodashStable.map(values, stubString);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.escapeRegExp(value) : _.escapeRegExp();
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.every');
- (function() {
- QUnit.test('should return `true` if `predicate` returns truthy for all elements', function(assert) {
- assert.expect(1);
- assert.strictEqual(lodashStable.every([true, 1, 'a'], identity), true);
- });
- QUnit.test('should return `true` for empty collections', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(empties, stubTrue);
- var actual = lodashStable.map(empties, function(value) {
- try {
- return _.every(value, identity);
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `false` as soon as `predicate` returns falsey', function(assert) {
- assert.expect(2);
- var count = 0;
- assert.strictEqual(_.every([true, null, true], function(value) {
- count++;
- return value;
- }), false);
- assert.strictEqual(count, 2);
- });
- QUnit.test('should work with collections of `undefined` values (test in IE < 9)', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.every([undefined, undefined, undefined], identity), false);
- });
- QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value, index) {
- var array = [0];
- return index ? _.every(array, value) : _.every(array);
- });
- assert.deepEqual(actual, expected);
- expected = lodashStable.map(values, stubTrue);
- actual = lodashStable.map(values, function(value, index) {
- var array = [1];
- return index ? _.every(array, value) : _.every(array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(2);
- var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
- assert.strictEqual(_.every(objects, 'a'), false);
- assert.strictEqual(_.every(objects, 'b'), true);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(2);
- var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
- assert.strictEqual(_.every(objects, { 'a': 0 }), true);
- assert.strictEqual(_.every(objects, { 'b': 1 }), false);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map([[1]], _.every);
- assert.deepEqual(actual, [true]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('strict mode checks');
- lodashStable.each(['assign', 'assignIn', 'bindAll', 'defaults'], function(methodName) {
- var func = _[methodName],
- isBindAll = methodName == 'bindAll';
- QUnit.test('`_.' + methodName + '` should ' + (isStrict ? '' : 'not ') + 'throw strict mode errors', function(assert) {
- assert.expect(1);
- if (freeze) {
- var object = freeze({ 'a': undefined, 'b': function() {} }),
- pass = !isStrict;
- try {
- func(object, isBindAll ? 'b' : { 'a': 1 });
- } catch (e) {
- pass = !pass;
- }
- assert.ok(pass);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.fill');
- (function() {
- QUnit.test('should use a default `start` of `0` and a default `end` of `length`', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a'), ['a', 'a', 'a']);
- });
- QUnit.test('should use `undefined` for `value` if not given', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3],
- actual = _.fill(array);
- assert.deepEqual(actual, Array(3));
- assert.ok(lodashStable.every(actual, function(value, index) {
- return index in actual;
- }));
- });
- QUnit.test('should work with a positive `start`', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a', 1), [1, 'a', 'a']);
- });
- QUnit.test('should work with a `start` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a', start), [1, 2, 3]);
- });
- });
- QUnit.test('should treat falsey `start` values as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, lodashStable.constant(['a', 'a', 'a']));
- var actual = lodashStable.map(falsey, function(start) {
- var array = [1, 2, 3];
- return _.fill(array, 'a', start);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with a negative `start`', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a', -1), [1, 2, 'a']);
- });
- QUnit.test('should work with a negative `start` <= negative `length`', function(assert) {
- assert.expect(3);
- lodashStable.each([-3, -4, -Infinity], function(start) {
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a', start), ['a', 'a', 'a']);
- });
- });
- QUnit.test('should work with `start` >= `end`', function(assert) {
- assert.expect(2);
- lodashStable.each([2, 3], function(start) {
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a', start, 2), [1, 2, 3]);
- });
- });
- QUnit.test('should work with a positive `end`', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a', 0, 1), ['a', 2, 3]);
- });
- QUnit.test('should work with a `end` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a', 0, end), ['a', 'a', 'a']);
- });
- });
- QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? ['a', 'a', 'a'] : [1, 2, 3];
- });
- var actual = lodashStable.map(falsey, function(end) {
- var array = [1, 2, 3];
- return _.fill(array, 'a', 0, end);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with a negative `end`', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a', 0, -1), ['a', 'a', 3]);
- });
- QUnit.test('should work with a negative `end` <= negative `length`', function(assert) {
- assert.expect(3);
- lodashStable.each([-3, -4, -Infinity], function(end) {
- var array = [1, 2, 3];
- assert.deepEqual(_.fill(array, 'a', 0, end), [1, 2, 3]);
- });
- });
- QUnit.test('should coerce `start` and `end` to integers', function(assert) {
- assert.expect(1);
- var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
- var actual = lodashStable.map(positions, function(pos) {
- var array = [1, 2, 3];
- return _.fill.apply(_, [array, 'a'].concat(pos));
- });
- assert.deepEqual(actual, [['a', 2, 3], ['a', 2, 3], ['a', 2, 3], [1, 'a', 'a'], ['a', 2, 3], [1, 2, 3]]);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[1, 2], [3, 4]],
- actual = lodashStable.map(array, _.fill);
- assert.deepEqual(actual, [[0, 0], [1, 1]]);
- });
- QUnit.test('should return a wrapped value when chaining', function(assert) {
- assert.expect(3);
- if (!isNpm) {
- var array = [1, 2, 3],
- wrapped = _(array).fill('a'),
- actual = wrapped.value();
- assert.ok(wrapped instanceof _);
- assert.strictEqual(actual, array);
- assert.deepEqual(actual, ['a', 'a', 'a']);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.filter');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should return elements `predicate` returns truthy for', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.filter(array, isEven), [2]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- lodashStable.each(['find', 'findIndex', 'findKey', 'findLast', 'findLastIndex', 'findLastKey'], function(methodName) {
- QUnit.module('lodash.' + methodName);
- var array = [1, 2, 3, 4],
- func = _[methodName];
- var objects = [
- { 'a': 0, 'b': 0 },
- { 'a': 1, 'b': 1 },
- { 'a': 2, 'b': 2 }
- ];
- var expected = ({
- 'find': [objects[1], undefined, objects[2]],
- 'findIndex': [1, -1, 2],
- 'findKey': ['1', undefined, '2'],
- 'findLast': [objects[2], undefined, objects[2]],
- 'findLastIndex': [2, -1, 2],
- 'findLastKey': ['2', undefined, '2']
- })[methodName];
- QUnit.test('`_.' + methodName + '` should return the found value', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(objects, function(object) { return object.a; }), expected[0]);
- });
- QUnit.test('`_.' + methodName + '` should return `' + expected[1] + '` if value is not found', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(objects, function(object) { return object.a === 3; }), expected[1]);
- });
- QUnit.test('`_.' + methodName + '` should work with `_.matches` shorthands', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(objects, { 'b': 2 }), expected[2]);
- });
- QUnit.test('`_.' + methodName + '` should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(objects, ['b', 2]), expected[2]);
- });
- QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(objects, 'b'), expected[0]);
- });
- QUnit.test('`_.' + methodName + '` should return `' + expected[1] + '` for empty collections', function(assert) {
- assert.expect(1);
- var emptyValues = lodashStable.endsWith(methodName, 'Index') ? lodashStable.reject(empties, lodashStable.isPlainObject) : empties,
- expecting = lodashStable.map(emptyValues, lodashStable.constant(expected[1]));
- var actual = lodashStable.map(emptyValues, function(value) {
- try {
- return func(value, { 'a': 3 });
- } catch (e) {}
- });
- assert.deepEqual(actual, expecting);
- });
- QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- var expected = ({
- 'find': 1,
- 'findIndex': 0,
- 'findKey': '0',
- 'findLast': 4,
- 'findLastIndex': 3,
- 'findLastKey': '3'
- })[methodName];
- if (!isNpm) {
- assert.strictEqual(_(array)[methodName](), expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_(array).chain()[methodName]() instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should not execute immediately when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var wrapped = _(array).chain()[methodName]();
- assert.strictEqual(wrapped.__wrapped__, array);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var largeArray = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
- smallArray = array;
- lodashStable.times(2, function(index) {
- var array = index ? largeArray : smallArray,
- wrapped = _(array).filter(isEven);
- assert.strictEqual(wrapped[methodName](), func(lodashStable.filter(array, isEven)));
- });
- }
- else {
- skipAssert(assert, 2);
- }
- });
- });
- _.each(['find', 'findIndex', 'findLast', 'findLastIndex'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should provide correct `predicate` arguments for arrays', function(assert) {
- assert.expect(1);
- var args,
- array = ['a'];
- func(array, function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, ['a', 0, array]);
- });
- });
- _.each(['find', 'findKey', 'findLast', 'findLastKey'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should work with an object for `collection`', function(assert) {
- assert.expect(1);
- var actual = func({ 'a': 1, 'b': 2, 'c': 3 }, function(n) {
- return n < 3;
- });
- var expected = ({
- 'find': 1,
- 'findKey': 'a',
- 'findLast': 2,
- 'findLastKey': 'b'
- })[methodName];
- assert.strictEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should provide correct `predicate` arguments for objects', function(assert) {
- assert.expect(1);
- var args,
- object = { 'a': 1 };
- func(object, function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [1, 'a', object]);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.find and lodash.findLast');
- lodashStable.each(['find', 'findLast'], function(methodName) {
- var isFind = methodName == 'find';
- QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
- assert.expect(3);
- if (!isNpm) {
- var findCount = 0,
- mapCount = 0,
- array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
- iteratee = function(value) { mapCount++; return square(value); },
- predicate = function(value) { findCount++; return isEven(value); },
- actual = _(array).map(iteratee)[methodName](predicate);
- assert.strictEqual(findCount, isFind ? 2 : 1);
- assert.strictEqual(mapCount, isFind ? 2 : 1);
- assert.strictEqual(actual, isFind ? 4 : square(LARGE_ARRAY_SIZE));
- }
- else {
- skipAssert(assert, 3);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.find and lodash.includes');
- lodashStable.each(['includes', 'find'], function(methodName) {
- var args = (function() { return arguments; }(1, 2, 3, 4)),
- func = _[methodName],
- isIncludes = methodName == 'includes',
- resolve = methodName == 'find' ? lodashStable.curry(lodashStable.eq) : identity;
- lodashStable.each({
- 'an `arguments` object': args,
- 'an array': [1, 2, 3, 4]
- },
- function(collection, key) {
- var values = lodashStable.toArray(collection);
- QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a positive `fromIndex`', function(assert) {
- assert.expect(1);
- var expected = [
- isIncludes || values[2],
- isIncludes ? false : undefined
- ];
- var actual = [
- func(collection, resolve(values[2]), 2),
- func(collection, resolve(values[1]), 2)
- ];
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a `fromIndex` >= `length`', function(assert) {
- assert.expect(1);
- var indexes = [4, 6, Math.pow(2, 32), Infinity];
- var expected = lodashStable.map(indexes, function() {
- var result = isIncludes ? false : undefined;
- return [result, result, result];
- });
- var actual = lodashStable.map(indexes, function(fromIndex) {
- return [
- func(collection, resolve(1), fromIndex),
- func(collection, resolve(undefined), fromIndex),
- func(collection, resolve(''), fromIndex)
- ];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with ' + key + ' and treat falsey `fromIndex` values as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, lodashStable.constant(isIncludes || values[0]));
- var actual = lodashStable.map(falsey, function(fromIndex) {
- return func(collection, resolve(values[0]), fromIndex);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with ' + key + ' and coerce `fromIndex` to an integer', function(assert) {
- assert.expect(1);
- var expected = [
- isIncludes || values[0],
- isIncludes || values[0],
- isIncludes ? false : undefined
- ];
- var actual = [
- func(collection, resolve(values[0]), 0.1),
- func(collection, resolve(values[0]), NaN),
- func(collection, resolve(values[0]), '1')
- ];
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a negative `fromIndex`', function(assert) {
- assert.expect(1);
- var expected = [
- isIncludes || values[2],
- isIncludes ? false : undefined
- ];
- var actual = [
- func(collection, resolve(values[2]), -2),
- func(collection, resolve(values[1]), -2)
- ];
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with ' + key + ' and a negative `fromIndex` <= `-length`', function(assert) {
- assert.expect(1);
- var indexes = [-4, -6, -Infinity],
- expected = lodashStable.map(indexes, lodashStable.constant(isIncludes || values[0]));
- var actual = lodashStable.map(indexes, function(fromIndex) {
- return func(collection, resolve(values[0]), fromIndex);
- });
- assert.deepEqual(actual, expected);
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.findIndex and lodash.indexOf');
- lodashStable.each(['findIndex', 'indexOf'], function(methodName) {
- var array = [1, 2, 3, 1, 2, 3],
- func = _[methodName],
- resolve = methodName == 'findIndex' ? lodashStable.curry(lodashStable.eq) : identity;
- QUnit.test('`_.' + methodName + '` should return the index of the first matched value', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(array, resolve(3)), 2);
- });
- QUnit.test('`_.' + methodName + '` should work with a positive `fromIndex`', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(array, resolve(1), 2), 3);
- });
- QUnit.test('`_.' + methodName + '` should work with a `fromIndex` >= `length`', function(assert) {
- assert.expect(1);
- var values = [6, 8, Math.pow(2, 32), Infinity],
- expected = lodashStable.map(values, lodashStable.constant([-1, -1, -1]));
- var actual = lodashStable.map(values, function(fromIndex) {
- return [
- func(array, resolve(undefined), fromIndex),
- func(array, resolve(1), fromIndex),
- func(array, resolve(''), fromIndex)
- ];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex`', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(array, resolve(2), -3), 4);
- });
- QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex` <= `-length`', function(assert) {
- assert.expect(1);
- var values = [-6, -8, -Infinity],
- expected = lodashStable.map(values, stubZero);
- var actual = lodashStable.map(values, function(fromIndex) {
- return func(array, resolve(1), fromIndex);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should treat falsey `fromIndex` values as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubZero);
- var actual = lodashStable.map(falsey, function(fromIndex) {
- return func(array, resolve(1), fromIndex);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should coerce `fromIndex` to an integer', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(array, resolve(2), 1.2), 1);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.findLast');
- (function() {
- var args = (function() { return arguments; }(1, 2, 3, 4)),
- resolve = lodashStable.curry(lodashStable.eq);
- lodashStable.each({
- 'an `arguments` object': args,
- 'an array': [1, 2, 3, 4],
- },
- function(collection, key) {
- var values = lodashStable.toArray(collection);
- QUnit.test('should work with ' + key + ' and a positive `fromIndex`', function(assert) {
- assert.expect(1);
- var expected = [
- values[2],
- undefined
- ];
- var actual = [
- _.findLast(collection, resolve(values[2]), 2),
- _.findLast(collection, resolve(values[3]), 2)
- ];
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with ' + key + ' and a `fromIndex` >= `length`', function(assert) {
- assert.expect(1);
- var indexes = [4, 6, Math.pow(2, 32), Infinity];
- var expected = lodashStable.map(indexes, lodashStable.constant([values[0], undefined, undefined]));
- var actual = lodashStable.map(indexes, function(fromIndex) {
- return [
- _.findLast(collection, resolve(1), fromIndex),
- _.findLast(collection, resolve(undefined), fromIndex),
- _.findLast(collection, resolve(''), fromIndex)
- ];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with ' + key + ' and treat falsey `fromIndex` values correctly', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? values[3] : undefined;
- });
- var actual = lodashStable.map(falsey, function(fromIndex) {
- return _.findLast(collection, resolve(values[3]), fromIndex);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with ' + key + ' and coerce `fromIndex` to an integer', function(assert) {
- assert.expect(1);
- var expected = [
- values[0],
- values[0],
- undefined
- ];
- var actual = [
- _.findLast(collection, resolve(values[0]), 0.1),
- _.findLast(collection, resolve(values[0]), NaN),
- _.findLast(collection, resolve(values[2]), '1')
- ];
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with ' + key + ' and a negative `fromIndex`', function(assert) {
- assert.expect(1);
- var expected = [
- values[2],
- undefined
- ];
- var actual = [
- _.findLast(collection, resolve(values[2]), -2),
- _.findLast(collection, resolve(values[3]), -2)
- ];
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with ' + key + ' and a negative `fromIndex` <= `-length`', function(assert) {
- assert.expect(1);
- var indexes = [-4, -6, -Infinity],
- expected = lodashStable.map(indexes, lodashStable.constant(values[0]));
- var actual = lodashStable.map(indexes, function(fromIndex) {
- return _.findLast(collection, resolve(values[0]), fromIndex);
- });
- assert.deepEqual(actual, expected);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.flip');
- (function() {
- function fn() {
- return slice.call(arguments);
- }
- QUnit.test('should flip arguments provided to `func`', function(assert) {
- assert.expect(1);
- var flipped = _.flip(fn);
- assert.deepEqual(flipped('a', 'b', 'c', 'd'), ['d', 'c', 'b', 'a']);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.flatMapDepth');
- (function() {
- var array = [1, [2, [3, [4]], 5]];
- QUnit.test('should use a default `depth` of `1`', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.flatMapDepth(array, identity), [1, 2, [3, [4]], 5]);
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant([1, 2, [3, [4]], 5]));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.flatMapDepth(array, value) : _.flatMapDepth(array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should treat a `depth` of < `1` as a shallow clone', function(assert) {
- assert.expect(2);
- lodashStable.each([-1, 0], function(depth) {
- assert.deepEqual(_.flatMapDepth(array, identity, depth), [1, [2, [3, [4]], 5]]);
- });
- });
- QUnit.test('should coerce `depth` to an integer', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.flatMapDepth(array, identity, 2.2), [1, 2, 3, [4], 5]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('flatMap methods');
- lodashStable.each(['flatMap', 'flatMapDeep', 'flatMapDepth'], function(methodName) {
- var func = _[methodName],
- array = [1, 2, 3, 4];
- function duplicate(n) {
- return [n, n];
- }
- QUnit.test('`_.' + methodName + '` should map values in `array` to a new flattened array', function(assert) {
- assert.expect(1);
- var actual = func(array, duplicate),
- expected = lodashStable.flatten(lodashStable.map(array, duplicate));
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': [1, 2] }, { 'a': [3, 4] }];
- assert.deepEqual(func(objects, 'a'), array);
- });
- QUnit.test('`_.' + methodName + '` should iterate over own string keyed properties of objects', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = [1, 2];
- }
- Foo.prototype.b = [3, 4];
- var actual = func(new Foo, identity);
- assert.deepEqual(actual, [1, 2]);
- });
- QUnit.test('`_.' + methodName + '` should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(2);
- var array = [[1, 2], [3, 4]],
- object = { 'a': [1, 2], 'b': [3, 4] },
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant([1, 2, 3, 4]));
- lodashStable.each([array, object], function(collection) {
- var actual = lodashStable.map(values, function(value, index) {
- return index ? func(collection, value) : func(collection);
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('`_.' + methodName + '` should accept a falsey `collection` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubArray);
- var actual = lodashStable.map(falsey, function(collection, index) {
- try {
- return index ? func(collection) : func();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should treat number values for `collection` as empty', function(assert) {
- assert.expect(1);
- assert.deepEqual(func(1), []);
- });
- QUnit.test('`_.' + methodName + '` should work with objects with non-number length properties', function(assert) {
- assert.expect(1);
- var object = { 'length': [1, 2] };
- assert.deepEqual(func(object, identity), [1, 2]);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.flattenDepth');
- (function() {
- var array = [1, [2, [3, [4]], 5]];
- QUnit.test('should use a default `depth` of `1`', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.flattenDepth(array), [1, 2, [3, [4]], 5]);
- });
- QUnit.test('should treat a `depth` of < `1` as a shallow clone', function(assert) {
- assert.expect(2);
- lodashStable.each([-1, 0], function(depth) {
- assert.deepEqual(_.flattenDepth(array, depth), [1, [2, [3, [4]], 5]]);
- });
- });
- QUnit.test('should coerce `depth` to an integer', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.flattenDepth(array, 2.2), [1, 2, 3, [4], 5]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('flatten methods');
- (function() {
- var args = arguments,
- array = [1, [2, [3, [4]], 5]],
- methodNames = ['flatten', 'flattenDeep', 'flattenDepth'];
- QUnit.test('should flatten `arguments` objects', function(assert) {
- assert.expect(3);
- var array = [args, [args]];
- assert.deepEqual(_.flatten(array), [1, 2, 3, args]);
- assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 1, 2, 3]);
- assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, 1, 2, 3]);
- });
- QUnit.test('should treat sparse arrays as dense', function(assert) {
- assert.expect(6);
- var array = [[1, 2, 3], Array(3)],
- expected = [1, 2, 3];
- expected.push(undefined, undefined, undefined);
- lodashStable.each(methodNames, function(methodName) {
- var actual = _[methodName](array);
- assert.deepEqual(actual, expected);
- assert.ok('4' in actual);
- });
- });
- QUnit.test('should flatten objects with a truthy `Symbol.isConcatSpreadable` value', function(assert) {
- assert.expect(1);
- if (Symbol && Symbol.isConcatSpreadable) {
- var object = { '0': 'a', 'length': 1 },
- array = [object],
- expected = lodashStable.map(methodNames, lodashStable.constant(['a']));
- object[Symbol.isConcatSpreadable] = true;
- var actual = lodashStable.map(methodNames, function(methodName) {
- return _[methodName](array);
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should work with extremely large arrays', function(assert) {
- assert.expect(3);
- lodashStable.times(3, function(index) {
- var expected = Array(5e5);
- try {
- var func = _.flatten;
- if (index == 1) {
- func = _.flattenDeep;
- } else if (index == 2) {
- func = _.flattenDepth;
- }
- assert.deepEqual(func([expected]), expected);
- } catch (e) {
- assert.ok(false, e.message);
- }
- });
- });
- QUnit.test('should work with empty arrays', function(assert) {
- assert.expect(3);
- var array = [[], [[]], [[], [[[]]]]];
- assert.deepEqual(_.flatten(array), [[], [], [[[]]]]);
- assert.deepEqual(_.flattenDeep(array), []);
- assert.deepEqual(_.flattenDepth(array, 2), [[[]]]);
- });
- QUnit.test('should support flattening of nested arrays', function(assert) {
- assert.expect(3);
- assert.deepEqual(_.flatten(array), [1, 2, [3, [4]], 5]);
- assert.deepEqual(_.flattenDeep(array), [1, 2, 3, 4, 5]);
- assert.deepEqual(_.flattenDepth(array, 2), [1, 2, 3, [4], 5]);
- });
- QUnit.test('should return an empty array for non array-like objects', function(assert) {
- assert.expect(3);
- var expected = [],
- nonArray = { '0': 'a' };
- assert.deepEqual(_.flatten(nonArray), expected);
- assert.deepEqual(_.flattenDeep(nonArray), expected);
- assert.deepEqual(_.flattenDepth(nonArray, 2), expected);
- });
- QUnit.test('should return a wrapped value when chaining', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- var wrapped = _(array),
- actual = wrapped.flatten();
- assert.ok(actual instanceof _);
- assert.deepEqual(actual.value(), [1, 2, [3, [4]], 5]);
- actual = wrapped.flattenDeep();
- assert.ok(actual instanceof _);
- assert.deepEqual(actual.value(), [1, 2, 3, 4, 5]);
- actual = wrapped.flattenDepth(2);
- assert.ok(actual instanceof _);
- assert.deepEqual(actual.value(), [1, 2, 3, [4], 5]);
- }
- else {
- skipAssert(assert, 6);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('flow methods');
- lodashStable.each(['flow', 'flowRight'], function(methodName) {
- var func = _[methodName],
- isFlow = methodName == 'flow';
- QUnit.test('`_.' + methodName + '` should supply each function with the return value of the previous', function(assert) {
- assert.expect(1);
- var fixed = function(n) { return n.toFixed(1); },
- combined = isFlow ? func(add, square, fixed) : func(fixed, square, add);
- assert.strictEqual(combined(1, 2), '9.0');
- });
- QUnit.test('`_.' + methodName + '` should return a new function', function(assert) {
- assert.expect(1);
- assert.notStrictEqual(func(noop), noop);
- });
- QUnit.test('`_.' + methodName + '` should return an identity function when no arguments are given', function(assert) {
- assert.expect(6);
- _.times(2, function(index) {
- try {
- var combined = index ? func([]) : func();
- assert.strictEqual(combined('a'), 'a');
- } catch (e) {
- assert.ok(false, e.message);
- }
- assert.strictEqual(combined.length, 0);
- assert.notStrictEqual(combined, identity);
- });
- });
- QUnit.test('`_.' + methodName + '` should work with a curried function and `_.head`', function(assert) {
- assert.expect(1);
- var curried = _.curry(identity);
- var combined = isFlow
- ? func(_.head, curried)
- : func(curried, _.head);
- assert.strictEqual(combined([1]), 1);
- });
- QUnit.test('`_.' + methodName + '` should support shortcut fusion', function(assert) {
- assert.expect(6);
- var filterCount,
- mapCount,
- array = lodashStable.range(LARGE_ARRAY_SIZE),
- iteratee = function(value) { mapCount++; return square(value); },
- predicate = function(value) { filterCount++; return isEven(value); };
- lodashStable.times(2, function(index) {
- var filter1 = _.filter,
- filter2 = _.curry(_.rearg(_.ary(_.filter, 2), 1, 0), 2),
- filter3 = (_.filter = index ? filter2 : filter1, filter2(predicate));
- var map1 = _.map,
- map2 = _.curry(_.rearg(_.ary(_.map, 2), 1, 0), 2),
- map3 = (_.map = index ? map2 : map1, map2(iteratee));
- var take1 = _.take,
- take2 = _.curry(_.rearg(_.ary(_.take, 2), 1, 0), 2),
- take3 = (_.take = index ? take2 : take1, take2(2));
- var combined = isFlow
- ? func(map3, filter3, _.compact, take3)
- : func(take3, _.compact, filter3, map3);
- filterCount = mapCount = 0;
- assert.deepEqual(combined(array), [4, 16]);
- if (!isNpm && WeakMap && WeakMap.name) {
- assert.strictEqual(filterCount, 5, 'filterCount');
- assert.strictEqual(mapCount, 5, 'mapCount');
- }
- else {
- skipAssert(assert, 2);
- }
- _.filter = filter1;
- _.map = map1;
- _.take = take1;
- });
- });
- QUnit.test('`_.' + methodName + '` should work with curried functions with placeholders', function(assert) {
- assert.expect(1);
- var curried = _.curry(_.ary(_.map, 2), 2),
- getProp = curried(curried.placeholder, 'a'),
- objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 1 }];
- var combined = isFlow
- ? func(getProp, _.uniq)
- : func(_.uniq, getProp);
- assert.deepEqual(combined(objects), [1, 2]);
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var wrapped = _(noop)[methodName]();
- assert.ok(wrapped instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.forEach');
- (function() {
- QUnit.test('should be aliased', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.each, _.forEach);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.forEachRight');
- (function() {
- QUnit.test('should be aliased', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.eachRight, _.forEachRight);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('forIn methods');
- lodashStable.each(['forIn', 'forInRight'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` iterates over inherited string keyed properties', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var keys = [];
- func(new Foo, function(value, key) { keys.push(key); });
- assert.deepEqual(keys.sort(), ['a', 'b']);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('forOwn methods');
- lodashStable.each(['forOwn', 'forOwnRight'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should iterate over `length` properties', function(assert) {
- assert.expect(1);
- var object = { '0': 'zero', '1': 'one', 'length': 2 },
- props = [];
- func(object, function(value, prop) { props.push(prop); });
- assert.deepEqual(props.sort(), ['0', '1', 'length']);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('iteration methods');
- (function() {
- var methods = [
- '_baseEach',
- 'countBy',
- 'every',
- 'filter',
- 'find',
- 'findIndex',
- 'findKey',
- 'findLast',
- 'findLastIndex',
- 'findLastKey',
- 'forEach',
- 'forEachRight',
- 'forIn',
- 'forInRight',
- 'forOwn',
- 'forOwnRight',
- 'groupBy',
- 'keyBy',
- 'map',
- 'mapKeys',
- 'mapValues',
- 'maxBy',
- 'minBy',
- 'omitBy',
- 'partition',
- 'pickBy',
- 'reject',
- 'some'
- ];
- var arrayMethods = [
- 'findIndex',
- 'findLastIndex',
- 'maxBy',
- 'minBy'
- ];
- var collectionMethods = [
- '_baseEach',
- 'countBy',
- 'every',
- 'filter',
- 'find',
- 'findLast',
- 'forEach',
- 'forEachRight',
- 'groupBy',
- 'keyBy',
- 'map',
- 'partition',
- 'reduce',
- 'reduceRight',
- 'reject',
- 'some'
- ];
- var forInMethods = [
- 'forIn',
- 'forInRight',
- 'omitBy',
- 'pickBy'
- ];
- var iterationMethods = [
- '_baseEach',
- 'forEach',
- 'forEachRight',
- 'forIn',
- 'forInRight',
- 'forOwn',
- 'forOwnRight'
- ];
- var objectMethods = [
- 'findKey',
- 'findLastKey',
- 'forIn',
- 'forInRight',
- 'forOwn',
- 'forOwnRight',
- 'mapKeys',
- 'mapValues',
- 'omitBy',
- 'pickBy'
- ];
- var rightMethods = [
- 'findLast',
- 'findLastIndex',
- 'findLastKey',
- 'forEachRight',
- 'forInRight',
- 'forOwnRight'
- ];
- var unwrappedMethods = [
- 'each',
- 'eachRight',
- 'every',
- 'find',
- 'findIndex',
- 'findKey',
- 'findLast',
- 'findLastIndex',
- 'findLastKey',
- 'forEach',
- 'forEachRight',
- 'forIn',
- 'forInRight',
- 'forOwn',
- 'forOwnRight',
- 'max',
- 'maxBy',
- 'min',
- 'minBy',
- 'some'
- ];
- lodashStable.each(methods, function(methodName) {
- var array = [1, 2, 3],
- func = _[methodName],
- isBy = /(^partition|By)$/.test(methodName),
- isFind = /^find/.test(methodName),
- isOmitPick = /^(?:omit|pick)By$/.test(methodName),
- isSome = methodName == 'some';
- QUnit.test('`_.' + methodName + '` should provide correct iteratee arguments', function(assert) {
- assert.expect(1);
- if (func) {
- var args,
- expected = [1, 0, array];
- func(array, function() {
- args || (args = slice.call(arguments));
- });
- if (lodashStable.includes(rightMethods, methodName)) {
- expected[0] = 3;
- expected[1] = 2;
- }
- if (lodashStable.includes(objectMethods, methodName)) {
- expected[1] += '';
- }
- if (isBy) {
- expected.length = isOmitPick ? 2 : 1;
- }
- assert.deepEqual(args, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
- assert.expect(1);
- if (func) {
- var array = [1];
- array[2] = 3;
- var expected = lodashStable.includes(objectMethods, methodName)
- ? [[1, '0', array], [undefined, '1', array], [3, '2', array]]
- : [[1, 0, array], [undefined, 1, array], [3, 2, array]];
- if (isBy) {
- expected = lodashStable.map(expected, function(args) {
- return args.slice(0, isOmitPick ? 2 : 1);
- });
- }
- else if (lodashStable.includes(objectMethods, methodName)) {
- expected = lodashStable.map(expected, function(args) {
- args[1] += '';
- return args;
- });
- }
- if (lodashStable.includes(rightMethods, methodName)) {
- expected.reverse();
- }
- var argsList = [];
- func(array, function() {
- argsList.push(slice.call(arguments));
- return !(isFind || isSome);
- });
- assert.deepEqual(argsList, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- lodashStable.each(lodashStable.difference(methods, objectMethods), function(methodName) {
- var array = [1, 2, 3],
- func = _[methodName],
- isEvery = methodName == 'every';
- array.a = 1;
- QUnit.test('`_.' + methodName + '` should not iterate custom properties on arrays', function(assert) {
- assert.expect(1);
- if (func) {
- var keys = [];
- func(array, function(value, key) {
- keys.push(key);
- return isEvery;
- });
- assert.notOk(lodashStable.includes(keys, 'a'));
- }
- else {
- skipAssert(assert);
- }
- });
- });
- lodashStable.each(lodashStable.difference(methods, unwrappedMethods), function(methodName) {
- var array = [1, 2, 3],
- isBaseEach = methodName == '_baseEach';
- QUnit.test('`_.' + methodName + '` should return a wrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!(isBaseEach || isNpm)) {
- var wrapped = _(array)[methodName](noop);
- assert.ok(wrapped instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- lodashStable.each(unwrappedMethods, function(methodName) {
- var array = [1, 2, 3];
- QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = _(array)[methodName](noop);
- assert.notOk(actual instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _(array).chain(),
- actual = wrapped[methodName](noop);
- assert.ok(actual instanceof _);
- assert.notStrictEqual(actual, wrapped);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- });
- lodashStable.each(lodashStable.difference(methods, arrayMethods, forInMethods), function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` iterates over own string keyed properties of objects', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- if (func) {
- var values = [];
- func(new Foo, function(value) { values.push(value); });
- assert.deepEqual(values, [1]);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- lodashStable.each(iterationMethods, function(methodName) {
- var array = [1, 2, 3],
- func = _[methodName];
- QUnit.test('`_.' + methodName + '` should return the collection', function(assert) {
- assert.expect(1);
- if (func) {
- assert.strictEqual(func(array, Boolean), array);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- lodashStable.each(collectionMethods, function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should use `isArrayLike` to determine whether a value is array-like', function(assert) {
- assert.expect(3);
- if (func) {
- var isIteratedAsObject = function(object) {
- var result = false;
- func(object, function() { result = true; }, 0);
- return result;
- };
- var values = [-1, '1', 1.1, Object(1), MAX_SAFE_INTEGER + 1],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(length) {
- return isIteratedAsObject({ 'length': length });
- });
- var Foo = function(a) {};
- Foo.a = 1;
- assert.deepEqual(actual, expected);
- assert.ok(isIteratedAsObject(Foo));
- assert.notOk(isIteratedAsObject({ 'length': 0 }));
- }
- else {
- skipAssert(assert, 3);
- }
- });
- });
- lodashStable.each(methods, function(methodName) {
- var func = _[methodName],
- isFind = /^find/.test(methodName),
- isSome = methodName == 'some',
- isReduce = /^reduce/.test(methodName);
- QUnit.test('`_.' + methodName + '` should ignore changes to `length`', function(assert) {
- assert.expect(1);
- if (func) {
- var count = 0,
- array = [1];
- func(array, function() {
- if (++count == 1) {
- array.push(2);
- }
- return !(isFind || isSome);
- }, isReduce ? array : null);
- assert.strictEqual(count, 1);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- lodashStable.each(lodashStable.difference(lodashStable.union(methods, collectionMethods), arrayMethods), function(methodName) {
- var func = _[methodName],
- isFind = /^find/.test(methodName),
- isSome = methodName == 'some',
- isReduce = /^reduce/.test(methodName);
- QUnit.test('`_.' + methodName + '` should ignore added `object` properties', function(assert) {
- assert.expect(1);
- if (func) {
- var count = 0,
- object = { 'a': 1 };
- func(object, function() {
- if (++count == 1) {
- object.b = 2;
- }
- return !(isFind || isSome);
- }, isReduce ? object : null);
- assert.strictEqual(count, 1);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('object assignments');
- lodashStable.each(['assign', 'assignIn', 'defaults', 'merge'], function(methodName) {
- var func = _[methodName],
- isAssign = methodName == 'assign',
- isDefaults = methodName == 'defaults';
- QUnit.test('`_.' + methodName + '` should coerce primitives to objects', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(primitives, function(value) {
- var object = Object(value);
- object.a = 1;
- return object;
- });
- var actual = lodashStable.map(primitives, function(value) {
- return func(value, { 'a': 1 });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should assign own ' + (isAssign ? '' : 'and inherited ') + 'string keyed source properties', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var expected = isAssign ? { 'a': 1 } : { 'a': 1, 'b': 2 };
- assert.deepEqual(func({}, new Foo), expected);
- });
- QUnit.test('`_.' + methodName + '` should not skip a trailing function source', function(assert) {
- assert.expect(1);
- function fn() {}
- fn.b = 2;
- assert.deepEqual(func({}, { 'a': 1 }, fn), { 'a': 1, 'b': 2 });
- });
- QUnit.test('`_.' + methodName + '` should not error on nullish sources', function(assert) {
- assert.expect(1);
- try {
- assert.deepEqual(func({ 'a': 1 }, undefined, { 'b': 2 }, null), { 'a': 1, 'b': 2 });
- } catch (e) {
- assert.ok(false, e.message);
- }
- });
- QUnit.test('`_.' + methodName + '` should create an object when `object` is nullish', function(assert) {
- assert.expect(2);
- var source = { 'a': 1 },
- values = [null, undefined],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value) {
- var object = func(value, source);
- return object !== source && lodashStable.isEqual(object, source);
- });
- assert.deepEqual(actual, expected);
- actual = lodashStable.map(values, function(value) {
- return lodashStable.isEqual(func(value), {});
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
- assert.expect(2);
- var array = [{ 'a': 1 }, { 'b': 2 }, { 'c': 3 }],
- expected = { 'a': isDefaults ? 0 : 1, 'b': 2, 'c': 3 };
- function fn() {};
- fn.a = array[0];
- fn.b = array[1];
- fn.c = array[2];
- assert.deepEqual(lodashStable.reduce(array, func, { 'a': 0 }), expected);
- assert.deepEqual(lodashStable.reduce(fn, func, { 'a': 0 }), expected);
- });
- QUnit.test('`_.' + methodName + '` should not return the existing wrapped value when chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var wrapped = _({ 'a': 1 }),
- actual = wrapped[methodName]({ 'b': 2 });
- assert.notStrictEqual(actual, wrapped);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- lodashStable.each(['assign', 'assignIn', 'merge'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should not treat `object` as `source`', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.prototype.a = 1;
- var actual = func(new Foo, { 'b': 2 });
- assert.notOk(_.has(actual, 'a'));
- });
- });
- lodashStable.each(['assign', 'assignIn', 'assignInWith', 'assignWith', 'defaults', 'merge', 'mergeWith'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
- assert.expect(4);
- lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
- var object = {},
- pass = true;
- defineProperty(object, 'a', {
- 'enumerable': true,
- 'configurable': true,
- 'get': lodashStable.constant(value),
- 'set': function() { pass = false; }
- });
- func(object, { 'a': value });
- assert.ok(pass);
- });
- });
- });
- lodashStable.each(['assignWith', 'assignInWith', 'mergeWith'], function(methodName) {
- var func = _[methodName],
- isMergeWith = methodName == 'mergeWith';
- QUnit.test('`_.' + methodName + '` should provide correct `customizer` arguments', function(assert) {
- assert.expect(3);
- var args,
- object = { 'a': 1 },
- source = { 'a': 2 },
- expected = lodashStable.map([1, 2, 'a', object, source], lodashStable.cloneDeep);
- func(object, source, function() {
- args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
- });
- assert.deepEqual(args, expected, 'primitive property values');
- args = undefined;
- object = { 'a': 1 };
- source = { 'b': 2 };
- expected = lodashStable.map([undefined, 2, 'b', object, source], lodashStable.cloneDeep);
- func(object, source, function() {
- args || (args = lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
- });
- assert.deepEqual(args, expected, 'missing destination property');
- var argsList = [],
- objectValue = [1, 2],
- sourceValue = { 'b': 2 };
- object = { 'a': objectValue };
- source = { 'a': sourceValue };
- expected = [lodashStable.map([objectValue, sourceValue, 'a', object, source], lodashStable.cloneDeep)];
- if (isMergeWith) {
- expected.push(lodashStable.map([undefined, 2, 'b', objectValue, sourceValue], lodashStable.cloneDeep));
- }
- func(object, source, function() {
- argsList.push(lodashStable.map(slice.call(arguments, 0, 5), lodashStable.cloneDeep));
- });
- assert.deepEqual(argsList, expected, 'object property values');
- });
- QUnit.test('`_.' + methodName + '` should not treat the second argument as a `customizer` callback', function(assert) {
- assert.expect(2);
- function callback() {}
- callback.b = 2;
- var actual = func({ 'a': 1 }, callback);
- assert.deepEqual(actual, { 'a': 1, 'b': 2 });
- actual = func({ 'a': 1 }, callback, { 'c': 3 });
- assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('exit early');
- lodashStable.each(['_baseEach', 'forEach', 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'transform'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` can exit early when iterating arrays', function(assert) {
- assert.expect(1);
- if (func) {
- var array = [1, 2, 3],
- values = [];
- func(array, function(value, other) {
- values.push(lodashStable.isArray(value) ? other : value);
- return false;
- });
- assert.deepEqual(values, [lodashStable.endsWith(methodName, 'Right') ? 3 : 1]);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` can exit early when iterating objects', function(assert) {
- assert.expect(1);
- if (func) {
- var object = { 'a': 1, 'b': 2, 'c': 3 },
- values = [];
- func(object, function(value, other) {
- values.push(lodashStable.isArray(value) ? other : value);
- return false;
- });
- assert.strictEqual(values.length, 1);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('`__proto__` property bugs');
- (function() {
- QUnit.test('internal data objects should work with the `__proto__` key', function(assert) {
- assert.expect(4);
- var stringLiteral = '__proto__',
- stringObject = Object(stringLiteral),
- expected = [stringLiteral, stringObject];
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(count) {
- return isEven(count) ? stringLiteral : stringObject;
- });
- assert.deepEqual(_.difference(largeArray, largeArray), []);
- assert.deepEqual(_.intersection(largeArray, largeArray), expected);
- assert.deepEqual(_.uniq(largeArray), expected);
- assert.deepEqual(_.without.apply(_, [largeArray].concat(largeArray)), []);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.fromPairs');
- (function() {
- QUnit.test('should accept a two dimensional array', function(assert) {
- assert.expect(1);
- var array = [['a', 1], ['b', 2]],
- object = { 'a': 1, 'b': 2 },
- actual = _.fromPairs(array);
- assert.deepEqual(actual, object);
- });
- QUnit.test('should accept a falsey `array` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubObject);
- var actual = lodashStable.map(falsey, function(array, index) {
- try {
- return index ? _.fromPairs(array) : _.fromPairs();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should not support deep paths', function(assert) {
- assert.expect(1);
- var actual = _.fromPairs([['a.b', 1]]);
- assert.deepEqual(actual, { 'a.b': 1 });
- });
- QUnit.test('should support consuming the return value of `_.toPairs`', function(assert) {
- assert.expect(1);
- var object = { 'a.b': 1 };
- assert.deepEqual(_.fromPairs(_.toPairs(object)), object);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
- return ['key' + index, index];
- });
- var actual = _(array).fromPairs().map(square).filter(isEven).take().value();
- assert.deepEqual(actual, _.take(_.filter(_.map(_.fromPairs(array), square), isEven)));
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.functions');
- (function() {
- QUnit.test('should return the function names of an object', function(assert) {
- assert.expect(1);
- var object = { 'a': 'a', 'b': identity, 'c': /x/, 'd': noop },
- actual = _.functions(object).sort();
- assert.deepEqual(actual, ['b', 'd']);
- });
- QUnit.test('should not include inherited functions', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = identity;
- this.b = 'b';
- }
- Foo.prototype.c = noop;
- assert.deepEqual(_.functions(new Foo), ['a']);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.groupBy');
- (function() {
- var array = [6.1, 4.2, 6.3];
- QUnit.test('should transform keys by `iteratee`', function(assert) {
- assert.expect(1);
- var actual = _.groupBy(array, Math.floor);
- assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var array = [6, 4, 6],
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant({ '4': [4], '6': [6, 6] }));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.groupBy(array, value) : _.groupBy(array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var actual = _.groupBy(['one', 'two', 'three'], 'length');
- assert.deepEqual(actual, { '3': ['one', 'two'], '5': ['three'] });
- });
- QUnit.test('should only add values to own, not inherited, properties', function(assert) {
- assert.expect(2);
- var actual = _.groupBy(array, function(n) {
- return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
- });
- assert.deepEqual(actual.constructor, [4.2]);
- assert.deepEqual(actual.hasOwnProperty, [6.1, 6.3]);
- });
- QUnit.test('should work with a number for `iteratee`', function(assert) {
- assert.expect(2);
- var array = [
- [1, 'a'],
- [2, 'a'],
- [2, 'b']
- ];
- assert.deepEqual(_.groupBy(array, 0), { '1': [[1, 'a']], '2': [[2, 'a'], [2, 'b']] });
- assert.deepEqual(_.groupBy(array, 1), { 'a': [[1, 'a'], [2, 'a']], 'b': [[2, 'b']] });
- });
- QUnit.test('should work with an object for `collection`', function(assert) {
- assert.expect(1);
- var actual = _.groupBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
- assert.deepEqual(actual, { '4': [4.2], '6': [6.1, 6.3] });
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
- lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
- lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
- );
- var iteratee = function(value) { value.push(value[0]); return value; },
- predicate = function(value) { return isEven(value[0]); },
- actual = _(array).groupBy().map(iteratee).filter(predicate).take().value();
- assert.deepEqual(actual, _.take(_.filter(lodashStable.map(_.groupBy(array), iteratee), predicate)));
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.gt');
- (function() {
- QUnit.test('should return `true` if `value` > `other`', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.gt(3, 1), true);
- assert.strictEqual(_.gt('def', 'abc'), true);
- });
- QUnit.test('should return `false` if `value` is <= `other`', function(assert) {
- assert.expect(4);
- assert.strictEqual(_.gt(1, 3), false);
- assert.strictEqual(_.gt(3, 3), false);
- assert.strictEqual(_.gt('abc', 'def'), false);
- assert.strictEqual(_.gt('def', 'def'), false);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.gte');
- (function() {
- QUnit.test('should return `true` if `value` >= `other`', function(assert) {
- assert.expect(4);
- assert.strictEqual(_.gte(3, 1), true);
- assert.strictEqual(_.gte(3, 3), true);
- assert.strictEqual(_.gte('def', 'abc'), true);
- assert.strictEqual(_.gte('def', 'def'), true);
- });
- QUnit.test('should return `false` if `value` is less than `other`', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.gte(1, 3), false);
- assert.strictEqual(_.gte('abc', 'def'), false);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('has methods');
- lodashStable.each(['has', 'hasIn'], function(methodName) {
- var args = (function() { return arguments; }(1, 2, 3)),
- func = _[methodName],
- isHas = methodName == 'has';
- QUnit.test('`_.' + methodName + '` should check for own properties', function(assert) {
- assert.expect(2);
- var object = { 'a': 1 };
- lodashStable.each(['a', ['a']], function(path) {
- assert.strictEqual(func(object, path), true);
- });
- });
- QUnit.test('`_.' + methodName + '` should not use the `hasOwnProperty` method of the object', function(assert) {
- assert.expect(1);
- var object = { 'hasOwnProperty': null, 'a': 1 };
- assert.strictEqual(func(object, 'a'), true);
- });
- QUnit.test('`_.' + methodName + '` should support deep paths', function(assert) {
- assert.expect(4);
- var object = { 'a': { 'b': 2 } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.strictEqual(func(object, path), true);
- });
- lodashStable.each(['a.a', ['a', 'a']], function(path) {
- assert.strictEqual(func(object, path), false);
- });
- });
- QUnit.test('`_.' + methodName + '` should coerce `path` to a string', function(assert) {
- assert.expect(1);
- function fn() {}
- fn.toString = lodashStable.constant('fn');
- var expected = [1, 1, 2, 2, 3, 3, 4, 4],
- objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
- values = [null, undefined, fn, {}];
- var actual = lodashStable.transform(objects, function(result, object, index) {
- var key = values[index];
- lodashStable.each([key, [key]], function(path) {
- var prop = _.property(key);
- result.push(prop(object));
- });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(args, 1), true);
- });
- QUnit.test('`_.' + methodName + '` should work with a non-string `path`', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3];
- lodashStable.each([1, [1]], function(path) {
- assert.strictEqual(func(array, path), true);
- });
- });
- QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var object = { '-0': 'a', '0': 'b' },
- props = [-0, Object(-0), 0, Object(0)],
- expected = lodashStable.map(props, stubTrue);
- var actual = lodashStable.map(props, function(key) {
- return func(object, key);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with a symbol `path`', function(assert) {
- assert.expect(1);
- function Foo() {
- this[symbol] = 1;
- }
- if (Symbol) {
- var symbol2 = Symbol('b');
- Foo.prototype[symbol2] = 2;
- var path = isHas ? symbol : symbol2;
- assert.strictEqual(func(new Foo, path), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should check for a key over a path', function(assert) {
- assert.expect(2);
- var object = { 'a.b': 1 };
- lodashStable.each(['a.b', ['a.b']], function(path) {
- assert.strictEqual(func(object, path), true);
- });
- });
- QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for inherited properties', function(assert) {
- assert.expect(2);
- function Foo() {}
- Foo.prototype.a = 1;
- lodashStable.each(['a', ['a']], function(path) {
- assert.strictEqual(func(new Foo, path), !isHas);
- });
- });
- QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for nested inherited properties', function(assert) {
- assert.expect(2);
- function Foo() {}
- Foo.prototype.a = { 'b': 1 };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.strictEqual(func(new Foo, path), !isHas);
- });
- });
- QUnit.test('`_.' + methodName + '` should return `true` for index values within bounds for arrays, `arguments` objects, and strings', function(assert) {
- assert.expect(2);
- var string = Object('abc');
- delete args[0];
- delete string[0];
- var values = [Array(3), args, string],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value) {
- return func(value, 0);
- });
- assert.deepEqual(actual, expected);
- expected = lodashStable.map(values, lodashStable.constant([true, true]));
- actual = lodashStable.map(values, function(value) {
- return lodashStable.map(['a[0]', ['a', '0']], function(path) {
- return func({ 'a': value }, path);
- });
- });
- assert.deepEqual(actual, expected);
- args[0] = 1;
- });
- QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [null, undefined],
- expected = lodashStable.map(values, stubFalse);
- lodashStable.each(['constructor', ['constructor']], function(path) {
- var actual = lodashStable.map(values, function(value) {
- return func(value, path);
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('`_.' + methodName + '` should return `false` for deep paths when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [null, undefined],
- expected = lodashStable.map(values, stubFalse);
- lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
- var actual = lodashStable.map(values, function(value) {
- return func(value, path);
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('`_.' + methodName + '` should return `false` for nullish values of nested objects', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubFalse);
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var actual = lodashStable.map(values, function(value, index) {
- var object = index ? { 'a': value } : {};
- return func(object, path);
- });
- assert.deepEqual(actual, expected);
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.head');
- (function() {
- var array = [1, 2, 3, 4];
- QUnit.test('should return the first element', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.head(array), 1);
- });
- QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
- assert.expect(1);
- arrayProto[0] = 1;
- assert.strictEqual(_.head([]), undefined);
- arrayProto.length = 0;
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- actual = lodashStable.map(array, _.head);
- assert.deepEqual(actual, [1, 4, 7]);
- });
- QUnit.test('should be aliased', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.first, _.head);
- });
- QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _(array);
- assert.strictEqual(wrapped.head(), 1);
- assert.strictEqual(wrapped.first(), 1);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _(array).chain();
- assert.ok(wrapped.head() instanceof _);
- assert.ok(wrapped.first() instanceof _);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _(array).chain();
- assert.strictEqual(wrapped.head().__wrapped__, array);
- assert.strictEqual(wrapped.first().__wrapped__, array);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
- smallArray = array;
- lodashStable.each(['head', 'first'], function(methodName) {
- lodashStable.times(2, function(index) {
- var array = index ? largeArray : smallArray,
- actual = _(array).filter(isEven)[methodName]();
- assert.strictEqual(actual, _[methodName](_.filter(array, isEven)));
- });
- });
- }
- else {
- skipAssert(assert, 4);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.identity');
- (function() {
- QUnit.test('should return the first argument given', function(assert) {
- assert.expect(1);
- var object = { 'name': 'fred' };
- assert.strictEqual(_.identity(object), object);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.includes');
- (function() {
- lodashStable.each({
- 'an `arguments` object': arguments,
- 'an array': [1, 2, 3, 4],
- 'an object': { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
- 'a string': '1234'
- },
- function(collection, key) {
- QUnit.test('should work with ' + key + ' and return `true` for matched values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.includes(collection, 3), true);
- });
- QUnit.test('should work with ' + key + ' and return `false` for unmatched values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.includes(collection, 5), false);
- });
- QUnit.test('should work with ' + key + ' and floor `position` values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.includes(collection, 2, 1.2), true);
- });
- QUnit.test('should work with ' + key + ' and return an unwrapped value implicitly when chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.strictEqual(_(collection).includes(3), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should work with ' + key + ' and return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_(collection).chain().includes(3) instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- lodashStable.each({
- 'literal': 'abc',
- 'object': Object('abc')
- },
- function(collection, key) {
- QUnit.test('should work with a string ' + key + ' for `collection`', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.includes(collection, 'bc'), true);
- assert.strictEqual(_.includes(collection, 'd'), false);
- });
- });
- QUnit.test('should return `false` for empty collections', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(empties, stubFalse);
- var actual = lodashStable.map(empties, function(value) {
- try {
- return _.includes(value);
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with a string and a `fromIndex` >= `length`', function(assert) {
- assert.expect(1);
- var string = '1234',
- length = string.length,
- indexes = [4, 6, Math.pow(2, 32), Infinity];
- var expected = lodashStable.map(indexes, function(index) {
- return [false, false, index == length];
- });
- var actual = lodashStable.map(indexes, function(fromIndex) {
- return [
- _.includes(string, 1, fromIndex),
- _.includes(string, undefined, fromIndex),
- _.includes(string, '', fromIndex)
- ];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should match `NaN`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.includes([1, NaN, 3], NaN), true);
- });
- QUnit.test('should match `-0` as `0`', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.includes([-0], 0), true);
- assert.strictEqual(_.includes([0], -0), true);
- });
- QUnit.test('should work as an iteratee for methods like `_.every`', function(assert) {
- assert.expect(1);
- var array = [2, 3, 1],
- values = [1, 2, 3];
- assert.ok(lodashStable.every(values, lodashStable.partial(_.includes, array)));
- });
- }(1, 2, 3, 4));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.initial');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should accept a falsey `array` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubArray);
- var actual = lodashStable.map(falsey, function(array, index) {
- try {
- return index ? _.initial(array) : _.initial();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should exclude last element', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.initial(array), [1, 2]);
- });
- QUnit.test('should return an empty when querying empty arrays', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.initial([]), []);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- actual = lodashStable.map(array, _.initial);
- assert.deepEqual(actual, [[1, 2], [4, 5], [7, 8]]);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE),
- values = [];
- var actual = _(array).initial().filter(function(value) {
- values.push(value);
- return false;
- })
- .value();
- assert.deepEqual(actual, []);
- assert.deepEqual(values, _.initial(array));
- values = [];
- actual = _(array).filter(function(value) {
- values.push(value);
- return isEven(value);
- })
- .initial()
- .value();
- assert.deepEqual(actual, _.initial(lodashStable.filter(array, isEven)));
- assert.deepEqual(values, array);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.inRange');
- (function() {
- QUnit.test('should work with an `end` argument', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.inRange(3, 5), true);
- assert.strictEqual(_.inRange(5, 5), false);
- assert.strictEqual(_.inRange(6, 5), false);
- });
- QUnit.test('should work with `start` and `end` arguments', function(assert) {
- assert.expect(4);
- assert.strictEqual(_.inRange(1, 1, 5), true);
- assert.strictEqual(_.inRange(3, 1, 5), true);
- assert.strictEqual(_.inRange(0, 1, 5), false);
- assert.strictEqual(_.inRange(5, 1, 5), false);
- });
- QUnit.test('should treat falsey `start` arguments as `0`', function(assert) {
- assert.expect(13);
- lodashStable.each(falsey, function(value, index) {
- if (index) {
- assert.strictEqual(_.inRange(0, value), false);
- assert.strictEqual(_.inRange(0, value, 1), true);
- } else {
- assert.strictEqual(_.inRange(0), false);
- }
- });
- });
- QUnit.test('should swap `start` and `end` when `start` > `end`', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.inRange(2, 5, 1), true);
- assert.strictEqual(_.inRange(-3, -2, -6), true);
- });
- QUnit.test('should work with a floating point `n` value', function(assert) {
- assert.expect(4);
- assert.strictEqual(_.inRange(0.5, 5), true);
- assert.strictEqual(_.inRange(1.2, 1, 5), true);
- assert.strictEqual(_.inRange(5.2, 5), false);
- assert.strictEqual(_.inRange(0.5, 1, 5), false);
- });
- QUnit.test('should coerce arguments to finite numbers', function(assert) {
- assert.expect(1);
- var actual = [
- _.inRange(0, '1'),
- _.inRange(0, '0', 1),
- _.inRange(0, 0, '1'),
- _.inRange(0, NaN, 1),
- _.inRange(-1, -1, NaN)
- ];
- assert.deepEqual(actual, lodashStable.map(actual, stubTrue));
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('intersection methods');
- lodashStable.each(['intersection', 'intersectionBy', 'intersectionWith'], function(methodName) {
- var args = (function() { return arguments; }(1, 2, 3)),
- func = _[methodName];
- QUnit.test('`_.' + methodName + '` should return the intersection of two arrays', function(assert) {
- assert.expect(1);
- var actual = func([2, 1], [2, 3]);
- assert.deepEqual(actual, [2]);
- });
- QUnit.test('`_.' + methodName + '` should return the intersection of multiple arrays', function(assert) {
- assert.expect(1);
- var actual = func([2, 1, 2, 3], [3, 4], [3, 2]);
- assert.deepEqual(actual, [3]);
- });
- QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
- assert.expect(1);
- var actual = func([1, 1, 3, 2, 2], [5, 2, 2, 1, 4], [2, 1, 1]);
- assert.deepEqual(actual, [1, 2]);
- });
- QUnit.test('`_.' + methodName + '` should work with a single array', function(assert) {
- assert.expect(1);
- var actual = func([1, 1, 3, 2, 2]);
- assert.deepEqual(actual, [1, 3, 2]);
- });
- QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
- assert.expect(2);
- var array = [0, 1, null, 3],
- expected = [1, 3];
- assert.deepEqual(func(array, args), expected);
- assert.deepEqual(func(args, array), expected);
- });
- QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
- assert.expect(1);
- var values = [-0, 0],
- expected = lodashStable.map(values, lodashStable.constant(['0']));
- var actual = lodashStable.map(values, function(value) {
- return lodashStable.map(func(values, [value]), lodashStable.toString);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
- assert.expect(1);
- var actual = func([1, NaN, 3], [NaN, 5, NaN]);
- assert.deepEqual(actual, [NaN]);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
- assert.expect(1);
- var values = [-0, 0],
- expected = lodashStable.map(values, lodashStable.constant(['0']));
- var actual = lodashStable.map(values, function(value) {
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(value));
- return lodashStable.map(func(values, largeArray), lodashStable.toString);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
- assert.expect(1);
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubNaN);
- assert.deepEqual(func([1, NaN, 3], largeArray), [NaN]);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of objects', function(assert) {
- assert.expect(2);
- var object = {},
- largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
- assert.deepEqual(func([object], largeArray), [object]);
- assert.deepEqual(func(lodashStable.range(LARGE_ARRAY_SIZE), [1]), [1]);
- });
- QUnit.test('`_.' + methodName + '` should treat values that are not arrays or `arguments` objects as empty', function(assert) {
- assert.expect(3);
- var array = [0, 1, null, 3];
- assert.deepEqual(func(array, 3, { '0': 1 }, null), []);
- assert.deepEqual(func(null, array, null, [2, 3]), []);
- assert.deepEqual(func(array, null, args, null), []);
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _([1, 3, 2])[methodName]([5, 2, 1, 4]);
- assert.ok(wrapped instanceof _);
- assert.deepEqual(wrapped.value(), [1, 2]);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.intersectionBy');
- (function() {
- QUnit.test('should accept an `iteratee` argument', function(assert) {
- assert.expect(2);
- var actual = _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
- assert.deepEqual(actual, [2.1]);
- actual = _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
- assert.deepEqual(actual, [{ 'x': 1 }]);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.intersectionBy([2.1, 1.2], [2.3, 3.4], function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [2.3]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.intersectionWith');
- (function() {
- QUnit.test('should work with a `comparator` argument', function(assert) {
- assert.expect(1);
- var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
- others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
- actual = _.intersectionWith(objects, others, lodashStable.isEqual);
- assert.deepEqual(actual, [objects[0]]);
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var array = [-0],
- largeArray = lodashStable.times(LARGE_ARRAY_SIZE, stubZero),
- others = [[0], largeArray],
- expected = lodashStable.map(others, lodashStable.constant(['-0']));
- var actual = lodashStable.map(others, function(other) {
- return lodashStable.map(_.intersectionWith(array, other, lodashStable.eq), lodashStable.toString);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.invert');
- (function() {
- QUnit.test('should invert an object', function(assert) {
- assert.expect(2);
- var object = { 'a': 1, 'b': 2 },
- actual = _.invert(object);
- assert.deepEqual(actual, { '1': 'a', '2': 'b' });
- assert.deepEqual(_.invert(actual), { 'a': '1', 'b': '2' });
- });
- QUnit.test('should work with values that shadow keys on `Object.prototype`', function(assert) {
- assert.expect(1);
- var object = { 'a': 'hasOwnProperty', 'b': 'constructor' };
- assert.deepEqual(_.invert(object), { 'hasOwnProperty': 'a', 'constructor': 'b' });
- });
- QUnit.test('should work with an object that has a `length` property', function(assert) {
- assert.expect(1);
- var object = { '0': 'a', '1': 'b', 'length': 2 };
- assert.deepEqual(_.invert(object), { 'a': '0', 'b': '1', '2': 'length' });
- });
- QUnit.test('should return a wrapped value when chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var object = { 'a': 1, 'b': 2 },
- wrapped = _(object).invert();
- assert.ok(wrapped instanceof _);
- assert.deepEqual(wrapped.value(), { '1': 'a', '2': 'b' });
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.invertBy');
- (function() {
- var object = { 'a': 1, 'b': 2, 'c': 1 };
- QUnit.test('should transform keys by `iteratee`', function(assert) {
- assert.expect(1);
- var expected = { 'group1': ['a', 'c'], 'group2': ['b'] };
- var actual = _.invertBy(object, function(value) {
- return 'group' + value;
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant({ '1': ['a', 'c'], '2': ['b'] }));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.invertBy(object, value) : _.invertBy(object);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should only add multiple values to own, not inherited, properties', function(assert) {
- assert.expect(1);
- var object = { 'a': 'hasOwnProperty', 'b': 'constructor' },
- expected = { 'hasOwnProperty': ['a'], 'constructor': ['b'] };
- assert.ok(lodashStable.isEqual(_.invertBy(object), expected));
- });
- QUnit.test('should return a wrapped value when chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _(object).invertBy();
- assert.ok(wrapped instanceof _);
- assert.deepEqual(wrapped.value(), { '1': ['a', 'c'], '2': ['b'] });
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.invoke');
- (function() {
- QUnit.test('should invoke a method on `object`', function(assert) {
- assert.expect(1);
- var object = { 'a': lodashStable.constant('A') },
- actual = _.invoke(object, 'a');
- assert.strictEqual(actual, 'A');
- });
- QUnit.test('should support invoking with arguments', function(assert) {
- assert.expect(1);
- var object = { 'a': function(a, b) { return [a, b]; } },
- actual = _.invoke(object, 'a', 1, 2);
- assert.deepEqual(actual, [1, 2]);
- });
- QUnit.test('should not error on nullish elements', function(assert) {
- assert.expect(1);
- var values = [null, undefined],
- expected = lodashStable.map(values, noop);
- var actual = lodashStable.map(values, function(value) {
- try {
- return _.invoke(value, 'a.b', 1, 2);
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var object = { '-0': stubA, '0': stubB },
- props = [-0, Object(-0), 0, Object(0)];
- var actual = lodashStable.map(props, function(key) {
- return _.invoke(object, key);
- });
- assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
- });
- QUnit.test('should support deep paths', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': function(a, b) { return [a, b]; } } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var actual = _.invoke(object, path, 1, 2);
- assert.deepEqual(actual, [1, 2]);
- });
- });
- QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.deepEqual(_.invoke(object, path), 1);
- });
- });
- QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var object = { 'a': stubOne };
- assert.strictEqual(_(object).invoke('a'), 1);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var object = { 'a': stubOne };
- assert.ok(_(object).chain().invoke('a') instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.invokeMap');
- (function() {
- QUnit.test('should invoke a methods on each element of `collection`', function(assert) {
- assert.expect(1);
- var array = ['a', 'b', 'c'],
- actual = _.invokeMap(array, 'toUpperCase');
- assert.deepEqual(actual, ['A', 'B', 'C']);
- });
- QUnit.test('should support invoking with arguments', function(assert) {
- assert.expect(1);
- var array = [function() { return slice.call(arguments); }],
- actual = _.invokeMap(array, 'call', null, 'a', 'b', 'c');
- assert.deepEqual(actual, [['a', 'b', 'c']]);
- });
- QUnit.test('should work with a function for `methodName`', function(assert) {
- assert.expect(1);
- var array = ['a', 'b', 'c'];
- var actual = _.invokeMap(array, function(left, right) {
- return left + this.toUpperCase() + right;
- }, '(', ')');
- assert.deepEqual(actual, ['(A)', '(B)', '(C)']);
- });
- QUnit.test('should work with an object for `collection`', function(assert) {
- assert.expect(1);
- var object = { 'a': 1, 'b': 2, 'c': 3 },
- actual = _.invokeMap(object, 'toFixed', 1);
- assert.deepEqual(actual, ['1.0', '2.0', '3.0']);
- });
- QUnit.test('should treat number values for `collection` as empty', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.invokeMap(1), []);
- });
- QUnit.test('should not error on nullish elements', function(assert) {
- assert.expect(1);
- var array = ['a', null, undefined, 'd'];
- try {
- var actual = _.invokeMap(array, 'toUpperCase');
- } catch (e) {}
- assert.deepEqual(actual, ['A', undefined, undefined, 'D']);
- });
- QUnit.test('should not error on elements with missing properties', function(assert) {
- assert.expect(1);
- var objects = lodashStable.map([null, undefined, stubOne], function(value) {
- return { 'a': value };
- });
- var expected = lodashStable.map(objects, function(object) {
- return object.a ? object.a() : undefined;
- });
- try {
- var actual = _.invokeMap(objects, 'a');
- } catch (e) {}
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.deepEqual(_.invokeMap([object], path), [1]);
- });
- });
- QUnit.test('should return a wrapped value when chaining', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- var array = ['a', 'b', 'c'],
- wrapped = _(array),
- actual = wrapped.invokeMap('toUpperCase');
- assert.ok(actual instanceof _);
- assert.deepEqual(actual.valueOf(), ['A', 'B', 'C']);
- actual = wrapped.invokeMap(function(left, right) {
- return left + this.toUpperCase() + right;
- }, '(', ')');
- assert.ok(actual instanceof _);
- assert.deepEqual(actual.valueOf(), ['(A)', '(B)', '(C)']);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should support shortcut fusion', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var count = 0,
- method = function() { count++; return this.index; };
- var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
- return { 'index': index, 'method': method };
- });
- var actual = _(array).invokeMap('method').take(1).value();
- assert.strictEqual(count, 1);
- assert.deepEqual(actual, [0]);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isArguments');
- (function() {
- var args = (function() { return arguments; }(1, 2, 3)),
- strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3));
- QUnit.test('should return `true` for `arguments` objects', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.isArguments(args), true);
- assert.strictEqual(_.isArguments(strictArgs), true);
- });
- QUnit.test('should return `false` for non `arguments` objects', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isArguments(value) : _.isArguments();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isArguments([1, 2, 3]), false);
- assert.strictEqual(_.isArguments(true), false);
- assert.strictEqual(_.isArguments(new Date), false);
- assert.strictEqual(_.isArguments(new Error), false);
- assert.strictEqual(_.isArguments(_), false);
- assert.strictEqual(_.isArguments(slice), false);
- assert.strictEqual(_.isArguments({ '0': 1, 'callee': noop, 'length': 1 }), false);
- assert.strictEqual(_.isArguments(1), false);
- assert.strictEqual(_.isArguments(/x/), false);
- assert.strictEqual(_.isArguments('a'), false);
- assert.strictEqual(_.isArguments(symbol), false);
- });
- QUnit.test('should work with an `arguments` object from another realm', function(assert) {
- assert.expect(1);
- if (realm.arguments) {
- assert.strictEqual(_.isArguments(realm.arguments), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isArray');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for arrays', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isArray([1, 2, 3]), true);
- });
- QUnit.test('should return `false` for non-arrays', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isArray(value) : _.isArray();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isArray(args), false);
- assert.strictEqual(_.isArray(true), false);
- assert.strictEqual(_.isArray(new Date), false);
- assert.strictEqual(_.isArray(new Error), false);
- assert.strictEqual(_.isArray(_), false);
- assert.strictEqual(_.isArray(slice), false);
- assert.strictEqual(_.isArray({ '0': 1, 'length': 1 }), false);
- assert.strictEqual(_.isArray(1), false);
- assert.strictEqual(_.isArray(/x/), false);
- assert.strictEqual(_.isArray('a'), false);
- assert.strictEqual(_.isArray(symbol), false);
- });
- QUnit.test('should work with an array from another realm', function(assert) {
- assert.expect(1);
- if (realm.array) {
- assert.strictEqual(_.isArray(realm.array), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isArrayBuffer');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for array buffers', function(assert) {
- assert.expect(1);
- if (ArrayBuffer) {
- assert.strictEqual(_.isArrayBuffer(arrayBuffer), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for non array buffers', function(assert) {
- assert.expect(13);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isArrayBuffer(value) : _.isArrayBuffer();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isArrayBuffer(args), false);
- assert.strictEqual(_.isArrayBuffer([1, 2, 3]), false);
- assert.strictEqual(_.isArrayBuffer(true), false);
- assert.strictEqual(_.isArrayBuffer(new Date), false);
- assert.strictEqual(_.isArrayBuffer(new Error), false);
- assert.strictEqual(_.isArrayBuffer(_), false);
- assert.strictEqual(_.isArrayBuffer(slice), false);
- assert.strictEqual(_.isArrayBuffer({ 'a': 1 }), false);
- assert.strictEqual(_.isArrayBuffer(1), false);
- assert.strictEqual(_.isArrayBuffer(/x/), false);
- assert.strictEqual(_.isArrayBuffer('a'), false);
- assert.strictEqual(_.isArrayBuffer(symbol), false);
- });
- QUnit.test('should work with array buffers from another realm', function(assert) {
- assert.expect(1);
- if (realm.arrayBuffer) {
- assert.strictEqual(_.isArrayBuffer(realm.arrayBuffer), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isArrayLike');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for array-like values', function(assert) {
- assert.expect(1);
- var values = [args, [1, 2, 3], { '0': 'a', 'length': 1 }, 'a'],
- expected = lodashStable.map(values, stubTrue),
- actual = lodashStable.map(values, _.isArrayLike);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `false` for non-arrays', function(assert) {
- assert.expect(11);
- var expected = lodashStable.map(falsey, function(value) {
- return value === '';
- });
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isArrayLike(value) : _.isArrayLike();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isArrayLike(true), false);
- assert.strictEqual(_.isArrayLike(new Date), false);
- assert.strictEqual(_.isArrayLike(new Error), false);
- assert.strictEqual(_.isArrayLike(_), false);
- assert.strictEqual(_.isArrayLike(generator), false);
- assert.strictEqual(_.isArrayLike(slice), false);
- assert.strictEqual(_.isArrayLike({ 'a': 1 }), false);
- assert.strictEqual(_.isArrayLike(1), false);
- assert.strictEqual(_.isArrayLike(/x/), false);
- assert.strictEqual(_.isArrayLike(symbol), false);
- });
- QUnit.test('should work with an array from another realm', function(assert) {
- assert.expect(1);
- if (realm.object) {
- var values = [realm.arguments, realm.array, realm.string],
- expected = lodashStable.map(values, stubTrue),
- actual = lodashStable.map(values, _.isArrayLike);
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isBoolean');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for booleans', function(assert) {
- assert.expect(4);
- assert.strictEqual(_.isBoolean(true), true);
- assert.strictEqual(_.isBoolean(false), true);
- assert.strictEqual(_.isBoolean(Object(true)), true);
- assert.strictEqual(_.isBoolean(Object(false)), true);
- });
- QUnit.test('should return `false` for non-booleans', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, function(value) {
- return value === false;
- });
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isBoolean(value) : _.isBoolean();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isBoolean(args), false);
- assert.strictEqual(_.isBoolean([1, 2, 3]), false);
- assert.strictEqual(_.isBoolean(new Date), false);
- assert.strictEqual(_.isBoolean(new Error), false);
- assert.strictEqual(_.isBoolean(_), false);
- assert.strictEqual(_.isBoolean(slice), false);
- assert.strictEqual(_.isBoolean({ 'a': 1 }), false);
- assert.strictEqual(_.isBoolean(1), false);
- assert.strictEqual(_.isBoolean(/x/), false);
- assert.strictEqual(_.isBoolean('a'), false);
- assert.strictEqual(_.isBoolean(symbol), false);
- });
- QUnit.test('should work with a boolean from another realm', function(assert) {
- assert.expect(1);
- if (realm.boolean) {
- assert.strictEqual(_.isBoolean(realm.boolean), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isBuffer');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for buffers', function(assert) {
- assert.expect(1);
- if (Buffer) {
- assert.strictEqual(_.isBuffer(new Buffer(2)), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for non-buffers', function(assert) {
- assert.expect(13);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isBuffer(value) : _.isBuffer();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isBuffer(args), false);
- assert.strictEqual(_.isBuffer([1, 2, 3]), false);
- assert.strictEqual(_.isBuffer(true), false);
- assert.strictEqual(_.isBuffer(new Date), false);
- assert.strictEqual(_.isBuffer(new Error), false);
- assert.strictEqual(_.isBuffer(_), false);
- assert.strictEqual(_.isBuffer(slice), false);
- assert.strictEqual(_.isBuffer({ 'a': 1 }), false);
- assert.strictEqual(_.isBuffer(1), false);
- assert.strictEqual(_.isBuffer(/x/), false);
- assert.strictEqual(_.isBuffer('a'), false);
- assert.strictEqual(_.isBuffer(symbol), false);
- });
- QUnit.test('should return `false` if `Buffer` is not defined', function(assert) {
- assert.expect(1);
- if (!isStrict && Buffer && lodashBizarro) {
- assert.strictEqual(lodashBizarro.isBuffer(new Buffer(2)), false);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isDate');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for dates', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isDate(new Date), true);
- });
- QUnit.test('should return `false` for non-dates', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isDate(value) : _.isDate();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isDate(args), false);
- assert.strictEqual(_.isDate([1, 2, 3]), false);
- assert.strictEqual(_.isDate(true), false);
- assert.strictEqual(_.isDate(new Error), false);
- assert.strictEqual(_.isDate(_), false);
- assert.strictEqual(_.isDate(slice), false);
- assert.strictEqual(_.isDate({ 'a': 1 }), false);
- assert.strictEqual(_.isDate(1), false);
- assert.strictEqual(_.isDate(/x/), false);
- assert.strictEqual(_.isDate('a'), false);
- assert.strictEqual(_.isDate(symbol), false);
- });
- QUnit.test('should work with a date object from another realm', function(assert) {
- assert.expect(1);
- if (realm.date) {
- assert.strictEqual(_.isDate(realm.date), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isElement');
- (function() {
- var args = arguments;
- function Element() {
- this.nodeType = 1;
- }
- QUnit.test('should return `false` for plain objects', function(assert) {
- assert.expect(7);
- var element = body || new Element;
- assert.strictEqual(_.isElement(element), true);
- assert.strictEqual(_.isElement({ 'nodeType': 1 }), false);
- assert.strictEqual(_.isElement({ 'nodeType': Object(1) }), false);
- assert.strictEqual(_.isElement({ 'nodeType': true }), false);
- assert.strictEqual(_.isElement({ 'nodeType': [1] }), false);
- assert.strictEqual(_.isElement({ 'nodeType': '1' }), false);
- assert.strictEqual(_.isElement({ 'nodeType': '001' }), false);
- });
- QUnit.test('should return `false` for non DOM elements', function(assert) {
- assert.expect(13);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isElement(value) : _.isElement();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isElement(args), false);
- assert.strictEqual(_.isElement([1, 2, 3]), false);
- assert.strictEqual(_.isElement(true), false);
- assert.strictEqual(_.isElement(new Date), false);
- assert.strictEqual(_.isElement(new Error), false);
- assert.strictEqual(_.isElement(_), false);
- assert.strictEqual(_.isElement(slice), false);
- assert.strictEqual(_.isElement({ 'a': 1 }), false);
- assert.strictEqual(_.isElement(1), false);
- assert.strictEqual(_.isElement(/x/), false);
- assert.strictEqual(_.isElement('a'), false);
- assert.strictEqual(_.isElement(symbol), false);
- });
- QUnit.test('should work with a DOM element from another realm', function(assert) {
- assert.expect(1);
- if (realm.element) {
- assert.strictEqual(_.isElement(realm.element), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isEmpty');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for empty values', function(assert) {
- assert.expect(10);
- var expected = lodashStable.map(empties, stubTrue),
- actual = lodashStable.map(empties, _.isEmpty);
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isEmpty(true), true);
- assert.strictEqual(_.isEmpty(slice), true);
- assert.strictEqual(_.isEmpty(1), true);
- assert.strictEqual(_.isEmpty(NaN), true);
- assert.strictEqual(_.isEmpty(/x/), true);
- assert.strictEqual(_.isEmpty(symbol), true);
- assert.strictEqual(_.isEmpty(), true);
- if (Buffer) {
- assert.strictEqual(_.isEmpty(new Buffer(0)), true);
- assert.strictEqual(_.isEmpty(new Buffer(1)), false);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should return `false` for non-empty values', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.isEmpty([0]), false);
- assert.strictEqual(_.isEmpty({ 'a': 0 }), false);
- assert.strictEqual(_.isEmpty('a'), false);
- });
- QUnit.test('should work with an object that has a `length` property', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isEmpty({ 'length': 0 }), false);
- });
- QUnit.test('should work with `arguments` objects', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isEmpty(args), false);
- });
- QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
- assert.expect(1);
- function Foo(elements) {
- push.apply(this, elements);
- }
- Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
- assert.strictEqual(_.isEmpty(new Foo([])), true);
- });
- QUnit.test('should work with maps', function(assert) {
- assert.expect(4);
- if (Map) {
- lodashStable.each([new Map, realm.map], function(map) {
- assert.strictEqual(_.isEmpty(map), true);
- map.set('a', 1);
- assert.strictEqual(_.isEmpty(map), false);
- map.clear();
- });
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should work with sets', function(assert) {
- assert.expect(4);
- if (Set) {
- lodashStable.each([new Set, realm.set], function(set) {
- assert.strictEqual(_.isEmpty(set), true);
- set.add(1);
- assert.strictEqual(_.isEmpty(set), false);
- set.clear();
- });
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.prototype.length = -1;
- assert.strictEqual(_.isEmpty(new Foo), true);
- });
- QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.prototype.length = MAX_SAFE_INTEGER + 1;
- assert.strictEqual(_.isEmpty(new Foo), true);
- });
- QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isEmpty({ 'length': '0' }), false);
- });
- QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.strictEqual(_({}).isEmpty(), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_({}).chain().isEmpty() instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isEqual');
- (function() {
- var symbol1 = Symbol ? Symbol('a') : true,
- symbol2 = Symbol ? Symbol('b') : false;
- QUnit.test('should compare primitives', function(assert) {
- assert.expect(1);
- var pairs = [
- [1, 1, true], [1, Object(1), true], [1, '1', false], [1, 2, false],
- [-0, -0, true], [0, 0, true], [0, Object(0), true], [Object(0), Object(0), true], [-0, 0, true], [0, '0', false], [0, null, false],
- [NaN, NaN, true], [NaN, Object(NaN), true], [Object(NaN), Object(NaN), true], [NaN, 'a', false], [NaN, Infinity, false],
- ['a', 'a', true], ['a', Object('a'), true], [Object('a'), Object('a'), true], ['a', 'b', false], ['a', ['a'], false],
- [true, true, true], [true, Object(true), true], [Object(true), Object(true), true], [true, 1, false], [true, 'a', false],
- [false, false, true], [false, Object(false), true], [Object(false), Object(false), true], [false, 0, false], [false, '', false],
- [symbol1, symbol1, true], [symbol1, Object(symbol1), true], [Object(symbol1), Object(symbol1), true], [symbol1, symbol2, false],
- [null, null, true], [null, undefined, false], [null, {}, false], [null, '', false],
- [undefined, undefined, true], [undefined, null, false], [undefined, '', false]
- ];
- var expected = lodashStable.map(pairs, function(pair) {
- return pair[2];
- });
- var actual = lodashStable.map(pairs, function(pair) {
- return _.isEqual(pair[0], pair[1]);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should compare arrays', function(assert) {
- assert.expect(6);
- var array1 = [true, null, 1, 'a', undefined],
- array2 = [true, null, 1, 'a', undefined];
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
- array2 = [[1, 2, 3], new Date(2012, 4, 23), /x/, { 'e': 1 }];
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1 = [1];
- array1[2] = 3;
- array2 = [1];
- array2[1] = undefined;
- array2[2] = 3;
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1 = [Object(1), false, Object('a'), /x/, new Date(2012, 4, 23), ['a', 'b', [Object('c')]], { 'a': 1 }];
- array2 = [1, Object(false), 'a', /x/, new Date(2012, 4, 23), ['a', Object('b'), ['c']], { 'a': 1 }];
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1 = [1, 2, 3];
- array2 = [3, 2, 1];
- assert.strictEqual(_.isEqual(array1, array2), false);
- array1 = [1, 2];
- array2 = [1, 2, 3];
- assert.strictEqual(_.isEqual(array1, array2), false);
- });
- QUnit.test('should treat arrays with identical values but different non-index properties as equal', function(assert) {
- assert.expect(3);
- var array1 = [1, 2, 3],
- array2 = [1, 2, 3];
- array1.every = array1.filter = array1.forEach =
- array1.indexOf = array1.lastIndexOf = array1.map =
- array1.some = array1.reduce = array1.reduceRight = null;
- array2.concat = array2.join = array2.pop =
- array2.reverse = array2.shift = array2.slice =
- array2.sort = array2.splice = array2.unshift = null;
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1 = [1, 2, 3];
- array1.a = 1;
- array2 = [1, 2, 3];
- array2.b = 1;
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1 = /c/.exec('abcde');
- array2 = ['c'];
- assert.strictEqual(_.isEqual(array1, array2), true);
- });
- QUnit.test('should compare sparse arrays', function(assert) {
- assert.expect(3);
- var array = Array(1);
- assert.strictEqual(_.isEqual(array, Array(1)), true);
- assert.strictEqual(_.isEqual(array, [undefined]), true);
- assert.strictEqual(_.isEqual(array, Array(2)), false);
- });
- QUnit.test('should compare plain objects', function(assert) {
- assert.expect(5);
- var object1 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined },
- object2 = { 'a': true, 'b': null, 'c': 1, 'd': 'a', 'e': undefined };
- assert.strictEqual(_.isEqual(object1, object2), true);
- object1 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
- object2 = { 'a': [1, 2, 3], 'b': new Date(2012, 4, 23), 'c': /x/, 'd': { 'e': 1 } };
- assert.strictEqual(_.isEqual(object1, object2), true);
- object1 = { 'a': 1, 'b': 2, 'c': 3 };
- object2 = { 'a': 3, 'b': 2, 'c': 1 };
- assert.strictEqual(_.isEqual(object1, object2), false);
- object1 = { 'a': 1, 'b': 2, 'c': 3 };
- object2 = { 'd': 1, 'e': 2, 'f': 3 };
- assert.strictEqual(_.isEqual(object1, object2), false);
- object1 = { 'a': 1, 'b': 2 };
- object2 = { 'a': 1, 'b': 2, 'c': 3 };
- assert.strictEqual(_.isEqual(object1, object2), false);
- });
- QUnit.test('should compare objects regardless of key order', function(assert) {
- assert.expect(1);
- var object1 = { 'a': 1, 'b': 2, 'c': 3 },
- object2 = { 'c': 3, 'a': 1, 'b': 2 };
- assert.strictEqual(_.isEqual(object1, object2), true);
- });
- QUnit.test('should compare nested objects', function(assert) {
- assert.expect(1);
- var object1 = {
- 'a': [1, 2, 3],
- 'b': true,
- 'c': Object(1),
- 'd': 'a',
- 'e': {
- 'f': ['a', Object('b'), 'c'],
- 'g': Object(false),
- 'h': new Date(2012, 4, 23),
- 'i': noop,
- 'j': 'a'
- }
- };
- var object2 = {
- 'a': [1, Object(2), 3],
- 'b': Object(true),
- 'c': 1,
- 'd': Object('a'),
- 'e': {
- 'f': ['a', 'b', 'c'],
- 'g': false,
- 'h': new Date(2012, 4, 23),
- 'i': noop,
- 'j': 'a'
- }
- };
- assert.strictEqual(_.isEqual(object1, object2), true);
- });
- QUnit.test('should compare object instances', function(assert) {
- assert.expect(4);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.a = 1;
- function Bar() {
- this.a = 1;
- }
- Bar.prototype.a = 2;
- assert.strictEqual(_.isEqual(new Foo, new Foo), true);
- assert.strictEqual(_.isEqual(new Foo, new Bar), false);
- assert.strictEqual(_.isEqual({ 'a': 1 }, new Foo), false);
- assert.strictEqual(_.isEqual({ 'a': 2 }, new Bar), false);
- });
- QUnit.test('should compare objects with constructor properties', function(assert) {
- assert.expect(5);
- assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': 1 }), true);
- assert.strictEqual(_.isEqual({ 'constructor': 1 }, { 'constructor': '1' }), false);
- assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': [1] }), true);
- assert.strictEqual(_.isEqual({ 'constructor': [1] }, { 'constructor': ['1'] }), false);
- assert.strictEqual(_.isEqual({ 'constructor': Object }, {}), false);
- });
- QUnit.test('should compare arrays with circular references', function(assert) {
- assert.expect(4);
- var array1 = [],
- array2 = [];
- array1.push(array1);
- array2.push(array2);
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1.push('b');
- array2.push('b');
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1.push('c');
- array2.push('d');
- assert.strictEqual(_.isEqual(array1, array2), false);
- array1 = ['a', 'b', 'c'];
- array1[1] = array1;
- array2 = ['a', ['a', 'b', 'c'], 'c'];
- assert.strictEqual(_.isEqual(array1, array2), false);
- });
- QUnit.test('should have transitive equivalence for circular references of arrays', function(assert) {
- assert.expect(3);
- var array1 = [],
- array2 = [array1],
- array3 = [array2];
- array1[0] = array1;
- assert.strictEqual(_.isEqual(array1, array2), true);
- assert.strictEqual(_.isEqual(array2, array3), true);
- assert.strictEqual(_.isEqual(array1, array3), true);
- });
- QUnit.test('should compare objects with circular references', function(assert) {
- assert.expect(4);
- var object1 = {},
- object2 = {};
- object1.a = object1;
- object2.a = object2;
- assert.strictEqual(_.isEqual(object1, object2), true);
- object1.b = 0;
- object2.b = Object(0);
- assert.strictEqual(_.isEqual(object1, object2), true);
- object1.c = Object(1);
- object2.c = Object(2);
- assert.strictEqual(_.isEqual(object1, object2), false);
- object1 = { 'a': 1, 'b': 2, 'c': 3 };
- object1.b = object1;
- object2 = { 'a': 1, 'b': { 'a': 1, 'b': 2, 'c': 3 }, 'c': 3 };
- assert.strictEqual(_.isEqual(object1, object2), false);
- });
- QUnit.test('should have transitive equivalence for circular references of objects', function(assert) {
- assert.expect(3);
- var object1 = {},
- object2 = { 'a': object1 },
- object3 = { 'a': object2 };
- object1.a = object1;
- assert.strictEqual(_.isEqual(object1, object2), true);
- assert.strictEqual(_.isEqual(object2, object3), true);
- assert.strictEqual(_.isEqual(object1, object3), true);
- });
- QUnit.test('should compare objects with multiple circular references', function(assert) {
- assert.expect(3);
- var array1 = [{}],
- array2 = [{}];
- (array1[0].a = array1).push(array1);
- (array2[0].a = array2).push(array2);
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1[0].b = 0;
- array2[0].b = Object(0);
- assert.strictEqual(_.isEqual(array1, array2), true);
- array1[0].c = Object(1);
- array2[0].c = Object(2);
- assert.strictEqual(_.isEqual(array1, array2), false);
- });
- QUnit.test('should compare objects with complex circular references', function(assert) {
- assert.expect(1);
- var object1 = {
- 'foo': { 'b': { 'c': { 'd': {} } } },
- 'bar': { 'a': 2 }
- };
- var object2 = {
- 'foo': { 'b': { 'c': { 'd': {} } } },
- 'bar': { 'a': 2 }
- };
- object1.foo.b.c.d = object1;
- object1.bar.b = object1.foo.b;
- object2.foo.b.c.d = object2;
- object2.bar.b = object2.foo.b;
- assert.strictEqual(_.isEqual(object1, object2), true);
- });
- QUnit.test('should compare objects with shared property values', function(assert) {
- assert.expect(1);
- var object1 = {
- 'a': [1, 2]
- };
- var object2 = {
- 'a': [1, 2],
- 'b': [1, 2]
- };
- object1.b = object1.a;
- assert.strictEqual(_.isEqual(object1, object2), true);
- });
- QUnit.test('should treat objects created by `Object.create(null)` like a plain object', function(assert) {
- assert.expect(2);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.constructor = null;
- var object2 = { 'a': 1 };
- assert.strictEqual(_.isEqual(new Foo, object2), false);
- if (create) {
- var object1 = create(null);
- object1.a = 1;
- assert.strictEqual(_.isEqual(object1, object2), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for objects with custom `toString` methods', function(assert) {
- assert.expect(1);
- var primitive,
- object = { 'toString': function() { return primitive; } },
- values = [true, null, 1, 'a', undefined],
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value) {
- primitive = value;
- return _.isEqual(object, value);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should avoid common type coercions', function(assert) {
- assert.expect(9);
- assert.strictEqual(_.isEqual(true, Object(false)), false);
- assert.strictEqual(_.isEqual(Object(false), Object(0)), false);
- assert.strictEqual(_.isEqual(false, Object('')), false);
- assert.strictEqual(_.isEqual(Object(36), Object('36')), false);
- assert.strictEqual(_.isEqual(0, ''), false);
- assert.strictEqual(_.isEqual(1, true), false);
- assert.strictEqual(_.isEqual(1337756400000, new Date(2012, 4, 23)), false);
- assert.strictEqual(_.isEqual('36', 36), false);
- assert.strictEqual(_.isEqual(36, '36'), false);
- });
- QUnit.test('should compare `arguments` objects', function(assert) {
- assert.expect(2);
- var args1 = (function() { return arguments; }(1, 2, 3)),
- args2 = (function() { return arguments; }(1, 2, 3)),
- args3 = (function() { return arguments; }(1, 2));
- assert.strictEqual(_.isEqual(args1, args2), true);
- assert.strictEqual(_.isEqual(args1, args3), false);
- });
- QUnit.test('should treat `arguments` objects like `Object` objects', function(assert) {
- assert.expect(4);
- var args = (function() { return arguments; }(1, 2, 3)),
- object = { '0': 1, '1': 2, '2': 3 };
- function Foo() {}
- Foo.prototype = object;
- assert.strictEqual(_.isEqual(args, object), true);
- assert.strictEqual(_.isEqual(object, args), true);
- assert.strictEqual(_.isEqual(args, new Foo), false);
- assert.strictEqual(_.isEqual(new Foo, args), false);
- });
- QUnit.test('should compare array buffers', function(assert) {
- assert.expect(2);
- if (ArrayBuffer) {
- var buffer1 = new ArrayBuffer(4),
- buffer2 = new ArrayBuffer(8);
- assert.strictEqual(_.isEqual(buffer1, buffer2), false);
- buffer1 = new Int8Array([-1]).buffer;
- buffer2 = new Uint8Array([255]).buffer;
- assert.strictEqual(_.isEqual(buffer1, buffer2), true);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should compare array views', function(assert) {
- assert.expect(2);
- lodashStable.times(2, function(index) {
- var ns = index ? realm : root;
- var pairs = lodashStable.map(arrayViews, function(type, viewIndex) {
- var otherType = arrayViews[(viewIndex + 1) % arrayViews.length],
- CtorA = ns[type] || function(n) { this.n = n; },
- CtorB = ns[otherType] || function(n) { this.n = n; },
- bufferA = ns[type] ? new ns.ArrayBuffer(8) : 8,
- bufferB = ns[otherType] ? new ns.ArrayBuffer(8) : 8,
- bufferC = ns[otherType] ? new ns.ArrayBuffer(16) : 16;
- return [new CtorA(bufferA), new CtorA(bufferA), new CtorB(bufferB), new CtorB(bufferC)];
- });
- var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
- var actual = lodashStable.map(pairs, function(pair) {
- return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should compare date objects', function(assert) {
- assert.expect(4);
- var date = new Date(2012, 4, 23);
- assert.strictEqual(_.isEqual(date, new Date(2012, 4, 23)), true);
- assert.strictEqual(_.isEqual(new Date('a'), new Date('b')), true);
- assert.strictEqual(_.isEqual(date, new Date(2013, 3, 25)), false);
- assert.strictEqual(_.isEqual(date, { 'getTime': lodashStable.constant(+date) }), false);
- });
- QUnit.test('should compare error objects', function(assert) {
- assert.expect(1);
- var pairs = lodashStable.map([
- 'Error',
- 'EvalError',
- 'RangeError',
- 'ReferenceError',
- 'SyntaxError',
- 'TypeError',
- 'URIError'
- ], function(type, index, errorTypes) {
- var otherType = errorTypes[++index % errorTypes.length],
- CtorA = root[type],
- CtorB = root[otherType];
- return [new CtorA('a'), new CtorA('a'), new CtorB('a'), new CtorB('b')];
- });
- var expected = lodashStable.map(pairs, lodashStable.constant([true, false, false]));
- var actual = lodashStable.map(pairs, function(pair) {
- return [_.isEqual(pair[0], pair[1]), _.isEqual(pair[0], pair[2]), _.isEqual(pair[2], pair[3])];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should compare functions', function(assert) {
- assert.expect(2);
- function a() { return 1 + 2; }
- function b() { return 1 + 2; }
- assert.strictEqual(_.isEqual(a, a), true);
- assert.strictEqual(_.isEqual(a, b), false);
- });
- QUnit.test('should compare maps', function(assert) {
- assert.expect(8);
- if (Map) {
- lodashStable.each([[map, new Map], [map, realm.map]], function(maps) {
- var map1 = maps[0],
- map2 = maps[1];
- map1.set('a', 1);
- map2.set('b', 2);
- assert.strictEqual(_.isEqual(map1, map2), false);
- map1.set('b', 2);
- map2.set('a', 1);
- assert.strictEqual(_.isEqual(map1, map2), true);
- map1['delete']('a');
- map1.set('a', 1);
- assert.strictEqual(_.isEqual(map1, map2), true);
- map2['delete']('a');
- assert.strictEqual(_.isEqual(map1, map2), false);
- map1.clear();
- map2.clear();
- });
- }
- else {
- skipAssert(assert, 8);
- }
- });
- QUnit.test('should compare maps with circular references', function(assert) {
- assert.expect(2);
- if (Map) {
- var map1 = new Map,
- map2 = new Map;
- map1.set('a', map1);
- map2.set('a', map2);
- assert.strictEqual(_.isEqual(map1, map2), true);
- map1.set('b', 1);
- map2.set('b', 2);
- assert.strictEqual(_.isEqual(map1, map2), false);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should compare promises by reference', function(assert) {
- assert.expect(4);
- if (promise) {
- lodashStable.each([[promise, Promise.resolve(1)], [promise, realm.promise]], function(promises) {
- var promise1 = promises[0],
- promise2 = promises[1];
- assert.strictEqual(_.isEqual(promise1, promise2), false);
- assert.strictEqual(_.isEqual(promise1, promise1), true);
- });
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should compare regexes', function(assert) {
- assert.expect(5);
- assert.strictEqual(_.isEqual(/x/gim, /x/gim), true);
- assert.strictEqual(_.isEqual(/x/gim, /x/mgi), true);
- assert.strictEqual(_.isEqual(/x/gi, /x/g), false);
- assert.strictEqual(_.isEqual(/x/, /y/), false);
- assert.strictEqual(_.isEqual(/x/g, { 'global': true, 'ignoreCase': false, 'multiline': false, 'source': 'x' }), false);
- });
- QUnit.test('should compare sets', function(assert) {
- assert.expect(8);
- if (Set) {
- lodashStable.each([[set, new Set], [set, realm.set]], function(sets) {
- var set1 = sets[0],
- set2 = sets[1];
- set1.add(1);
- set2.add(2);
- assert.strictEqual(_.isEqual(set1, set2), false);
- set1.add(2);
- set2.add(1);
- assert.strictEqual(_.isEqual(set1, set2), true);
- set1['delete'](1);
- set1.add(1);
- assert.strictEqual(_.isEqual(set1, set2), true);
- set2['delete'](1);
- assert.strictEqual(_.isEqual(set1, set2), false);
- set1.clear();
- set2.clear();
- });
- }
- else {
- skipAssert(assert, 8);
- }
- });
- QUnit.test('should compare sets with circular references', function(assert) {
- assert.expect(2);
- if (Set) {
- var set1 = new Set,
- set2 = new Set;
- set1.add(set1);
- set2.add(set2);
- assert.strictEqual(_.isEqual(set1, set2), true);
- set1.add(1);
- set2.add(2);
- assert.strictEqual(_.isEqual(set1, set2), false);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should work as an iteratee for `_.every`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.every([1, 1, 1], lodashStable.partial(_.isEqual, 1));
- assert.ok(actual);
- });
- QUnit.test('should return `true` for like-objects from different documents', function(assert) {
- assert.expect(4);
- if (realm.object) {
- assert.strictEqual(_.isEqual([1], realm.array), true);
- assert.strictEqual(_.isEqual([2], realm.array), false);
- assert.strictEqual(_.isEqual({ 'a': 1 }, realm.object), true);
- assert.strictEqual(_.isEqual({ 'a': 2 }, realm.object), false);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should not error on DOM elements', function(assert) {
- assert.expect(1);
- if (document) {
- var element1 = document.createElement('div'),
- element2 = element1.cloneNode(true);
- try {
- assert.strictEqual(_.isEqual(element1, element2), false);
- } catch (e) {
- assert.ok(false, e.message);
- }
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should compare wrapped values', function(assert) {
- assert.expect(32);
- var stamp = +new Date;
- var values = [
- [[1, 2], [1, 2], [1, 2, 3]],
- [true, true, false],
- [new Date(stamp), new Date(stamp), new Date(stamp - 100)],
- [{ 'a': 1, 'b': 2 }, { 'a': 1, 'b': 2 }, { 'a': 1, 'b': 1 }],
- [1, 1, 2],
- [NaN, NaN, Infinity],
- [/x/, /x/, /x/i],
- ['a', 'a', 'A']
- ];
- lodashStable.each(values, function(vals) {
- if (!isNpm) {
- var wrapped1 = _(vals[0]),
- wrapped2 = _(vals[1]),
- actual = wrapped1.isEqual(wrapped2);
- assert.strictEqual(actual, true);
- assert.strictEqual(_.isEqual(_(actual), _(true)), true);
- wrapped1 = _(vals[0]);
- wrapped2 = _(vals[2]);
- actual = wrapped1.isEqual(wrapped2);
- assert.strictEqual(actual, false);
- assert.strictEqual(_.isEqual(_(actual), _(false)), true);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- });
- QUnit.test('should compare wrapped and non-wrapped values', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- var object1 = _({ 'a': 1, 'b': 2 }),
- object2 = { 'a': 1, 'b': 2 };
- assert.strictEqual(object1.isEqual(object2), true);
- assert.strictEqual(_.isEqual(object1, object2), true);
- object1 = _({ 'a': 1, 'b': 2 });
- object2 = { 'a': 1, 'b': 1 };
- assert.strictEqual(object1.isEqual(object2), false);
- assert.strictEqual(_.isEqual(object1, object2), false);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.strictEqual(_('a').isEqual('a'), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_('a').chain().isEqual('a') instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isEqualWith');
- (function() {
- QUnit.test('should provide correct `customizer` arguments', function(assert) {
- assert.expect(1);
- var argsList = [],
- object1 = { 'a': [1, 2], 'b': null },
- object2 = { 'a': [1, 2], 'b': null };
- object1.b = object2;
- object2.b = object1;
- var expected = [
- [object1, object2],
- [object1.a, object2.a, 'a', object1, object2],
- [object1.a[0], object2.a[0], 0, object1.a, object2.a],
- [object1.a[1], object2.a[1], 1, object1.a, object2.a],
- [object1.b, object2.b, 'b', object1.b, object2.b]
- ];
- _.isEqualWith(object1, object2, function(assert) {
- var length = arguments.length,
- args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
- argsList.push(args);
- });
- assert.deepEqual(argsList, expected);
- });
- QUnit.test('should handle comparisons when `customizer` returns `undefined`', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.isEqualWith('a', 'a', noop), true);
- assert.strictEqual(_.isEqualWith(['a'], ['a'], noop), true);
- assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, noop), true);
- });
- QUnit.test('should not handle comparisons when `customizer` returns `true`', function(assert) {
- assert.expect(3);
- var customizer = function(value) {
- return _.isString(value) || undefined;
- };
- assert.strictEqual(_.isEqualWith('a', 'b', customizer), true);
- assert.strictEqual(_.isEqualWith(['a'], ['b'], customizer), true);
- assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
- });
- QUnit.test('should not handle comparisons when `customizer` returns `false`', function(assert) {
- assert.expect(3);
- var customizer = function(value) {
- return _.isString(value) ? false : undefined;
- };
- assert.strictEqual(_.isEqualWith('a', 'a', customizer), false);
- assert.strictEqual(_.isEqualWith(['a'], ['a'], customizer), false);
- assert.strictEqual(_.isEqualWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
- });
- QUnit.test('should return a boolean value even when `customizer` does not', function(assert) {
- assert.expect(2);
- var actual = _.isEqualWith('a', 'b', stubC);
- assert.strictEqual(actual, true);
- var values = _.without(falsey, undefined),
- expected = lodashStable.map(values, stubFalse);
- actual = [];
- lodashStable.each(values, function(value) {
- actual.push(_.isEqualWith('a', 'a', lodashStable.constant(value)));
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should ensure `customizer` is a function', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3],
- eq = _.partial(_.isEqualWith, array),
- actual = lodashStable.map([array, [1, 0, 3]], eq);
- assert.deepEqual(actual, [true, false]);
- });
- QUnit.test('should call `customizer` for values maps and sets', function(assert) {
- assert.expect(2);
- var value = { 'a': { 'b': 2 } };
- if (Map) {
- var map1 = new Map;
- map1.set('a', value);
- var map2 = new Map;
- map2.set('a', value);
- }
- if (Set) {
- var set1 = new Set;
- set1.add(value);
- var set2 = new Set;
- set2.add(value);
- }
- lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
- if (pair[0]) {
- var argsList = [],
- array = lodashStable.toArray(pair[0]);
- var expected = [
- [pair[0], pair[1]],
- [array[0], array[0], 0, array, array],
- [array[0][0], array[0][0], 0, array[0], array[0]],
- [array[0][1], array[0][1], 1, array[0], array[0]]
- ];
- if (index) {
- expected.length = 2;
- }
- _.isEqualWith(pair[0], pair[1], function() {
- var length = arguments.length,
- args = slice.call(arguments, 0, length - (length > 2 ? 1 : 0));
- argsList.push(args);
- });
- assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
- }
- else {
- skipAssert(assert);
- }
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isError');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for error objects', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(errors, stubTrue);
- var actual = lodashStable.map(errors, function(error) {
- return _.isError(error) === true;
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `true` for subclassed values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isError(new CustomError('x')), true);
- });
- QUnit.test('should return `false` for non error objects', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isError(value) : _.isError();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isError(args), false);
- assert.strictEqual(_.isError([1, 2, 3]), false);
- assert.strictEqual(_.isError(true), false);
- assert.strictEqual(_.isError(new Date), false);
- assert.strictEqual(_.isError(_), false);
- assert.strictEqual(_.isError(slice), false);
- assert.strictEqual(_.isError({ 'a': 1 }), false);
- assert.strictEqual(_.isError(1), false);
- assert.strictEqual(_.isError(/x/), false);
- assert.strictEqual(_.isError('a'), false);
- assert.strictEqual(_.isError(symbol), false);
- });
- QUnit.test('should work with an error object from another realm', function(assert) {
- assert.expect(1);
- if (realm.errors) {
- var expected = lodashStable.map(realm.errors, stubTrue);
- var actual = lodashStable.map(realm.errors, function(error) {
- return _.isError(error) === true;
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isFinite');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for finite values', function(assert) {
- assert.expect(1);
- var values = [0, 1, 3.14, -1],
- expected = lodashStable.map(values, stubTrue),
- actual = lodashStable.map(values, _.isFinite);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `false` for non-finite values', function(assert) {
- assert.expect(1);
- var values = [NaN, Infinity, -Infinity, Object(1)],
- expected = lodashStable.map(values, stubFalse),
- actual = lodashStable.map(values, _.isFinite);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `false` for non-numeric values', function(assert) {
- assert.expect(10);
- var values = [undefined, [], true, '', ' ', '2px'],
- expected = lodashStable.map(values, stubFalse),
- actual = lodashStable.map(values, _.isFinite);
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isFinite(args), false);
- assert.strictEqual(_.isFinite([1, 2, 3]), false);
- assert.strictEqual(_.isFinite(true), false);
- assert.strictEqual(_.isFinite(new Date), false);
- assert.strictEqual(_.isFinite(new Error), false);
- assert.strictEqual(_.isFinite({ 'a': 1 }), false);
- assert.strictEqual(_.isFinite(/x/), false);
- assert.strictEqual(_.isFinite('a'), false);
- assert.strictEqual(_.isFinite(symbol), false);
- });
- QUnit.test('should return `false` for numeric string values', function(assert) {
- assert.expect(1);
- var values = ['2', '0', '08'],
- expected = lodashStable.map(values, stubFalse),
- actual = lodashStable.map(values, _.isFinite);
- assert.deepEqual(actual, expected);
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isFunction');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for functions', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.isFunction(_), true);
- assert.strictEqual(_.isFunction(slice), true);
- });
- QUnit.test('should return `true` for generator functions', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isFunction(generator), typeof generator == 'function');
- });
- QUnit.test('should return `true` for array view constructors', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(arrayViews, function(type) {
- return objToString.call(root[type]) == funcTag;
- });
- var actual = lodashStable.map(arrayViews, function(type) {
- return _.isFunction(root[type]);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `false` for non-functions', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isFunction(value) : _.isFunction();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isFunction(args), false);
- assert.strictEqual(_.isFunction([1, 2, 3]), false);
- assert.strictEqual(_.isFunction(true), false);
- assert.strictEqual(_.isFunction(new Date), false);
- assert.strictEqual(_.isFunction(new Error), false);
- assert.strictEqual(_.isFunction({ 'a': 1 }), false);
- assert.strictEqual(_.isFunction(1), false);
- assert.strictEqual(_.isFunction(/x/), false);
- assert.strictEqual(_.isFunction('a'), false);
- assert.strictEqual(_.isFunction(symbol), false);
- if (document) {
- assert.strictEqual(_.isFunction(document.getElementsByTagName('body')), false);
- } else {
- skipAssert(assert);
- }
- });
- QUnit.test('should work with host objects in IE 8 document mode (test in IE 11)', function(assert) {
- assert.expect(2);
- // Trigger a Chakra JIT bug.
- // See https://github.com/jashkenas/underscore/issues/1621.
- lodashStable.each([body, xml], function(object) {
- if (object) {
- lodashStable.times(100, _.isFunction);
- assert.strictEqual(_.isFunction(object), false);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- QUnit.test('should work with a function from another realm', function(assert) {
- assert.expect(1);
- if (realm.function) {
- assert.strictEqual(_.isFunction(realm.function), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('isInteger methods');
- lodashStable.each(['isInteger', 'isSafeInteger'], function(methodName) {
- var args = arguments,
- func = _[methodName],
- isSafe = methodName == 'isSafeInteger';
- QUnit.test('`_.' + methodName + '` should return `true` for integer values', function(assert) {
- assert.expect(2);
- var values = [-1, 0, 1],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value) {
- return func(value);
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(func(MAX_INTEGER), !isSafe);
- });
- QUnit.test('should return `false` for non-integer number values', function(assert) {
- assert.expect(1);
- var values = [NaN, Infinity, -Infinity, Object(1), 3.14],
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value) {
- return func(value);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `false` for non-numeric values', function(assert) {
- assert.expect(10);
- var expected = lodashStable.map(falsey, function(value) {
- return value === 0;
- });
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? func(value) : func();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(func(args), false);
- assert.strictEqual(func([1, 2, 3]), false);
- assert.strictEqual(func(true), false);
- assert.strictEqual(func(new Date), false);
- assert.strictEqual(func(new Error), false);
- assert.strictEqual(func({ 'a': 1 }), false);
- assert.strictEqual(func(/x/), false);
- assert.strictEqual(func('a'), false);
- assert.strictEqual(func(symbol), false);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isLength');
- (function() {
- QUnit.test('should return `true` for lengths', function(assert) {
- assert.expect(1);
- var values = [0, 3, MAX_SAFE_INTEGER],
- expected = lodashStable.map(values, stubTrue),
- actual = lodashStable.map(values, _.isLength);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `false` for non-lengths', function(assert) {
- assert.expect(1);
- var values = [-1, '1', 1.1, MAX_SAFE_INTEGER + 1],
- expected = lodashStable.map(values, stubFalse),
- actual = lodashStable.map(values, _.isLength);
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isMap');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for maps', function(assert) {
- assert.expect(1);
- if (Map) {
- assert.strictEqual(_.isMap(map), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for non-maps', function(assert) {
- assert.expect(14);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isMap(value) : _.isMap();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isMap(args), false);
- assert.strictEqual(_.isMap([1, 2, 3]), false);
- assert.strictEqual(_.isMap(true), false);
- assert.strictEqual(_.isMap(new Date), false);
- assert.strictEqual(_.isMap(new Error), false);
- assert.strictEqual(_.isMap(_), false);
- assert.strictEqual(_.isMap(slice), false);
- assert.strictEqual(_.isMap({ 'a': 1 }), false);
- assert.strictEqual(_.isMap(1), false);
- assert.strictEqual(_.isMap(/x/), false);
- assert.strictEqual(_.isMap('a'), false);
- assert.strictEqual(_.isMap(symbol), false);
- assert.strictEqual(_.isMap(weakMap), false);
- });
- QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
- assert.expect(1);
- var values = [false, true],
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value) {
- return _.isMap({ 'constructor': value });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with maps from another realm', function(assert) {
- assert.expect(1);
- if (realm.map) {
- assert.strictEqual(_.isMap(realm.map), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isMatchWith');
- (function() {
- QUnit.test('should provide correct `customizer` arguments', function(assert) {
- assert.expect(1);
- var argsList = [],
- object1 = { 'a': [1, 2], 'b': null },
- object2 = { 'a': [1, 2], 'b': null };
- object1.b = object2;
- object2.b = object1;
- var expected = [
- [object1.a, object2.a, 'a', object1, object2],
- [object1.a[0], object2.a[0], 0, object1.a, object2.a],
- [object1.a[1], object2.a[1], 1, object1.a, object2.a],
- [object1.b, object2.b, 'b', object1, object2],
- [object1.b.a, object2.b.a, 'a', object1.b, object2.b],
- [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a],
- [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a],
- [object1.b.b, object2.b.b, 'b', object1.b, object2.b]
- ];
- _.isMatchWith(object1, object2, function(assert) {
- argsList.push(slice.call(arguments, 0, -1));
- });
- assert.deepEqual(argsList, expected);
- });
- QUnit.test('should handle comparisons when `customizer` returns `undefined`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isMatchWith({ 'a': 1 }, { 'a': 1 }, noop), true);
- });
- QUnit.test('should not handle comparisons when `customizer` returns `true`', function(assert) {
- assert.expect(2);
- var customizer = function(value) {
- return _.isString(value) || undefined;
- };
- assert.strictEqual(_.isMatchWith(['a'], ['b'], customizer), true);
- assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'b' }, customizer), true);
- });
- QUnit.test('should not handle comparisons when `customizer` returns `false`', function(assert) {
- assert.expect(2);
- var customizer = function(value) {
- return _.isString(value) ? false : undefined;
- };
- assert.strictEqual(_.isMatchWith(['a'], ['a'], customizer), false);
- assert.strictEqual(_.isMatchWith({ '0': 'a' }, { '0': 'a' }, customizer), false);
- });
- QUnit.test('should return a boolean value even when `customizer` does not', function(assert) {
- assert.expect(2);
- var object = { 'a': 1 },
- actual = _.isMatchWith(object, { 'a': 1 }, stubA);
- assert.strictEqual(actual, true);
- var expected = lodashStable.map(falsey, stubFalse);
- actual = [];
- lodashStable.each(falsey, function(value) {
- actual.push(_.isMatchWith(object, { 'a': 2 }, lodashStable.constant(value)));
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should provide `stack` to `customizer`', function(assert) {
- assert.expect(1);
- var actual;
- _.isMatchWith({ 'a': 1 }, { 'a': 1 }, function() {
- actual = _.last(arguments);
- });
- assert.ok(isNpm
- ? actual.constructor.name == 'Stack'
- : actual instanceof mapCaches.Stack
- );
- });
- QUnit.test('should ensure `customizer` is a function', function(assert) {
- assert.expect(1);
- var object = { 'a': 1 },
- matches = _.partial(_.isMatchWith, object),
- actual = lodashStable.map([object, { 'a': 2 }], matches);
- assert.deepEqual(actual, [true, false]);
- });
- QUnit.test('should call `customizer` for values maps and sets', function(assert) {
- assert.expect(2);
- var value = { 'a': { 'b': 2 } };
- if (Map) {
- var map1 = new Map;
- map1.set('a', value);
- var map2 = new Map;
- map2.set('a', value);
- }
- if (Set) {
- var set1 = new Set;
- set1.add(value);
- var set2 = new Set;
- set2.add(value);
- }
- lodashStable.each([[map1, map2], [set1, set2]], function(pair, index) {
- if (pair[0]) {
- var argsList = [],
- array = lodashStable.toArray(pair[0]),
- object1 = { 'a': pair[0] },
- object2 = { 'a': pair[1] };
- var expected = [
- [pair[0], pair[1], 'a', object1, object2],
- [array[0], array[0], 0, array, array],
- [array[0][0], array[0][0], 0, array[0], array[0]],
- [array[0][1], array[0][1], 1, array[0], array[0]]
- ];
- if (index) {
- expected.length = 2;
- }
- _.isMatchWith({ 'a': pair[0] }, { 'a': pair[1] }, function() {
- argsList.push(slice.call(arguments, 0, -1));
- });
- assert.deepEqual(argsList, expected, index ? 'Set' : 'Map');
- }
- else {
- skipAssert(assert);
- }
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isNaN');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for NaNs', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.isNaN(NaN), true);
- assert.strictEqual(_.isNaN(Object(NaN)), true);
- });
- QUnit.test('should return `false` for non-NaNs', function(assert) {
- assert.expect(14);
- var expected = lodashStable.map(falsey, function(value) {
- return value !== value;
- });
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isNaN(value) : _.isNaN();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isNaN(args), false);
- assert.strictEqual(_.isNaN([1, 2, 3]), false);
- assert.strictEqual(_.isNaN(true), false);
- assert.strictEqual(_.isNaN(new Date), false);
- assert.strictEqual(_.isNaN(new Error), false);
- assert.strictEqual(_.isNaN(_), false);
- assert.strictEqual(_.isNaN(slice), false);
- assert.strictEqual(_.isNaN({ 'a': 1 }), false);
- assert.strictEqual(_.isNaN(1), false);
- assert.strictEqual(_.isNaN(Object(1)), false);
- assert.strictEqual(_.isNaN(/x/), false);
- assert.strictEqual(_.isNaN('a'), false);
- assert.strictEqual(_.isNaN(symbol), false);
- });
- QUnit.test('should work with `NaN` from another realm', function(assert) {
- assert.expect(1);
- if (realm.object) {
- assert.strictEqual(_.isNaN(realm.nan), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isNative');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for native methods', function(assert) {
- assert.expect(1);
- var values = [Array, body && body.cloneNode, create, root.encodeURI, Promise, slice, Uint8Array],
- expected = lodashStable.map(values, Boolean),
- actual = lodashStable.map(values, _.isNative);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `false` for non-native methods', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isNative(value) : _.isNative();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isNative(args), false);
- assert.strictEqual(_.isNative([1, 2, 3]), false);
- assert.strictEqual(_.isNative(true), false);
- assert.strictEqual(_.isNative(new Date), false);
- assert.strictEqual(_.isNative(new Error), false);
- assert.strictEqual(_.isNative(_), false);
- assert.strictEqual(_.isNative({ 'a': 1 }), false);
- assert.strictEqual(_.isNative(1), false);
- assert.strictEqual(_.isNative(/x/), false);
- assert.strictEqual(_.isNative('a'), false);
- assert.strictEqual(_.isNative(symbol), false);
- });
- QUnit.test('should work with native functions from another realm', function(assert) {
- assert.expect(2);
- if (realm.element) {
- assert.strictEqual(_.isNative(realm.element.cloneNode), true);
- }
- else {
- skipAssert(assert);
- }
- if (realm.object) {
- assert.strictEqual(_.isNative(realm.object.valueOf), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should throw an error if core-js is detected', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var lodash = _.runInContext({
- '__core-js_shared__': {}
- });
- assert.raises(function() { lodash.isNative(noop); });
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should detect methods masquerading as native', function(assert) {
- assert.expect(2);
- if (!amd && _._baseEach) {
- var path = require('path'),
- basePath = path.dirname(filePath),
- uid = 'e0gvgyrad1jor',
- coreKey = '__core-js_shared__',
- fakeSrcKey = 'Symbol(src)_1.' + uid;
- root[coreKey] = { 'keys': { 'IE_PROTO': 'Symbol(IE_PROTO)_3.' + uid } };
- emptyObject(require.cache);
- var baseIsNative = interopRequire(path.join(basePath, '_baseIsNative'));
- assert.strictEqual(baseIsNative(slice), true);
- slice[fakeSrcKey] = slice + '';
- assert.strictEqual(baseIsNative(slice), false);
- delete slice[fakeSrcKey];
- delete root[coreKey];
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isNil');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for nullish values', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.isNil(null), true);
- assert.strictEqual(_.isNil(), true);
- assert.strictEqual(_.isNil(undefined), true);
- });
- QUnit.test('should return `false` for non-nullish values', function(assert) {
- assert.expect(13);
- var expected = lodashStable.map(falsey, function(value) {
- return value == null;
- });
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isNil(value) : _.isNil();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isNil(args), false);
- assert.strictEqual(_.isNil([1, 2, 3]), false);
- assert.strictEqual(_.isNil(true), false);
- assert.strictEqual(_.isNil(new Date), false);
- assert.strictEqual(_.isNil(new Error), false);
- assert.strictEqual(_.isNil(_), false);
- assert.strictEqual(_.isNil(slice), false);
- assert.strictEqual(_.isNil({ 'a': 1 }), false);
- assert.strictEqual(_.isNil(1), false);
- assert.strictEqual(_.isNil(/x/), false);
- assert.strictEqual(_.isNil('a'), false);
- if (Symbol) {
- assert.strictEqual(_.isNil(symbol), false);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should work with nils from another realm', function(assert) {
- assert.expect(2);
- if (realm.object) {
- assert.strictEqual(_.isNil(realm.null), true);
- assert.strictEqual(_.isNil(realm.undefined), true);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isNull');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for `null` values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isNull(null), true);
- });
- QUnit.test('should return `false` for non `null` values', function(assert) {
- assert.expect(13);
- var expected = lodashStable.map(falsey, function(value) {
- return value === null;
- });
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isNull(value) : _.isNull();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isNull(args), false);
- assert.strictEqual(_.isNull([1, 2, 3]), false);
- assert.strictEqual(_.isNull(true), false);
- assert.strictEqual(_.isNull(new Date), false);
- assert.strictEqual(_.isNull(new Error), false);
- assert.strictEqual(_.isNull(_), false);
- assert.strictEqual(_.isNull(slice), false);
- assert.strictEqual(_.isNull({ 'a': 1 }), false);
- assert.strictEqual(_.isNull(1), false);
- assert.strictEqual(_.isNull(/x/), false);
- assert.strictEqual(_.isNull('a'), false);
- assert.strictEqual(_.isNull(symbol), false);
- });
- QUnit.test('should work with nulls from another realm', function(assert) {
- assert.expect(1);
- if (realm.object) {
- assert.strictEqual(_.isNull(realm.null), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isNumber');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for numbers', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.isNumber(0), true);
- assert.strictEqual(_.isNumber(Object(0)), true);
- assert.strictEqual(_.isNumber(NaN), true);
- });
- QUnit.test('should return `false` for non-numbers', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, function(value) {
- return typeof value == 'number';
- });
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isNumber(value) : _.isNumber();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isNumber(args), false);
- assert.strictEqual(_.isNumber([1, 2, 3]), false);
- assert.strictEqual(_.isNumber(true), false);
- assert.strictEqual(_.isNumber(new Date), false);
- assert.strictEqual(_.isNumber(new Error), false);
- assert.strictEqual(_.isNumber(_), false);
- assert.strictEqual(_.isNumber(slice), false);
- assert.strictEqual(_.isNumber({ 'a': 1 }), false);
- assert.strictEqual(_.isNumber(/x/), false);
- assert.strictEqual(_.isNumber('a'), false);
- assert.strictEqual(_.isNumber(symbol), false);
- });
- QUnit.test('should work with numbers from another realm', function(assert) {
- assert.expect(1);
- if (realm.number) {
- assert.strictEqual(_.isNumber(realm.number), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should avoid `[xpconnect wrapped native prototype]` in Firefox', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.isNumber(+'2'), true);
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isObject');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for objects', function(assert) {
- assert.expect(13);
- assert.strictEqual(_.isObject(args), true);
- assert.strictEqual(_.isObject([1, 2, 3]), true);
- assert.strictEqual(_.isObject(Object(false)), true);
- assert.strictEqual(_.isObject(new Date), true);
- assert.strictEqual(_.isObject(new Error), true);
- assert.strictEqual(_.isObject(_), true);
- assert.strictEqual(_.isObject(slice), true);
- assert.strictEqual(_.isObject({ 'a': 1 }), true);
- assert.strictEqual(_.isObject(Object(0)), true);
- assert.strictEqual(_.isObject(/x/), true);
- assert.strictEqual(_.isObject(Object('a')), true);
- if (document) {
- assert.strictEqual(_.isObject(body), true);
- }
- else {
- skipAssert(assert);
- }
- if (Symbol) {
- assert.strictEqual(_.isObject(Object(symbol)), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for non-objects', function(assert) {
- assert.expect(1);
- var values = falsey.concat(true, 1, 'a', symbol),
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.isObject(value) : _.isObject();
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with objects from another realm', function(assert) {
- assert.expect(8);
- if (realm.element) {
- assert.strictEqual(_.isObject(realm.element), true);
- }
- else {
- skipAssert(assert);
- }
- if (realm.object) {
- assert.strictEqual(_.isObject(realm.boolean), true);
- assert.strictEqual(_.isObject(realm.date), true);
- assert.strictEqual(_.isObject(realm.function), true);
- assert.strictEqual(_.isObject(realm.number), true);
- assert.strictEqual(_.isObject(realm.object), true);
- assert.strictEqual(_.isObject(realm.regexp), true);
- assert.strictEqual(_.isObject(realm.string), true);
- }
- else {
- skipAssert(assert, 7);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isObjectLike');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for objects', function(assert) {
- assert.expect(9);
- assert.strictEqual(_.isObjectLike(args), true);
- assert.strictEqual(_.isObjectLike([1, 2, 3]), true);
- assert.strictEqual(_.isObjectLike(Object(false)), true);
- assert.strictEqual(_.isObjectLike(new Date), true);
- assert.strictEqual(_.isObjectLike(new Error), true);
- assert.strictEqual(_.isObjectLike({ 'a': 1 }), true);
- assert.strictEqual(_.isObjectLike(Object(0)), true);
- assert.strictEqual(_.isObjectLike(/x/), true);
- assert.strictEqual(_.isObjectLike(Object('a')), true);
- });
- QUnit.test('should return `false` for non-objects', function(assert) {
- assert.expect(1);
- var values = falsey.concat(true, _, slice, 1, 'a', symbol),
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.isObjectLike(value) : _.isObjectLike();
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with objects from another realm', function(assert) {
- assert.expect(6);
- if (realm.object) {
- assert.strictEqual(_.isObjectLike(realm.boolean), true);
- assert.strictEqual(_.isObjectLike(realm.date), true);
- assert.strictEqual(_.isObjectLike(realm.number), true);
- assert.strictEqual(_.isObjectLike(realm.object), true);
- assert.strictEqual(_.isObjectLike(realm.regexp), true);
- assert.strictEqual(_.isObjectLike(realm.string), true);
- }
- else {
- skipAssert(assert, 6);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isPlainObject');
- (function() {
- var element = document && document.createElement('div');
- QUnit.test('should detect plain objects', function(assert) {
- assert.expect(5);
- function Foo(a) {
- this.a = 1;
- }
- assert.strictEqual(_.isPlainObject({}), true);
- assert.strictEqual(_.isPlainObject({ 'a': 1 }), true);
- assert.strictEqual(_.isPlainObject({ 'constructor': Foo }), true);
- assert.strictEqual(_.isPlainObject([1, 2, 3]), false);
- assert.strictEqual(_.isPlainObject(new Foo(1)), false);
- });
- QUnit.test('should return `true` for objects with a `[[Prototype]]` of `null`', function(assert) {
- assert.expect(2);
- if (create) {
- var object = create(null);
- assert.strictEqual(_.isPlainObject(object), true);
- object.constructor = objectProto.constructor;
- assert.strictEqual(_.isPlainObject(object), true);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should return `true` for plain objects with a custom `valueOf` property', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.isPlainObject({ 'valueOf': 0 }), true);
- if (element) {
- var valueOf = element.valueOf;
- element.valueOf = 0;
- assert.strictEqual(_.isPlainObject(element), false);
- element.valueOf = valueOf;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for objects with a custom `[[Prototype]]`', function(assert) {
- assert.expect(1);
- if (create) {
- var object = create({ 'a': 1 });
- assert.strictEqual(_.isPlainObject(object), false);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for DOM elements', function(assert) {
- assert.expect(1);
- if (element) {
- assert.strictEqual(_.isPlainObject(element), false);
- } else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for Object objects without a `toStringTag` of "Object"', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.isPlainObject(arguments), false);
- assert.strictEqual(_.isPlainObject(Error), false);
- assert.strictEqual(_.isPlainObject(Math), false);
- });
- QUnit.test('should return `false` for non-objects', function(assert) {
- assert.expect(4);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isPlainObject(value) : _.isPlainObject();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isPlainObject(true), false);
- assert.strictEqual(_.isPlainObject('a'), false);
- assert.strictEqual(_.isPlainObject(symbol), false);
- });
- QUnit.test('should work with objects from another realm', function(assert) {
- assert.expect(1);
- if (realm.object) {
- assert.strictEqual(_.isPlainObject(realm.object), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isRegExp');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for regexes', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.isRegExp(/x/), true);
- assert.strictEqual(_.isRegExp(RegExp('x')), true);
- });
- QUnit.test('should return `false` for non-regexes', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isRegExp(value) : _.isRegExp();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isRegExp(args), false);
- assert.strictEqual(_.isRegExp([1, 2, 3]), false);
- assert.strictEqual(_.isRegExp(true), false);
- assert.strictEqual(_.isRegExp(new Date), false);
- assert.strictEqual(_.isRegExp(new Error), false);
- assert.strictEqual(_.isRegExp(_), false);
- assert.strictEqual(_.isRegExp(slice), false);
- assert.strictEqual(_.isRegExp({ 'a': 1 }), false);
- assert.strictEqual(_.isRegExp(1), false);
- assert.strictEqual(_.isRegExp('a'), false);
- assert.strictEqual(_.isRegExp(symbol), false);
- });
- QUnit.test('should work with regexes from another realm', function(assert) {
- assert.expect(1);
- if (realm.regexp) {
- assert.strictEqual(_.isRegExp(realm.regexp), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isSet');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for sets', function(assert) {
- assert.expect(1);
- if (Set) {
- assert.strictEqual(_.isSet(set), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for non-sets', function(assert) {
- assert.expect(14);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isSet(value) : _.isSet();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isSet(args), false);
- assert.strictEqual(_.isSet([1, 2, 3]), false);
- assert.strictEqual(_.isSet(true), false);
- assert.strictEqual(_.isSet(new Date), false);
- assert.strictEqual(_.isSet(new Error), false);
- assert.strictEqual(_.isSet(_), false);
- assert.strictEqual(_.isSet(slice), false);
- assert.strictEqual(_.isSet({ 'a': 1 }), false);
- assert.strictEqual(_.isSet(1), false);
- assert.strictEqual(_.isSet(/x/), false);
- assert.strictEqual(_.isSet('a'), false);
- assert.strictEqual(_.isSet(symbol), false);
- assert.strictEqual(_.isSet(weakSet), false);
- });
- QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
- assert.expect(1);
- var values = [false, true],
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value) {
- return _.isSet({ 'constructor': value });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with weak sets from another realm', function(assert) {
- assert.expect(1);
- if (realm.set) {
- assert.strictEqual(_.isSet(realm.set), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isString');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for strings', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.isString('a'), true);
- assert.strictEqual(_.isString(Object('a')), true);
- });
- QUnit.test('should return `false` for non-strings', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, function(value) {
- return value === '';
- });
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isString(value) : _.isString();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isString(args), false);
- assert.strictEqual(_.isString([1, 2, 3]), false);
- assert.strictEqual(_.isString(true), false);
- assert.strictEqual(_.isString(new Date), false);
- assert.strictEqual(_.isString(new Error), false);
- assert.strictEqual(_.isString(_), false);
- assert.strictEqual(_.isString(slice), false);
- assert.strictEqual(_.isString({ '0': 1, 'length': 1 }), false);
- assert.strictEqual(_.isString(1), false);
- assert.strictEqual(_.isString(/x/), false);
- assert.strictEqual(_.isString(symbol), false);
- });
- QUnit.test('should work with strings from another realm', function(assert) {
- assert.expect(1);
- if (realm.string) {
- assert.strictEqual(_.isString(realm.string), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isSymbol');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for symbols', function(assert) {
- assert.expect(2);
- if (Symbol) {
- assert.strictEqual(_.isSymbol(symbol), true);
- assert.strictEqual(_.isSymbol(Object(symbol)), true);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should return `false` for non-symbols', function(assert) {
- assert.expect(12);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isSymbol(value) : _.isSymbol();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isSymbol(args), false);
- assert.strictEqual(_.isSymbol([1, 2, 3]), false);
- assert.strictEqual(_.isSymbol(true), false);
- assert.strictEqual(_.isSymbol(new Date), false);
- assert.strictEqual(_.isSymbol(new Error), false);
- assert.strictEqual(_.isSymbol(_), false);
- assert.strictEqual(_.isSymbol(slice), false);
- assert.strictEqual(_.isSymbol({ '0': 1, 'length': 1 }), false);
- assert.strictEqual(_.isSymbol(1), false);
- assert.strictEqual(_.isSymbol(/x/), false);
- assert.strictEqual(_.isSymbol('a'), false);
- });
- QUnit.test('should work with symbols from another realm', function(assert) {
- assert.expect(1);
- if (Symbol && realm.symbol) {
- assert.strictEqual(_.isSymbol(realm.symbol), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isTypedArray');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for typed arrays', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(typedArrays, function(type) {
- return type in root;
- });
- var actual = lodashStable.map(typedArrays, function(type) {
- var Ctor = root[type];
- return Ctor ? _.isTypedArray(new Ctor(new ArrayBuffer(8))) : false;
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `false` for non typed arrays', function(assert) {
- assert.expect(13);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isTypedArray(value) : _.isTypedArray();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isTypedArray(args), false);
- assert.strictEqual(_.isTypedArray([1, 2, 3]), false);
- assert.strictEqual(_.isTypedArray(true), false);
- assert.strictEqual(_.isTypedArray(new Date), false);
- assert.strictEqual(_.isTypedArray(new Error), false);
- assert.strictEqual(_.isTypedArray(_), false);
- assert.strictEqual(_.isTypedArray(slice), false);
- assert.strictEqual(_.isTypedArray({ 'a': 1 }), false);
- assert.strictEqual(_.isTypedArray(1), false);
- assert.strictEqual(_.isTypedArray(/x/), false);
- assert.strictEqual(_.isTypedArray('a'), false);
- assert.strictEqual(_.isTypedArray(symbol), false);
- });
- QUnit.test('should work with typed arrays from another realm', function(assert) {
- assert.expect(1);
- if (realm.object) {
- var props = lodashStable.invokeMap(typedArrays, 'toLowerCase');
- var expected = lodashStable.map(props, function(key) {
- return realm[key] !== undefined;
- });
- var actual = lodashStable.map(props, function(key) {
- var value = realm[key];
- return value ? _.isTypedArray(value) : false;
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isUndefined');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for `undefined` values', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.isUndefined(), true);
- assert.strictEqual(_.isUndefined(undefined), true);
- });
- QUnit.test('should return `false` for non `undefined` values', function(assert) {
- assert.expect(13);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined;
- });
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isUndefined(value) : _.isUndefined();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isUndefined(args), false);
- assert.strictEqual(_.isUndefined([1, 2, 3]), false);
- assert.strictEqual(_.isUndefined(true), false);
- assert.strictEqual(_.isUndefined(new Date), false);
- assert.strictEqual(_.isUndefined(new Error), false);
- assert.strictEqual(_.isUndefined(_), false);
- assert.strictEqual(_.isUndefined(slice), false);
- assert.strictEqual(_.isUndefined({ 'a': 1 }), false);
- assert.strictEqual(_.isUndefined(1), false);
- assert.strictEqual(_.isUndefined(/x/), false);
- assert.strictEqual(_.isUndefined('a'), false);
- if (Symbol) {
- assert.strictEqual(_.isUndefined(symbol), false);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should work with `undefined` from another realm', function(assert) {
- assert.expect(1);
- if (realm.object) {
- assert.strictEqual(_.isUndefined(realm.undefined), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isWeakMap');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for weak maps', function(assert) {
- assert.expect(1);
- if (WeakMap) {
- assert.strictEqual(_.isWeakMap(weakMap), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for non weak maps', function(assert) {
- assert.expect(14);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isWeakMap(value) : _.isWeakMap();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isWeakMap(args), false);
- assert.strictEqual(_.isWeakMap([1, 2, 3]), false);
- assert.strictEqual(_.isWeakMap(true), false);
- assert.strictEqual(_.isWeakMap(new Date), false);
- assert.strictEqual(_.isWeakMap(new Error), false);
- assert.strictEqual(_.isWeakMap(_), false);
- assert.strictEqual(_.isWeakMap(slice), false);
- assert.strictEqual(_.isWeakMap({ 'a': 1 }), false);
- assert.strictEqual(_.isWeakMap(map), false);
- assert.strictEqual(_.isWeakMap(1), false);
- assert.strictEqual(_.isWeakMap(/x/), false);
- assert.strictEqual(_.isWeakMap('a'), false);
- assert.strictEqual(_.isWeakMap(symbol), false);
- });
- QUnit.test('should work for objects with a non-function `constructor` (test in IE 11)', function(assert) {
- assert.expect(1);
- var values = [false, true],
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value) {
- return _.isWeakMap({ 'constructor': value });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with weak maps from another realm', function(assert) {
- assert.expect(1);
- if (realm.weakMap) {
- assert.strictEqual(_.isWeakMap(realm.weakMap), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.isWeakSet');
- (function() {
- var args = arguments;
- QUnit.test('should return `true` for weak sets', function(assert) {
- assert.expect(1);
- if (WeakSet) {
- assert.strictEqual(_.isWeakSet(weakSet), true);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return `false` for non weak sets', function(assert) {
- assert.expect(14);
- var expected = lodashStable.map(falsey, stubFalse);
- var actual = lodashStable.map(falsey, function(value, index) {
- return index ? _.isWeakSet(value) : _.isWeakSet();
- });
- assert.deepEqual(actual, expected);
- assert.strictEqual(_.isWeakSet(args), false);
- assert.strictEqual(_.isWeakSet([1, 2, 3]), false);
- assert.strictEqual(_.isWeakSet(true), false);
- assert.strictEqual(_.isWeakSet(new Date), false);
- assert.strictEqual(_.isWeakSet(new Error), false);
- assert.strictEqual(_.isWeakSet(_), false);
- assert.strictEqual(_.isWeakSet(slice), false);
- assert.strictEqual(_.isWeakSet({ 'a': 1 }), false);
- assert.strictEqual(_.isWeakSet(1), false);
- assert.strictEqual(_.isWeakSet(/x/), false);
- assert.strictEqual(_.isWeakSet('a'), false);
- assert.strictEqual(_.isWeakSet(set), false);
- assert.strictEqual(_.isWeakSet(symbol), false);
- });
- QUnit.test('should work with weak sets from another realm', function(assert) {
- assert.expect(1);
- if (realm.weakSet) {
- assert.strictEqual(_.isWeakSet(realm.weakSet), true);
- }
- else {
- skipAssert(assert);
- }
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('isType checks');
- (function() {
- QUnit.test('should return `false` for subclassed values', function(assert) {
- assert.expect(7);
- var funcs = [
- 'isArray', 'isBoolean', 'isDate', 'isFunction',
- 'isNumber', 'isRegExp', 'isString'
- ];
- lodashStable.each(funcs, function(methodName) {
- function Foo() {}
- Foo.prototype = root[methodName.slice(2)].prototype;
- var object = new Foo;
- if (objToString.call(object) == objectTag) {
- assert.strictEqual(_[methodName](object), false, '`_.' + methodName + '` returns `false`');
- }
- else {
- skipAssert(assert);
- }
- });
- });
- QUnit.test('should not error on host objects (test in IE)', function(assert) {
- assert.expect(26);
- var funcs = [
- 'isArguments', 'isArray', 'isArrayBuffer', 'isArrayLike', 'isBoolean',
- 'isBuffer', 'isDate', 'isElement', 'isError', 'isFinite', 'isFunction',
- 'isInteger', 'isMap', 'isNaN', 'isNil', 'isNull', 'isNumber', 'isObject',
- 'isObjectLike', 'isRegExp', 'isSet', 'isSafeInteger', 'isString',
- 'isUndefined', 'isWeakMap', 'isWeakSet'
- ];
- lodashStable.each(funcs, function(methodName) {
- if (xml) {
- var pass = true;
- try {
- _[methodName](xml);
- } catch (e) {
- pass = false;
- }
- assert.ok(pass, '`_.' + methodName + '` should not error');
- }
- else {
- skipAssert(assert);
- }
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.iteratee');
- (function() {
- QUnit.test('should provide arguments to `func`', function(assert) {
- assert.expect(1);
- var fn = function() { return slice.call(arguments); },
- iteratee = _.iteratee(fn),
- actual = iteratee('a', 'b', 'c', 'd', 'e', 'f');
- assert.deepEqual(actual, ['a', 'b', 'c', 'd', 'e', 'f']);
- });
- QUnit.test('should return `_.identity` when `func` is nullish', function(assert) {
- assert.expect(1);
- var object = {},
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant([!isNpm && _.identity, object]));
- var actual = lodashStable.map(values, function(value, index) {
- var identity = index ? _.iteratee(value) : _.iteratee();
- return [!isNpm && identity, identity(object)];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return an iteratee created by `_.matches` when `func` is an object', function(assert) {
- assert.expect(2);
- var matches = _.iteratee({ 'a': 1, 'b': 2 });
- assert.strictEqual(matches({ 'a': 1, 'b': 2, 'c': 3 }), true);
- assert.strictEqual(matches({ 'b': 2 }), false);
- });
- QUnit.test('should not change `_.matches` behavior if `source` is modified', function(assert) {
- assert.expect(9);
- var sources = [
- { 'a': { 'b': 2, 'c': 3 } },
- { 'a': 1, 'b': 2 },
- { 'a': 1 }
- ];
- lodashStable.each(sources, function(source, index) {
- var object = lodashStable.cloneDeep(source),
- matches = _.iteratee(source);
- assert.strictEqual(matches(object), true);
- if (index) {
- source.a = 2;
- source.b = 1;
- source.c = 3;
- } else {
- source.a.b = 1;
- source.a.c = 2;
- source.a.d = 3;
- }
- assert.strictEqual(matches(object), true);
- assert.strictEqual(matches(source), false);
- });
- });
- QUnit.test('should return an iteratee created by `_.matchesProperty` when `func` is an array', function(assert) {
- assert.expect(3);
- var array = ['a', undefined],
- matches = _.iteratee([0, 'a']);
- assert.strictEqual(matches(array), true);
- matches = _.iteratee(['0', 'a']);
- assert.strictEqual(matches(array), true);
- matches = _.iteratee([1, undefined]);
- assert.strictEqual(matches(array), true);
- });
- QUnit.test('should support deep paths for `_.matchesProperty` shorthands', function(assert) {
- assert.expect(1);
- var object = { 'a': { 'b': { 'c': 1, 'd': 2 } } },
- matches = _.iteratee(['a.b', { 'c': 1 }]);
- assert.strictEqual(matches(object), true);
- });
- QUnit.test('should not change `_.matchesProperty` behavior if `source` is modified', function(assert) {
- assert.expect(9);
- var sources = [
- { 'a': { 'b': 2, 'c': 3 } },
- { 'a': 1, 'b': 2 },
- { 'a': 1 }
- ];
- lodashStable.each(sources, function(source, index) {
- var object = { 'a': lodashStable.cloneDeep(source) },
- matches = _.iteratee(['a', source]);
- assert.strictEqual(matches(object), true);
- if (index) {
- source.a = 2;
- source.b = 1;
- source.c = 3;
- } else {
- source.a.b = 1;
- source.a.c = 2;
- source.a.d = 3;
- }
- assert.strictEqual(matches(object), true);
- assert.strictEqual(matches({ 'a': source }), false);
- });
- });
- QUnit.test('should return an iteratee created by `_.property` when `func` is a number or string', function(assert) {
- assert.expect(2);
- var array = ['a'],
- prop = _.iteratee(0);
- assert.strictEqual(prop(array), 'a');
- prop = _.iteratee('0');
- assert.strictEqual(prop(array), 'a');
- });
- QUnit.test('should support deep paths for `_.property` shorthands', function(assert) {
- assert.expect(1);
- var object = { 'a': { 'b': 2 } },
- prop = _.iteratee('a.b');
- assert.strictEqual(prop(object), 2);
- });
- QUnit.test('should work with functions created by `_.partial` and `_.partialRight`', function(assert) {
- assert.expect(2);
- var fn = function() {
- var result = [this.a];
- push.apply(result, arguments);
- return result;
- };
- var expected = [1, 2, 3],
- object = { 'a': 1 , 'iteratee': _.iteratee(_.partial(fn, 2)) };
- assert.deepEqual(object.iteratee(3), expected);
- object.iteratee = _.iteratee(_.partialRight(fn, 3));
- assert.deepEqual(object.iteratee(2), expected);
- });
- QUnit.test('should use internal `iteratee` if external is unavailable', function(assert) {
- assert.expect(1);
- var iteratee = _.iteratee;
- delete _.iteratee;
- assert.deepEqual(_.map([{ 'a': 1 }], 'a'), [1]);
- _.iteratee = iteratee;
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var fn = function() { return this instanceof Number; },
- array = [fn, fn, fn],
- iteratees = lodashStable.map(array, _.iteratee),
- expected = lodashStable.map(array, stubFalse);
- var actual = lodashStable.map(iteratees, function(iteratee) {
- return iteratee();
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('custom `_.iteratee` methods');
- (function() {
- var array = ['one', 'two', 'three'],
- getPropA = _.partial(_.property, 'a'),
- getPropB = _.partial(_.property, 'b'),
- getLength = _.partial(_.property, 'length'),
- iteratee = _.iteratee;
- var getSum = function() {
- return function(result, object) {
- return result + object.a;
- };
- };
- var objects = [
- { 'a': 0, 'b': 0 },
- { 'a': 1, 'b': 0 },
- { 'a': 1, 'b': 1 }
- ];
- QUnit.test('`_.countBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getLength;
- assert.deepEqual(_.countBy(array), { '3': 2, '5': 1 });
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.differenceBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.deepEqual(_.differenceBy(objects, [objects[1]]), [objects[0]]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.dropRightWhile` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.dropRightWhile(objects), objects.slice(0, 2));
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.dropWhile` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.dropWhile(objects.reverse()).reverse(), objects.reverse().slice(0, 2));
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.every` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.strictEqual(_.every(objects.slice(1)), true);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.filter` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var objects = [{ 'a': 0 }, { 'a': 1 }];
- _.iteratee = getPropA;
- assert.deepEqual(_.filter(objects), [objects[1]]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.find` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.strictEqual(_.find(objects), objects[1]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.findIndex` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.strictEqual(_.findIndex(objects), 1);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.findLast` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.strictEqual(_.findLast(objects), objects[2]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.findLastIndex` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.strictEqual(_.findLastIndex(objects), 2);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.findKey` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.strictEqual(_.findKey(objects), '2');
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.findLastKey` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.strictEqual(_.findLastKey(objects), '2');
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.groupBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getLength;
- assert.deepEqual(_.groupBy(array), { '3': ['one', 'two'], '5': ['three'] });
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.intersectionBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.deepEqual(_.intersectionBy(objects, [objects[2]]), [objects[1]]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.keyBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getLength;
- assert.deepEqual(_.keyBy(array), { '3': 'two', '5': 'three' });
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.map` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.deepEqual(_.map(objects), [0, 1, 1]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.mapKeys` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.mapKeys({ 'a': { 'b': 2 } }), { '2': { 'b': 2 } });
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.mapValues` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.mapValues({ 'a': { 'b': 2 } }), { 'a': 2 });
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.maxBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.maxBy(objects), objects[2]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.meanBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.strictEqual(_.meanBy(objects), 2 / 3);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.minBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.minBy(objects), objects[0]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.partition` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }];
- _.iteratee = getPropA;
- assert.deepEqual(_.partition(objects), [objects.slice(0, 2), objects.slice(2)]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.pullAllBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.deepEqual(_.pullAllBy(objects.slice(), [{ 'a': 1, 'b': 0 }]), [objects[0]]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.reduce` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getSum;
- assert.strictEqual(_.reduce(objects, undefined, 0), 2);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.reduceRight` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getSum;
- assert.strictEqual(_.reduceRight(objects, undefined, 0), 2);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.reject` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var objects = [{ 'a': 0 }, { 'a': 1 }];
- _.iteratee = getPropA;
- assert.deepEqual(_.reject(objects), [objects[0]]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.remove` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var objects = [{ 'a': 0 }, { 'a': 1 }];
- _.iteratee = getPropA;
- _.remove(objects);
- assert.deepEqual(objects, [{ 'a': 0 }]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.some` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.strictEqual(_.some(objects), true);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.sortBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.deepEqual(_.sortBy(objects.slice().reverse()), [objects[0], objects[2], objects[1]]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.sortedIndexBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var objects = [{ 'a': 30 }, { 'a': 50 }];
- _.iteratee = getPropA;
- assert.strictEqual(_.sortedIndexBy(objects, { 'a': 40 }), 1);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.sortedLastIndexBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var objects = [{ 'a': 30 }, { 'a': 50 }];
- _.iteratee = getPropA;
- assert.strictEqual(_.sortedLastIndexBy(objects, { 'a': 40 }), 1);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.sumBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.strictEqual(_.sumBy(objects), 1);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.takeRightWhile` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.takeRightWhile(objects), objects.slice(2));
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.takeWhile` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.takeWhile(objects.reverse()), objects.reverse().slice(2));
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.transform` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = function() {
- return function(result, object) {
- result.sum += object.a;
- };
- };
- assert.deepEqual(_.transform(objects, undefined, { 'sum': 0 }), { 'sum': 2 });
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.uniqBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.uniqBy(objects), [objects[0], objects[2]]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.unionBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropB;
- assert.deepEqual(_.unionBy(objects.slice(0, 1), [objects[2]]), [objects[0], objects[2]]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.xorBy` should use `_.iteratee` internally', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- _.iteratee = getPropA;
- assert.deepEqual(_.xorBy(objects, objects.slice(1)), [objects[0]]);
- _.iteratee = iteratee;
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.join');
- (function() {
- var array = ['a', 'b', 'c'];
- QUnit.test('should return join all array elements into a string', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.join(array, '~'), 'a~b~c');
- });
- QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _(array);
- assert.strictEqual(wrapped.join('~'), 'a~b~c');
- assert.strictEqual(wrapped.value(), array);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_(array).chain().join('~') instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.keyBy');
- (function() {
- var array = [
- { 'dir': 'left', 'code': 97 },
- { 'dir': 'right', 'code': 100 }
- ];
- QUnit.test('should transform keys by `iteratee`', function(assert) {
- assert.expect(1);
- var expected = { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } };
- var actual = _.keyBy(array, function(object) {
- return String.fromCharCode(object.code);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var array = [4, 6, 6],
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant({ '4': 4, '6': 6 }));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.keyBy(array, value) : _.keyBy(array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var expected = { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } },
- actual = _.keyBy(array, 'dir');
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should only add values to own, not inherited, properties', function(assert) {
- assert.expect(2);
- var actual = _.keyBy([6.1, 4.2, 6.3], function(n) {
- return Math.floor(n) > 4 ? 'hasOwnProperty' : 'constructor';
- });
- assert.deepEqual(actual.constructor, 4.2);
- assert.deepEqual(actual.hasOwnProperty, 6.3);
- });
- QUnit.test('should work with a number for `iteratee`', function(assert) {
- assert.expect(2);
- var array = [
- [1, 'a'],
- [2, 'a'],
- [2, 'b']
- ];
- assert.deepEqual(_.keyBy(array, 0), { '1': [1, 'a'], '2': [2, 'b'] });
- assert.deepEqual(_.keyBy(array, 1), { 'a': [2, 'a'], 'b': [2, 'b'] });
- });
- QUnit.test('should work with an object for `collection`', function(assert) {
- assert.expect(1);
- var actual = _.keyBy({ 'a': 6.1, 'b': 4.2, 'c': 6.3 }, Math.floor);
- assert.deepEqual(actual, { '4': 4.2, '6': 6.3 });
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE).concat(
- lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE),
- lodashStable.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE)
- );
- var actual = _(array).keyBy().map(square).filter(isEven).take().value();
- assert.deepEqual(actual, _.take(_.filter(_.map(_.keyBy(array), square), isEven)));
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('keys methods');
- lodashStable.each(['keys', 'keysIn'], function(methodName) {
- var args = (function() { return arguments; }(1, 2, 3)),
- strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3)),
- func = _[methodName],
- isKeys = methodName == 'keys';
- QUnit.test('`_.' + methodName + '` should return the string keyed property names of `object`', function(assert) {
- assert.expect(1);
- var actual = func({ 'a': 1, 'b': 1 }).sort();
- assert.deepEqual(actual, ['a', 'b']);
- });
- QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var expected = isKeys ? ['a'] : ['a', 'b'],
- actual = func(new Foo).sort();
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) {
- assert.expect(1);
- var array = [1];
- array[2] = 3;
- var actual = func(array).sort();
- assert.deepEqual(actual, ['0', '1', '2']);
- });
- QUnit.test('`_.' + methodName + '` should return keys for custom properties on arrays', function(assert) {
- assert.expect(1);
- var array = [1];
- array.a = 1;
- var actual = func(array).sort();
- assert.deepEqual(actual, ['0', 'a']);
- });
- QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of arrays', function(assert) {
- assert.expect(1);
- arrayProto.a = 1;
- var expected = isKeys ? ['0'] : ['0', 'a'],
- actual = func([1]).sort();
- assert.deepEqual(actual, expected);
- delete arrayProto.a;
- });
- QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
- assert.expect(1);
- var values = [args, strictArgs],
- expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2']));
- var actual = lodashStable.map(values, function(value) {
- return func(value).sort();
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should return keys for custom properties on `arguments` objects', function(assert) {
- assert.expect(1);
- var values = [args, strictArgs],
- expected = lodashStable.map(values, lodashStable.constant(['0', '1', '2', 'a']));
- var actual = lodashStable.map(values, function(value) {
- value.a = 1;
- var result = func(value).sort();
- delete value.a;
- return result;
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of `arguments` objects', function(assert) {
- assert.expect(1);
- var values = [args, strictArgs],
- expected = lodashStable.map(values, lodashStable.constant(isKeys ? ['0', '1', '2'] : ['0', '1', '2', 'a']));
- var actual = lodashStable.map(values, function(value) {
- objectProto.a = 1;
- var result = func(value).sort();
- delete objectProto.a;
- return result;
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with string objects', function(assert) {
- assert.expect(1);
- var actual = func(Object('abc')).sort();
- assert.deepEqual(actual, ['0', '1', '2']);
- });
- QUnit.test('`_.' + methodName + '` should return keys for custom properties on string objects', function(assert) {
- assert.expect(1);
- var object = Object('a');
- object.a = 1;
- var actual = func(object).sort();
- assert.deepEqual(actual, ['0', 'a']);
- });
- QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of string objects', function(assert) {
- assert.expect(1);
- stringProto.a = 1;
- var expected = isKeys ? ['0'] : ['0', 'a'],
- actual = func(Object('a')).sort();
- assert.deepEqual(actual, expected);
- delete stringProto.a;
- });
- QUnit.test('`_.' + methodName + '` should work with array-like objects', function(assert) {
- assert.expect(1);
- var object = { '0': 'a', 'length': 1 },
- actual = func(object).sort();
- assert.deepEqual(actual, ['0', 'length']);
- });
- QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) {
- assert.expect(2);
- var expected = lodashStable.map(primitives, function(value) {
- return typeof value == 'string' ? ['0'] : [];
- });
- var actual = lodashStable.map(primitives, func);
- assert.deepEqual(actual, expected);
- // IE 9 doesn't box numbers in for-in loops.
- numberProto.a = 1;
- assert.deepEqual(func(0), isKeys ? [] : ['a']);
- delete numberProto.a;
- });
- QUnit.test('`_.' + methodName + '` skips the `constructor` property on prototype objects', function(assert) {
- assert.expect(3);
- function Foo() {}
- Foo.prototype.a = 1;
- var expected = ['a'];
- assert.deepEqual(func(Foo.prototype), expected);
- Foo.prototype = { 'constructor': Foo, 'a': 1 };
- assert.deepEqual(func(Foo.prototype), expected);
- var Fake = { 'prototype': {} };
- Fake.prototype.constructor = Fake;
- assert.deepEqual(func(Fake.prototype), ['constructor']);
- });
- QUnit.test('`_.' + methodName + '` should return an empty array when `object` is nullish', function(assert) {
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubArray);
- var actual = lodashStable.map(values, function(value, index) {
- objectProto.a = 1;
- var result = index ? func(value) : func();
- delete objectProto.a;
- return result;
- });
- assert.deepEqual(actual, expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.last');
- (function() {
- var array = [1, 2, 3, 4];
- QUnit.test('should return the last element', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.last(array), 4);
- });
- QUnit.test('should return `undefined` when querying empty arrays', function(assert) {
- assert.expect(1);
- var array = [];
- array['-1'] = 1;
- assert.strictEqual(_.last([]), undefined);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- actual = lodashStable.map(array, _.last);
- assert.deepEqual(actual, [3, 6, 9]);
- });
- QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.strictEqual(_(array).last(), 4);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_(array).chain().last() instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should not execute immediately when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var wrapped = _(array).chain().last();
- assert.strictEqual(wrapped.__wrapped__, array);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
- smallArray = array;
- lodashStable.times(2, function(index) {
- var array = index ? largeArray : smallArray,
- wrapped = _(array).filter(isEven);
- assert.strictEqual(wrapped.last(), _.last(_.filter(array, isEven)));
- });
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.lowerCase');
- (function() {
- QUnit.test('should lowercase as space-separated words', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.lowerCase('--Foo-Bar--'), 'foo bar');
- assert.strictEqual(_.lowerCase('fooBar'), 'foo bar');
- assert.strictEqual(_.lowerCase('__FOO_BAR__'), 'foo bar');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.lowerFirst');
- (function() {
- QUnit.test('should lowercase only the first character', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.lowerFirst('fred'), 'fred');
- assert.strictEqual(_.lowerFirst('Fred'), 'fred');
- assert.strictEqual(_.lowerFirst('FRED'), 'fRED');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.lt');
- (function() {
- QUnit.test('should return `true` if `value` is less than `other`', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.lt(1, 3), true);
- assert.strictEqual(_.lt('abc', 'def'), true);
- });
- QUnit.test('should return `false` if `value` >= `other`', function(assert) {
- assert.expect(4);
- assert.strictEqual(_.lt(3, 1), false);
- assert.strictEqual(_.lt(3, 3), false);
- assert.strictEqual(_.lt('def', 'abc'), false);
- assert.strictEqual(_.lt('def', 'def'), false);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.lte');
- (function() {
- QUnit.test('should return `true` if `value` is <= `other`', function(assert) {
- assert.expect(4);
- assert.strictEqual(_.lte(1, 3), true);
- assert.strictEqual(_.lte(3, 3), true);
- assert.strictEqual(_.lte('abc', 'def'), true);
- assert.strictEqual(_.lte('def', 'def'), true);
- });
- QUnit.test('should return `false` if `value` > `other`', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.lt(3, 1), false);
- assert.strictEqual(_.lt('def', 'abc'), false);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.findLastIndex and lodash.lastIndexOf');
- lodashStable.each(['findLastIndex', 'lastIndexOf'], function(methodName) {
- var array = [1, 2, 3, 1, 2, 3],
- func = _[methodName],
- resolve = methodName == 'findLastIndex' ? lodashStable.curry(lodashStable.eq) : identity;
- QUnit.test('`_.' + methodName + '` should return the index of the last matched value', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(array, resolve(3)), 5);
- });
- QUnit.test('`_.' + methodName + '` should work with a positive `fromIndex`', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(array, resolve(1), 2), 0);
- });
- QUnit.test('`_.' + methodName + '` should work with a `fromIndex` >= `length`', function(assert) {
- assert.expect(1);
- var values = [6, 8, Math.pow(2, 32), Infinity],
- expected = lodashStable.map(values, lodashStable.constant([-1, 3, -1]));
- var actual = lodashStable.map(values, function(fromIndex) {
- return [
- func(array, resolve(undefined), fromIndex),
- func(array, resolve(1), fromIndex),
- func(array, resolve(''), fromIndex)
- ];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex`', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(array, resolve(2), -3), 1);
- });
- QUnit.test('`_.' + methodName + '` should work with a negative `fromIndex` <= `-length`', function(assert) {
- assert.expect(1);
- var values = [-6, -8, -Infinity],
- expected = lodashStable.map(values, stubZero);
- var actual = lodashStable.map(values, function(fromIndex) {
- return func(array, resolve(1), fromIndex);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should treat falsey `fromIndex` values correctly', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? 5 : -1;
- });
- var actual = lodashStable.map(falsey, function(fromIndex) {
- return func(array, resolve(3), fromIndex);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should coerce `fromIndex` to an integer', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(array, resolve(2), 4.2), 4);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('indexOf methods');
- lodashStable.each(['indexOf', 'lastIndexOf', 'sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
- var func = _[methodName],
- isIndexOf = !/last/i.test(methodName),
- isSorted = /^sorted/.test(methodName);
- QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, lodashStable.constant(-1));
- var actual = lodashStable.map(falsey, function(array, index) {
- try {
- return index ? func(array) : func();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should return `-1` for an unmatched value', function(assert) {
- assert.expect(5);
- var array = [1, 2, 3],
- empty = [];
- assert.strictEqual(func(array, 4), -1);
- assert.strictEqual(func(array, 4, true), -1);
- assert.strictEqual(func(array, undefined, true), -1);
- assert.strictEqual(func(empty, undefined), -1);
- assert.strictEqual(func(empty, undefined, true), -1);
- });
- QUnit.test('`_.' + methodName + '` should not match values on empty arrays', function(assert) {
- assert.expect(2);
- var array = [];
- array[-1] = 0;
- assert.strictEqual(func(array, undefined), -1);
- assert.strictEqual(func(array, 0, true), -1);
- });
- QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
- assert.expect(3);
- var array = isSorted
- ? [1, 2, NaN, NaN]
- : [1, NaN, 3, NaN, 5, NaN];
- if (isSorted) {
- assert.strictEqual(func(array, NaN, true), isIndexOf ? 2 : 3);
- skipAssert(assert, 2);
- }
- else {
- assert.strictEqual(func(array, NaN), isIndexOf ? 1 : 5);
- assert.strictEqual(func(array, NaN, 2), isIndexOf ? 3 : 1);
- assert.strictEqual(func(array, NaN, -2), isIndexOf ? 5 : 3);
- }
- });
- QUnit.test('`_.' + methodName + '` should match `-0` as `0`', function(assert) {
- assert.expect(2);
- assert.strictEqual(func([-0], 0), 0);
- assert.strictEqual(func([0], -0), 0);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.map');
- (function() {
- var array = [1, 2];
- QUnit.test('should map values in `collection` to a new array', function(assert) {
- assert.expect(2);
- var object = { 'a': 1, 'b': 2 },
- expected = ['1', '2'];
- assert.deepEqual(_.map(array, String), expected);
- assert.deepEqual(_.map(object, String), expected);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': 'x' }, { 'a': 'y' }];
- assert.deepEqual(_.map(objects, 'a'), ['x', 'y']);
- });
- QUnit.test('should iterate over own string keyed properties of objects', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var actual = _.map(new Foo, identity);
- assert.deepEqual(actual, [1]);
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(2);
- var object = { 'a': 1, 'b': 2 },
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant([1, 2]));
- lodashStable.each([array, object], function(collection) {
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.map(collection, value) : _.map(collection);
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should accept a falsey `collection` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubArray);
- var actual = lodashStable.map(falsey, function(collection, index) {
- try {
- return index ? _.map(collection) : _.map();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should treat number values for `collection` as empty', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.map(1), []);
- });
- QUnit.test('should treat a nodelist as an array-like object', function(assert) {
- assert.expect(1);
- if (document) {
- var actual = _.map(document.getElementsByTagName('body'), function(element) {
- return element.nodeName.toLowerCase();
- });
- assert.deepEqual(actual, ['body']);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should work with objects with non-number length properties', function(assert) {
- assert.expect(1);
- var value = { 'value': 'x' },
- object = { 'length': { 'value': 'x' } };
- assert.deepEqual(_.map(object, identity), [value]);
- });
- QUnit.test('should return a wrapped value when chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_(array).map(noop) instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should provide correct `predicate` arguments in a lazy sequence', function(assert) {
- assert.expect(5);
- if (!isNpm) {
- var args,
- array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
- expected = [1, 0, _.map(array.slice(1), square)];
- _(array).slice(1).map(function(value, index, array) {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, [1, 0, array.slice(1)]);
- args = undefined;
- _(array).slice(1).map(square).map(function(value, index, array) {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, expected);
- args = undefined;
- _(array).slice(1).map(square).map(function(value, index) {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, expected);
- args = undefined;
- _(array).slice(1).map(square).map(function(value) {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, [1]);
- args = undefined;
- _(array).slice(1).map(square).map(function() {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, expected);
- }
- else {
- skipAssert(assert, 5);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.mapKeys');
- (function() {
- var array = [1, 2],
- object = { 'a': 1, 'b': 2 };
- QUnit.test('should map keys in `object` to a new object', function(assert) {
- assert.expect(1);
- var actual = _.mapKeys(object, String);
- assert.deepEqual(actual, { '1': 1, '2': 2 });
- });
- QUnit.test('should treat arrays like objects', function(assert) {
- assert.expect(1);
- var actual = _.mapKeys(array, String);
- assert.deepEqual(actual, { '1': 1, '2': 2 });
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var actual = _.mapKeys({ 'a': { 'b': 'c' } }, 'b');
- assert.deepEqual(actual, { 'c': { 'b': 'c' } });
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var object = { 'a': 1, 'b': 2 },
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant({ '1': 1, '2': 2 }));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.mapKeys(object, value) : _.mapKeys(object);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.mapValues');
- (function() {
- var array = [1, 2],
- object = { 'a': 1, 'b': 2 };
- QUnit.test('should map values in `object` to a new object', function(assert) {
- assert.expect(1);
- var actual = _.mapValues(object, String);
- assert.deepEqual(actual, { 'a': '1', 'b': '2' });
- });
- QUnit.test('should treat arrays like objects', function(assert) {
- assert.expect(1);
- var actual = _.mapValues(array, String);
- assert.deepEqual(actual, { '0': '1', '1': '2' });
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var actual = _.mapValues({ 'a': { 'b': 2 } }, 'b');
- assert.deepEqual(actual, { 'a': 2 });
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var object = { 'a': 1, 'b': 2 },
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant([true, false]));
- var actual = lodashStable.map(values, function(value, index) {
- var result = index ? _.mapValues(object, value) : _.mapValues(object);
- return [lodashStable.isEqual(result, object), result === object];
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.mapKeys and lodash.mapValues');
- lodashStable.each(['mapKeys', 'mapValues'], function(methodName) {
- var func = _[methodName],
- object = { 'a': 1, 'b': 2 };
- QUnit.test('`_.' + methodName + '` should iterate over own string keyed properties of objects', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 'a';
- }
- Foo.prototype.b = 'b';
- var actual = func(new Foo, function(value, key) { return key; });
- assert.deepEqual(actual, { 'a': 'a' });
- });
- QUnit.test('`_.' + methodName + '` should accept a falsey `object` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubObject);
- var actual = lodashStable.map(falsey, function(object, index) {
- try {
- return index ? func(object) : func();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_(object)[methodName](noop) instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- QUnit.module('lodash.matches');
- (function() {
- QUnit.test('should not change behavior if `source` is modified', function(assert) {
- assert.expect(9);
- var sources = [
- { 'a': { 'b': 2, 'c': 3 } },
- { 'a': 1, 'b': 2 },
- { 'a': 1 }
- ];
- lodashStable.each(sources, function(source, index) {
- var object = lodashStable.cloneDeep(source),
- par = _.matches(source);
- assert.strictEqual(par(object), true);
- if (index) {
- source.a = 2;
- source.b = 1;
- source.c = 3;
- } else {
- source.a.b = 1;
- source.a.c = 2;
- source.a.d = 3;
- }
- assert.strictEqual(par(object), true);
- assert.strictEqual(par(source), false);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('matches methods');
- lodashStable.each(['matches', 'isMatch'], function(methodName) {
- var isMatches = methodName == 'matches';
- function matches(source) {
- return isMatches ? _.matches(source) : function(object) {
- return _.isMatch(object, source);
- };
- }
- QUnit.test('`_.' + methodName + '` should perform a deep comparison between `source` and `object`', function(assert) {
- assert.expect(5);
- var object = { 'a': 1, 'b': 2, 'c': 3 },
- par = matches({ 'a': 1 });
- assert.strictEqual(par(object), true);
- par = matches({ 'b': 1 });
- assert.strictEqual(par(object), false);
- par = matches({ 'a': 1, 'c': 3 });
- assert.strictEqual(par(object), true);
- par = matches({ 'c': 3, 'd': 4 });
- assert.strictEqual(par(object), false);
- object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
- par = matches({ 'a': { 'b': { 'c': 1 } } });
- assert.strictEqual(par(object), true);
- });
- QUnit.test('`_.' + methodName + '` should match inherited string keyed `object` properties', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var object = { 'a': new Foo },
- par = matches({ 'a': { 'b': 2 } });
- assert.strictEqual(par(object), true);
- });
- QUnit.test('`_.' + methodName + '` should not match by inherited `source` properties', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var objects = [{ 'a': 1 }, { 'a': 1, 'b': 2 }],
- source = new Foo,
- actual = lodashStable.map(objects, matches(source)),
- expected = lodashStable.map(objects, stubTrue);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should compare a variety of `source` property values', function(assert) {
- assert.expect(2);
- var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
- object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
- par = matches(object1);
- assert.strictEqual(par(object1), true);
- assert.strictEqual(par(object2), false);
- });
- QUnit.test('`_.' + methodName + '` should match `-0` as `0`', function(assert) {
- assert.expect(2);
- var object1 = { 'a': -0 },
- object2 = { 'a': 0 },
- par = matches(object1);
- assert.strictEqual(par(object2), true);
- par = matches(object2);
- assert.strictEqual(par(object1), true);
- });
- QUnit.test('`_.' + methodName + '` should compare functions by reference', function(assert) {
- assert.expect(3);
- var object1 = { 'a': lodashStable.noop },
- object2 = { 'a': noop },
- object3 = { 'a': {} },
- par = matches(object1);
- assert.strictEqual(par(object1), true);
- assert.strictEqual(par(object2), false);
- assert.strictEqual(par(object3), false);
- });
- QUnit.test('`_.' + methodName + '` should work with a function for `object`', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.a = { 'b': 2, 'c': 3 };
- var par = matches({ 'a': { 'b': 2 } });
- assert.strictEqual(par(Foo), true);
- });
- QUnit.test('`_.' + methodName + '` should work with a function for `source`', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.a = 1;
- Foo.b = function() {};
- Foo.c = 3;
- var objects = [{ 'a': 1 }, { 'a': 1, 'b': Foo.b, 'c': 3 }],
- actual = lodashStable.map(objects, matches(Foo));
- assert.deepEqual(actual, [false, true]);
- });
- QUnit.test('`_.' + methodName + '` should work with a non-plain `object`', function(assert) {
- assert.expect(1);
- function Foo(object) { lodashStable.assign(this, object); }
- var object = new Foo({ 'a': new Foo({ 'b': 2, 'c': 3 }) }),
- par = matches({ 'a': { 'b': 2 } });
- assert.strictEqual(par(object), true);
- });
- QUnit.test('`_.' + methodName + '` should partial match arrays', function(assert) {
- assert.expect(3);
- var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
- actual = lodashStable.filter(objects, matches({ 'a': ['d'] }));
- assert.deepEqual(actual, [objects[1]]);
- actual = lodashStable.filter(objects, matches({ 'a': ['b', 'd'] }));
- assert.deepEqual(actual, []);
- actual = lodashStable.filter(objects, matches({ 'a': ['d', 'b'] }));
- assert.deepEqual(actual, []);
- });
- QUnit.test('`_.' + methodName + '` should partial match arrays with duplicate values', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
- actual = lodashStable.filter(objects, matches({ 'a': [2, 2] }));
- assert.deepEqual(actual, [objects[1]]);
- });
- QUnit.test('should partial match arrays of objects', function(assert) {
- assert.expect(1);
- var objects = [
- { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 5, 'd': 6 }] },
- { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 4, 'c': 6, 'd': 7 }] }
- ];
- var actual = lodashStable.filter(objects, matches({ 'a': [{ 'b': 1 }, { 'b': 4, 'c': 5 }] }));
- assert.deepEqual(actual, [objects[0]]);
- });
- QUnit.test('`_.' + methodName + '` should partial match maps', function(assert) {
- assert.expect(3);
- if (Map) {
- var objects = [{ 'a': new Map }, { 'a': new Map }];
- objects[0].a.set('a', 1);
- objects[1].a.set('a', 1);
- objects[1].a.set('b', 2);
- var map = new Map;
- map.set('b', 2);
- var actual = lodashStable.filter(objects, matches({ 'a': map }));
- assert.deepEqual(actual, [objects[1]]);
- map['delete']('b');
- actual = lodashStable.filter(objects, matches({ 'a': map }));
- assert.deepEqual(actual, objects);
- map.set('c', 3);
- actual = lodashStable.filter(objects, matches({ 'a': map }));
- assert.deepEqual(actual, []);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('`_.' + methodName + '` should partial match sets', function(assert) {
- assert.expect(3);
- if (Set) {
- var objects = [{ 'a': new Set }, { 'a': new Set }];
- objects[0].a.add(1);
- objects[1].a.add(1);
- objects[1].a.add(2);
- var set = new Set;
- set.add(2);
- var actual = lodashStable.filter(objects, matches({ 'a': set }));
- assert.deepEqual(actual, [objects[1]]);
- set['delete'](2);
- actual = lodashStable.filter(objects, matches({ 'a': set }));
- assert.deepEqual(actual, objects);
- set.add(3);
- actual = lodashStable.filter(objects, matches({ 'a': set }));
- assert.deepEqual(actual, []);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('`_.' + methodName + '` should match `undefined` values', function(assert) {
- assert.expect(3);
- var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
- actual = lodashStable.map(objects, matches({ 'b': undefined })),
- expected = [false, false, true];
- assert.deepEqual(actual, expected);
- actual = lodashStable.map(objects, matches({ 'a': 1, 'b': undefined }));
- assert.deepEqual(actual, expected);
- objects = [{ 'a': { 'b': 2 } }, { 'a': { 'b': 2, 'c': 3 } }, { 'a': { 'b': 2, 'c': undefined } }];
- actual = lodashStable.map(objects, matches({ 'a': { 'c': undefined } }));
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should match `undefined` values on primitives', function(assert) {
- assert.expect(3);
- numberProto.a = 1;
- numberProto.b = undefined;
- try {
- var par = matches({ 'b': undefined });
- assert.strictEqual(par(1), true);
- } catch (e) {
- assert.ok(false, e.message);
- }
- try {
- par = matches({ 'a': 1, 'b': undefined });
- assert.strictEqual(par(1), true);
- } catch (e) {
- assert.ok(false, e.message);
- }
- numberProto.a = { 'b': 1, 'c': undefined };
- try {
- par = matches({ 'a': { 'c': undefined } });
- assert.strictEqual(par(1), true);
- } catch (e) {
- assert.ok(false, e.message);
- }
- delete numberProto.a;
- delete numberProto.b;
- });
- QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubFalse),
- par = matches({ 'a': 1 });
- var actual = lodashStable.map(values, function(value, index) {
- try {
- return index ? par(value) : par();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` hould return `true` when comparing an empty `source`', function(assert) {
- assert.expect(1);
- var object = { 'a': 1 },
- expected = lodashStable.map(empties, stubTrue);
- var actual = lodashStable.map(empties, function(value) {
- var par = matches(value);
- return par(object);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should return `true` when comparing an empty `source` to a nullish `object`', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubTrue),
- par = matches({});
- var actual = lodashStable.map(values, function(value, index) {
- try {
- return index ? par(value) : par();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should return `true` when comparing a `source` of empty arrays and objects', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
- actual = lodashStable.filter(objects, matches({ 'a': [], 'b': {} }));
- assert.deepEqual(actual, objects);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.matchesProperty');
- (function() {
- QUnit.test('should create a function that performs a deep comparison between a property value and `srcValue`', function(assert) {
- assert.expect(6);
- var object = { 'a': 1, 'b': 2, 'c': 3 },
- matches = _.matchesProperty('a', 1);
- assert.strictEqual(matches.length, 1);
- assert.strictEqual(matches(object), true);
- matches = _.matchesProperty('b', 3);
- assert.strictEqual(matches(object), false);
- matches = _.matchesProperty('a', { 'a': 1, 'c': 3 });
- assert.strictEqual(matches({ 'a': object }), true);
- matches = _.matchesProperty('a', { 'c': 3, 'd': 4 });
- assert.strictEqual(matches(object), false);
- object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 };
- matches = _.matchesProperty('a', { 'b': { 'c': 1 } });
- assert.strictEqual(matches(object), true);
- });
- QUnit.test('should support deep paths', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': 2 } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var matches = _.matchesProperty(path, 2);
- assert.strictEqual(matches(object), true);
- });
- });
- QUnit.test('should work with a non-string `path`', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3];
- lodashStable.each([1, [1]], function(path) {
- var matches = _.matchesProperty(path, 2);
- assert.strictEqual(matches(array), true);
- });
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var object1 = { '-0': 'a' },
- object2 = { '0': 'b' },
- pairs = [[object1, object2], [object1, object2], [object2, object1], [object2, object1]],
- props = [-0, Object(-0), 0, Object(0)],
- values = ['a', 'a', 'b', 'b'],
- expected = lodashStable.map(props, lodashStable.constant([true, false]));
- var actual = lodashStable.map(props, function(key, index) {
- var matches = _.matchesProperty(key, values[index]),
- pair = pairs[index];
- return [matches(pair[0]), matches(pair[1])];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should coerce key to a string', function(assert) {
- assert.expect(1);
- function fn() {}
- fn.toString = lodashStable.constant('fn');
- var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
- values = [null, undefined, fn, {}];
- var expected = lodashStable.transform(values, function(result) {
- result.push(true, true);
- });
- var actual = lodashStable.transform(objects, function(result, object, index) {
- var key = values[index];
- lodashStable.each([key, [key]], function(path) {
- var matches = _.matchesProperty(path, object[key]);
- result.push(matches(object));
- });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should match a key over a path', function(assert) {
- assert.expect(2);
- var object = { 'a.b': 1, 'a': { 'b': 2 } };
- lodashStable.each(['a.b', ['a.b']], function(path) {
- var matches = _.matchesProperty(path, 1);
- assert.strictEqual(matches(object), true);
- });
- });
- QUnit.test('should return `false` when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubFalse);
- lodashStable.each(['constructor', ['constructor']], function(path) {
- var matches = _.matchesProperty(path, 1);
- var actual = lodashStable.map(values, function(value, index) {
- try {
- return index ? matches(value) : matches();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `false` for deep paths when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubFalse);
- lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
- var matches = _.matchesProperty(path, 1);
- var actual = lodashStable.map(values, function(value, index) {
- try {
- return index ? matches(value) : matches();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `false` if parts of `path` are missing', function(assert) {
- assert.expect(4);
- var object = {};
- lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
- var matches = _.matchesProperty(path, 1);
- assert.strictEqual(matches(object), false);
- });
- });
- QUnit.test('should match inherited string keyed `srcValue` properties', function(assert) {
- assert.expect(2);
- function Foo() {}
- Foo.prototype.b = 2;
- var object = { 'a': new Foo };
- lodashStable.each(['a', ['a']], function(path) {
- var matches = _.matchesProperty(path, { 'b': 2 });
- assert.strictEqual(matches(object), true);
- });
- });
- QUnit.test('should not match by inherited `srcValue` properties', function(assert) {
- assert.expect(2);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 2 } }],
- expected = lodashStable.map(objects, stubTrue);
- lodashStable.each(['a', ['a']], function(path) {
- assert.deepEqual(lodashStable.map(objects, _.matchesProperty(path, new Foo)), expected);
- });
- });
- QUnit.test('should compare a variety of values', function(assert) {
- assert.expect(2);
- var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } },
- object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } },
- matches = _.matchesProperty('a', object1);
- assert.strictEqual(matches({ 'a': object1 }), true);
- assert.strictEqual(matches({ 'a': object2 }), false);
- });
- QUnit.test('should match `-0` as `0`', function(assert) {
- assert.expect(2);
- var matches = _.matchesProperty('a', -0);
- assert.strictEqual(matches({ 'a': 0 }), true);
- matches = _.matchesProperty('a', 0);
- assert.strictEqual(matches({ 'a': -0 }), true);
- });
- QUnit.test('should compare functions by reference', function(assert) {
- assert.expect(3);
- var object1 = { 'a': lodashStable.noop },
- object2 = { 'a': noop },
- object3 = { 'a': {} },
- matches = _.matchesProperty('a', object1);
- assert.strictEqual(matches({ 'a': object1 }), true);
- assert.strictEqual(matches({ 'a': object2 }), false);
- assert.strictEqual(matches({ 'a': object3 }), false);
- });
- QUnit.test('should work with a function for `srcValue`', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.a = 1;
- Foo.b = function() {};
- Foo.c = 3;
- var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': Foo.b, 'c': 3 } }],
- actual = lodashStable.map(objects, _.matchesProperty('a', Foo));
- assert.deepEqual(actual, [false, true]);
- });
- QUnit.test('should work with a non-plain `srcValue`', function(assert) {
- assert.expect(1);
- function Foo(object) { lodashStable.assign(this, object); }
- var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
- matches = _.matchesProperty('a', { 'b': 1 });
- assert.strictEqual(matches(object), true);
- });
- QUnit.test('should partial match arrays', function(assert) {
- assert.expect(3);
- var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }],
- actual = lodashStable.filter(objects, _.matchesProperty('a', ['d']));
- assert.deepEqual(actual, [objects[1]]);
- actual = lodashStable.filter(objects, _.matchesProperty('a', ['b', 'd']));
- assert.deepEqual(actual, []);
- actual = lodashStable.filter(objects, _.matchesProperty('a', ['d', 'b']));
- assert.deepEqual(actual, []);
- });
- QUnit.test('should partial match arrays with duplicate values', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
- actual = lodashStable.filter(objects, _.matchesProperty('a', [2, 2]));
- assert.deepEqual(actual, [objects[1]]);
- });
- QUnit.test('should partial match arrays of objects', function(assert) {
- assert.expect(1);
- var objects = [
- { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 5, 'c': 6 }] },
- { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 6, 'c': 7 }] }
- ];
- var actual = lodashStable.filter(objects, _.matchesProperty('a', [{ 'a': 1 }, { 'a': 4, 'b': 5 }]));
- assert.deepEqual(actual, [objects[0]]);
- });
- QUnit.test('should partial match maps', function(assert) {
- assert.expect(3);
- if (Map) {
- var objects = [{ 'a': new Map }, { 'a': new Map }];
- objects[0].a.set('a', 1);
- objects[1].a.set('a', 1);
- objects[1].a.set('b', 2);
- var map = new Map;
- map.set('b', 2);
- var actual = lodashStable.filter(objects, _.matchesProperty('a', map));
- assert.deepEqual(actual, [objects[1]]);
- map['delete']('b');
- actual = lodashStable.filter(objects, _.matchesProperty('a', map));
- assert.deepEqual(actual, objects);
- map.set('c', 3);
- actual = lodashStable.filter(objects, _.matchesProperty('a', map));
- assert.deepEqual(actual, []);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('should partial match sets', function(assert) {
- assert.expect(3);
- if (Set) {
- var objects = [{ 'a': new Set }, { 'a': new Set }];
- objects[0].a.add(1);
- objects[1].a.add(1);
- objects[1].a.add(2);
- var set = new Set;
- set.add(2);
- var actual = lodashStable.filter(objects, _.matchesProperty('a', set));
- assert.deepEqual(actual, [objects[1]]);
- set['delete'](2);
- actual = lodashStable.filter(objects, _.matchesProperty('a', set));
- assert.deepEqual(actual, objects);
- set.add(3);
- actual = lodashStable.filter(objects, _.matchesProperty('a', set));
- assert.deepEqual(actual, []);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('should match `undefined` values', function(assert) {
- assert.expect(2);
- var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
- actual = lodashStable.map(objects, _.matchesProperty('b', undefined)),
- expected = [false, false, true];
- assert.deepEqual(actual, expected);
- objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 1 } }, { 'a': { 'a': 1, 'b': undefined } }];
- actual = lodashStable.map(objects, _.matchesProperty('a', { 'b': undefined }));
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should match `undefined` values of nested objects', function(assert) {
- assert.expect(4);
- var object = { 'a': { 'b': undefined } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var matches = _.matchesProperty(path, undefined);
- assert.strictEqual(matches(object), true);
- });
- lodashStable.each(['a.a', ['a', 'a']], function(path) {
- var matches = _.matchesProperty(path, undefined);
- assert.strictEqual(matches(object), false);
- });
- });
- QUnit.test('should match `undefined` values on primitives', function(assert) {
- assert.expect(2);
- numberProto.a = 1;
- numberProto.b = undefined;
- try {
- var matches = _.matchesProperty('b', undefined);
- assert.strictEqual(matches(1), true);
- } catch (e) {
- assert.ok(false, e.message);
- }
- numberProto.a = { 'b': 1, 'c': undefined };
- try {
- matches = _.matchesProperty('a', { 'c': undefined });
- assert.strictEqual(matches(1), true);
- } catch (e) {
- assert.ok(false, e.message);
- }
- delete numberProto.a;
- delete numberProto.b;
- });
- QUnit.test('should return `true` when comparing a `srcValue` of empty arrays and objects', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }],
- matches = _.matchesProperty('a', { 'a': [], 'b': {} });
- var actual = lodashStable.filter(objects, function(object) {
- return matches({ 'a': object });
- });
- assert.deepEqual(actual, objects);
- });
- QUnit.test('should not change behavior if `srcValue` is modified', function(assert) {
- assert.expect(9);
- lodashStable.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) {
- var object = lodashStable.cloneDeep(source),
- matches = _.matchesProperty('a', source);
- assert.strictEqual(matches({ 'a': object }), true);
- if (index) {
- source.a = 2;
- source.b = 1;
- source.c = 3;
- } else {
- source.a.b = 1;
- source.a.c = 2;
- source.a.d = 3;
- }
- assert.strictEqual(matches({ 'a': object }), true);
- assert.strictEqual(matches({ 'a': source }), false);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.max');
- (function() {
- QUnit.test('should return the largest value from a collection', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.max([1, 2, 3]), 3);
- });
- QUnit.test('should return `undefined` for empty collections', function(assert) {
- assert.expect(1);
- var values = falsey.concat([[]]),
- expected = lodashStable.map(values, noop);
- var actual = lodashStable.map(values, function(value, index) {
- try {
- return index ? _.max(value) : _.max();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with non-numeric collection values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.max(['a', 'b']), 'b');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.mean');
- (function() {
- QUnit.test('should return the mean of an array of numbers', function(assert) {
- assert.expect(1);
- var array = [4, 2, 8, 6];
- assert.strictEqual(_.mean(array), 5);
- });
- QUnit.test('should return `NaN` when passing empty `array` values', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(empties, stubNaN),
- actual = lodashStable.map(empties, _.mean);
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.meanBy');
- (function() {
- var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
- QUnit.test('should work with an `iteratee` argument', function(assert) {
- assert.expect(1);
- var actual = _.meanBy(objects, function(object) {
- return object.a;
- });
- assert.deepEqual(actual, 2);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.meanBy(objects, function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [{ 'a': 2 }]);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(2);
- var arrays = [[2], [3], [1]];
- assert.strictEqual(_.meanBy(arrays, 0), 2);
- assert.strictEqual(_.meanBy(objects, 'a'), 2);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.memoize');
- (function() {
- QUnit.test('should memoize results based on the first argument given', function(assert) {
- assert.expect(2);
- var memoized = _.memoize(function(a, b, c) {
- return a + b + c;
- });
- assert.strictEqual(memoized(1, 2, 3), 6);
- assert.strictEqual(memoized(1, 3, 5), 6);
- });
- QUnit.test('should support a `resolver` argument', function(assert) {
- assert.expect(2);
- var fn = function(a, b, c) { return a + b + c; },
- memoized = _.memoize(fn, fn);
- assert.strictEqual(memoized(1, 2, 3), 6);
- assert.strictEqual(memoized(1, 3, 5), 9);
- });
- QUnit.test('should use `this` binding of function for `resolver`', function(assert) {
- assert.expect(2);
- var fn = function(a, b, c) { return a + this.b + this.c; },
- memoized = _.memoize(fn, fn);
- var object = { 'memoized': memoized, 'b': 2, 'c': 3 };
- assert.strictEqual(object.memoized(1), 6);
- object.b = 3;
- object.c = 5;
- assert.strictEqual(object.memoized(1), 9);
- });
- QUnit.test('should throw a TypeError if `resolve` is truthy and not a function', function(assert) {
- assert.expect(1);
- assert.raises(function() { _.memoize(noop, true); }, TypeError);
- });
- QUnit.test('should not error if `resolver` is falsey', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(resolver, index) {
- try {
- return _.isFunction(index ? _.memoize(noop, resolver) : _.memoize(noop));
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should check cache for own properties', function(assert) {
- assert.expect(1);
- var props = [
- 'constructor',
- 'hasOwnProperty',
- 'isPrototypeOf',
- 'propertyIsEnumerable',
- 'toLocaleString',
- 'toString',
- 'valueOf'
- ];
- var memoized = _.memoize(identity);
- var actual = lodashStable.map(props, function(value) {
- return memoized(value);
- });
- assert.deepEqual(actual, props);
- });
- QUnit.test('should cache the `__proto__` key', function(assert) {
- assert.expect(8);
- var array = [],
- key = '__proto__';
- lodashStable.times(2, function(index) {
- var count = 0,
- resolver = index && identity;
- var memoized = _.memoize(function() {
- count++;
- return array;
- }, resolver);
- var cache = memoized.cache;
- memoized(key);
- memoized(key);
- assert.strictEqual(count, 1);
- assert.strictEqual(cache.get(key), array);
- assert.notOk(cache.__data__ instanceof Array);
- assert.strictEqual(cache['delete'](key), true);
- });
- });
- QUnit.test('should allow `_.memoize.Cache` to be customized', function(assert) {
- assert.expect(4);
- var oldCache = _.memoize.Cache;
- function Cache() {
- this.__data__ = [];
- }
- Cache.prototype = {
- 'get': function(key) {
- var entry = _.find(this.__data__, function(entry) {
- return key === entry.key;
- });
- return entry && entry.value;
- },
- 'has': function(key) {
- return _.some(this.__data__, function(entry) {
- return key === entry.key;
- });
- },
- 'set': function(key, value) {
- this.__data__.push({ 'key': key, 'value': value });
- return this;
- }
- };
- _.memoize.Cache = Cache;
- var memoized = _.memoize(function(object) {
- return 'value:' + object.id;
- });
- var cache = memoized.cache,
- key1 = { 'id': 'a' },
- key2 = { 'id': 'b' };
- assert.strictEqual(memoized(key1), 'value:a');
- assert.strictEqual(cache.has(key1), true);
- assert.strictEqual(memoized(key2), 'value:b');
- assert.strictEqual(cache.has(key2), true);
- _.memoize.Cache = oldCache;
- });
- QUnit.test('should works with an immutable `_.memoize.Cache` ', function(assert) {
- assert.expect(2);
- var oldCache = _.memoize.Cache;
- function Cache() {
- this.__data__ = [];
- }
- Cache.prototype = {
- 'get': function(key) {
- return _.find(this.__data__, function(entry) {
- return key === entry.key;
- }).value;
- },
- 'has': function(key) {
- return _.some(this.__data__, function(entry) {
- return key === entry.key;
- });
- },
- 'set': function(key, value) {
- var result = new Cache;
- result.__data__ = this.__data__.concat({ 'key': key, 'value': value });
- return result;
- }
- };
- _.memoize.Cache = Cache;
- var memoized = _.memoize(function(object) {
- return object.id;
- });
- var key1 = { 'id': 'a' },
- key2 = { 'id': 'b' };
- memoized(key1);
- memoized(key2);
- var cache = memoized.cache;
- assert.strictEqual(cache.has(key1), true);
- assert.strictEqual(cache.has(key2), true);
- _.memoize.Cache = oldCache;
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.merge');
- (function() {
- var args = arguments;
- QUnit.test('should merge `source` into `object`', function(assert) {
- assert.expect(1);
- var names = {
- 'characters': [
- { 'name': 'barney' },
- { 'name': 'fred' }
- ]
- };
- var ages = {
- 'characters': [
- { 'age': 36 },
- { 'age': 40 }
- ]
- };
- var heights = {
- 'characters': [
- { 'height': '5\'4"' },
- { 'height': '5\'5"' }
- ]
- };
- var expected = {
- 'characters': [
- { 'name': 'barney', 'age': 36, 'height': '5\'4"' },
- { 'name': 'fred', 'age': 40, 'height': '5\'5"' }
- ]
- };
- assert.deepEqual(_.merge(names, ages, heights), expected);
- });
- QUnit.test('should merge sources containing circular references', function(assert) {
- assert.expect(2);
- var object = {
- 'foo': { 'a': 1 },
- 'bar': { 'a': 2 }
- };
- var source = {
- 'foo': { 'b': { 'c': { 'd': {} } } },
- 'bar': {}
- };
- source.foo.b.c.d = source;
- source.bar.b = source.foo.b;
- var actual = _.merge(object, source);
- assert.notStrictEqual(actual.bar.b, actual.foo.b);
- assert.strictEqual(actual.foo.b.c.d, actual.foo.b.c.d.foo.b.c.d);
- });
- QUnit.test('should work with four arguments', function(assert) {
- assert.expect(1);
- var expected = { 'a': 4 },
- actual = _.merge({ 'a': 1 }, { 'a': 2 }, { 'a': 3 }, expected);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should merge onto function `object` values', function(assert) {
- assert.expect(2);
- function Foo() {}
- var source = { 'a': 1 },
- actual = _.merge(Foo, source);
- assert.strictEqual(actual, Foo);
- assert.strictEqual(Foo.a, 1);
- });
- QUnit.test('should not merge onto function values of sources', function(assert) {
- assert.expect(3);
- var source1 = { 'a': function() {} },
- source2 = { 'a': { 'b': 2 } },
- actual = _.merge({}, source1, source2);
- assert.deepEqual(actual, { 'a': { 'b': 2 } });
- actual = _.merge(source1, source2);
- assert.strictEqual(typeof actual.a, 'function');
- assert.strictEqual(actual.a.b, 2);
- });
- QUnit.test('should merge onto non-plain `object` values', function(assert) {
- assert.expect(2);
- function Foo() {}
- var object = new Foo,
- actual = _.merge(object, { 'a': 1 });
- assert.strictEqual(actual, object);
- assert.strictEqual(object.a, 1);
- });
- QUnit.test('should treat sparse array sources as dense', function(assert) {
- assert.expect(2);
- var array = [1];
- array[2] = 3;
- var actual = _.merge([], array),
- expected = array.slice();
- expected[1] = undefined;
- assert.ok('1' in actual);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should merge `arguments` objects', function(assert) {
- assert.expect(7);
- var object1 = { 'value': args },
- object2 = { 'value': { '3': 4 } },
- expected = { '0': 1, '1': 2, '2': 3, '3': 4 },
- actual = _.merge(object1, object2);
- assert.notOk('3' in args);
- assert.notOk(_.isArguments(actual.value));
- assert.deepEqual(actual.value, expected);
- object1.value = args;
- actual = _.merge(object2, object1);
- assert.notOk(_.isArguments(actual.value));
- assert.deepEqual(actual.value, expected);
- expected = { '0': 1, '1': 2, '2': 3 };
- actual = _.merge({}, object1);
- assert.notOk(_.isArguments(actual.value));
- assert.deepEqual(actual.value, expected);
- });
- QUnit.test('should merge typed arrays', function(assert) {
- assert.expect(4);
- var array1 = [0],
- array2 = [0, 0],
- array3 = [0, 0, 0, 0],
- array4 = [0, 0, 0, 0, 0, 0, 0, 0];
- var arrays = [array2, array1, array4, array3, array2, array4, array4, array3, array2],
- buffer = ArrayBuffer && new ArrayBuffer(8);
- // Juggle for `Float64Array` shim.
- if (root.Float64Array && (new Float64Array(buffer)).length == 8) {
- arrays[1] = array4;
- }
- var expected = lodashStable.map(typedArrays, function(type, index) {
- var array = arrays[index].slice();
- array[0] = 1;
- return root[type] ? { 'value': array } : false;
- });
- var actual = lodashStable.map(typedArrays, function(type) {
- var Ctor = root[type];
- return Ctor ? _.merge({ 'value': new Ctor(buffer) }, { 'value': [1] }) : false;
- });
- assert.ok(lodashStable.isArray(actual));
- assert.deepEqual(actual, expected);
- expected = lodashStable.map(typedArrays, function(type, index) {
- var array = arrays[index].slice();
- array.push(1);
- return root[type] ? { 'value': array } : false;
- });
- actual = lodashStable.map(typedArrays, function(type, index) {
- var Ctor = root[type],
- array = lodashStable.range(arrays[index].length);
- array.push(1);
- return Ctor ? _.merge({ 'value': array }, { 'value': new Ctor(buffer) }) : false;
- });
- assert.ok(lodashStable.isArray(actual));
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should assign `null` values', function(assert) {
- assert.expect(1);
- var actual = _.merge({ 'a': 1 }, { 'a': null });
- assert.strictEqual(actual.a, null);
- });
- QUnit.test('should assign non array/typed-array/plain-object sources directly', function(assert) {
- assert.expect(1);
- function Foo() {}
- var values = [new Foo, new Boolean, new Date, Foo, new Number, new String, new RegExp],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value) {
- var object = _.merge({}, { 'value': value });
- return object.value === value;
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should deep clone array/typed-array/plain-object sources', function(assert) {
- assert.expect(1);
- var typedArray = Uint8Array
- ? new Uint8Array(new ArrayBuffer(2))
- : { 'buffer': [0, 0] };
- var props = ['0', 'a', 'buffer'],
- values = [[{ 'a': 1 }], { 'a': [1] }, typedArray],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value, index) {
- var key = props[index],
- object = _.merge({}, { 'value': value }),
- newValue = object.value;
- return (
- newValue !== value &&
- newValue[key] !== value[key] &&
- lodashStable.isEqual(newValue, value)
- );
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should not augment source objects', function(assert) {
- assert.expect(6);
- var source1 = { 'a': [{ 'a': 1 }] },
- source2 = { 'a': [{ 'b': 2 }] },
- actual = _.merge({}, source1, source2);
- assert.deepEqual(source1.a, [{ 'a': 1 }]);
- assert.deepEqual(source2.a, [{ 'b': 2 }]);
- assert.deepEqual(actual.a, [{ 'a': 1, 'b': 2 }]);
- var source1 = { 'a': [[1, 2, 3]] },
- source2 = { 'a': [[3, 4]] },
- actual = _.merge({}, source1, source2);
- assert.deepEqual(source1.a, [[1, 2, 3]]);
- assert.deepEqual(source2.a, [[3, 4]]);
- assert.deepEqual(actual.a, [[3, 4, 3]]);
- });
- QUnit.test('should merge plain-objects onto non plain-objects', function(assert) {
- assert.expect(4);
- function Foo(object) {
- lodashStable.assign(this, object);
- }
- var object = { 'a': 1 },
- actual = _.merge(new Foo, object);
- assert.ok(actual instanceof Foo);
- assert.deepEqual(actual, new Foo(object));
- actual = _.merge([new Foo], [object]);
- assert.ok(actual[0] instanceof Foo);
- assert.deepEqual(actual, [new Foo(object)]);
- });
- QUnit.test('should not assign `undefined` values', function(assert) {
- assert.expect(1);
- var actual = _.merge({ 'a': 1 }, { 'a': undefined, 'b': undefined });
- assert.deepEqual(actual, { 'a': 1 });
- });
- QUnit.test('should skip `undefined` values in array sources if a destination value exists', function(assert) {
- assert.expect(2);
- var array = [1];
- array[2] = 3;
- var actual = _.merge([4, 5, 6], array),
- expected = [1, 5, 3];
- assert.deepEqual(actual, expected);
- array = [1, , 3];
- array[1] = undefined;
- actual = _.merge([4, 5, 6], array);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should skip merging when `object` and `source` are the same value', function(assert) {
- assert.expect(1);
- var object = {},
- pass = true;
- defineProperty(object, 'a', {
- 'enumerable': true,
- 'configurable': true,
- 'get': function() { pass = false; },
- 'set': function() { pass = false; }
- });
- _.merge(object, object);
- assert.ok(pass);
- });
- QUnit.test('should convert values to arrays when merging arrays of `source`', function(assert) {
- assert.expect(2);
- var object = { 'a': { '1': 'y', 'b': 'z', 'length': 2 } },
- actual = _.merge(object, { 'a': ['x'] });
- assert.deepEqual(actual, { 'a': ['x', 'y'] });
- actual = _.merge({ 'a': {} }, { 'a': [] });
- assert.deepEqual(actual, { 'a': [] });
- });
- QUnit.test('should not convert strings to arrays when merging arrays of `source`', function(assert) {
- assert.expect(1);
- var object = { 'a': 'abcde' },
- actual = _.merge(object, { 'a': ['x', 'y', 'z'] });
- assert.deepEqual(actual, { 'a': ['x', 'y', 'z'] });
- });
- QUnit.test('should not error on DOM elements', function(assert) {
- assert.expect(1);
- var object1 = { 'el': document && document.createElement('div') },
- object2 = { 'el': document && document.createElement('div') },
- pairs = [[{}, object1], [object1, object2]],
- expected = lodashStable.map(pairs, stubTrue);
- var actual = lodashStable.map(pairs, function(pair) {
- try {
- return _.merge(pair[0], pair[1]).el === pair[1].el;
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.mergeWith');
- (function() {
- QUnit.test('should handle merging when `customizer` returns `undefined`', function(assert) {
- assert.expect(2);
- var actual = _.mergeWith({ 'a': { 'b': [1, 1] } }, { 'a': { 'b': [0] } }, noop);
- assert.deepEqual(actual, { 'a': { 'b': [0, 1] } });
- actual = _.mergeWith([], [undefined], identity);
- assert.deepEqual(actual, [undefined]);
- });
- QUnit.test('should clone sources when `customizer` returns `undefined`', function(assert) {
- assert.expect(1);
- var source1 = { 'a': { 'b': { 'c': 1 } } },
- source2 = { 'a': { 'b': { 'd': 2 } } };
- _.mergeWith({}, source1, source2, noop);
- assert.deepEqual(source1.a.b, { 'c': 1 });
- });
- QUnit.test('should defer to `customizer` for non `undefined` results', function(assert) {
- assert.expect(1);
- var actual = _.mergeWith({ 'a': { 'b': [0, 1] } }, { 'a': { 'b': [2] } }, function(a, b) {
- return lodashStable.isArray(a) ? a.concat(b) : undefined;
- });
- assert.deepEqual(actual, { 'a': { 'b': [0, 1, 2] } });
- });
- QUnit.test('should provide `stack` to `customizer`', function(assert) {
- assert.expect(1);
- var actual;
- _.mergeWith({}, { 'a': { 'b': 2 } }, function() {
- actual = _.last(arguments);
- });
- assert.ok(isNpm
- ? actual.constructor.name == 'Stack'
- : actual instanceof mapCaches.Stack
- );
- });
- QUnit.test('should overwrite primitives with source object clones', function(assert) {
- assert.expect(1);
- var actual = _.mergeWith({ 'a': 0 }, { 'a': { 'b': ['c'] } }, function(a, b) {
- return lodashStable.isArray(a) ? a.concat(b) : undefined;
- });
- assert.deepEqual(actual, { 'a': { 'b': ['c'] } });
- });
- QUnit.test('should pop the stack of sources for each sibling property', function(assert) {
- assert.expect(1);
- var array = ['b', 'c'],
- object = { 'a': ['a'] },
- source = { 'a': array, 'b': array };
- var actual = _.mergeWith(object, source, function(a, b) {
- return lodashStable.isArray(a) ? a.concat(b) : undefined;
- });
- assert.deepEqual(actual, { 'a': ['a', 'b', 'c'], 'b': ['b', 'c'] });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.method');
- (function() {
- QUnit.test('should create a function that calls a method of a given object', function(assert) {
- assert.expect(4);
- var object = { 'a': stubOne };
- lodashStable.each(['a', ['a']], function(path) {
- var method = _.method(path);
- assert.strictEqual(method.length, 1);
- assert.strictEqual(method(object), 1);
- });
- });
- QUnit.test('should work with deep property values', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': stubTwo } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var method = _.method(path);
- assert.strictEqual(method(object), 2);
- });
- });
- QUnit.test('should work with a non-string `path`', function(assert) {
- assert.expect(2);
- var array = lodashStable.times(3, _.constant);
- lodashStable.each([1, [1]], function(path) {
- var method = _.method(path);
- assert.strictEqual(method(array), 1);
- });
- });
- QUnit.test('should coerce key to a string', function(assert) {
- assert.expect(1);
- function fn() {}
- fn.toString = lodashStable.constant('fn');
- var expected = [1, 1, 2, 2, 3, 3, 4, 4],
- objects = [{ 'null': stubOne }, { 'undefined': stubTwo }, { 'fn': stubThree }, { '[object Object]': stubFour }],
- values = [null, undefined, fn, {}];
- var actual = lodashStable.transform(objects, function(result, object, index) {
- var key = values[index];
- lodashStable.each([key, [key]], function(path) {
- var method = _.method(key);
- result.push(method(object));
- });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with inherited property values', function(assert) {
- assert.expect(2);
- function Foo() {}
- Foo.prototype.a = stubOne;
- lodashStable.each(['a', ['a']], function(path) {
- var method = _.method(path);
- assert.strictEqual(method(new Foo), 1);
- });
- });
- QUnit.test('should use a key over a path', function(assert) {
- assert.expect(2);
- var object = { 'a.b': stubOne, 'a': { 'b': stubTwo } };
- lodashStable.each(['a.b', ['a.b']], function(path) {
- var method = _.method(path);
- assert.strictEqual(method(object), 1);
- });
- });
- QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, noop);
- lodashStable.each(['constructor', ['constructor']], function(path) {
- var method = _.method(path);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? method(value) : method();
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, noop);
- lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
- var method = _.method(path);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? method(value) : method();
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
- assert.expect(4);
- var object = {};
- lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
- var method = _.method(path);
- assert.strictEqual(method(object), undefined);
- });
- });
- QUnit.test('should apply partial arguments to function', function(assert) {
- assert.expect(2);
- var object = {
- 'fn': function() {
- return slice.call(arguments);
- }
- };
- lodashStable.each(['fn', ['fn']], function(path) {
- var method = _.method(path, 1, 2, 3);
- assert.deepEqual(method(object), [1, 2, 3]);
- });
- });
- QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var method = _.method(path);
- assert.strictEqual(method(object), 1);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.methodOf');
- (function() {
- QUnit.test('should create a function that calls a method of a given key', function(assert) {
- assert.expect(4);
- var object = { 'a': stubOne };
- lodashStable.each(['a', ['a']], function(path) {
- var methodOf = _.methodOf(object);
- assert.strictEqual(methodOf.length, 1);
- assert.strictEqual(methodOf(path), 1);
- });
- });
- QUnit.test('should work with deep property values', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': stubTwo } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var methodOf = _.methodOf(object);
- assert.strictEqual(methodOf(path), 2);
- });
- });
- QUnit.test('should work with a non-string `path`', function(assert) {
- assert.expect(2);
- var array = lodashStable.times(3, _.constant);
- lodashStable.each([1, [1]], function(path) {
- var methodOf = _.methodOf(array);
- assert.strictEqual(methodOf(path), 1);
- });
- });
- QUnit.test('should coerce key to a string', function(assert) {
- assert.expect(1);
- function fn() {}
- fn.toString = lodashStable.constant('fn');
- var expected = [1, 1, 2, 2, 3, 3, 4, 4],
- objects = [{ 'null': stubOne }, { 'undefined': stubTwo }, { 'fn': stubThree }, { '[object Object]': stubFour }],
- values = [null, undefined, fn, {}];
- var actual = lodashStable.transform(objects, function(result, object, index) {
- var key = values[index];
- lodashStable.each([key, [key]], function(path) {
- var methodOf = _.methodOf(object);
- result.push(methodOf(key));
- });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with inherited property values', function(assert) {
- assert.expect(2);
- function Foo() {}
- Foo.prototype.a = stubOne;
- lodashStable.each(['a', ['a']], function(path) {
- var methodOf = _.methodOf(new Foo);
- assert.strictEqual(methodOf(path), 1);
- });
- });
- QUnit.test('should use a key over a path', function(assert) {
- assert.expect(2);
- var object = { 'a.b': stubOne, 'a': { 'b': stubTwo } };
- lodashStable.each(['a.b', ['a.b']], function(path) {
- var methodOf = _.methodOf(object);
- assert.strictEqual(methodOf(path), 1);
- });
- });
- QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, noop);
- lodashStable.each(['constructor', ['constructor']], function(path) {
- var actual = lodashStable.map(values, function(value, index) {
- var methodOf = index ? _.methodOf() : _.methodOf(value);
- return methodOf(path);
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, noop);
- lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
- var actual = lodashStable.map(values, function(value, index) {
- var methodOf = index ? _.methodOf() : _.methodOf(value);
- return methodOf(path);
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
- assert.expect(4);
- var object = {},
- methodOf = _.methodOf(object);
- lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
- assert.strictEqual(methodOf(path), undefined);
- });
- });
- QUnit.test('should apply partial arguments to function', function(assert) {
- assert.expect(2);
- var object = {
- 'fn': function() {
- return slice.call(arguments);
- }
- };
- var methodOf = _.methodOf(object, 1, 2, 3);
- lodashStable.each(['fn', ['fn']], function(path) {
- assert.deepEqual(methodOf(path), [1, 2, 3]);
- });
- });
- QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } },
- methodOf = _.methodOf(object);
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.strictEqual(methodOf(path), 1);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.min');
- (function() {
- QUnit.test('should return the smallest value from a collection', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.min([1, 2, 3]), 1);
- });
- QUnit.test('should return `undefined` for empty collections', function(assert) {
- assert.expect(1);
- var values = falsey.concat([[]]),
- expected = lodashStable.map(values, noop);
- var actual = lodashStable.map(values, function(value, index) {
- try {
- return index ? _.min(value) : _.min();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with non-numeric collection values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.min(['a', 'b']), 'a');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('extremum methods');
- lodashStable.each(['max', 'maxBy', 'min', 'minBy'], function(methodName) {
- var func = _[methodName],
- isMax = /^max/.test(methodName);
- QUnit.test('`_.' + methodName + '` should work with Date objects', function(assert) {
- assert.expect(1);
- var curr = new Date,
- past = new Date(0);
- assert.strictEqual(func([curr, past]), isMax ? curr : past);
- });
- QUnit.test('`_.' + methodName + '` should work with extremely large arrays', function(assert) {
- assert.expect(1);
- var array = lodashStable.range(0, 5e5);
- assert.strictEqual(func(array), isMax ? 499999 : 0);
- });
- QUnit.test('`_.' + methodName + '` should work when chaining on an array with only one value', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = _([40])[methodName]();
- assert.strictEqual(actual, 40);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- lodashStable.each(['maxBy', 'minBy'], function(methodName) {
- var array = [1, 2, 3],
- func = _[methodName],
- isMax = methodName == 'maxBy';
- QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
- assert.expect(1);
- var actual = func(array, function(n) {
- return -n;
- });
- assert.strictEqual(actual, isMax ? 1 : 3);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(2);
- var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }],
- actual = func(objects, 'a');
- assert.deepEqual(actual, objects[isMax ? 1 : 2]);
- var arrays = [[2], [3], [1]];
- actual = func(arrays, 0);
- assert.deepEqual(actual, arrays[isMax ? 1 : 2]);
- });
- QUnit.test('`_.' + methodName + '` should work when `iteratee` returns +/-Infinity', function(assert) {
- assert.expect(1);
- var value = isMax ? -Infinity : Infinity,
- object = { 'a': value };
- var actual = func([object, { 'a': value }], function(object) {
- return object.a;
- });
- assert.strictEqual(actual, object);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.mixin');
- (function() {
- function reset(wrapper) {
- delete wrapper.a;
- delete wrapper.prototype.a;
- delete wrapper.b;
- delete wrapper.prototype.b;
- }
- function Wrapper(value) {
- if (!(this instanceof Wrapper)) {
- return new Wrapper(value);
- }
- if (_.has(value, '__wrapped__')) {
- var actions = slice.call(value.__actions__),
- chain = value.__chain__;
- value = value.__wrapped__;
- }
- this.__wrapped__ = value;
- this.__actions__ = actions || [];
- this.__chain__ = chain || false;
- }
- Wrapper.prototype.value = function() {
- return getUnwrappedValue(this);
- };
- var array = ['a'],
- source = { 'a': function(array) { return array[0]; }, 'b': 'B' };
- QUnit.test('should mixin `source` methods into lodash', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- _.mixin(source);
- assert.strictEqual(_.a(array), 'a');
- assert.strictEqual(_(array).a().value(), 'a');
- assert.notOk('b' in _);
- assert.notOk('b' in _.prototype);
- reset(_);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should mixin chaining methods by reference', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- _.mixin(source);
- _.a = stubB;
- assert.strictEqual(_.a(array), 'b');
- assert.strictEqual(_(array).a().value(), 'a');
- reset(_);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should use a default `object` of `this`', function(assert) {
- assert.expect(3);
- var object = lodashStable.create(_);
- object.mixin(source);
- assert.strictEqual(object.a(array), 'a');
- assert.notOk('a' in _);
- assert.notOk('a' in _.prototype);
- reset(_);
- });
- QUnit.test('should accept an `object` argument', function(assert) {
- assert.expect(1);
- var object = {};
- _.mixin(object, source);
- assert.strictEqual(object.a(array), 'a');
- });
- QUnit.test('should accept a function `object`', function(assert) {
- assert.expect(2);
- _.mixin(Wrapper, source);
- var wrapped = Wrapper(array),
- actual = wrapped.a();
- assert.strictEqual(actual.value(), 'a');
- assert.ok(actual instanceof Wrapper);
- reset(Wrapper);
- });
- QUnit.test('should return `object`', function(assert) {
- assert.expect(3);
- var object = {};
- assert.strictEqual(_.mixin(object, source), object);
- assert.strictEqual(_.mixin(Wrapper, source), Wrapper);
- assert.strictEqual(_.mixin(), _);
- reset(Wrapper);
- });
- QUnit.test('should not assign inherited `source` methods', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.prototype.a = noop;
- var object = {};
- assert.strictEqual(_.mixin(object, new Foo), object);
- });
- QUnit.test('should accept an `options` argument', function(assert) {
- assert.expect(8);
- function message(func, chain) {
- return (func === _ ? 'lodash' : 'given') + ' function should ' + (chain ? '' : 'not ') + 'chain';
- }
- lodashStable.each([_, Wrapper], function(func) {
- lodashStable.each([{ 'chain': false }, { 'chain': true }], function(options) {
- if (!isNpm) {
- if (func === _) {
- _.mixin(source, options);
- } else {
- _.mixin(func, source, options);
- }
- var wrapped = func(array),
- actual = wrapped.a();
- if (options.chain) {
- assert.strictEqual(actual.value(), 'a', message(func, true));
- assert.ok(actual instanceof func, message(func, true));
- } else {
- assert.strictEqual(actual, 'a', message(func, false));
- assert.notOk(actual instanceof func, message(func, false));
- }
- reset(func);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- });
- });
- QUnit.test('should not extend lodash when an `object` is given with an empty `options` object', function(assert) {
- assert.expect(1);
- _.mixin({ 'a': noop }, {});
- assert.notOk('a' in _);
- reset(_);
- });
- QUnit.test('should not error for non-object `options` values', function(assert) {
- assert.expect(2);
- var pass = true;
- try {
- _.mixin({}, source, 1);
- } catch (e) {
- pass = false;
- }
- assert.ok(pass);
- pass = true;
- try {
- _.mixin(source, 1);
- } catch (e) {
- pass = false;
- }
- assert.ok(pass);
- reset(_);
- });
- QUnit.test('should not return the existing wrapped value when chaining', function(assert) {
- assert.expect(2);
- lodashStable.each([_, Wrapper], function(func) {
- if (!isNpm) {
- if (func === _) {
- var wrapped = _(source),
- actual = wrapped.mixin();
- assert.strictEqual(actual.value(), _);
- }
- else {
- wrapped = _(func);
- actual = wrapped.mixin(source);
- assert.notStrictEqual(actual, wrapped);
- }
- reset(func);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- QUnit.test('should produce methods that work in a lazy sequence', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- _.mixin({ 'a': _.countBy, 'b': _.filter });
- var array = lodashStable.range(LARGE_ARRAY_SIZE),
- actual = _(array).a().map(square).b(isEven).take().value();
- assert.deepEqual(actual, _.take(_.b(_.map(_.a(array), square), isEven)));
- reset(_);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.multiply');
- (function() {
- QUnit.test('should multiply two numbers', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.multiply(6, 4), 24);
- assert.strictEqual(_.multiply(-6, 4), -24);
- assert.strictEqual(_.multiply(-6, -4), 24);
- });
- QUnit.test('should coerce arguments to numbers', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.multiply('6', '4'), 24);
- assert.deepEqual(_.multiply('x', 'y'), NaN);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.orderBy');
- (function() {
- var objects = [
- { 'a': 'x', 'b': 3 },
- { 'a': 'y', 'b': 4 },
- { 'a': 'x', 'b': 1 },
- { 'a': 'y', 'b': 2 }
- ];
- QUnit.test('should sort by a single property by a specified order', function(assert) {
- assert.expect(1);
- var actual = _.orderBy(objects, 'a', 'desc');
- assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
- });
- QUnit.test('should sort by multiple properties by specified orders', function(assert) {
- assert.expect(1);
- var actual = _.orderBy(objects, ['a', 'b'], ['desc', 'asc']);
- assert.deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
- });
- QUnit.test('should sort by a property in ascending order when its order is not specified', function(assert) {
- assert.expect(2);
- var expected = [objects[2], objects[0], objects[3], objects[1]],
- actual = _.orderBy(objects, ['a', 'b']);
- assert.deepEqual(actual, expected);
- expected = lodashStable.map(falsey, lodashStable.constant([objects[3], objects[1], objects[2], objects[0]]));
- actual = lodashStable.map(falsey, function(order, index) {
- return _.orderBy(objects, ['a', 'b'], index ? ['desc', order] : ['desc']);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with `orders` specified as string objects', function(assert) {
- assert.expect(1);
- var actual = _.orderBy(objects, ['a'], [Object('desc')]);
- assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.overArgs');
- (function() {
- function fn() {
- return slice.call(arguments);
- }
- QUnit.test('should transform each argument', function(assert) {
- assert.expect(1);
- var over = _.overArgs(fn, doubled, square);
- assert.deepEqual(over(5, 10), [10, 100]);
- });
- QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
- assert.expect(1);
- var over = _.overArgs(fn, undefined, null);
- assert.deepEqual(over('a', 'b'), ['a', 'b']);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var over = _.overArgs(fn, 'b', 'a');
- assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [2, 1]);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(1);
- var over = _.overArgs(fn, { 'b': 1 }, { 'a': 1 });
- assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [false, true]);
- });
- QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(1);
- var over = _.overArgs(fn, [['b', 1], ['a', 1]]);
- assert.deepEqual(over({ 'b': 2 }, { 'a': 1 }), [false, true]);
- });
- QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
- assert.expect(2);
- var over = _.overArgs(fn, ['a', 1]);
- assert.deepEqual(over({ 'a': 1 }, { '1': 2 }), [1, 2]);
- over = _.overArgs(fn, [['a', 1]]);
- assert.deepEqual(over({ 'a': 1 }), [true]);
- });
- QUnit.test('should flatten `transforms`', function(assert) {
- assert.expect(1);
- var over = _.overArgs(fn, [doubled, square], String);
- assert.deepEqual(over(5, 10, 15), [10, 100, '15']);
- });
- QUnit.test('should not transform any argument greater than the number of transforms', function(assert) {
- assert.expect(1);
- var over = _.overArgs(fn, doubled, square);
- assert.deepEqual(over(5, 10, 18), [10, 100, 18]);
- });
- QUnit.test('should not transform any arguments if no transforms are given', function(assert) {
- assert.expect(1);
- var over = _.overArgs(fn);
- assert.deepEqual(over(5, 10, 18), [5, 10, 18]);
- });
- QUnit.test('should not pass `undefined` if there are more transforms than arguments', function(assert) {
- assert.expect(1);
- var over = _.overArgs(fn, doubled, identity);
- assert.deepEqual(over(5), [10]);
- });
- QUnit.test('should provide the correct argument to each transform', function(assert) {
- assert.expect(1);
- var argsList = [],
- transform = function() { argsList.push(slice.call(arguments)); },
- over = _.overArgs(noop, transform, transform, transform);
- over('a', 'b');
- assert.deepEqual(argsList, [['a'], ['b']]);
- });
- QUnit.test('should use `this` binding of function for `transforms`', function(assert) {
- assert.expect(1);
- var over = _.overArgs(function(x) {
- return this[x];
- }, function(x) {
- return this === x;
- });
- var object = { 'over': over, 'true': 1 };
- assert.strictEqual(object.over(object), 1);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.negate');
- (function() {
- QUnit.test('should create a function that negates the result of `func`', function(assert) {
- assert.expect(2);
- var negate = _.negate(isEven);
- assert.strictEqual(negate(1), true);
- assert.strictEqual(negate(2), false);
- });
- QUnit.test('should create a function that negates the result of `func`', function(assert) {
- assert.expect(2);
- var negate = _.negate(isEven);
- assert.strictEqual(negate(1), true);
- assert.strictEqual(negate(2), false);
- });
- QUnit.test('should create a function that accepts multiple arguments', function(assert) {
- assert.expect(1);
- var argCount,
- count = 4,
- negate = _.negate(function() { argCount = arguments.length; }),
- expected = lodashStable.times(count, stubTrue);
- var actual = lodashStable.times(count, function(index) {
- switch (index) {
- case 0: negate(); break;
- case 1: negate(1); break;
- case 2: negate(1, 2); break;
- case 3: negate(1, 2, 3); break;
- case 4: negate(1, 2, 3, 4);
- }
- return argCount == index;
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.noConflict');
- (function() {
- QUnit.test('should return the `lodash` function', function(assert) {
- assert.expect(2);
- if (!isModularize) {
- assert.strictEqual(_.noConflict(), oldDash);
- assert.notStrictEqual(root._, oldDash);
- root._ = oldDash;
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should restore `_` only if `lodash` is the current `_` value', function(assert) {
- assert.expect(2);
- if (!isModularize) {
- var object = root._ = {};
- assert.strictEqual(_.noConflict(), oldDash);
- assert.strictEqual(root._, object);
- root._ = oldDash;
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should work with a `root` of `this`', function(assert) {
- assert.expect(2);
- if (!coverage && !document && !isModularize && realm.object) {
- var fs = require('fs'),
- vm = require('vm'),
- expected = {},
- context = vm.createContext({ '_': expected, 'console': console }),
- source = fs.readFileSync(filePath, 'utf8');
- vm.runInContext(source + '\nthis.lodash = this._.noConflict()', context);
- assert.strictEqual(context._, expected);
- assert.ok(context.lodash);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.now');
- (function() {
- QUnit.test('should return the number of milliseconds that have elapsed since the Unix epoch', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var stamp = +new Date,
- actual = _.now();
- assert.ok(actual >= stamp);
- setTimeout(function() {
- assert.ok(_.now() > actual);
- done();
- }, 32);
- });
- QUnit.test('should work with mocked `Date.now`', function(assert) {
- assert.expect(1);
- var now = Date.now;
- Date.now = stubA;
- var actual = _.now();
- Date.now = now;
- assert.strictEqual(actual, 'a');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.nth');
- (function() {
- var array = ['a', 'b', 'c', 'd'];
- QUnit.test('should get the nth element of `array`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(array, function(value, index) {
- return _.nth(array, index);
- });
- assert.deepEqual(actual, array);
- });
- QUnit.test('should work with a negative `n`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(lodashStable.range(1, array.length + 1), function(n) {
- return _.nth(array, -n);
- });
- assert.deepEqual(actual, ['d', 'c', 'b', 'a']);
- });
- QUnit.test('should coerce `n` to an integer', function(assert) {
- assert.expect(2);
- var values = falsey,
- expected = lodashStable.map(values, stubA);
- var actual = lodashStable.map(values, function(n) {
- return n ? _.nth(array, n) : _.nth(array);
- });
- assert.deepEqual(actual, expected);
- values = ['1', 1.6];
- expected = lodashStable.map(values, stubB);
- actual = lodashStable.map(values, function(n) {
- return _.nth(array, n);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `undefined` for empty arrays', function(assert) {
- assert.expect(1);
- var values = [null, undefined, []],
- expected = lodashStable.map(values, noop);
- var actual = lodashStable.map(values, function(array) {
- return _.nth(array, 1);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `undefined` for non-indexes', function(assert) {
- assert.expect(1);
- var array = [1, 2],
- values = [Infinity, array.length],
- expected = lodashStable.map(values, noop);
- array[-1] = 3;
- var actual = lodashStable.map(values, function(n) {
- return _.nth(array, n);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.nthArg');
- (function() {
- var args = ['a', 'b', 'c', 'd'];
- QUnit.test('should create a function that returns its nth argument', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(args, function(value, index) {
- var func = _.nthArg(index);
- return func.apply(undefined, args);
- });
- assert.deepEqual(actual, args);
- });
- QUnit.test('should work with a negative `n`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(lodashStable.range(1, args.length + 1), function(n) {
- var func = _.nthArg(-n);
- return func.apply(undefined, args);
- });
- assert.deepEqual(actual, ['d', 'c', 'b', 'a']);
- });
- QUnit.test('should coerce `n` to an integer', function(assert) {
- assert.expect(2);
- var values = falsey,
- expected = lodashStable.map(values, stubA);
- var actual = lodashStable.map(values, function(n) {
- var func = n ? _.nthArg(n) : _.nthArg();
- return func.apply(undefined, args);
- });
- assert.deepEqual(actual, expected);
- values = ['1', 1.6];
- expected = lodashStable.map(values, stubB);
- actual = lodashStable.map(values, function(n) {
- var func = _.nthArg(n);
- return func.apply(undefined, args);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `undefined` for empty arrays', function(assert) {
- assert.expect(1);
- var func = _.nthArg(1);
- assert.strictEqual(func(), undefined);
- });
- QUnit.test('should return `undefined` for non-indexes', function(assert) {
- assert.expect(1);
- var values = [Infinity, args.length],
- expected = lodashStable.map(values, noop);
- var actual = lodashStable.map(values, function(n) {
- var func = _.nthArg(n);
- return func.apply(undefined, args);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.omit');
- (function() {
- var args = arguments,
- object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
- QUnit.test('should flatten `props`', function(assert) {
- assert.expect(2);
- assert.deepEqual(_.omit(object, 'a', 'c'), { 'b': 2, 'd': 4 });
- assert.deepEqual(_.omit(object, ['a', 'd'], 'c'), { 'b': 2 });
- });
- QUnit.test('should work with a primitive `object` argument', function(assert) {
- assert.expect(1);
- stringProto.a = 1;
- stringProto.b = 2;
- assert.deepEqual(_.omit('', 'b'), { 'a': 1 });
- delete stringProto.a;
- delete stringProto.b;
- });
- QUnit.test('should return an empty object when `object` is nullish', function(assert) {
- assert.expect(2);
- lodashStable.each([null, undefined], function(value) {
- objectProto.a = 1;
- var actual = _.omit(value, 'valueOf');
- delete objectProto.a;
- assert.deepEqual(actual, {});
- });
- });
- QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.omit(object, args), { 'b': 2, 'd': 4 });
- });
- QUnit.test('should coerce property names to strings', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.omit({ '0': 'a' }, 0), {});
- });
- }('a', 'c'));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.omitBy');
- (function() {
- QUnit.test('should work with a predicate argument', function(assert) {
- assert.expect(1);
- var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
- var actual = _.omitBy(object, function(n) {
- return n != 2 && n != 4;
- });
- assert.deepEqual(actual, { 'b': 2, 'd': 4 });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('omit methods');
- lodashStable.each(['omit', 'omitBy'], function(methodName) {
- var expected = { 'b': 2, 'd': 4 },
- func = _[methodName],
- object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
- resolve = lodashStable.nthArg(1);
- if (methodName == 'omitBy') {
- resolve = function(object, props) {
- props = lodashStable.castArray(props);
- return function(value) {
- return lodashStable.some(props, function(key) {
- key = lodashStable.isSymbol(key) ? key : lodashStable.toString(key);
- return object[key] === value;
- });
- };
- };
- }
- QUnit.test('`_.' + methodName + '` should create an object with omitted string keyed properties', function(assert) {
- assert.expect(2);
- assert.deepEqual(func(object, resolve(object, 'a')), { 'b': 2, 'c': 3, 'd': 4 });
- assert.deepEqual(func(object, resolve(object, ['a', 'c'])), expected);
- });
- QUnit.test('`_.' + methodName + '` should include inherited string keyed properties', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.prototype = object;
- assert.deepEqual(func(new Foo, resolve(object, ['a', 'c'])), expected);
- });
- QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var object = { '-0': 'a', '0': 'b' },
- props = [-0, Object(-0), 0, Object(0)],
- expected = [{ '0': 'b' }, { '0': 'b' }, { '-0': 'a' }, { '-0': 'a' }];
- var actual = lodashStable.map(props, function(key) {
- return func(object, resolve(object, key));
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should include symbol properties', function(assert) {
- assert.expect(2);
- function Foo() {
- this.a = 0;
- this[symbol] = 1;
- }
- if (Symbol) {
- var symbol2 = Symbol('b');
- Foo.prototype[symbol2] = 2;
- var foo = new Foo,
- actual = func(foo, resolve(foo, 'a'));
- assert.strictEqual(actual[symbol], 1);
- assert.strictEqual(actual[symbol2], 2);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('`_.' + methodName + '` should create an object with omitted symbol properties', function(assert) {
- assert.expect(6);
- function Foo() {
- this.a = 0;
- this[symbol] = 1;
- }
- if (Symbol) {
- var symbol2 = Symbol('b');
- Foo.prototype[symbol2] = 2;
- var foo = new Foo,
- actual = func(foo, resolve(foo, symbol));
- assert.strictEqual(actual.a, 0);
- assert.strictEqual(actual[symbol], undefined);
- assert.strictEqual(actual[symbol2], 2);
- actual = func(foo, resolve(foo, symbol2));
- assert.strictEqual(actual.a, 0);
- assert.strictEqual(actual[symbol], 1);
- assert.strictEqual(actual[symbol2], undefined);
- }
- else {
- skipAssert(assert, 6);
- }
- });
- QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- assert.deepEqual(func(array, resolve(array, ['0', '2'])), { '1': 2 });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.once');
- (function() {
- QUnit.test('should invoke `func` once', function(assert) {
- assert.expect(2);
- var count = 0,
- once = _.once(function() { return ++count; });
- once();
- assert.strictEqual(once(), 1);
- assert.strictEqual(count, 1);
- });
- QUnit.test('should ignore recursive calls', function(assert) {
- assert.expect(2);
- var count = 0;
- var once = _.once(function() {
- once();
- return ++count;
- });
- assert.strictEqual(once(), 1);
- assert.strictEqual(count, 1);
- });
- QUnit.test('should not throw more than once', function(assert) {
- assert.expect(2);
- var pass = true;
- var once = _.once(function() {
- throw new Error;
- });
- assert.raises(once);
- try {
- once();
- } catch (e) {
- pass = false;
- }
- assert.ok(pass);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.over');
- (function() {
- QUnit.test('should create a function that invokes `iteratees`', function(assert) {
- assert.expect(1);
- var over = _.over(Math.max, Math.min);
- assert.deepEqual(over(1, 2, 3, 4), [4, 1]);
- });
- QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
- assert.expect(1);
- var over = _.over(undefined, null);
- assert.deepEqual(over('a', 'b', 'c'), ['a', 'a']);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var over = _.over('b', 'a');
- assert.deepEqual(over({ 'a': 1, 'b': 2 }), [2, 1]);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(1);
- var over = _.over({ 'b': 1 }, { 'a': 1 });
- assert.deepEqual(over({ 'a': 1, 'b': 2 }), [false, true]);
- });
- QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(2);
- var over = _.over([['b', 2], ['a', 2]]);
- assert.deepEqual(over({ 'a': 1, 'b': 2 }), [true, false]);
- assert.deepEqual(over({ 'a': 2, 'b': 1 }), [false, true]);
- });
- QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
- assert.expect(4);
- var over = _.over(['a', 1]);
- assert.deepEqual(over({ 'a': 1, '1': 2 }), [1, 2]);
- assert.deepEqual(over({ 'a': 2, '1': 1 }), [2, 1]);
- over = _.over([['a', 1]]);
- assert.deepEqual(over({ 'a': 1 }), [true]);
- assert.deepEqual(over({ 'a': 2 }), [false]);
- });
- QUnit.test('should provide arguments to predicates', function(assert) {
- assert.expect(1);
- var over = _.over(function() {
- return slice.call(arguments);
- });
- assert.deepEqual(over('a', 'b', 'c'), [['a', 'b', 'c']]);
- });
- QUnit.test('should use `this` binding of function for `iteratees`', function(assert) {
- assert.expect(1);
- var over = _.over(function() { return this.b; }, function() { return this.a; }),
- object = { 'over': over, 'a': 1, 'b': 2 };
- assert.deepEqual(object.over(), [2, 1]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.overEvery');
- (function() {
- QUnit.test('should create a function that returns `true` if all predicates return truthy', function(assert) {
- assert.expect(1);
- var over = _.overEvery(stubTrue, stubOne, stubA);
- assert.strictEqual(over(), true);
- });
- QUnit.test('should return `false` as soon as a predicate returns falsey', function(assert) {
- assert.expect(2);
- var count = 0,
- countFalse = function() { count++; return false; },
- countTrue = function() { count++; return true; },
- over = _.overEvery(countTrue, countFalse, countTrue);
- assert.strictEqual(over(), false);
- assert.strictEqual(count, 2);
- });
- QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
- assert.expect(2);
- var over = _.overEvery(undefined, null);
- assert.strictEqual(over(true), true);
- assert.strictEqual(over(false), false);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(2);
- var over = _.overEvery('b', 'a');
- assert.strictEqual(over({ 'a': 1, 'b': 1 }), true);
- assert.strictEqual(over({ 'a': 0, 'b': 1 }), false);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(2);
- var over = _.overEvery({ 'b': 2 }, { 'a': 1 });
- assert.strictEqual(over({ 'a': 1, 'b': 2 }), true);
- assert.strictEqual(over({ 'a': 0, 'b': 2 }), false);
- });
- QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(2);
- var over = _.overEvery([['b', 2], ['a', 1]]);
- assert.strictEqual(over({ 'a': 1, 'b': 2 }), true);
- assert.strictEqual(over({ 'a': 0, 'b': 2 }), false);
- });
- QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
- assert.expect(5);
- var over = _.overEvery(['a', 1]);
- assert.strictEqual(over({ 'a': 1, '1': 1 }), true);
- assert.strictEqual(over({ 'a': 1, '1': 0 }), false);
- assert.strictEqual(over({ 'a': 0, '1': 1 }), false);
- over = _.overEvery([['a', 1]]);
- assert.strictEqual(over({ 'a': 1 }), true);
- assert.strictEqual(over({ 'a': 2 }), false);
- });
- QUnit.test('should flatten `predicates`', function(assert) {
- assert.expect(1);
- var over = _.overEvery(stubTrue, [stubFalse]);
- assert.strictEqual(over(), false);
- });
- QUnit.test('should provide arguments to predicates', function(assert) {
- assert.expect(1);
- var args;
- var over = _.overEvery(function() {
- args = slice.call(arguments);
- });
- over('a', 'b', 'c');
- assert.deepEqual(args, ['a', 'b', 'c']);
- });
- QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
- assert.expect(2);
- var over = _.overEvery(function() { return this.b; }, function() { return this.a; }),
- object = { 'over': over, 'a': 1, 'b': 2 };
- assert.strictEqual(object.over(), true);
- object.a = 0;
- assert.strictEqual(object.over(), false);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.overSome');
- (function() {
- QUnit.test('should create a function that returns `true` if any predicates return truthy', function(assert) {
- assert.expect(2);
- var over = _.overSome(stubFalse, stubOne, stubString);
- assert.strictEqual(over(), true);
- over = _.overSome(stubNull, stubA, stubZero);
- assert.strictEqual(over(), true);
- });
- QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
- assert.expect(2);
- var count = 0,
- countFalse = function() { count++; return false; },
- countTrue = function() { count++; return true; },
- over = _.overSome(countFalse, countTrue, countFalse);
- assert.strictEqual(over(), true);
- assert.strictEqual(count, 2);
- });
- QUnit.test('should return `false` if all predicates return falsey', function(assert) {
- assert.expect(2);
- var over = _.overSome(stubFalse, stubFalse, stubFalse);
- assert.strictEqual(over(), false);
- over = _.overSome(stubNull, stubZero, stubString);
- assert.strictEqual(over(), false);
- });
- QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) {
- assert.expect(2);
- var over = _.overSome(undefined, null);
- assert.strictEqual(over(true), true);
- assert.strictEqual(over(false), false);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(2);
- var over = _.overSome('b', 'a');
- assert.strictEqual(over({ 'a': 1, 'b': 0 }), true);
- assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(2);
- var over = _.overSome({ 'b': 2 }, { 'a': 1 });
- assert.strictEqual(over({ 'a': 0, 'b': 2 }), true);
- assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
- });
- QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(2);
- var over = _.overSome([['b', 2], ['a', 1]]);
- assert.strictEqual(over({ 'a': 0, 'b': 2 }), true);
- assert.strictEqual(over({ 'a': 0, 'b': 0 }), false);
- });
- QUnit.test('should differentiate between `_.property` and `_.matchesProperty` shorthands', function(assert) {
- assert.expect(5);
- var over = _.overSome(['a', 1]);
- assert.strictEqual(over({ 'a': 0, '1': 0 }), false);
- assert.strictEqual(over({ 'a': 1, '1': 0 }), true);
- assert.strictEqual(over({ 'a': 0, '1': 1 }), true);
- over = _.overSome([['a', 1]]);
- assert.strictEqual(over({ 'a': 1 }), true);
- assert.strictEqual(over({ 'a': 2 }), false);
- });
- QUnit.test('should flatten `predicates`', function(assert) {
- assert.expect(1);
- var over = _.overSome(stubFalse, [stubTrue]);
- assert.strictEqual(over(), true);
- });
- QUnit.test('should provide arguments to predicates', function(assert) {
- assert.expect(1);
- var args;
- var over = _.overSome(function() {
- args = slice.call(arguments);
- });
- over('a', 'b', 'c');
- assert.deepEqual(args, ['a', 'b', 'c']);
- });
- QUnit.test('should use `this` binding of function for `predicates`', function(assert) {
- assert.expect(2);
- var over = _.overSome(function() { return this.b; }, function() { return this.a; }),
- object = { 'over': over, 'a': 1, 'b': 2 };
- assert.strictEqual(object.over(), true);
- object.a = object.b = 0;
- assert.strictEqual(object.over(), false);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.pad');
- (function() {
- var string = 'abc';
- QUnit.test('should pad a string to a given length', function(assert) {
- assert.expect(1);
- var values = [, undefined],
- expected = lodashStable.map(values, lodashStable.constant(' abc '));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.pad(string, 6, value) : _.pad(string, 6);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.pad(string, 8), ' abc ');
- assert.strictEqual(_.pad(string, 8, '_-'), '_-abc_-_');
- });
- QUnit.test('should coerce `string` to a string', function(assert) {
- assert.expect(1);
- var values = [Object(string), { 'toString': lodashStable.constant(string) }],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value) {
- return _.pad(value, 6) === ' abc ';
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.padEnd');
- (function() {
- var string = 'abc';
- QUnit.test('should pad a string to a given length', function(assert) {
- assert.expect(1);
- var values = [, undefined],
- expected = lodashStable.map(values, lodashStable.constant('abc '));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.padEnd(string, 6, value) : _.padEnd(string, 6);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.padEnd(string, 6, '_-'), 'abc_-_');
- });
- QUnit.test('should coerce `string` to a string', function(assert) {
- assert.expect(1);
- var values = [Object(string), { 'toString': lodashStable.constant(string) }],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value) {
- return _.padEnd(value, 6) === 'abc ';
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.padStart');
- (function() {
- var string = 'abc';
- QUnit.test('should pad a string to a given length', function(assert) {
- assert.expect(1);
- var values = [, undefined],
- expected = lodashStable.map(values, lodashStable.constant(' abc'));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.padStart(string, 6, value) : _.padStart(string, 6);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should truncate pad characters to fit the pad length', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.padStart(string, 6, '_-'), '_-_abc');
- });
- QUnit.test('should coerce `string` to a string', function(assert) {
- assert.expect(1);
- var values = [Object(string), { 'toString': lodashStable.constant(string) }],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value) {
- return _.padStart(value, 6) === ' abc';
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('pad methods');
- lodashStable.each(['pad', 'padStart', 'padEnd'], function(methodName) {
- var func = _[methodName],
- isPad = methodName == 'pad',
- isStart = methodName == 'padStart',
- string = 'abc';
- QUnit.test('`_.' + methodName + '` should not pad if string is >= `length`', function(assert) {
- assert.expect(2);
- assert.strictEqual(func(string, 2), string);
- assert.strictEqual(func(string, 3), string);
- });
- QUnit.test('`_.' + methodName + '` should treat negative `length` as `0`', function(assert) {
- assert.expect(2);
- lodashStable.each([0, -2], function(length) {
- assert.strictEqual(func(string, length), string);
- });
- });
- QUnit.test('`_.' + methodName + '` should coerce `length` to a number', function(assert) {
- assert.expect(2);
- lodashStable.each(['', '4'], function(length) {
- var actual = length ? (isStart ? ' abc' : 'abc ') : string;
- assert.strictEqual(func(string, length), actual);
- });
- });
- QUnit.test('`_.' + methodName + '` should treat nullish values as empty strings', function(assert) {
- assert.expect(6);
- lodashStable.each([undefined, '_-'], function(chars) {
- var expected = chars ? (isPad ? '__' : chars) : ' ';
- assert.strictEqual(func(null, 2, chars), expected);
- assert.strictEqual(func(undefined, 2, chars), expected);
- assert.strictEqual(func('', 2, chars), expected);
- });
- });
- QUnit.test('`_.' + methodName + '` should return `string` when `chars` coerces to an empty string', function(assert) {
- assert.expect(1);
- var values = ['', Object('')],
- expected = lodashStable.map(values, lodashStable.constant(string));
- var actual = lodashStable.map(values, function(value) {
- return _.pad(string, 6, value);
- });
- assert.deepEqual(actual, expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.parseInt');
- (function() {
- QUnit.test('should accept a `radix` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.range(2, 37);
- var actual = lodashStable.map(expected, function(radix) {
- return _.parseInt('10', radix);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should use a radix of `10`, for non-hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
- assert.expect(4);
- assert.strictEqual(_.parseInt('10'), 10);
- assert.strictEqual(_.parseInt('10', 0), 10);
- assert.strictEqual(_.parseInt('10', 10), 10);
- assert.strictEqual(_.parseInt('10', undefined), 10);
- });
- QUnit.test('should use a radix of `16`, for hexadecimals, if `radix` is `undefined` or `0`', function(assert) {
- assert.expect(8);
- lodashStable.each(['0x20', '0X20'], function(string) {
- assert.strictEqual(_.parseInt(string), 32);
- assert.strictEqual(_.parseInt(string, 0), 32);
- assert.strictEqual(_.parseInt(string, 16), 32);
- assert.strictEqual(_.parseInt(string, undefined), 32);
- });
- });
- QUnit.test('should use a radix of `10` for string with leading zeros', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.parseInt('08'), 8);
- assert.strictEqual(_.parseInt('08', 10), 8);
- });
- QUnit.test('should parse strings with leading whitespace (test in Chrome and Firefox)', function(assert) {
- assert.expect(2);
- var expected = [8, 8, 10, 10, 32, 32, 32, 32];
- lodashStable.times(2, function(index) {
- var actual = [],
- func = (index ? (lodashBizarro || {}) : _).parseInt;
- if (func) {
- lodashStable.times(2, function(otherIndex) {
- var string = otherIndex ? '10' : '08';
- actual.push(
- func(whitespace + string, 10),
- func(whitespace + string)
- );
- });
- lodashStable.each(['0x20', '0X20'], function(string) {
- actual.push(
- func(whitespace + string),
- func(whitespace + string, 16)
- );
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- QUnit.test('should coerce `radix` to a number', function(assert) {
- assert.expect(2);
- var object = { 'valueOf': stubZero };
- assert.strictEqual(_.parseInt('08', object), 8);
- assert.strictEqual(_.parseInt('0x20', object), 32);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(2);
- var strings = lodashStable.map(['6', '08', '10'], Object),
- actual = lodashStable.map(strings, _.parseInt);
- assert.deepEqual(actual, [6, 8, 10]);
- actual = lodashStable.map('123', _.parseInt);
- assert.deepEqual(actual, [1, 2, 3]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('partial methods');
- lodashStable.each(['partial', 'partialRight'], function(methodName) {
- var func = _[methodName],
- isPartial = methodName == 'partial',
- ph = func.placeholder;
- QUnit.test('`_.' + methodName + '` partially applies arguments', function(assert) {
- assert.expect(1);
- var par = func(identity, 'a');
- assert.strictEqual(par(), 'a');
- });
- QUnit.test('`_.' + methodName + '` creates a function that can be invoked with additional arguments', function(assert) {
- assert.expect(1);
- var fn = function(a, b) { return [a, b]; },
- par = func(fn, 'a'),
- expected = isPartial ? ['a', 'b'] : ['b', 'a'];
- assert.deepEqual(par('b'), expected);
- });
- QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked without additional arguments', function(assert) {
- assert.expect(1);
- var fn = function() { return arguments.length; },
- par = func(fn);
- assert.strictEqual(par(), 0);
- });
- QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked with additional arguments', function(assert) {
- assert.expect(1);
- var par = func(identity);
- assert.strictEqual(par('a'), 'a');
- });
- QUnit.test('`_.' + methodName + '` should support placeholders', function(assert) {
- assert.expect(4);
- var fn = function() { return slice.call(arguments); },
- par = func(fn, ph, 'b', ph);
- assert.deepEqual(par('a', 'c'), ['a', 'b', 'c']);
- assert.deepEqual(par('a'), ['a', 'b', undefined]);
- assert.deepEqual(par(), [undefined, 'b', undefined]);
- if (isPartial) {
- assert.deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
- } else {
- par = func(fn, ph, 'c', ph);
- assert.deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
- }
- });
- QUnit.test('`_.' + methodName + '` should use `_.placeholder` when set', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var _ph = _.placeholder = {},
- fn = function() { return slice.call(arguments); },
- par = func(fn, _ph, 'b', ph),
- expected = isPartial ? ['a', 'b', ph, 'c'] : ['a', 'c', 'b', ph];
- assert.deepEqual(par('a', 'c'), expected);
- delete _.placeholder;
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` creates a function with a `length` of `0`', function(assert) {
- assert.expect(1);
- var fn = function(a, b, c) {},
- par = func(fn, 'a');
- assert.strictEqual(par.length, 0);
- });
- QUnit.test('`_.' + methodName + '` should ensure `new par` is an instance of `func`', function(assert) {
- assert.expect(2);
- function Foo(value) {
- return value && object;
- }
- var object = {},
- par = func(Foo);
- assert.ok(new par instanceof Foo);
- assert.strictEqual(new par(true), object);
- });
- QUnit.test('`_.' + methodName + '` should clone metadata for created functions', function(assert) {
- assert.expect(3);
- function greet(greeting, name) {
- return greeting + ' ' + name;
- }
- var par1 = func(greet, 'hi'),
- par2 = func(par1, 'barney'),
- par3 = func(par1, 'pebbles');
- assert.strictEqual(par1('fred'), isPartial ? 'hi fred' : 'fred hi');
- assert.strictEqual(par2(), isPartial ? 'hi barney' : 'barney hi');
- assert.strictEqual(par3(), isPartial ? 'hi pebbles' : 'pebbles hi');
- });
- QUnit.test('`_.' + methodName + '` should work with curried functions', function(assert) {
- assert.expect(2);
- var fn = function(a, b, c) { return a + b + c; },
- curried = _.curry(func(fn, 1), 2);
- assert.strictEqual(curried(2, 3), 6);
- assert.strictEqual(curried(2)(3), 6);
- });
- QUnit.test('should work with placeholders and curried functions', function(assert) {
- assert.expect(1);
- var fn = function() { return slice.call(arguments); },
- curried = _.curry(fn),
- par = func(curried, ph, 'b', ph, 'd');
- assert.deepEqual(par('a', 'c'), ['a', 'b', 'c', 'd']);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.partialRight');
- (function() {
- QUnit.test('should work as a deep `_.defaults`', function(assert) {
- assert.expect(1);
- var object = { 'a': { 'b': 2 } },
- source = { 'a': { 'b': 3, 'c': 3 } },
- expected = { 'a': { 'b': 2, 'c': 3 } };
- var defaultsDeep = _.partialRight(_.mergeWith, function deep(value, other) {
- return lodashStable.isObject(value) ? _.mergeWith(value, other, deep) : value;
- });
- assert.deepEqual(defaultsDeep(object, source), expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('methods using `createWrapper`');
- (function() {
- function fn() {
- return slice.call(arguments);
- }
- var ph1 = _.bind.placeholder,
- ph2 = _.bindKey.placeholder,
- ph3 = _.partial.placeholder,
- ph4 = _.partialRight.placeholder;
- QUnit.test('should work with combinations of partial functions', function(assert) {
- assert.expect(1);
- var a = _.partial(fn),
- b = _.partialRight(a, 3),
- c = _.partial(b, 1);
- assert.deepEqual(c(2), [1, 2, 3]);
- });
- QUnit.test('should work with combinations of bound and partial functions', function(assert) {
- assert.expect(3);
- var fn = function() {
- var result = [this.a];
- push.apply(result, arguments);
- return result;
- };
- var expected = [1, 2, 3, 4],
- object = { 'a': 1, 'fn': fn };
- var a = _.bindKey(object, 'fn'),
- b = _.partialRight(a, 4),
- c = _.partial(b, 2);
- assert.deepEqual(c(3), expected);
- a = _.bind(fn, object);
- b = _.partialRight(a, 4);
- c = _.partial(b, 2);
- assert.deepEqual(c(3), expected);
- a = _.partial(fn, 2);
- b = _.bind(a, object);
- c = _.partialRight(b, 4);
- assert.deepEqual(c(3), expected);
- });
- QUnit.test('should ensure `new combo` is an instance of `func`', function(assert) {
- assert.expect(2);
- function Foo(a, b, c) {
- return b === 0 && object;
- }
- var combo = _.partial(_.partialRight(Foo, 3), 1),
- object = {};
- assert.ok(new combo(2) instanceof Foo);
- assert.strictEqual(new combo(0), object);
- });
- QUnit.test('should work with combinations of functions with placeholders', function(assert) {
- assert.expect(3);
- var expected = [1, 2, 3, 4, 5, 6],
- object = { 'fn': fn };
- var a = _.bindKey(object, 'fn', ph2, 2),
- b = _.partialRight(a, ph4, 6),
- c = _.partial(b, 1, ph3, 4);
- assert.deepEqual(c(3, 5), expected);
- a = _.bind(fn, object, ph1, 2);
- b = _.partialRight(a, ph4, 6);
- c = _.partial(b, 1, ph3, 4);
- assert.deepEqual(c(3, 5), expected);
- a = _.partial(fn, ph3, 2);
- b = _.bind(a, object, 1, ph1, 4);
- c = _.partialRight(b, ph4, 6);
- assert.deepEqual(c(3, 5), expected);
- });
- QUnit.test('should work with combinations of functions with overlapping placeholders', function(assert) {
- assert.expect(3);
- var expected = [1, 2, 3, 4],
- object = { 'fn': fn };
- var a = _.bindKey(object, 'fn', ph2, 2),
- b = _.partialRight(a, ph4, 4),
- c = _.partial(b, ph3, 3);
- assert.deepEqual(c(1), expected);
- a = _.bind(fn, object, ph1, 2);
- b = _.partialRight(a, ph4, 4);
- c = _.partial(b, ph3, 3);
- assert.deepEqual(c(1), expected);
- a = _.partial(fn, ph3, 2);
- b = _.bind(a, object, ph1, 3);
- c = _.partialRight(b, ph4, 4);
- assert.deepEqual(c(1), expected);
- });
- QUnit.test('should work with recursively bound functions', function(assert) {
- assert.expect(1);
- var fn = function() {
- return this.a;
- };
- var a = _.bind(fn, { 'a': 1 }),
- b = _.bind(a, { 'a': 2 }),
- c = _.bind(b, { 'a': 3 });
- assert.strictEqual(c(), 1);
- });
- QUnit.test('should work when hot', function(assert) {
- assert.expect(12);
- lodashStable.times(2, function(index) {
- var fn = function() {
- var result = [this];
- push.apply(result, arguments);
- return result;
- };
- var object = {},
- bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
- expected = [object, 1, 2, 3];
- var actual = _.last(lodashStable.times(HOT_COUNT, function() {
- var bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
- return index ? bound2(3) : bound2(1, 2, 3);
- }));
- assert.deepEqual(actual, expected);
- actual = _.last(lodashStable.times(HOT_COUNT, function() {
- var bound1 = index ? _.bind(fn, object, 1) : _.bind(fn, object),
- bound2 = index ? _.bind(bound1, null, 2) : _.bind(bound1);
- return index ? bound2(3) : bound2(1, 2, 3);
- }));
- assert.deepEqual(actual, expected);
- });
- lodashStable.each(['curry', 'curryRight'], function(methodName, index) {
- var fn = function(a, b, c) { return [a, b, c]; },
- curried = _[methodName](fn),
- expected = index ? [3, 2, 1] : [1, 2, 3];
- var actual = _.last(lodashStable.times(HOT_COUNT, function() {
- return curried(1)(2)(3);
- }));
- assert.deepEqual(actual, expected);
- actual = _.last(lodashStable.times(HOT_COUNT, function() {
- var curried = _[methodName](fn);
- return curried(1)(2)(3);
- }));
- assert.deepEqual(actual, expected);
- });
- lodashStable.each(['partial', 'partialRight'], function(methodName, index) {
- var func = _[methodName],
- fn = function() { return slice.call(arguments); },
- par1 = func(fn, 1),
- expected = index ? [3, 2, 1] : [1, 2, 3];
- var actual = _.last(lodashStable.times(HOT_COUNT, function() {
- var par2 = func(par1, 2);
- return par2(3);
- }));
- assert.deepEqual(actual, expected);
- actual = _.last(lodashStable.times(HOT_COUNT, function() {
- var par1 = func(fn, 1),
- par2 = func(par1, 2);
- return par2(3);
- }));
- assert.deepEqual(actual, expected);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.partition');
- (function() {
- var array = [1, 0, 1];
- QUnit.test('should split elements into two groups by `predicate`', function(assert) {
- assert.expect(3);
- assert.deepEqual(_.partition([], identity), [[], []]);
- assert.deepEqual(_.partition(array, stubTrue), [array, []]);
- assert.deepEqual(_.partition(array, stubFalse), [[], array]);
- });
- QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant([[1, 1], [0]]));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.partition(array, value) : _.partition(array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }],
- actual = _.partition(objects, 'a');
- assert.deepEqual(actual, [objects.slice(0, 2), objects.slice(2)]);
- });
- QUnit.test('should work with a number for `predicate`', function(assert) {
- assert.expect(2);
- var array = [
- [1, 0],
- [0, 1],
- [1, 0]
- ];
- assert.deepEqual(_.partition(array, 0), [[array[0], array[2]], [array[1]]]);
- assert.deepEqual(_.partition(array, 1), [[array[1]], [array[0], array[2]]]);
- });
- QUnit.test('should work with an object for `collection`', function(assert) {
- assert.expect(1);
- var actual = _.partition({ 'a': 1.1, 'b': 0.2, 'c': 1.3 }, Math.floor);
- assert.deepEqual(actual, [[1.1, 1.3], [0.2]]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.pick');
- (function() {
- var args = arguments,
- object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
- QUnit.test('should flatten `props`', function(assert) {
- assert.expect(2);
- assert.deepEqual(_.pick(object, 'a', 'c'), { 'a': 1, 'c': 3 });
- assert.deepEqual(_.pick(object, ['a', 'd'], 'c'), { 'a': 1, 'c': 3, 'd': 4 });
- });
- QUnit.test('should work with a primitive `object` argument', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.pick('', 'slice'), { 'slice': ''.slice });
- });
- QUnit.test('should return an empty object when `object` is nullish', function(assert) {
- assert.expect(2);
- lodashStable.each([null, undefined], function(value) {
- assert.deepEqual(_.pick(value, 'valueOf'), {});
- });
- });
- QUnit.test('should work with `arguments` objects as secondary arguments', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.pick(object, args), { 'a': 1, 'c': 3 });
- });
- QUnit.test('should coerce property names to strings', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.pick({ '0': 'a', '1': 'b' }, 0), { '0': 'a' });
- });
- }('a', 'c'));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.pickBy');
- (function() {
- QUnit.test('should work with a predicate argument', function(assert) {
- assert.expect(1);
- var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 };
- var actual = _.pickBy(object, function(n) {
- return n == 1 || n == 3;
- });
- assert.deepEqual(actual, { 'a': 1, 'c': 3 });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('pick methods');
- lodashStable.each(['pick', 'pickBy'], function(methodName) {
- var expected = { 'a': 1, 'c': 3 },
- func = _[methodName],
- object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
- resolve = lodashStable.nthArg(1);
- if (methodName == 'pickBy') {
- resolve = function(object, props) {
- props = lodashStable.castArray(props);
- return function(value) {
- return lodashStable.some(props, function(key) {
- key = lodashStable.isSymbol(key) ? key : lodashStable.toString(key);
- return object[key] === value;
- });
- };
- };
- }
- QUnit.test('`_.' + methodName + '` should create an object of picked string keyed properties', function(assert) {
- assert.expect(2);
- assert.deepEqual(func(object, resolve(object, 'a')), { 'a': 1 });
- assert.deepEqual(func(object, resolve(object, ['a', 'c'])), expected);
- });
- QUnit.test('`_.' + methodName + '` should pick inherited string keyed properties', function(assert) {
- assert.expect(1);
- function Foo() {}
- Foo.prototype = object;
- var foo = new Foo;
- assert.deepEqual(func(foo, resolve(foo, ['a', 'c'])), expected);
- });
- QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var object = { '-0': 'a', '0': 'b' },
- props = [-0, Object(-0), 0, Object(0)],
- expected = [{ '-0': 'a' }, { '-0': 'a' }, { '0': 'b' }, { '0': 'b' }];
- var actual = lodashStable.map(props, function(key) {
- return func(object, resolve(object, key));
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should pick symbol properties', function(assert) {
- assert.expect(2);
- function Foo() {
- this[symbol] = 1;
- }
- if (Symbol) {
- var symbol2 = Symbol('b');
- Foo.prototype[symbol2] = 2;
- var foo = new Foo,
- actual = func(foo, resolve(foo, [symbol, symbol2]));
- assert.strictEqual(actual[symbol], 1);
- assert.strictEqual(actual[symbol2], 2);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('`_.' + methodName + '` should work with an array `object` argument', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- assert.deepEqual(func(array, resolve(array, '1')), { '1': 2 });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.property');
- (function() {
- QUnit.test('should create a function that plucks a property value of a given object', function(assert) {
- assert.expect(4);
- var object = { 'a': 1 };
- lodashStable.each(['a', ['a']], function(path) {
- var prop = _.property(path);
- assert.strictEqual(prop.length, 1);
- assert.strictEqual(prop(object), 1);
- });
- });
- QUnit.test('should pluck deep property values', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': 2 } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var prop = _.property(path);
- assert.strictEqual(prop(object), 2);
- });
- });
- QUnit.test('should pluck inherited property values', function(assert) {
- assert.expect(2);
- function Foo() {}
- Foo.prototype.a = 1;
- lodashStable.each(['a', ['a']], function(path) {
- var prop = _.property(path);
- assert.strictEqual(prop(new Foo), 1);
- });
- });
- QUnit.test('should work with a non-string `path`', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3];
- lodashStable.each([1, [1]], function(path) {
- var prop = _.property(path);
- assert.strictEqual(prop(array), 2);
- });
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var object = { '-0': 'a', '0': 'b' },
- props = [-0, Object(-0), 0, Object(0)];
- var actual = lodashStable.map(props, function(key) {
- var prop = _.property(key);
- return prop(object);
- });
- assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
- });
- QUnit.test('should coerce key to a string', function(assert) {
- assert.expect(1);
- function fn() {}
- fn.toString = lodashStable.constant('fn');
- var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
- values = [null, undefined, fn, {}];
- var actual = lodashStable.transform(objects, function(result, object, index) {
- var key = values[index];
- lodashStable.each([key, [key]], function(path) {
- var prop = _.property(key);
- result.push(prop(object));
- });
- });
- assert.deepEqual(actual, [1, 1, 2, 2, 3, 3, 4, 4]);
- });
- QUnit.test('should pluck a key over a path', function(assert) {
- assert.expect(2);
- var object = { 'a.b': 1, 'a': { 'b': 2 } };
- lodashStable.each(['a.b', ['a.b']], function(path) {
- var prop = _.property(path);
- assert.strictEqual(prop(object), 1);
- });
- });
- QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, noop);
- lodashStable.each(['constructor', ['constructor']], function(path) {
- var prop = _.property(path);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? prop(value) : prop();
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, noop);
- lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
- var prop = _.property(path);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? prop(value) : prop();
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
- assert.expect(4);
- var object = {};
- lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
- var prop = _.property(path);
- assert.strictEqual(prop(object), undefined);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.propertyOf');
- (function() {
- QUnit.test('should create a function that plucks a property value of a given key', function(assert) {
- assert.expect(3);
- var object = { 'a': 1 },
- propOf = _.propertyOf(object);
- assert.strictEqual(propOf.length, 1);
- lodashStable.each(['a', ['a']], function(path) {
- assert.strictEqual(propOf(path), 1);
- });
- });
- QUnit.test('should pluck deep property values', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': 2 } },
- propOf = _.propertyOf(object);
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.strictEqual(propOf(path), 2);
- });
- });
- QUnit.test('should pluck inherited property values', function(assert) {
- assert.expect(2);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var propOf = _.propertyOf(new Foo);
- lodashStable.each(['b', ['b']], function(path) {
- assert.strictEqual(propOf(path), 2);
- });
- });
- QUnit.test('should work with a non-string `path`', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3],
- propOf = _.propertyOf(array);
- lodashStable.each([1, [1]], function(path) {
- assert.strictEqual(propOf(path), 2);
- });
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var object = { '-0': 'a', '0': 'b' },
- props = [-0, Object(-0), 0, Object(0)];
- var actual = lodashStable.map(props, function(key) {
- var propOf = _.propertyOf(object);
- return propOf(key);
- });
- assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
- });
- QUnit.test('should coerce key to a string', function(assert) {
- assert.expect(1);
- function fn() {}
- fn.toString = lodashStable.constant('fn');
- var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
- values = [null, undefined, fn, {}];
- var actual = lodashStable.transform(objects, function(result, object, index) {
- var key = values[index];
- lodashStable.each([key, [key]], function(path) {
- var propOf = _.propertyOf(object);
- result.push(propOf(key));
- });
- });
- assert.deepEqual(actual, [1, 1, 2, 2, 3, 3, 4, 4]);
- });
- QUnit.test('should pluck a key over a path', function(assert) {
- assert.expect(2);
- var object = { 'a.b': 1, 'a': { 'b': 2 } },
- propOf = _.propertyOf(object);
- lodashStable.each(['a.b', ['a.b']], function(path) {
- assert.strictEqual(propOf(path), 1);
- });
- });
- QUnit.test('should return `undefined` when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, noop);
- lodashStable.each(['constructor', ['constructor']], function(path) {
- var actual = lodashStable.map(values, function(value, index) {
- var propOf = index ? _.propertyOf(value) : _.propertyOf();
- return propOf(path);
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `undefined` with deep paths when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, noop);
- lodashStable.each(['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']], function(path) {
- var actual = lodashStable.map(values, function(value, index) {
- var propOf = index ? _.propertyOf(value) : _.propertyOf();
- return propOf(path);
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should return `undefined` if parts of `path` are missing', function(assert) {
- assert.expect(4);
- var propOf = _.propertyOf({});
- lodashStable.each(['a', 'a[1].b.c', ['a'], ['a', '1', 'b', 'c']], function(path) {
- assert.strictEqual(propOf(path), undefined);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.pullAll');
- (function() {
- QUnit.test('should work with the same value for `array` and `values`', function(assert) {
- assert.expect(1);
- var array = [{ 'a': 1 }, { 'b': 2 }],
- actual = _.pullAll(array, array);
- assert.deepEqual(actual, []);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.pullAllBy');
- (function() {
- QUnit.test('should accept an `iteratee` argument', function(assert) {
- assert.expect(1);
- var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
- var actual = _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function(object) {
- return object.x;
- });
- assert.deepEqual(actual, [{ 'x': 2 }]);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args,
- array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
- _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [{ 'x': 1 }]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.pullAllWith');
- (function() {
- QUnit.test('should work with a `comparator` argument', function(assert) {
- assert.expect(1);
- var objects = [{ 'x': 1, 'y': 1 }, { 'x': 2, 'y': 2 }, { 'x': 3, 'y': 3 }],
- expected = [objects[0], objects[2]],
- actual = _.pullAllWith(objects, [{ 'x': 2, 'y': 2 }], lodashStable.isEqual);
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('pull methods');
- lodashStable.each(['pull', 'pullAll', 'pullAllWith'], function(methodName) {
- var func = _[methodName],
- isPull = methodName == 'pull';
- function pull(array, values) {
- return isPull
- ? func.apply(undefined, [array].concat(values))
- : func(array, values);
- }
- QUnit.test('`_.' + methodName + '` should modify and return the array', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3],
- actual = pull(array, [1, 3]);
- assert.strictEqual(actual, array);
- assert.deepEqual(array, [2]);
- });
- QUnit.test('`_.' + methodName + '` should preserve holes in arrays', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3, 4];
- delete array[1];
- delete array[3];
- pull(array, [1]);
- assert.notOk('0' in array);
- assert.notOk('2' in array);
- });
- QUnit.test('`_.' + methodName + '` should treat holes as `undefined`', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- delete array[1];
- pull(array, [undefined]);
- assert.deepEqual(array, [1, 3]);
- });
- QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
- assert.expect(1);
- var array = [1, NaN, 3, NaN];
- pull(array, [NaN]);
- assert.deepEqual(array, [1, 3]);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.pullAt');
- (function() {
- QUnit.test('should modify the array and return removed elements', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3],
- actual = _.pullAt(array, [0, 1]);
- assert.deepEqual(array, [3]);
- assert.deepEqual(actual, [1, 2]);
- });
- QUnit.test('should work with unsorted indexes', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
- actual = _.pullAt(array, [1, 3, 11, 7, 5, 9]);
- assert.deepEqual(array, [1, 3, 5, 7, 9, 11]);
- assert.deepEqual(actual, [2, 4, 12, 8, 6, 10]);
- });
- QUnit.test('should work with repeated indexes', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3, 4],
- actual = _.pullAt(array, [0, 2, 0, 1, 0, 2]);
- assert.deepEqual(array, [4]);
- assert.deepEqual(actual, [1, 3, 1, 2, 1, 3]);
- });
- QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
- assert.expect(2);
- var array = ['a', 'b', 'c'],
- actual = _.pullAt(array, [2, 4, 0]);
- assert.deepEqual(array, ['b']);
- assert.deepEqual(actual, ['c', undefined, 'a']);
- });
- QUnit.test('should flatten `indexes`', function(assert) {
- assert.expect(4);
- var array = ['a', 'b', 'c'];
- assert.deepEqual(_.pullAt(array, 2, 0), ['c', 'a']);
- assert.deepEqual(array, ['b']);
- array = ['a', 'b', 'c', 'd'];
- assert.deepEqual(_.pullAt(array, [3, 0], 2), ['d', 'a', 'c']);
- assert.deepEqual(array, ['b']);
- });
- QUnit.test('should return an empty array when no indexes are given', function(assert) {
- assert.expect(4);
- var array = ['a', 'b', 'c'],
- actual = _.pullAt(array);
- assert.deepEqual(array, ['a', 'b', 'c']);
- assert.deepEqual(actual, []);
- actual = _.pullAt(array, [], []);
- assert.deepEqual(array, ['a', 'b', 'c']);
- assert.deepEqual(actual, []);
- });
- QUnit.test('should work with non-index paths', function(assert) {
- assert.expect(2);
- var values = lodashStable.reject(empties, function(value) {
- return (value === 0) || lodashStable.isArray(value);
- }).concat(-1, 1.1);
- var array = lodashStable.transform(values, function(result, value) {
- result[value] = 1;
- }, []);
- var expected = lodashStable.map(values, stubOne),
- actual = _.pullAt(array, values);
- assert.deepEqual(actual, expected);
- expected = lodashStable.map(values, noop),
- actual = lodashStable.at(array, values);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var props = [-0, Object(-0), 0, Object(0)];
- var actual = lodashStable.map(props, function(key) {
- var array = [-1];
- array['-0'] = -2;
- return _.pullAt(array, key);
- });
- assert.deepEqual(actual, [[-2], [-2], [-1], [-1]]);
- });
- QUnit.test('should work with deep paths', function(assert) {
- assert.expect(3);
- var array = [];
- array.a = { 'b': 2 };
- var actual = _.pullAt(array, 'a.b');
- assert.deepEqual(actual, [2]);
- assert.deepEqual(array.a, {});
- try {
- actual = _.pullAt(array, 'a.b.c');
- } catch (e) {}
- assert.deepEqual(actual, [undefined]);
- });
- QUnit.test('should work with a falsey `array` argument when keys are given', function(assert) {
- assert.expect(1);
- var values = falsey.slice(),
- expected = lodashStable.map(values, lodashStable.constant(Array(4)));
- var actual = lodashStable.map(values, function(array) {
- try {
- return _.pullAt(array, 0, 1, 'pop', 'push');
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.random');
- (function() {
- var array = Array(1000);
- QUnit.test('should return `0` or `1` when no arguments are given', function(assert) {
- assert.expect(1);
- var actual = lodashStable.uniq(lodashStable.map(array, function() {
- return _.random();
- })).sort();
- assert.deepEqual(actual, [0, 1]);
- });
- QUnit.test('should support a `min` and `max` argument', function(assert) {
- assert.expect(1);
- var min = 5,
- max = 10;
- assert.ok(lodashStable.some(array, function() {
- var result = _.random(min, max);
- return result >= min && result <= max;
- }));
- });
- QUnit.test('should support not providing a `max` argument', function(assert) {
- assert.expect(1);
- var min = 0,
- max = 5;
- assert.ok(lodashStable.some(array, function() {
- var result = _.random(max);
- return result >= min && result <= max;
- }));
- });
- QUnit.test('should swap `min` and `max` when `min` > `max`', function(assert) {
- assert.expect(1);
- var min = 4,
- max = 2,
- expected = [2, 3, 4];
- var actual = lodashStable.uniq(lodashStable.map(array, function() {
- return _.random(min, max);
- })).sort();
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should support large integer values', function(assert) {
- assert.expect(2);
- var min = Math.pow(2, 31),
- max = Math.pow(2, 62);
- assert.ok(lodashStable.every(array, function() {
- var result = _.random(min, max);
- return result >= min && result <= max;
- }));
- assert.ok(lodashStable.some(array, function() {
- return _.random(MAX_INTEGER);
- }));
- });
- QUnit.test('should coerce arguments to finite numbers', function(assert) {
- assert.expect(1);
- var actual = [
- _.random(NaN, NaN),
- _.random('1', '1'),
- _.random(Infinity, Infinity)
- ];
- assert.deepEqual(actual, [0, 1, MAX_INTEGER]);
- });
- QUnit.test('should support floats', function(assert) {
- assert.expect(2);
- var min = 1.5,
- max = 1.6,
- actual = _.random(min, max);
- assert.ok(actual % 1);
- assert.ok(actual >= min && actual <= max);
- });
- QUnit.test('should support providing a `floating` argument', function(assert) {
- assert.expect(3);
- var actual = _.random(true);
- assert.ok(actual % 1 && actual >= 0 && actual <= 1);
- actual = _.random(2, true);
- assert.ok(actual % 1 && actual >= 0 && actual <= 2);
- actual = _.random(2, 4, true);
- assert.ok(actual % 1 && actual >= 2 && actual <= 4);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3],
- expected = lodashStable.map(array, stubTrue),
- randoms = lodashStable.map(array, _.random);
- var actual = lodashStable.map(randoms, function(result, index) {
- return result >= 0 && result <= array[index] && (result % 1) == 0;
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('range methods');
- lodashStable.each(['range', 'rangeRight'], function(methodName) {
- var func = _[methodName],
- isRange = methodName == 'range';
- function resolve(range) {
- return isRange ? range : range.reverse();
- }
- QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `end` is given', function(assert) {
- assert.expect(2);
- assert.deepEqual(func(4), resolve([0, 1, 2, 3]));
- assert.deepEqual(func(-4), resolve([0, -1, -2, -3]));
- });
- QUnit.test('`_.' + methodName + '` should infer the sign of `step` when only `start` and `end` are given', function(assert) {
- assert.expect(2);
- assert.deepEqual(func(1, 5), resolve([1, 2, 3, 4]));
- assert.deepEqual(func(5, 1), resolve([5, 4, 3, 2]));
- });
- QUnit.test('`_.' + methodName + '` should work with `start`, `end`, and `step` arguments', function(assert) {
- assert.expect(3);
- assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
- assert.deepEqual(func(5, 1, -1), resolve([5, 4, 3, 2]));
- assert.deepEqual(func(0, 20, 5), resolve([0, 5, 10, 15]));
- });
- QUnit.test('`_.' + methodName + '` should support a `step` of `0`', function(assert) {
- assert.expect(1);
- assert.deepEqual(func(1, 4, 0), [1, 1, 1]);
- });
- QUnit.test('`_.' + methodName + '` should work with a `step` larger than `end`', function(assert) {
- assert.expect(1);
- assert.deepEqual(func(1, 5, 20), [1]);
- });
- QUnit.test('`_.' + methodName + '` should work with a negative `step`', function(assert) {
- assert.expect(2);
- assert.deepEqual(func(0, -4, -1), resolve([0, -1, -2, -3]));
- assert.deepEqual(func(21, 10, -3), resolve([21, 18, 15, 12]));
- });
- QUnit.test('`_.' + methodName + '` should support `start` of `-0`', function(assert) {
- assert.expect(1);
- var actual = func(-0, 1);
- assert.strictEqual(1 / actual[0], -Infinity);
- });
- QUnit.test('`_.' + methodName + '` should treat falsey `start` arguments as `0`', function(assert) {
- assert.expect(13);
- lodashStable.each(falsey, function(value, index) {
- if (index) {
- assert.deepEqual(func(value), []);
- assert.deepEqual(func(value, 1), [0]);
- } else {
- assert.deepEqual(func(), []);
- }
- });
- });
- QUnit.test('`_.' + methodName + '` should coerce arguments to finite numbers', function(assert) {
- assert.expect(1);
- var actual = [
- func('1'),
- func('0', 1),
- func(0, 1, '1'),
- func(NaN),
- func(NaN, NaN)
- ];
- assert.deepEqual(actual, [[0], [0], [0], [], []]);
- });
- QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3],
- object = { 'a': 1, 'b': 2, 'c': 3 },
- expected = lodashStable.map([[0], [0, 1], [0, 1, 2]], resolve);
- lodashStable.each([array, object], function(collection) {
- var actual = lodashStable.map(collection, func);
- assert.deepEqual(actual, expected);
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.rearg');
- (function() {
- function fn() {
- return slice.call(arguments);
- }
- QUnit.test('should reorder arguments provided to `func`', function(assert) {
- assert.expect(1);
- var rearged = _.rearg(fn, [2, 0, 1]);
- assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
- });
- QUnit.test('should work with repeated indexes', function(assert) {
- assert.expect(1);
- var rearged = _.rearg(fn, [1, 1, 1]);
- assert.deepEqual(rearged('c', 'a', 'b'), ['a', 'a', 'a']);
- });
- QUnit.test('should use `undefined` for nonexistent indexes', function(assert) {
- assert.expect(1);
- var rearged = _.rearg(fn, [1, 4]);
- assert.deepEqual(rearged('b', 'a', 'c'), ['a', undefined, 'c']);
- });
- QUnit.test('should use `undefined` for non-index values', function(assert) {
- assert.expect(1);
- var values = lodashStable.reject(empties, function(value) {
- return (value === 0) || lodashStable.isArray(value);
- }).concat(-1, 1.1);
- var expected = lodashStable.map(values, lodashStable.constant([undefined, 'b', 'c']));
- var actual = lodashStable.map(values, function(value) {
- var rearged = _.rearg(fn, [value]);
- return rearged('a', 'b', 'c');
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should not rearrange arguments when no indexes are given', function(assert) {
- assert.expect(2);
- var rearged = _.rearg(fn);
- assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
- rearged = _.rearg(fn, [], []);
- assert.deepEqual(rearged('a', 'b', 'c'), ['a', 'b', 'c']);
- });
- QUnit.test('should accept multiple index arguments', function(assert) {
- assert.expect(1);
- var rearged = _.rearg(fn, 2, 0, 1);
- assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
- });
- QUnit.test('should accept multiple arrays of indexes', function(assert) {
- assert.expect(1);
- var rearged = _.rearg(fn, [2], [0, 1]);
- assert.deepEqual(rearged('b', 'c', 'a'), ['a', 'b', 'c']);
- });
- QUnit.test('should work with fewer indexes than arguments', function(assert) {
- assert.expect(1);
- var rearged = _.rearg(fn, [1, 0]);
- assert.deepEqual(rearged('b', 'a', 'c'), ['a', 'b', 'c']);
- });
- QUnit.test('should work on functions that have been rearged', function(assert) {
- assert.expect(1);
- var rearged1 = _.rearg(fn, 2, 1, 0),
- rearged2 = _.rearg(rearged1, 1, 0, 2);
- assert.deepEqual(rearged2('b', 'c', 'a'), ['a', 'b', 'c']);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.reduce');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should use the first element of a collection as the default `accumulator`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.reduce(array), 1);
- });
- QUnit.test('should provide correct `iteratee` arguments when iterating an array', function(assert) {
- assert.expect(2);
- var args;
- _.reduce(array, function() {
- args || (args = slice.call(arguments));
- }, 0);
- assert.deepEqual(args, [0, 1, 0, array]);
- args = undefined;
- _.reduce(array, function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [1, 2, 1, array]);
- });
- QUnit.test('should provide correct `iteratee` arguments when iterating an object', function(assert) {
- assert.expect(2);
- var args,
- object = { 'a': 1, 'b': 2 },
- firstKey = _.head(_.keys(object));
- var expected = firstKey == 'a'
- ? [0, 1, 'a', object]
- : [0, 2, 'b', object];
- _.reduce(object, function() {
- args || (args = slice.call(arguments));
- }, 0);
- assert.deepEqual(args, expected);
- args = undefined;
- expected = firstKey == 'a'
- ? [1, 2, 'b', object]
- : [2, 1, 'a', object];
- _.reduce(object, function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.reduceRight');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should use the last element of a collection as the default `accumulator`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.reduceRight(array), 3);
- });
- QUnit.test('should provide correct `iteratee` arguments when iterating an array', function(assert) {
- assert.expect(2);
- var args;
- _.reduceRight(array, function() {
- args || (args = slice.call(arguments));
- }, 0);
- assert.deepEqual(args, [0, 3, 2, array]);
- args = undefined;
- _.reduceRight(array, function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [3, 2, 1, array]);
- });
- QUnit.test('should provide correct `iteratee` arguments when iterating an object', function(assert) {
- assert.expect(2);
- var args,
- object = { 'a': 1, 'b': 2 },
- isFIFO = lodashStable.keys(object)[0] == 'a';
- var expected = isFIFO
- ? [0, 2, 'b', object]
- : [0, 1, 'a', object];
- _.reduceRight(object, function() {
- args || (args = slice.call(arguments));
- }, 0);
- assert.deepEqual(args, expected);
- args = undefined;
- expected = isFIFO
- ? [2, 1, 'a', object]
- : [1, 2, 'b', object];
- _.reduceRight(object, function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('reduce methods');
- lodashStable.each(['reduce', 'reduceRight'], function(methodName) {
- var func = _[methodName],
- array = [1, 2, 3],
- isReduce = methodName == 'reduce';
- QUnit.test('`_.' + methodName + '` should reduce a collection to a single value', function(assert) {
- assert.expect(1);
- var actual = func(['a', 'b', 'c'], function(accumulator, value) {
- return accumulator + value;
- }, '');
- assert.strictEqual(actual, isReduce ? 'abc' : 'cba');
- });
- QUnit.test('`_.' + methodName + '` should support empty collections without an initial `accumulator` value', function(assert) {
- assert.expect(1);
- var actual = [],
- expected = lodashStable.map(empties, noop);
- lodashStable.each(empties, function(value) {
- try {
- actual.push(func(value, noop));
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should support empty collections with an initial `accumulator` value', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(empties, lodashStable.constant('x'));
- var actual = lodashStable.map(empties, function(value) {
- try {
- return func(value, noop, 'x');
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should handle an initial `accumulator` value of `undefined`', function(assert) {
- assert.expect(1);
- var actual = func([], noop, undefined);
- assert.strictEqual(actual, undefined);
- });
- QUnit.test('`_.' + methodName + '` should return `undefined` for empty collections when no `accumulator` is given (test in IE > 9 and modern browsers)', function(assert) {
- assert.expect(2);
- var array = [],
- object = { '0': 1, 'length': 0 };
- if ('__proto__' in array) {
- array.__proto__ = object;
- assert.strictEqual(func(array, noop), undefined);
- }
- else {
- skipAssert(assert);
- }
- assert.strictEqual(func(object, noop), undefined);
- });
- QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.strictEqual(_(array)[methodName](add), 6);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_(array).chain()[methodName](add) instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.reject');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should return elements the `predicate` returns falsey for', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.reject(array, isEven), [1, 3]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('filter methods');
- lodashStable.each(['filter', 'reject'], function(methodName) {
- var array = [1, 2, 3, 4],
- func = _[methodName],
- isFilter = methodName == 'filter',
- objects = [{ 'a': 0 }, { 'a': 1 }];
- QUnit.test('`_.' + methodName + '` should not modify the resulting value from within `predicate`', function(assert) {
- assert.expect(1);
- var actual = func([0], function(value, index, array) {
- array[index] = 1;
- return isFilter;
- });
- assert.deepEqual(actual, [0]);
- });
- QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(func(objects, 'a'), [objects[isFilter ? 1 : 0]]);
- });
- QUnit.test('`_.' + methodName + '` should work with `_.matches` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(func(objects, objects[1]), [objects[isFilter ? 1 : 0]]);
- });
- QUnit.test('`_.' + methodName + '` should not modify wrapped values', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _(array);
- var actual = wrapped[methodName](function(n) {
- return n < 3;
- });
- assert.deepEqual(actual.value(), isFilter ? [1, 2] : [3, 4]);
- actual = wrapped[methodName](function(n) {
- return n > 2;
- });
- assert.deepEqual(actual.value(), isFilter ? [3, 4] : [1, 2]);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
- predicate = function(value) { return isFilter ? isEven(value) : !isEven(value); };
- var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
- return ['key' + index, index];
- }));
- var actual = _(array).slice(1).map(square)[methodName](predicate).value();
- assert.deepEqual(actual, _[methodName](lodashStable.map(array.slice(1), square), predicate));
- actual = _(object).mapValues(square)[methodName](predicate).value();
- assert.deepEqual(actual, _[methodName](lodashStable.mapValues(object, square), predicate));
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('`_.' + methodName + '` should provide correct `predicate` arguments in a lazy sequence', function(assert) {
- assert.expect(5);
- if (!isNpm) {
- var args,
- array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
- expected = [1, 0, lodashStable.map(array.slice(1), square)];
- _(array).slice(1)[methodName](function(value, index, array) {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, [1, 0, array.slice(1)]);
- args = undefined;
- _(array).slice(1).map(square)[methodName](function(value, index, array) {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, expected);
- args = undefined;
- _(array).slice(1).map(square)[methodName](function(value, index) {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, expected);
- args = undefined;
- _(array).slice(1).map(square)[methodName](function(value) {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, [1]);
- args = undefined;
- _(array).slice(1).map(square)[methodName](function() {
- args || (args = slice.call(arguments));
- }).value();
- assert.deepEqual(args, expected);
- }
- else {
- skipAssert(assert, 5);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.remove');
- (function() {
- QUnit.test('should modify the array and return removed elements', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3, 4],
- actual = _.remove(array, isEven);
- assert.deepEqual(array, [1, 3]);
- assert.deepEqual(actual, [2, 4]);
- });
- QUnit.test('should provide correct `predicate` arguments', function(assert) {
- assert.expect(1);
- var argsList = [],
- array = [1, 2, 3],
- clone = array.slice();
- _.remove(array, function(n, index) {
- var args = slice.call(arguments);
- args[2] = args[2].slice();
- argsList.push(args);
- return isEven(index);
- });
- assert.deepEqual(argsList, [[1, 0, clone], [2, 1, clone], [3, 2, clone]]);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
- _.remove(objects, { 'a': 1 });
- assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
- });
- QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
- _.remove(objects, ['a', 1]);
- assert.deepEqual(objects, [{ 'a': 0, 'b': 1 }]);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var objects = [{ 'a': 0 }, { 'a': 1 }];
- _.remove(objects, 'a');
- assert.deepEqual(objects, [{ 'a': 0 }]);
- });
- QUnit.test('should preserve holes in arrays', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3, 4];
- delete array[1];
- delete array[3];
- _.remove(array, function(n) {
- return n === 1;
- });
- assert.notOk('0' in array);
- assert.notOk('2' in array);
- });
- QUnit.test('should treat holes as `undefined`', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- delete array[1];
- _.remove(array, function(n) {
- return n == null;
- });
- assert.deepEqual(array, [1, 3]);
- });
- QUnit.test('should not mutate the array until all elements to remove are determined', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3];
- _.remove(array, function(n, index) {
- return isEven(index);
- });
- assert.deepEqual(array, [2]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.repeat');
- (function() {
- var string = 'abc';
- QUnit.test('should repeat a string `n` times', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.repeat('*', 3), '***');
- assert.strictEqual(_.repeat(string, 2), 'abcabc');
- });
- QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? string : '';
- });
- var actual = lodashStable.map(falsey, function(n, index) {
- return index ? _.repeat(string, n) : _.repeat(string);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return an empty string if `n` is <= `0`', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.repeat(string, 0), '');
- assert.strictEqual(_.repeat(string, -2), '');
- });
- QUnit.test('should coerce `n` to an integer', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.repeat(string, '2'), 'abcabc');
- assert.strictEqual(_.repeat(string, 2.6), 'abcabc');
- assert.strictEqual(_.repeat('*', { 'valueOf': stubThree }), '***');
- });
- QUnit.test('should coerce `string` to a string', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.repeat(Object(string), 2), 'abcabc');
- assert.strictEqual(_.repeat({ 'toString': lodashStable.constant('*') }, 3), '***');
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(['a', 'b', 'c'], _.repeat);
- assert.deepEqual(actual, ['a', 'b', 'c']);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.replace');
- (function() {
- QUnit.test('should replace the matched pattern', function(assert) {
- assert.expect(2);
- var string = 'abcde';
- assert.strictEqual(_.replace(string, 'de', '123'), 'abc123');
- assert.strictEqual(_.replace(string, /[bd]/g, '-'), 'a-c-e');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.result');
- (function() {
- var object = { 'a': 1, 'b': stubB };
- QUnit.test('should invoke function values', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.result(object, 'b'), 'b');
- });
- QUnit.test('should invoke default function values', function(assert) {
- assert.expect(1);
- var actual = _.result(object, 'c', object.b);
- assert.strictEqual(actual, 'b');
- });
- QUnit.test('should invoke nested function values', function(assert) {
- assert.expect(2);
- var value = { 'a': lodashStable.constant({ 'b': stubB }) };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.strictEqual(_.result(value, path), 'b');
- });
- });
- QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
- assert.expect(2);
- var value = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.strictEqual(_.result(value, path), 1);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.get and lodash.result');
- lodashStable.each(['get', 'result'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should get string keyed property values', function(assert) {
- assert.expect(2);
- var object = { 'a': 1 };
- lodashStable.each(['a', ['a']], function(path) {
- assert.strictEqual(func(object, path), 1);
- });
- });
- QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var object = { '-0': 'a', '0': 'b' },
- props = [-0, Object(-0), 0, Object(0)];
- var actual = lodashStable.map(props, function(key) {
- return func(object, key);
- });
- assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
- });
- QUnit.test('`_.' + methodName + '` should get symbol keyed property values', function(assert) {
- assert.expect(1);
- if (Symbol) {
- var object = {};
- object[symbol] = 1;
- assert.strictEqual(func(object, symbol), 1);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should get deep property values', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': 2 } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.strictEqual(func(object, path), 2);
- });
- });
- QUnit.test('`_.' + methodName + '` should get a key over a path', function(assert) {
- assert.expect(2);
- var object = { 'a.b': 1, 'a': { 'b': 2 } };
- lodashStable.each(['a.b', ['a.b']], function(path) {
- assert.strictEqual(func(object, path), 1);
- });
- });
- QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
- assert.expect(1);
- var object = { 'a,b,c': 3, 'a': { 'b': { 'c': 4 } } };
- assert.strictEqual(func(object, ['a', 'b', 'c']), 4);
- });
- QUnit.test('`_.' + methodName + '` should not ignore empty brackets', function(assert) {
- assert.expect(1);
- var object = { 'a': { '': 1 } };
- assert.strictEqual(func(object, 'a[]'), 1);
- });
- QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
- assert.expect(4);
- lodashStable.each([['', ''], [[], ['']]], function(pair) {
- assert.strictEqual(func({}, pair[0]), undefined);
- assert.strictEqual(func({ '': 3 }, pair[1]), 3);
- });
- });
- QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
- assert.expect(2);
- var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
- var paths = [
- 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
- ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
- ];
- lodashStable.each(paths, function(path) {
- assert.strictEqual(func(object, path), 8);
- });
- });
- QUnit.test('`_.' + methodName + '` should return `undefined` when `object` is nullish', function(assert) {
- assert.expect(4);
- lodashStable.each(['constructor', ['constructor']], function(path) {
- assert.strictEqual(func(null, path), undefined);
- assert.strictEqual(func(undefined, path), undefined);
- });
- });
- QUnit.test('`_.' + methodName + '` should return `undefined` with deep paths when `object` is nullish', function(assert) {
- assert.expect(2);
- var values = [null, undefined],
- expected = lodashStable.map(values, noop),
- paths = ['constructor.prototype.valueOf', ['constructor', 'prototype', 'valueOf']];
- lodashStable.each(paths, function(path) {
- var actual = lodashStable.map(values, function(value) {
- return func(value, path);
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('`_.' + methodName + '` should return `undefined` if parts of `path` are missing', function(assert) {
- assert.expect(2);
- var object = { 'a': [, null] };
- lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
- assert.strictEqual(func(object, path), undefined);
- });
- });
- QUnit.test('`_.' + methodName + '` should be able to return `null` values', function(assert) {
- assert.expect(2);
- var object = { 'a': { 'b': null } };
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- assert.strictEqual(func(object, path), null);
- });
- });
- QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
- assert.expect(2);
- var paths = ['a.b', ['a', 'b']];
- lodashStable.each(paths, function(path) {
- numberProto.a = { 'b': 2 };
- assert.strictEqual(func(0, path), 2);
- delete numberProto.a;
- });
- });
- QUnit.test('`_.' + methodName + '` should return the default value for `undefined` values', function(assert) {
- assert.expect(1);
- var object = { 'a': {} },
- values = empties.concat(true, new Date, 1, /x/, 'a');
- var expected = lodashStable.transform(values, function(result, value) {
- result.push(value, value, value, value);
- });
- var actual = lodashStable.transform(values, function(result, value) {
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- result.push(
- func(object, path, value),
- func(null, path, value)
- );
- });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should return the default value when `path` is empty', function(assert) {
- assert.expect(1);
- assert.strictEqual(func({}, [], 'a'), 'a');
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.rest');
- (function() {
- function fn(a, b, c) {
- return slice.call(arguments);
- }
- QUnit.test('should apply a rest parameter to `func`', function(assert) {
- assert.expect(1);
- var rest = _.rest(fn);
- assert.deepEqual(rest(1, 2, 3, 4), [1, 2, [3, 4]]);
- });
- QUnit.test('should work with `start`', function(assert) {
- assert.expect(1);
- var rest = _.rest(fn, 1);
- assert.deepEqual(rest(1, 2, 3, 4), [1, [2, 3, 4]]);
- });
- QUnit.test('should treat `start` as `0` for `NaN` or negative values', function(assert) {
- assert.expect(1);
- var values = [-1, NaN, 'a'],
- expected = lodashStable.map(values, lodashStable.constant([[1, 2, 3, 4]]));
- var actual = lodashStable.map(values, function(value) {
- var rest = _.rest(fn, value);
- return rest(1, 2, 3, 4);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should coerce `start` to an integer', function(assert) {
- assert.expect(1);
- var rest = _.rest(fn, 1.6);
- assert.deepEqual(rest(1, 2, 3), [1, [2, 3]]);
- });
- QUnit.test('should use an empty array when `start` is not reached', function(assert) {
- assert.expect(1);
- var rest = _.rest(fn);
- assert.deepEqual(rest(1), [1, undefined, []]);
- });
- QUnit.test('should work on functions with more than three parameters', function(assert) {
- assert.expect(1);
- var rest = _.rest(function(a, b, c, d) {
- return slice.call(arguments);
- });
- assert.deepEqual(rest(1, 2, 3, 4, 5), [1, 2, 3, [4, 5]]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.reverse');
- (function() {
- var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null),
- smallArray = [0, 1, 2, null];
- QUnit.test('should reverse `array`', function(assert) {
- assert.expect(2);
- var array = [1, 2, 3],
- actual = _.reverse(array);
- assert.strictEqual(actual, array);
- assert.deepEqual(array, [3, 2, 1]);
- });
- QUnit.test('should return the wrapped reversed `array`', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- lodashStable.times(2, function(index) {
- var array = (index ? largeArray : smallArray).slice(),
- clone = array.slice(),
- wrapped = _(array).reverse(),
- actual = wrapped.value();
- assert.ok(wrapped instanceof _);
- assert.strictEqual(actual, array);
- assert.deepEqual(actual, clone.slice().reverse());
- });
- }
- else {
- skipAssert(assert, 6);
- }
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- lodashStable.times(2, function(index) {
- var array = (index ? largeArray : smallArray).slice(),
- expected = array.slice(),
- actual = _(array).slice(1).reverse().value();
- assert.deepEqual(actual, expected.slice(1).reverse());
- assert.deepEqual(array, expected);
- });
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should be lazy when in a lazy sequence', function(assert) {
- assert.expect(3);
- if (!isNpm) {
- var spy = {
- 'toString': function() {
- throw new Error('spy was revealed');
- }
- };
- var array = largeArray.concat(spy),
- expected = array.slice();
- try {
- var wrapped = _(array).slice(1).map(String).reverse(),
- actual = wrapped.last();
- } catch (e) {}
- assert.ok(wrapped instanceof _);
- assert.strictEqual(actual, '1');
- assert.deepEqual(array, expected);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('should work in a hybrid sequence', function(assert) {
- assert.expect(8);
- if (!isNpm) {
- lodashStable.times(2, function(index) {
- var clone = (index ? largeArray : smallArray).slice();
- lodashStable.each(['map', 'filter'], function(methodName) {
- var array = clone.slice(),
- expected = clone.slice(1, -1).reverse(),
- actual = _(array)[methodName](identity).thru(_.compact).reverse().value();
- assert.deepEqual(actual, expected);
- array = clone.slice();
- actual = _(array).thru(_.compact)[methodName](identity).pull(1).push(3).reverse().value();
- assert.deepEqual(actual, [3].concat(expected.slice(0, -1)));
- });
- });
- }
- else {
- skipAssert(assert, 8);
- }
- });
- QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- lodashStable.times(2, function(index) {
- var array = (index ? largeArray : smallArray).slice(),
- expected = array.slice().reverse(),
- wrapped = _(array).chain().reverse().head();
- assert.ok(wrapped instanceof _);
- assert.strictEqual(wrapped.value(), _.head(expected));
- assert.deepEqual(array, expected);
- });
- }
- else {
- skipAssert(assert, 6);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('round methods');
- lodashStable.each(['ceil', 'floor', 'round'], function(methodName) {
- var func = _[methodName],
- isCeil = methodName == 'ceil',
- isFloor = methodName == 'floor';
- QUnit.test('`_.' + methodName + '` should return a rounded number without a precision', function(assert) {
- assert.expect(1);
- var actual = func(4.006);
- assert.strictEqual(actual, isCeil ? 5 : 4);
- });
- QUnit.test('`_.' + methodName + '` should work with a precision of `0`', function(assert) {
- assert.expect(1);
- var actual = func(4.006, 0);
- assert.strictEqual(actual, isCeil ? 5 : 4);
- });
- QUnit.test('`_.' + methodName + '` should work with a positive precision', function(assert) {
- assert.expect(2);
- var actual = func(4.016, 2);
- assert.strictEqual(actual, isFloor ? 4.01 : 4.02);
- actual = func(4.1, 2);
- assert.strictEqual(actual, 4.1);
- });
- QUnit.test('`_.' + methodName + '` should work with a negative precision', function(assert) {
- assert.expect(1);
- var actual = func(4160, -2);
- assert.strictEqual(actual, isFloor ? 4100 : 4200);
- });
- QUnit.test('`_.' + methodName + '` should coerce `precision` to an integer', function(assert) {
- assert.expect(3);
- var actual = func(4.006, NaN);
- assert.strictEqual(actual, isCeil ? 5 : 4);
- var expected = isFloor ? 4.01 : 4.02;
- actual = func(4.016, 2.6);
- assert.strictEqual(actual, expected);
- actual = func(4.016, '+2');
- assert.strictEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with exponential notation and `precision`', function(assert) {
- assert.expect(3);
- var actual = func(5e1, 2);
- assert.deepEqual(actual, 50);
- actual = func('5e', 1);
- assert.deepEqual(actual, NaN);
- actual = func('5e1e1', 1);
- assert.deepEqual(actual, NaN);
- });
- QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var values = [[0], [-0], ['0'], ['-0'], [0, 1], [-0, 1], ['0', 1], ['-0', 1]],
- expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];
- var actual = lodashStable.map(values, function(args) {
- return 1 / func.apply(undefined, args);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should not return `NaN` for large `precision` values', function(assert) {
- assert.expect(1);
- var results = [
- _.round(10.0000001, 1000),
- _.round(MAX_SAFE_INTEGER, 293)
- ];
- var expected = lodashStable.map(results, stubFalse),
- actual = lodashStable.map(results, lodashStable.isNaN);
- assert.deepEqual(actual, expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.runInContext');
- (function() {
- QUnit.test('should not require a fully populated `context` object', function(assert) {
- assert.expect(1);
- if (!isModularize) {
- var lodash = _.runInContext({
- 'setTimeout': function(func) { func(); }
- });
- var pass = false;
- lodash.delay(function() { pass = true; }, 32);
- assert.ok(pass);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should use a zeroed `_.uniqueId` counter', function(assert) {
- assert.expect(3);
- if (!isModularize) {
- lodashStable.times(2, _.uniqueId);
- var oldId = Number(_.uniqueId()),
- lodash = _.runInContext();
- assert.ok(_.uniqueId() > oldId);
- var id = lodash.uniqueId();
- assert.strictEqual(id, '1');
- assert.ok(id < oldId);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.sample');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should return a random element', function(assert) {
- assert.expect(1);
- var actual = _.sample(array);
- assert.ok(lodashStable.includes(array, actual));
- });
- QUnit.test('should return `undefined` when sampling empty collections', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(empties, noop);
- var actual = lodashStable.transform(empties, function(result, value) {
- try {
- result.push(_.sample(value));
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should sample an object', function(assert) {
- assert.expect(1);
- var object = { 'a': 1, 'b': 2, 'c': 3 },
- actual = _.sample(object);
- assert.ok(lodashStable.includes(array, actual));
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.sampleSize');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should return an array of random elements', function(assert) {
- assert.expect(2);
- var actual = _.sampleSize(array, 2);
- assert.strictEqual(actual.length, 2);
- assert.deepEqual(lodashStable.difference(actual, array), []);
- });
- QUnit.test('should contain elements of the collection', function(assert) {
- assert.expect(1);
- var actual = _.sampleSize(array, array.length).sort();
- assert.deepEqual(actual, array);
- });
- QUnit.test('should treat falsey `size` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? ['a'] : [];
- });
- var actual = lodashStable.map(falsey, function(size, index) {
- return index ? _.sampleSize(['a'], size) : _.sampleSize(['a']);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return an empty array when `n` < `1` or `NaN`', function(assert) {
- assert.expect(3);
- lodashStable.each([0, -1, -Infinity], function(n) {
- assert.deepEqual(_.sampleSize(array, n), []);
- });
- });
- QUnit.test('should return all elements when `n` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
- var actual = _.sampleSize(array, n).sort();
- assert.deepEqual(actual, array);
- });
- });
- QUnit.test('should coerce `n` to an integer', function(assert) {
- assert.expect(1);
- var actual = _.sampleSize(array, 1.6);
- assert.strictEqual(actual.length, 1);
- });
- QUnit.test('should return an empty array for empty collections', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(empties, stubArray);
- var actual = lodashStable.transform(empties, function(result, value) {
- try {
- result.push(_.sampleSize(value, 1));
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should sample an object', function(assert) {
- assert.expect(2);
- var object = { 'a': 1, 'b': 2, 'c': 3 },
- actual = _.sampleSize(object, 2);
- assert.strictEqual(actual.length, 2);
- assert.deepEqual(lodashStable.difference(actual, lodashStable.values(object)), []);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map([['a']], _.sampleSize);
- assert.deepEqual(actual, [['a']]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.setWith');
- (function() {
- QUnit.test('should work with a `customizer` callback', function(assert) {
- assert.expect(1);
- var actual = _.setWith({ '0': {} }, '[0][1][2]', 3, function(value) {
- return lodashStable.isObject(value) ? undefined : {};
- });
- assert.deepEqual(actual, { '0': { '1': { '2': 3 } } });
- });
- QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
- assert.expect(1);
- var actual = _.setWith({}, 'a[0].b.c', 4, noop);
- assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('set methods');
- lodashStable.each(['update', 'updateWith', 'set', 'setWith'], function(methodName) {
- var func = _[methodName],
- isUpdate = methodName == 'update' || methodName == 'updateWith';
- var oldValue = 1,
- value = 2,
- updater = isUpdate ? lodashStable.constant(value) : value;
- QUnit.test('`_.' + methodName + '` should set property values', function(assert) {
- assert.expect(4);
- lodashStable.each(['a', ['a']], function(path) {
- var object = { 'a': oldValue },
- actual = func(object, path, updater);
- assert.strictEqual(actual, object);
- assert.strictEqual(object.a, value);
- });
- });
- QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var props = [-0, Object(-0), 0, Object(0)],
- expected = lodashStable.map(props, lodashStable.constant(value));
- var actual = lodashStable.map(props, function(key) {
- var object = { '-0': 'a', '0': 'b' };
- func(object, key, updater);
- return object[lodashStable.toString(key)];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should unset symbol keyed property values', function(assert) {
- assert.expect(2);
- if (Symbol) {
- var object = {};
- object[symbol] = 1;
- assert.strictEqual(_.unset(object, symbol), true);
- assert.notOk(symbol in object);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('`_.' + methodName + '` should set deep property values', function(assert) {
- assert.expect(4);
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var object = { 'a': { 'b': oldValue } },
- actual = func(object, path, updater);
- assert.strictEqual(actual, object);
- assert.strictEqual(object.a.b, value);
- });
- });
- QUnit.test('`_.' + methodName + '` should set a key over a path', function(assert) {
- assert.expect(4);
- lodashStable.each(['a.b', ['a.b']], function(path) {
- var object = { 'a.b': oldValue },
- actual = func(object, path, updater);
- assert.strictEqual(actual, object);
- assert.deepEqual(object, { 'a.b': value });
- });
- });
- QUnit.test('`_.' + methodName + '` should not coerce array paths to strings', function(assert) {
- assert.expect(1);
- var object = { 'a,b,c': 1, 'a': { 'b': { 'c': 1 } } };
- func(object, ['a', 'b', 'c'], updater);
- assert.strictEqual(object.a.b.c, value);
- });
- QUnit.test('`_.' + methodName + '` should not ignore empty brackets', function(assert) {
- assert.expect(1);
- var object = {};
- func(object, 'a[]', updater);
- assert.deepEqual(object, { 'a': { '': value } });
- });
- QUnit.test('`_.' + methodName + '` should handle empty paths', function(assert) {
- assert.expect(4);
- lodashStable.each([['', ''], [[], ['']]], function(pair, index) {
- var object = {};
- func(object, pair[0], updater);
- assert.deepEqual(object, index ? {} : { '': value });
- func(object, pair[1], updater);
- assert.deepEqual(object, { '': value });
- });
- });
- QUnit.test('`_.' + methodName + '` should handle complex paths', function(assert) {
- assert.expect(2);
- var object = { 'a': { '1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': oldValue } } } } } } } };
- var paths = [
- 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
- ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
- ];
- lodashStable.each(paths, function(path) {
- func(object, path, updater);
- assert.strictEqual(object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g, value);
- object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g = oldValue;
- });
- });
- QUnit.test('`_.' + methodName + '` should create parts of `path` that are missing', function(assert) {
- assert.expect(6);
- var object = {};
- lodashStable.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
- var actual = func(object, path, updater);
- assert.strictEqual(actual, object);
- assert.deepEqual(actual, { 'a': [undefined, { 'b': { 'c': value } }] });
- assert.notOk('0' in object.a);
- delete object.a;
- });
- });
- QUnit.test('`_.' + methodName + '` should not error when `object` is nullish', function(assert) {
- assert.expect(1);
- var values = [null, undefined],
- expected = [[null, null], [undefined, undefined]];
- var actual = lodashStable.map(values, function(value) {
- try {
- return [func(value, 'a.b', updater), func(value, ['a', 'b'], updater)];
- } catch (e) {
- return e.message;
- }
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should overwrite primitives in the path', function(assert) {
- assert.expect(2);
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var object = { 'a': '' };
- func(object, path, updater);
- assert.deepEqual(object, { 'a': { 'b': 2 } });
- });;
- });
- QUnit.test('`_.' + methodName + '` should not create an array for missing non-index property names that start with numbers', function(assert) {
- assert.expect(1);
- var object = {};
- func(object, ['1a', '2b', '3c'], updater);
- assert.deepEqual(object, { '1a': { '2b': { '3c': value } } });
- });
- QUnit.test('`_.' + methodName + '` should not assign values that are the same as their destinations', function(assert) {
- assert.expect(4);
- lodashStable.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
- var object = {},
- pass = true,
- updater = isUpdate ? lodashStable.constant(value) : value;
- defineProperty(object, 'a', {
- 'enumerable': true,
- 'configurable': true,
- 'get': lodashStable.constant(value),
- 'set': function() { pass = false; }
- });
- func(object, 'a', updater);
- assert.ok(pass);
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.shuffle');
- (function() {
- var array = [1, 2, 3],
- object = { 'a': 1, 'b': 2, 'c': 3 };
- QUnit.test('should return a new array', function(assert) {
- assert.expect(1);
- assert.notStrictEqual(_.shuffle(array), array);
- });
- QUnit.test('should contain the same elements after a collection is shuffled', function(assert) {
- assert.expect(2);
- assert.deepEqual(_.shuffle(array).sort(), array);
- assert.deepEqual(_.shuffle(object).sort(), array);
- });
- QUnit.test('should shuffle small collections', function(assert) {
- assert.expect(1);
- var actual = lodashStable.times(1000, function(assert) {
- return _.shuffle([1, 2]);
- });
- assert.deepEqual(lodashStable.sortBy(lodashStable.uniqBy(actual, String), '0'), [[1, 2], [2, 1]]);
- });
- QUnit.test('should treat number values for `collection` as empty', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.shuffle(1), []);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.size');
- (function() {
- var args = arguments,
- array = [1, 2, 3];
- QUnit.test('should return the number of own enumerable string keyed properties of an object', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.size({ 'one': 1, 'two': 2, 'three': 3 }), 3);
- });
- QUnit.test('should return the length of an array', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.size(array), 3);
- });
- QUnit.test('should accept a falsey `object` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubZero);
- var actual = lodashStable.map(falsey, function(object, index) {
- try {
- return index ? _.size(object) : _.size();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with `arguments` objects', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.size(args), 3);
- });
- QUnit.test('should work with jQuery/MooTools DOM query collections', function(assert) {
- assert.expect(1);
- function Foo(elements) {
- push.apply(this, elements);
- }
- Foo.prototype = { 'length': 0, 'splice': arrayProto.splice };
- assert.strictEqual(_.size(new Foo(array)), 3);
- });
- QUnit.test('should work with maps', function(assert) {
- assert.expect(2);
- if (Map) {
- lodashStable.each([new Map, realm.map], function(map) {
- map.set('a', 1);
- map.set('b', 2);
- assert.strictEqual(_.size(map), 2);
- map.clear();
- });
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should work with sets', function(assert) {
- assert.expect(2);
- if (Set) {
- lodashStable.each([new Set, realm.set], function(set) {
- set.add(1);
- set.add(2);
- assert.strictEqual(_.size(set), 2);
- set.clear();
- });
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should not treat objects with negative lengths as array-like', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.size({ 'length': -1 }), 1);
- });
- QUnit.test('should not treat objects with lengths larger than `MAX_SAFE_INTEGER` as array-like', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.size({ 'length': MAX_SAFE_INTEGER + 1 }), 1);
- });
- QUnit.test('should not treat objects with non-number lengths as array-like', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.size({ 'length': '0' }), 1);
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.slice');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should use a default `start` of `0` and a default `end` of `length`', function(assert) {
- assert.expect(2);
- var actual = _.slice(array);
- assert.deepEqual(actual, array);
- assert.notStrictEqual(actual, array);
- });
- QUnit.test('should work with a positive `start`', function(assert) {
- assert.expect(2);
- assert.deepEqual(_.slice(array, 1), [2, 3]);
- assert.deepEqual(_.slice(array, 1, 3), [2, 3]);
- });
- QUnit.test('should work with a `start` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(start) {
- assert.deepEqual(_.slice(array, start), []);
- });
- });
- QUnit.test('should treat falsey `start` values as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, lodashStable.constant(array));
- var actual = lodashStable.map(falsey, function(start) {
- return _.slice(array, start);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with a negative `start`', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.slice(array, -1), [3]);
- });
- QUnit.test('should work with a negative `start` <= negative `length`', function(assert) {
- assert.expect(3);
- lodashStable.each([-3, -4, -Infinity], function(start) {
- assert.deepEqual(_.slice(array, start), array);
- });
- });
- QUnit.test('should work with `start` >= `end`', function(assert) {
- assert.expect(2);
- lodashStable.each([2, 3], function(start) {
- assert.deepEqual(_.slice(array, start, 2), []);
- });
- });
- QUnit.test('should work with a positive `end`', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.slice(array, 0, 1), [1]);
- });
- QUnit.test('should work with a `end` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(end) {
- assert.deepEqual(_.slice(array, 0, end), array);
- });
- });
- QUnit.test('should treat falsey `end` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? array : [];
- });
- var actual = lodashStable.map(falsey, function(end, index) {
- return index ? _.slice(array, 0, end) : _.slice(array, 0);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with a negative `end`', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.slice(array, 0, -1), [1, 2]);
- });
- QUnit.test('should work with a negative `end` <= negative `length`', function(assert) {
- assert.expect(3);
- lodashStable.each([-3, -4, -Infinity], function(end) {
- assert.deepEqual(_.slice(array, 0, end), []);
- });
- });
- QUnit.test('should coerce `start` and `end` to integers', function(assert) {
- assert.expect(1);
- var positions = [[0.1, 1.6], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]];
- var actual = lodashStable.map(positions, function(pos) {
- return _.slice.apply(_, [array].concat(pos));
- });
- assert.deepEqual(actual, [[1], [1], [1], [2, 3], [1], []]);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(2);
- var array = [[1], [2, 3]],
- actual = lodashStable.map(array, _.slice);
- assert.deepEqual(actual, array);
- assert.notStrictEqual(actual, array);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(38);
- if (!isNpm) {
- var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
- length = array.length,
- wrapped = _(array);
- lodashStable.each(['map', 'filter'], function(methodName) {
- assert.deepEqual(wrapped[methodName]().slice(0, -1).value(), array.slice(0, -1));
- assert.deepEqual(wrapped[methodName]().slice(1).value(), array.slice(1));
- assert.deepEqual(wrapped[methodName]().slice(1, 3).value(), array.slice(1, 3));
- assert.deepEqual(wrapped[methodName]().slice(-1).value(), array.slice(-1));
- assert.deepEqual(wrapped[methodName]().slice(length).value(), array.slice(length));
- assert.deepEqual(wrapped[methodName]().slice(3, 2).value(), array.slice(3, 2));
- assert.deepEqual(wrapped[methodName]().slice(0, -length).value(), array.slice(0, -length));
- assert.deepEqual(wrapped[methodName]().slice(0, null).value(), array.slice(0, null));
- assert.deepEqual(wrapped[methodName]().slice(0, length).value(), array.slice(0, length));
- assert.deepEqual(wrapped[methodName]().slice(-length).value(), array.slice(-length));
- assert.deepEqual(wrapped[methodName]().slice(null).value(), array.slice(null));
- assert.deepEqual(wrapped[methodName]().slice(0, 1).value(), array.slice(0, 1));
- assert.deepEqual(wrapped[methodName]().slice(NaN, '1').value(), array.slice(NaN, '1'));
- assert.deepEqual(wrapped[methodName]().slice(0.1, 1.1).value(), array.slice(0.1, 1.1));
- assert.deepEqual(wrapped[methodName]().slice('0', 1).value(), array.slice('0', 1));
- assert.deepEqual(wrapped[methodName]().slice(0, '1').value(), array.slice(0, '1'));
- assert.deepEqual(wrapped[methodName]().slice('1').value(), array.slice('1'));
- assert.deepEqual(wrapped[methodName]().slice(NaN, 1).value(), array.slice(NaN, 1));
- assert.deepEqual(wrapped[methodName]().slice(1, NaN).value(), array.slice(1, NaN));
- });
- }
- else {
- skipAssert(assert, 38);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.some');
- (function() {
- QUnit.test('should return `true` if `predicate` returns truthy for any element', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.some([false, 1, ''], identity), true);
- assert.strictEqual(_.some([null, 'a', 0], identity), true);
- });
- QUnit.test('should return `false` for empty collections', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(empties, stubFalse);
- var actual = lodashStable.map(empties, function(value) {
- try {
- return _.some(value, identity);
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return `true` as soon as `predicate` returns truthy', function(assert) {
- assert.expect(2);
- var count = 0;
- assert.strictEqual(_.some([null, true, null], function(value) {
- count++;
- return value;
- }), true);
- assert.strictEqual(count, 2);
- });
- QUnit.test('should return `false` if `predicate` returns falsey for all elements', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.some([false, false, false], identity), false);
- assert.strictEqual(_.some([null, 0, ''], identity), false);
- });
- QUnit.test('should use `_.identity` when `predicate` is nullish', function(assert) {
- assert.expect(2);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value, index) {
- var array = [0, 0];
- return index ? _.some(array, value) : _.some(array);
- });
- assert.deepEqual(actual, expected);
- expected = lodashStable.map(values, stubTrue);
- actual = lodashStable.map(values, function(value, index) {
- var array = [0, 1];
- return index ? _.some(array, value) : _.some(array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(2);
- var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
- assert.strictEqual(_.some(objects, 'a'), false);
- assert.strictEqual(_.some(objects, 'b'), true);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(2);
- var objects = [{ 'a': 0, 'b': 0 }, { 'a': 1, 'b': 1}];
- assert.strictEqual(_.some(objects, { 'a': 0 }), true);
- assert.strictEqual(_.some(objects, { 'b': 2 }), false);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map([[1]], _.some);
- assert.deepEqual(actual, [true]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.sortBy');
- (function() {
- var objects = [
- { 'a': 'x', 'b': 3 },
- { 'a': 'y', 'b': 4 },
- { 'a': 'x', 'b': 1 },
- { 'a': 'y', 'b': 2 }
- ];
- QUnit.test('should sort in ascending order by `iteratee`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(_.sortBy(objects, function(object) {
- return object.b;
- }), 'b');
- assert.deepEqual(actual, [1, 2, 3, 4]);
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var array = [3, 2, 1],
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.sortBy(array, value) : _.sortBy(array);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(_.sortBy(objects.concat(undefined), 'b'), 'b');
- assert.deepEqual(actual, [1, 2, 3, 4, undefined]);
- });
- QUnit.test('should work with an object for `collection`', function(assert) {
- assert.expect(1);
- var actual = _.sortBy({ 'a': 1, 'b': 2, 'c': 3 }, Math.sin);
- assert.deepEqual(actual, [3, 1, 2]);
- });
- QUnit.test('should move `NaN`, nullish, and symbol values to the end', function(assert) {
- assert.expect(2);
- var symbol1 = Symbol ? Symbol('a') : null,
- symbol2 = Symbol ? Symbol('b') : null,
- array = [NaN, undefined, null, 4, symbol1, null, 1, symbol2, undefined, 3, NaN, 2],
- expected = [1, 2, 3, 4, symbol1, symbol2, null, null, undefined, undefined, NaN, NaN];
- assert.deepEqual(_.sortBy(array), expected);
- array = [NaN, undefined, symbol1, null, 'd', null, 'a', symbol2, undefined, 'c', NaN, 'b'];
- expected = ['a', 'b', 'c', 'd', symbol1, symbol2, null, null, undefined, undefined, NaN, NaN];
- assert.deepEqual(_.sortBy(array), expected);
- });
- QUnit.test('should treat number values for `collection` as empty', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.sortBy(1), []);
- });
- QUnit.test('should coerce arrays returned from `iteratee`', function(assert) {
- assert.expect(1);
- var actual = _.sortBy(objects, function(object) {
- var result = [object.a, object.b];
- result.toString = function() { return String(this[0]); };
- return result;
- });
- assert.deepEqual(actual, [objects[0], objects[2], objects[1], objects[3]]);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map([[2, 1, 3], [3, 2, 1]], _.sortBy);
- assert.deepEqual(actual, [[1, 2, 3], [1, 2, 3]]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('sortBy methods');
- lodashStable.each(['orderBy', 'sortBy'], function(methodName) {
- var func = _[methodName];
- function Pair(a, b, c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
- var objects = [
- { 'a': 'x', 'b': 3 },
- { 'a': 'y', 'b': 4 },
- { 'a': 'x', 'b': 1 },
- { 'a': 'y', 'b': 2 }
- ];
- var stableArray = [
- new Pair(1, 1, 1), new Pair(1, 2, 1),
- new Pair(1, 1, 1), new Pair(1, 2, 1),
- new Pair(1, 3, 1), new Pair(1, 4, 1),
- new Pair(1, 5, 1), new Pair(1, 6, 1),
- new Pair(2, 1, 2), new Pair(2, 2, 2),
- new Pair(2, 3, 2), new Pair(2, 4, 2),
- new Pair(2, 5, 2), new Pair(2, 6, 2),
- new Pair(undefined, 1, 1), new Pair(undefined, 2, 1),
- new Pair(undefined, 3, 1), new Pair(undefined, 4, 1),
- new Pair(undefined, 5, 1), new Pair(undefined, 6, 1)
- ];
- var stableObject = lodashStable.zipObject('abcdefghijklmnopqrst'.split(''), stableArray);
- QUnit.test('`_.' + methodName + '` should sort multiple properties in ascending order', function(assert) {
- assert.expect(1);
- var actual = func(objects, ['a', 'b']);
- assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
- });
- QUnit.test('`_.' + methodName + '` should support iteratees', function(assert) {
- assert.expect(1);
- var actual = func(objects, ['a', function(object) { return object.b; }]);
- assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);
- });
- QUnit.test('`_.' + methodName + '` should perform a stable sort (test in IE > 8 and V8)', function(assert) {
- assert.expect(2);
- lodashStable.each([stableArray, stableObject], function(value, index) {
- var actual = func(value, ['a', 'c']);
- assert.deepEqual(actual, stableArray, index ? 'object' : 'array');
- });
- });
- QUnit.test('`_.' + methodName + '` should not error on nullish elements', function(assert) {
- assert.expect(1);
- try {
- var actual = func(objects.concat(null, undefined), ['a', 'b']);
- } catch (e) {}
- assert.deepEqual(actual, [objects[2], objects[0], objects[3], objects[1], null, undefined]);
- });
- QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.reduce`', function(assert) {
- assert.expect(3);
- var objects = [
- { 'a': 'x', '0': 3 },
- { 'a': 'y', '0': 4 },
- { 'a': 'x', '0': 1 },
- { 'a': 'y', '0': 2 }
- ];
- var funcs = [func, lodashStable.partialRight(func, 'bogus')];
- lodashStable.each(['a', 0, [0]], function(props, index) {
- var expected = lodashStable.map(funcs, lodashStable.constant(
- index
- ? [objects[2], objects[3], objects[0], objects[1]]
- : [objects[0], objects[2], objects[1], objects[3]]
- ));
- var actual = lodashStable.map(funcs, function(func) {
- return lodashStable.reduce([props], func, objects);
- });
- assert.deepEqual(actual, expected);
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('sortedIndex methods');
- lodashStable.each(['sortedIndex', 'sortedLastIndex'], function(methodName) {
- var func = _[methodName],
- isSortedIndex = methodName == 'sortedIndex';
- QUnit.test('`_.' + methodName + '` should return the insert index', function(assert) {
- assert.expect(1);
- var array = [30, 50],
- values = [30, 40, 50],
- expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
- var actual = lodashStable.map(values, function(value) {
- return func(array, value);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with an array of strings', function(assert) {
- assert.expect(1);
- var array = ['a', 'c'],
- values = ['a', 'b', 'c'],
- expected = isSortedIndex ? [0, 1, 1] : [1, 1, 2];
- var actual = lodashStable.map(values, function(value) {
- return func(array, value);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should accept a falsey `array` argument and a `value`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, lodashStable.constant([0, 0, 0]));
- var actual = lodashStable.map(falsey, function(array) {
- return [func(array, 1), func(array, undefined), func(array, NaN)];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should align with `_.sortBy`', function(assert) {
- assert.expect(12);
- var symbol1 = Symbol ? Symbol('a') : null,
- symbol2 = Symbol ? Symbol('b') : null,
- symbol3 = Symbol ? Symbol('c') : null,
- expected = [1, '2', {}, symbol1, symbol2, null, undefined, NaN, NaN];
- lodashStable.each([
- [NaN, symbol1, null, 1, '2', {}, symbol2, NaN, undefined],
- ['2', null, 1, symbol1, NaN, {}, NaN, symbol2, undefined]
- ], function(array) {
- assert.deepEqual(_.sortBy(array), expected);
- assert.strictEqual(func(expected, 3), 2);
- assert.strictEqual(func(expected, symbol3), isSortedIndex ? 3 : (Symbol ? 5 : 6));
- assert.strictEqual(func(expected, null), isSortedIndex ? (Symbol ? 5 : 3) : 6);
- assert.strictEqual(func(expected, undefined), isSortedIndex ? 6 : 7);
- assert.strictEqual(func(expected, NaN), isSortedIndex ? 7 : 9);
- });
- });
- QUnit.test('`_.' + methodName + '` should align with `_.sortBy` for nulls', function(assert) {
- assert.expect(3);
- var array = [null, null];
- assert.strictEqual(func(array, null), isSortedIndex ? 0 : 2);
- assert.strictEqual(func(array, 1), 0);
- assert.strictEqual(func(array, 'a'), 0);
- });
- QUnit.test('`_.' + methodName + '` should align with `_.sortBy` for symbols', function(assert) {
- assert.expect(3);
- var symbol1 = Symbol ? Symbol('a') : null,
- symbol2 = Symbol ? Symbol('b') : null,
- symbol3 = Symbol ? Symbol('c') : null,
- array = [symbol1, symbol2];
- assert.strictEqual(func(array, symbol3), isSortedIndex ? 0 : 2);
- assert.strictEqual(func(array, 1), 0);
- assert.strictEqual(func(array, 'a'), 0);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('sortedIndexBy methods');
- lodashStable.each(['sortedIndexBy', 'sortedLastIndexBy'], function(methodName) {
- var func = _[methodName],
- isSortedIndexBy = methodName == 'sortedIndexBy';
- QUnit.test('`_.' + methodName + '` should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- func([30, 50], 40, function(assert) {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [40]);
- });
- QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- var objects = [{ 'x': 30 }, { 'x': 50 }],
- actual = func(objects, { 'x': 40 }, 'x');
- assert.strictEqual(actual, 1);
- });
- QUnit.test('`_.' + methodName + '` should support arrays larger than `MAX_ARRAY_LENGTH / 2`', function(assert) {
- assert.expect(12);
- lodashStable.each([Math.ceil(MAX_ARRAY_LENGTH / 2), MAX_ARRAY_LENGTH], function(length) {
- var array = [],
- values = [MAX_ARRAY_LENGTH, NaN, undefined];
- array.length = length;
- lodashStable.each(values, function(value) {
- var steps = 0;
- var actual = func(array, value, function(value) {
- steps++;
- return value;
- });
- var expected = (isSortedIndexBy ? !lodashStable.isNaN(value) : lodashStable.isFinite(value))
- ? 0
- : Math.min(length, MAX_ARRAY_INDEX);
- // Avoid false fails in older Firefox.
- if (array.length == length) {
- assert.ok(steps == 32 || steps == 33);
- assert.strictEqual(actual, expected);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('sortedIndexOf methods');
- lodashStable.each(['sortedIndexOf', 'sortedLastIndexOf'], function(methodName) {
- var func = _[methodName],
- isSortedIndexOf = methodName == 'sortedIndexOf';
- QUnit.test('`_.' + methodName + '` should perform a binary search', function(assert) {
- assert.expect(1);
- var sorted = [4, 4, 5, 5, 6, 6];
- assert.deepEqual(func(sorted, 5), isSortedIndexOf ? 2 : 3);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.sortedUniq');
- (function() {
- QUnit.test('should return unique values of a sorted array', function(assert) {
- assert.expect(3);
- var expected = [1, 2, 3];
- lodashStable.each([[1, 2, 3], [1, 1, 2, 2, 3], [1, 2, 3, 3, 3, 3, 3]], function(array) {
- assert.deepEqual(_.sortedUniq(array), expected);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.split');
- (function() {
- QUnit.test('should split a string by `separator`', function(assert) {
- assert.expect(3);
- var string = 'abcde';
- assert.deepEqual(_.split(string, 'c'), ['ab', 'de']);
- assert.deepEqual(_.split(string, /[bd]/), ['a', 'c', 'e']);
- assert.deepEqual(_.split(string, '', 2), ['a', 'b']);
- });
- QUnit.test('should return an array containing an empty string for empty values', function(assert) {
- assert.expect(1);
- var values = [, null, undefined, ''],
- expected = lodashStable.map(values, lodashStable.constant(['']));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.split(value) : _.split();
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var strings = ['abc', 'def', 'ghi'],
- actual = lodashStable.map(strings, _.split);
- assert.deepEqual(actual, [['abc'], ['def'], ['ghi']]);
- });
- QUnit.test('should allow mixed string and array prototype methods', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var wrapped = _('abc');
- assert.strictEqual(wrapped.split('b').join(','), 'a,c');
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.spread');
- (function() {
- function fn(a, b, c) {
- return slice.call(arguments);
- }
- QUnit.test('should spread arguments to `func`', function(assert) {
- assert.expect(1);
- var spread = _.spread(fn);
- assert.deepEqual(spread([4, 2]), [4, 2]);
- });
- QUnit.test('should accept a falsey `array` argument', function(assert) {
- assert.expect(1);
- var spread = _.spread(stubTrue),
- expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(array, index) {
- try {
- return index ? spread(array) : spread();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should provide correct `func` arguments', function(assert) {
- assert.expect(1);
- var args;
- var spread = _.spread(function() {
- args = slice.call(arguments);
- });
- spread([4, 2], 'ignored');
- assert.deepEqual(args, [4, 2]);
- });
- QUnit.test('should work with `start`', function(assert) {
- assert.expect(1);
- var spread = _.spread(fn, 1);
- assert.deepEqual(spread(1, [2, 3, 4]), [1, 2, 3, 4]);
- });
- QUnit.test('should treat `start` as `0` for negative or `NaN` values', function(assert) {
- assert.expect(1);
- var values = [-1, NaN, 'a'],
- expected = lodashStable.map(values, lodashStable.constant([1, 2, 3, 4]));
- var actual = lodashStable.map(values, function(value) {
- var spread = _.spread(fn, value);
- return spread([1, 2, 3, 4]);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should coerce `start` to an integer', function(assert) {
- assert.expect(1);
- var spread = _.spread(fn, 1.6);
- assert.deepEqual(spread(1, [2, 3]), [1, 2, 3]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.startCase');
- (function() {
- QUnit.test('should uppercase only the first character of each word', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.startCase('--foo-bar--'), 'Foo Bar');
- assert.strictEqual(_.startCase('fooBar'), 'Foo Bar');
- assert.strictEqual(_.startCase('__FOO_BAR__'), 'FOO BAR');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.startsWith');
- (function() {
- var string = 'abc';
- QUnit.test('should return `true` if a string starts with `target`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.startsWith(string, 'a'), true);
- });
- QUnit.test('should return `false` if a string does not start with `target`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.startsWith(string, 'b'), false);
- });
- QUnit.test('should work with a `position` argument', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.startsWith(string, 'b', 1), true);
- });
- QUnit.test('should work with `position` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
- assert.strictEqual(_.startsWith(string, 'a', position), false);
- });
- });
- QUnit.test('should treat falsey `position` values as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(position) {
- return _.startsWith(string, 'a', position);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should treat a negative `position` as `0`', function(assert) {
- assert.expect(6);
- lodashStable.each([-1, -3, -Infinity], function(position) {
- assert.strictEqual(_.startsWith(string, 'a', position), true);
- assert.strictEqual(_.startsWith(string, 'b', position), false);
- });
- });
- QUnit.test('should coerce `position` to an integer', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.startsWith(string, 'bc', 1.2), true);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.startsWith and lodash.endsWith');
- lodashStable.each(['startsWith', 'endsWith'], function(methodName) {
- var func = _[methodName],
- isStartsWith = methodName == 'startsWith';
- var string = 'abc',
- chr = isStartsWith ? 'a' : 'c';
- QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
- assert.expect(2);
- assert.strictEqual(func(Object(string), chr), true);
- assert.strictEqual(func({ 'toString': lodashStable.constant(string) }, chr), true);
- });
- QUnit.test('`_.' + methodName + '` should coerce `target` to a string', function(assert) {
- assert.expect(2);
- assert.strictEqual(func(string, Object(chr)), true);
- assert.strictEqual(func(string, { 'toString': lodashStable.constant(chr) }), true);
- });
- QUnit.test('`_.' + methodName + '` should coerce `position` to a number', function(assert) {
- assert.expect(2);
- var position = isStartsWith ? 1 : 2;
- assert.strictEqual(func(string, 'b', Object(position)), true);
- assert.strictEqual(func(string, 'b', { 'toString': lodashStable.constant(String(position)) }), true);
- });
- QUnit.test('should return `true` when `target` is an empty string regardless of `position`', function(assert) {
- assert.expect(1);
- var positions = [-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity];
- assert.ok(lodashStable.every(positions, function(position) {
- return func(string, '', position);
- }));
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('stub methods');
- lodashStable.each(['noop', 'stubTrue', 'stubFalse', 'stubArray', 'stubObject', 'stubString'], function(methodName) {
- var func = _[methodName];
- var pair = ({
- 'stubArray': [[], 'an empty array'],
- 'stubFalse': [false, '`false`'],
- 'stubObject': [{}, 'an empty object'],
- 'stubString': ['', 'an empty string'],
- 'stubTrue': [true, '`true`'],
- 'noop': [undefined, '`undefined`']
- })[methodName];
- var values = Array(2).concat(empties, true, 1, 'a'),
- expected = lodashStable.map(values, lodashStable.constant(pair[0]));
- QUnit.test('`_.' + methodName + '` should return ' + pair[1], function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(values, function(value, index) {
- if (index < 2) {
- return index ? func.call({}) : func();
- }
- return func(value);
- });
- assert.deepEqual(actual, expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.subtract');
- (function() {
- QUnit.test('should subtract two numbers', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.subtract(6, 4), 2);
- assert.strictEqual(_.subtract(-6, 4), -10);
- assert.strictEqual(_.subtract(-6, -4), -2);
- });
- QUnit.test('should coerce arguments to numbers', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.subtract('6', '4'), 2);
- assert.deepEqual(_.subtract('x', 'y'), NaN);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('math operator methods');
- lodashStable.each(['add', 'divide', 'multiply', 'subtract'], function(methodName) {
- var func = _[methodName],
- isAddSub = methodName == 'add' || methodName == 'subtract';
- QUnit.test('`_.' + methodName + '` should return `' + (isAddSub ? 0 : 1) + '` when no arguments are given', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(), isAddSub ? 0 : 1);
- });
- QUnit.test('`_.' + methodName + '` should work with only one defined argument', function(assert) {
- assert.expect(3);
- assert.strictEqual(func(6), 6);
- assert.strictEqual(func(6, undefined), 6);
- assert.strictEqual(func(undefined, 4), 4);
- });
- QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
- assert.expect(2);
- var values = [0, '0', -0, '-0'],
- expected = [[0, Infinity], ['0', Infinity], [-0, -Infinity], ['-0', -Infinity]];
- lodashStable.times(2, function(index) {
- var actual = lodashStable.map(values, function(value) {
- var result = index ? func(undefined, value) : func(value);
- return [result, 1 / result];
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('`_.' + methodName + '` should convert objects to `NaN`', function(assert) {
- assert.expect(2);
- assert.deepEqual(func(0, {}), NaN);
- assert.deepEqual(func({}, 0), NaN);
- });
- QUnit.test('`_.' + methodName + '` should convert symbols to `NaN`', function(assert) {
- assert.expect(2);
- if (Symbol) {
- assert.deepEqual(func(0, symbol), NaN);
- assert.deepEqual(func(symbol, 0), NaN);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = _(1)[methodName](2);
- assert.notOk(actual instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = _(1).chain()[methodName](2);
- assert.ok(actual instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.sumBy');
- (function() {
- var array = [6, 4, 2],
- objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
- QUnit.test('should work with an `iteratee` argument', function(assert) {
- assert.expect(1);
- var actual = _.sumBy(objects, function(object) {
- return object.a;
- });
- assert.deepEqual(actual, 6);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.sumBy(array, function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [6]);
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(2);
- var arrays = [[2], [3], [1]];
- assert.strictEqual(_.sumBy(arrays, 0), 6);
- assert.strictEqual(_.sumBy(objects, 'a'), 6);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('sum methods');
- lodashStable.each(['sum', 'sumBy'], function(methodName) {
- var array = [6, 4, 2],
- func = _[methodName];
- QUnit.test('`_.' + methodName + '` should return the sum of an array of numbers', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(array), 12);
- });
- QUnit.test('`_.' + methodName + '` should return `0` when passing empty `array` values', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(empties, stubZero);
- var actual = lodashStable.map(empties, function(value) {
- return func(value);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should skip `undefined` values', function(assert) {
- assert.expect(1);
- assert.strictEqual(func([1, undefined]), 1);
- });
- QUnit.test('`_.' + methodName + '` should not skip `NaN` values', function(assert) {
- assert.expect(1);
- assert.deepEqual(func([1, NaN]), NaN);
- });
- QUnit.test('`_.' + methodName + '` should not coerce values to numbers', function(assert) {
- assert.expect(1);
- assert.strictEqual(func(['1', '2']), '12');
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.tail');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should accept a falsey `array` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubArray);
- var actual = lodashStable.map(falsey, function(array, index) {
- try {
- return index ? _.tail(array) : _.tail();
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should exclude the first element', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.tail(array), [2, 3]);
- });
- QUnit.test('should return an empty when querying empty arrays', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.tail([]), []);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- actual = lodashStable.map(array, _.tail);
- assert.deepEqual(actual, [[2, 3], [5, 6], [8, 9]]);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE),
- values = [];
- var actual = _(array).tail().filter(function(value) {
- values.push(value);
- return false;
- })
- .value();
- assert.deepEqual(actual, []);
- assert.deepEqual(values, array.slice(1));
- values = [];
- actual = _(array).filter(function(value) {
- values.push(value);
- return isEven(value);
- })
- .tail()
- .value();
- assert.deepEqual(actual, _.tail(_.filter(array, isEven)));
- assert.deepEqual(values, array);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should not execute subsequent iteratees on an empty array in a lazy sequence', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE),
- iteratee = function() { pass = false; },
- pass = true,
- actual = _(array).slice(0, 1).tail().map(iteratee).value();
- assert.ok(pass);
- assert.deepEqual(actual, []);
- pass = true;
- actual = _(array).filter().slice(0, 1).tail().map(iteratee).value();
- assert.ok(pass);
- assert.deepEqual(actual, []);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.take');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should take the first two elements', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.take(array, 2), [1, 2]);
- });
- QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? [1] : [];
- });
- var actual = lodashStable.map(falsey, function(n) {
- return _.take(array, n);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return an empty array when `n` < `1`', function(assert) {
- assert.expect(3);
- lodashStable.each([0, -1, -Infinity], function(n) {
- assert.deepEqual(_.take(array, n), []);
- });
- });
- QUnit.test('should return all elements when `n` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
- assert.deepEqual(_.take(array, n), array);
- });
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- actual = lodashStable.map(array, _.take);
- assert.deepEqual(actual, [[1], [4], [7]]);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- var array = lodashStable.range(1, LARGE_ARRAY_SIZE + 1),
- predicate = function(value) { values.push(value); return isEven(value); },
- values = [],
- actual = _(array).take(2).take().value();
- assert.deepEqual(actual, _.take(_.take(array, 2)));
- actual = _(array).filter(predicate).take(2).take().value();
- assert.deepEqual(values, [1, 2]);
- assert.deepEqual(actual, _.take(_.take(_.filter(array, predicate), 2)));
- actual = _(array).take(6).takeRight(4).take(2).takeRight().value();
- assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(array, 6), 4), 2)));
- values = [];
- actual = _(array).take(array.length - 1).filter(predicate).take(6).takeRight(4).take(2).takeRight().value();
- assert.deepEqual(values, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
- assert.deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(_.filter(_.take(array, array.length - 1), predicate), 6), 4), 2)));
- }
- else {
- skipAssert(assert, 6);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.takeRight');
- (function() {
- var array = [1, 2, 3];
- QUnit.test('should take the last two elements', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.takeRight(array, 2), [2, 3]);
- });
- QUnit.test('should treat falsey `n` values, except `undefined`, as `0`', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, function(value) {
- return value === undefined ? [3] : [];
- });
- var actual = lodashStable.map(falsey, function(n) {
- return _.takeRight(array, n);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return an empty array when `n` < `1`', function(assert) {
- assert.expect(3);
- lodashStable.each([0, -1, -Infinity], function(n) {
- assert.deepEqual(_.takeRight(array, n), []);
- });
- });
- QUnit.test('should return all elements when `n` >= `length`', function(assert) {
- assert.expect(4);
- lodashStable.each([3, 4, Math.pow(2, 32), Infinity], function(n) {
- assert.deepEqual(_.takeRight(array, n), array);
- });
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- actual = lodashStable.map(array, _.takeRight);
- assert.deepEqual(actual, [[3], [6], [9]]);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(6);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE),
- predicate = function(value) { values.push(value); return isEven(value); },
- values = [],
- actual = _(array).takeRight(2).takeRight().value();
- assert.deepEqual(actual, _.takeRight(_.takeRight(array)));
- actual = _(array).filter(predicate).takeRight(2).takeRight().value();
- assert.deepEqual(values, array);
- assert.deepEqual(actual, _.takeRight(_.takeRight(_.filter(array, predicate), 2)));
- actual = _(array).takeRight(6).take(4).takeRight(2).take().value();
- assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(array, 6), 4), 2)));
- values = [];
- actual = _(array).filter(predicate).takeRight(6).take(4).takeRight(2).take().value();
- assert.deepEqual(values, array);
- assert.deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(_.filter(array, predicate), 6), 4), 2)));
- }
- else {
- skipAssert(assert, 6);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.takeRightWhile');
- (function() {
- var array = [1, 2, 3, 4];
- var objects = [
- { 'a': 0, 'b': 0 },
- { 'a': 1, 'b': 1 },
- { 'a': 2, 'b': 2 }
- ];
- QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
- assert.expect(1);
- var actual = _.takeRightWhile(array, function(n) {
- return n > 2;
- });
- assert.deepEqual(actual, [3, 4]);
- });
- QUnit.test('should provide correct `predicate` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.takeRightWhile(array, function() {
- args = slice.call(arguments);
- });
- assert.deepEqual(args, [4, 3, array]);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.takeRightWhile(objects, { 'b': 2 }), objects.slice(2));
- });
- QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.takeRightWhile(objects, ['b', 2]), objects.slice(2));
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.takeRightWhile(objects, 'b'), objects.slice(1));
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(3);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE),
- predicate = function(n) { return n > 2; },
- expected = _.takeRightWhile(array, predicate),
- wrapped = _(array).takeRightWhile(predicate);
- assert.deepEqual(wrapped.value(), expected);
- assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
- assert.strictEqual(wrapped.last(), _.last(expected));
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('should provide correct `predicate` arguments in a lazy sequence', function(assert) {
- assert.expect(5);
- if (!isNpm) {
- var args,
- array = lodashStable.range(LARGE_ARRAY_SIZE + 1);
- var expected = [
- square(LARGE_ARRAY_SIZE),
- LARGE_ARRAY_SIZE - 1,
- lodashStable.map(array.slice(1), square)
- ];
- _(array).slice(1).takeRightWhile(function(value, index, array) {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, [LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE - 1, array.slice(1)]);
- _(array).slice(1).map(square).takeRightWhile(function(value, index, array) {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, expected);
- _(array).slice(1).map(square).takeRightWhile(function(value, index) {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, expected);
- _(array).slice(1).map(square).takeRightWhile(function(index) {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, [square(LARGE_ARRAY_SIZE)]);
- _(array).slice(1).map(square).takeRightWhile(function() {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, expected);
- }
- else {
- skipAssert(assert, 5);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.takeWhile');
- (function() {
- var array = [1, 2, 3, 4];
- var objects = [
- { 'a': 2, 'b': 2 },
- { 'a': 1, 'b': 1 },
- { 'a': 0, 'b': 0 }
- ];
- QUnit.test('should take elements while `predicate` returns truthy', function(assert) {
- assert.expect(1);
- var actual = _.takeWhile(array, function(n) {
- return n < 3;
- });
- assert.deepEqual(actual, [1, 2]);
- });
- QUnit.test('should provide correct `predicate` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.takeWhile(array, function() {
- args = slice.call(arguments);
- });
- assert.deepEqual(args, [1, 0, array]);
- });
- QUnit.test('should work with `_.matches` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.takeWhile(objects, { 'b': 2 }), objects.slice(0, 1));
- });
- QUnit.test('should work with `_.matchesProperty` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.takeWhile(objects, ['b', 2]), objects.slice(0, 1));
- });
- QUnit.test('should work with `_.property` shorthands', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2));
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(3);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE),
- predicate = function(n) { return n < 3; },
- expected = _.takeWhile(array, predicate),
- wrapped = _(array).takeWhile(predicate);
- assert.deepEqual(wrapped.value(), expected);
- assert.deepEqual(wrapped.reverse().value(), expected.slice().reverse());
- assert.strictEqual(wrapped.last(), _.last(expected));
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('should work in a lazy sequence with `take`', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE);
- var actual = _(array)
- .takeWhile(function(n) { return n < 4; })
- .take(2)
- .takeWhile(function(n) { return n == 0; })
- .value();
- assert.deepEqual(actual, [0]);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should provide correct `predicate` arguments in a lazy sequence', function(assert) {
- assert.expect(5);
- if (!isNpm) {
- var args,
- array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
- expected = [1, 0, lodashStable.map(array.slice(1), square)];
- _(array).slice(1).takeWhile(function(value, index, array) {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, [1, 0, array.slice(1)]);
- _(array).slice(1).map(square).takeWhile(function(value, index, array) {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, expected);
- _(array).slice(1).map(square).takeWhile(function(value, index) {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, expected);
- _(array).slice(1).map(square).takeWhile(function(value) {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, [1]);
- _(array).slice(1).map(square).takeWhile(function() {
- args = slice.call(arguments);
- }).value();
- assert.deepEqual(args, expected);
- }
- else {
- skipAssert(assert, 5);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.tap');
- (function() {
- QUnit.test('should intercept and return the given value', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var intercepted,
- array = [1, 2, 3];
- var actual = _.tap(array, function(value) {
- intercepted = value;
- });
- assert.strictEqual(actual, array);
- assert.strictEqual(intercepted, array);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should intercept unwrapped values and return wrapped values when chaining', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var intercepted,
- array = [1, 2, 3];
- var wrapped = _(array).tap(function(value) {
- intercepted = value;
- value.pop();
- });
- assert.ok(wrapped instanceof _);
- wrapped.value();
- assert.strictEqual(intercepted, array);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.template');
- (function() {
- QUnit.test('should escape values in "escape" delimiters', function(assert) {
- assert.expect(1);
- var strings = ['<p><%- value %></p>', '<p><%-value%></p>', '<p><%-\nvalue\n%></p>'],
- expected = lodashStable.map(strings, lodashStable.constant('<p>&<>"'`\/</p>')),
- data = { 'value': '&<>"\'`\/' };
- var actual = lodashStable.map(strings, function(string) {
- return _.template(string)(data);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should not reference `_.escape` when "escape" delimiters are not used', function(assert) {
- assert.expect(1);
- var compiled = _.template('<%= typeof __e %>');
- assert.strictEqual(compiled({}), 'undefined');
- });
- QUnit.test('should evaluate JavaScript in "evaluate" delimiters', function(assert) {
- assert.expect(1);
- var compiled = _.template(
- '<ul><%\
- for (var key in collection) {\
- %><li><%= collection[key] %></li><%\
- } %></ul>'
- );
- var data = { 'collection': { 'a': 'A', 'b': 'B' } },
- actual = compiled(data);
- assert.strictEqual(actual, '<ul><li>A</li><li>B</li></ul>');
- });
- QUnit.test('should support "evaluate" delimiters with single line comments (test production builds)', function(assert) {
- assert.expect(1);
- var compiled = _.template('<% // A code comment. %><% if (value) { %>yap<% } else { %>nope<% } %>'),
- data = { 'value': true };
- assert.strictEqual(compiled(data), 'yap');
- });
- QUnit.test('should support referencing variables declared in "evaluate" delimiters from other delimiters', function(assert) {
- assert.expect(1);
- var compiled = _.template('<% var b = a; %><%= b.value %>'),
- data = { 'a': { 'value': 1 } };
- assert.strictEqual(compiled(data), '1');
- });
- QUnit.test('should interpolate data properties in "interpolate" delimiters', function(assert) {
- assert.expect(1);
- var strings = ['<%= a %>BC', '<%=a%>BC', '<%=\na\n%>BC'],
- expected = lodashStable.map(strings, lodashStable.constant('ABC')),
- data = { 'a': 'A' };
- var actual = lodashStable.map(strings, function(string) {
- return _.template(string)(data);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should support "interpolate" delimiters with escaped values', function(assert) {
- assert.expect(1);
- var compiled = _.template('<%= a ? "a=\\"A\\"" : "" %>'),
- data = { 'a': true };
- assert.strictEqual(compiled(data), 'a="A"');
- });
- QUnit.test('should support "interpolate" delimiters containing ternary operators', function(assert) {
- assert.expect(1);
- var compiled = _.template('<%= value ? value : "b" %>'),
- data = { 'value': 'a' };
- assert.strictEqual(compiled(data), 'a');
- });
- QUnit.test('should support "interpolate" delimiters containing global values', function(assert) {
- assert.expect(1);
- var compiled = _.template('<%= typeof Math.abs %>');
- try {
- var actual = compiled();
- } catch (e) {}
- assert.strictEqual(actual, 'function');
- });
- QUnit.test('should support complex "interpolate" delimiters', function(assert) {
- assert.expect(22);
- lodashStable.forOwn({
- '<%= a + b %>': '3',
- '<%= b - a %>': '1',
- '<%= a = b %>': '2',
- '<%= !a %>': 'false',
- '<%= ~a %>': '-2',
- '<%= a * b %>': '2',
- '<%= a / b %>': '0.5',
- '<%= a % b %>': '1',
- '<%= a >> b %>': '0',
- '<%= a << b %>': '4',
- '<%= a & b %>': '0',
- '<%= a ^ b %>': '3',
- '<%= a | b %>': '3',
- '<%= {}.toString.call(0) %>': numberTag,
- '<%= a.toFixed(2) %>': '1.00',
- '<%= obj["a"] %>': '1',
- '<%= delete a %>': 'true',
- '<%= "a" in obj %>': 'true',
- '<%= obj instanceof Object %>': 'true',
- '<%= new Boolean %>': 'false',
- '<%= typeof a %>': 'number',
- '<%= void a %>': ''
- },
- function(value, key) {
- var compiled = _.template(key),
- data = { 'a': 1, 'b': 2 };
- assert.strictEqual(compiled(data), value, key);
- });
- });
- QUnit.test('should support ES6 template delimiters', function(assert) {
- assert.expect(2);
- var data = { 'value': 2 };
- assert.strictEqual(_.template('1${value}3')(data), '123');
- assert.strictEqual(_.template('${"{" + value + "\\}"}')(data), '{2}');
- });
- QUnit.test('should support the "imports" option', function(assert) {
- assert.expect(1);
- var compiled = _.template('<%= a %>', { 'imports': { 'a': 1 } });
- assert.strictEqual(compiled({}), '1');
- });
- QUnit.test('should support the "variable" options', function(assert) {
- assert.expect(1);
- var compiled = _.template(
- '<% _.each( data.a, function( value ) { %>' +
- '<%= value.valueOf() %>' +
- '<% }) %>', { 'variable': 'data' }
- );
- var data = { 'a': [1, 2, 3] };
- try {
- assert.strictEqual(compiled(data), '123');
- } catch (e) {
- assert.ok(false, e.message);
- }
- });
- QUnit.test('should support custom delimiters', function(assert) {
- assert.expect(2);
- lodashStable.times(2, function(index) {
- var settingsClone = lodashStable.clone(_.templateSettings);
- var settings = lodashStable.assign(index ? _.templateSettings : {}, {
- 'escape': /\{\{-([\s\S]+?)\}\}/g,
- 'evaluate': /\{\{([\s\S]+?)\}\}/g,
- 'interpolate': /\{\{=([\s\S]+?)\}\}/g
- });
- var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
- compiled = _.template('<ul>{{ _.each(collection, function(value, index) {}}<li>{{= index }}: {{- value }}</li>{{}); }}</ul>', index ? null : settings),
- data = { 'collection': ['a & A', 'b & B'] };
- assert.strictEqual(compiled(data), expected);
- lodashStable.assign(_.templateSettings, settingsClone);
- });
- });
- QUnit.test('should support custom delimiters containing special characters', function(assert) {
- assert.expect(2);
- lodashStable.times(2, function(index) {
- var settingsClone = lodashStable.clone(_.templateSettings);
- var settings = lodashStable.assign(index ? _.templateSettings : {}, {
- 'escape': /<\?-([\s\S]+?)\?>/g,
- 'evaluate': /<\?([\s\S]+?)\?>/g,
- 'interpolate': /<\?=([\s\S]+?)\?>/g
- });
- var expected = '<ul><li>0: a & A</li><li>1: b & B</li></ul>',
- compiled = _.template('<ul><? _.each(collection, function(value, index) { ?><li><?= index ?>: <?- value ?></li><? }); ?></ul>', index ? null : settings),
- data = { 'collection': ['a & A', 'b & B'] };
- assert.strictEqual(compiled(data), expected);
- lodashStable.assign(_.templateSettings, settingsClone);
- });
- });
- QUnit.test('should use a `with` statement by default', function(assert) {
- assert.expect(1);
- var compiled = _.template('<%= index %><%= collection[index] %><% _.each(collection, function(value, index) { %><%= index %><% }); %>'),
- actual = compiled({ 'index': 1, 'collection': ['a', 'b', 'c'] });
- assert.strictEqual(actual, '1b012');
- });
- QUnit.test('should use `_.templateSettings.imports._.templateSettings`', function(assert) {
- assert.expect(1);
- var lodash = _.templateSettings.imports._,
- settingsClone = lodashStable.clone(lodash.templateSettings);
- lodash.templateSettings = lodashStable.assign(lodash.templateSettings, {
- 'interpolate': /\{\{=([\s\S]+?)\}\}/g
- });
- var compiled = _.template('{{= a }}');
- assert.strictEqual(compiled({ 'a': 1 }), '1');
- if (settingsClone) {
- lodashStable.assign(lodash.templateSettings, settingsClone);
- } else {
- delete lodash.templateSettings;
- }
- });
- QUnit.test('should fallback to `_.templateSettings`', function(assert) {
- assert.expect(1);
- var lodash = _.templateSettings.imports._,
- delimiter = _.templateSettings.interpolate;
- _.templateSettings.imports._ = { 'escape': lodashStable.escape };
- _.templateSettings.interpolate = /\{\{=([\s\S]+?)\}\}/g;
- var compiled = _.template('{{= a }}');
- assert.strictEqual(compiled({ 'a': 1 }), '1');
- _.templateSettings.imports._ = lodash;
- _.templateSettings.interpolate = delimiter;
- });
- QUnit.test('should ignore `null` delimiters', function(assert) {
- assert.expect(3);
- var delimiter = {
- 'escape': /\{\{-([\s\S]+?)\}\}/g,
- 'evaluate': /\{\{([\s\S]+?)\}\}/g,
- 'interpolate': /\{\{=([\s\S]+?)\}\}/g
- };
- lodashStable.forOwn({
- 'escape': '{{- a }}',
- 'evaluate': '{{ print(a) }}',
- 'interpolate': '{{= a }}'
- },
- function(value, key) {
- var settings = { 'escape': null, 'evaluate': null, 'interpolate': null };
- settings[key] = delimiter[key];
- var expected = '1 <%- a %> <% print(a) %> <%= a %>',
- compiled = _.template(value + ' <%- a %> <% print(a) %> <%= a %>', settings),
- data = { 'a': 1 };
- assert.strictEqual(compiled(data), expected);
- });
- });
- QUnit.test('should work without delimiters', function(assert) {
- assert.expect(1);
- var expected = 'abc';
- assert.strictEqual(_.template(expected)({}), expected);
- });
- QUnit.test('should work with `this` references', function(assert) {
- assert.expect(2);
- var compiled = _.template('a<%= this.String("b") %>c');
- assert.strictEqual(compiled(), 'abc');
- var object = { 'b': 'B' };
- object.compiled = _.template('A<%= this.b %>C', { 'variable': 'obj' });
- assert.strictEqual(object.compiled(), 'ABC');
- });
- QUnit.test('should work with backslashes', function(assert) {
- assert.expect(1);
- var compiled = _.template('<%= a %> \\b'),
- data = { 'a': 'A' };
- assert.strictEqual(compiled(data), 'A \\b');
- });
- QUnit.test('should work with escaped characters in string literals', function(assert) {
- assert.expect(2);
- var compiled = _.template('<% print("\'\\n\\r\\t\\u2028\\u2029\\\\") %>');
- assert.strictEqual(compiled(), "'\n\r\t\u2028\u2029\\");
- var data = { 'a': 'A' };
- compiled = _.template('\'\n\r\t<%= a %>\u2028\u2029\\"');
- assert.strictEqual(compiled(data), '\'\n\r\tA\u2028\u2029\\"');
- });
- QUnit.test('should handle \\u2028 & \\u2029 characters', function(assert) {
- assert.expect(1);
- var compiled = _.template('\u2028<%= "\\u2028\\u2029" %>\u2029');
- assert.strictEqual(compiled(), '\u2028\u2028\u2029\u2029');
- });
- QUnit.test('should work with statements containing quotes', function(assert) {
- assert.expect(1);
- var compiled = _.template("<%\
- if (a == 'A' || a == \"a\") {\
- %>'a',\"A\"<%\
- } %>"
- );
- var data = { 'a': 'A' };
- assert.strictEqual(compiled(data), "'a',\"A\"");
- });
- QUnit.test('should work with templates containing newlines and comments', function(assert) {
- assert.expect(1);
- var compiled = _.template('<%\n\
- // A code comment.\n\
- if (value) { value += 3; }\n\
- %><p><%= value %></p>'
- );
- assert.strictEqual(compiled({ 'value': 3 }), '<p>6</p>');
- });
- QUnit.test('should not error with IE conditional comments enabled (test with development build)', function(assert) {
- assert.expect(1);
- var compiled = _.template(''),
- pass = true;
- /*@cc_on @*/
- try {
- compiled();
- } catch (e) {
- pass = false;
- }
- assert.ok(pass);
- });
- QUnit.test('should tokenize delimiters', function(assert) {
- assert.expect(1);
- var compiled = _.template('<span class="icon-<%= type %>2"></span>'),
- data = { 'type': 1 };
- assert.strictEqual(compiled(data), '<span class="icon-12"></span>');
- });
- QUnit.test('should evaluate delimiters once', function(assert) {
- assert.expect(1);
- var actual = [],
- compiled = _.template('<%= func("a") %><%- func("b") %><% func("c") %>'),
- data = { 'func': function(value) { actual.push(value); } };
- compiled(data);
- assert.deepEqual(actual, ['a', 'b', 'c']);
- });
- QUnit.test('should match delimiters before escaping text', function(assert) {
- assert.expect(1);
- var compiled = _.template('<<\n a \n>>', { 'evaluate': /<<(.*?)>>/g });
- assert.strictEqual(compiled(), '<<\n a \n>>');
- });
- QUnit.test('should resolve nullish values to an empty string', function(assert) {
- assert.expect(3);
- var compiled = _.template('<%= a %><%- a %>'),
- data = { 'a': null };
- assert.strictEqual(compiled(data), '');
- data = { 'a': undefined };
- assert.strictEqual(compiled(data), '');
- data = { 'a': {} };
- compiled = _.template('<%= a.b %><%- a.b %>');
- assert.strictEqual(compiled(data), '');
- });
- QUnit.test('should return an empty string for empty values', function(assert) {
- assert.expect(1);
- var values = [, null, undefined, ''],
- expected = lodashStable.map(values, stubString),
- data = { 'a': 1 };
- var actual = lodashStable.map(values, function(value, index) {
- var compiled = index ? _.template(value) : _.template();
- return compiled(data);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should parse delimiters without newlines', function(assert) {
- assert.expect(1);
- var expected = '<<\nprint("<p>" + (value ? "yes" : "no") + "</p>")\n>>',
- compiled = _.template(expected, { 'evaluate': /<<(.+?)>>/g }),
- data = { 'value': true };
- assert.strictEqual(compiled(data), expected);
- });
- QUnit.test('should support recursive calls', function(assert) {
- assert.expect(1);
- var compiled = _.template('<%= a %><% a = _.template(c)(obj) %><%= a %>'),
- data = { 'a': 'A', 'b': 'B', 'c': '<%= b %>' };
- assert.strictEqual(compiled(data), 'AB');
- });
- QUnit.test('should coerce `text` argument to a string', function(assert) {
- assert.expect(1);
- var object = { 'toString': lodashStable.constant('<%= a %>') },
- data = { 'a': 1 };
- assert.strictEqual(_.template(object)(data), '1');
- });
- QUnit.test('should not modify the `options` object', function(assert) {
- assert.expect(1);
- var options = {};
- _.template('', options);
- assert.deepEqual(options, {});
- });
- QUnit.test('should not modify `_.templateSettings` when `options` are given', function(assert) {
- assert.expect(2);
- var data = { 'a': 1 };
- assert.notOk('a' in _.templateSettings);
- _.template('', {}, data);
- assert.notOk('a' in _.templateSettings);
- delete _.templateSettings.a;
- });
- QUnit.test('should not error for non-object `data` and `options` values', function(assert) {
- assert.expect(2);
- var pass = true;
- try {
- _.template('')(1);
- } catch (e) {
- pass = false;
- }
- assert.ok(pass, '`data` value');
- pass = true;
- try {
- _.template('', 1)(1);
- } catch (e) {
- pass = false;
- }
- assert.ok(pass, '`options` value');
- });
- QUnit.test('should expose the source on compiled templates', function(assert) {
- assert.expect(1);
- var compiled = _.template('x'),
- values = [String(compiled), compiled.source],
- expected = lodashStable.map(values, stubTrue);
- var actual = lodashStable.map(values, function(value) {
- return lodashStable.includes(value, '__p');
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should expose the source on SyntaxErrors', function(assert) {
- assert.expect(1);
- try {
- _.template('<% if x %>');
- } catch (e) {
- var source = e.source;
- }
- assert.ok(lodashStable.includes(source, '__p'));
- });
- QUnit.test('should not include sourceURLs in the source', function(assert) {
- assert.expect(1);
- var options = { 'sourceURL': '/a/b/c' },
- compiled = _.template('x', options),
- values = [compiled.source, undefined];
- try {
- _.template('<% if x %>', options);
- } catch (e) {
- values[1] = e.source;
- }
- var expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(values, function(value) {
- return lodashStable.includes(value, 'sourceURL');
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = ['<%= a %>', '<%- b %>', '<% print(c) %>'],
- compiles = lodashStable.map(array, _.template),
- data = { 'a': 'one', 'b': '`two`', 'c': 'three' };
- var actual = lodashStable.map(compiles, function(compiled) {
- return compiled(data);
- });
- assert.deepEqual(actual, ['one', '`two`', 'three']);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.truncate');
- (function() {
- var string = 'hi-diddly-ho there, neighborino';
- QUnit.test('should use a default `length` of `30`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.truncate(string), 'hi-diddly-ho there, neighbo...');
- });
- QUnit.test('should not truncate if `string` is <= `length`', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.truncate(string, { 'length': string.length }), string);
- assert.strictEqual(_.truncate(string, { 'length': string.length + 2 }), string);
- });
- QUnit.test('should truncate string the given length', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.truncate(string, { 'length': 24 }), 'hi-diddly-ho there, n...');
- });
- QUnit.test('should support a `omission` option', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
- });
- QUnit.test('should coerce nullish `omission` values to strings', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.truncate(string, { 'omission': null }), 'hi-diddly-ho there, neighbnull');
- assert.strictEqual(_.truncate(string, { 'omission': undefined }), 'hi-diddly-ho there, nundefined');
- });
- QUnit.test('should support a `length` option', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.truncate(string, { 'length': 4 }), 'h...');
- });
- QUnit.test('should support a `separator` option', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
- assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
- assert.strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/g }), 'hi-diddly-ho there...');
- });
- QUnit.test('should treat negative `length` as `0`', function(assert) {
- assert.expect(2);
- lodashStable.each([0, -2], function(length) {
- assert.strictEqual(_.truncate(string, { 'length': length }), '...');
- });
- });
- QUnit.test('should coerce `length` to an integer', function(assert) {
- assert.expect(4);
- lodashStable.each(['', NaN, 4.6, '4'], function(length, index) {
- var actual = index > 1 ? 'h...' : '...';
- assert.strictEqual(_.truncate(string, { 'length': { 'valueOf': lodashStable.constant(length) } }), actual);
- });
- });
- QUnit.test('should coerce `string` to a string', function(assert) {
- assert.expect(2);
- assert.strictEqual(_.truncate(Object(string), { 'length': 4 }), 'h...');
- assert.strictEqual(_.truncate({ 'toString': lodashStable.constant(string) }, { 'length': 5 }), 'hi...');
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map([string, string, string], _.truncate),
- truncated = 'hi-diddly-ho there, neighbo...';
- assert.deepEqual(actual, [truncated, truncated, truncated]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.throttle');
- (function() {
- QUnit.test('should throttle a function', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var callCount = 0,
- throttled = _.throttle(function() { callCount++; }, 32);
- throttled();
- throttled();
- throttled();
- var lastCount = callCount;
- assert.ok(callCount);
- setTimeout(function() {
- assert.ok(callCount > lastCount);
- done();
- }, 64);
- });
- QUnit.test('subsequent calls should return the result of the first call', function(assert) {
- assert.expect(5);
- var done = assert.async();
- var throttled = _.throttle(identity, 32),
- results = [throttled('a'), throttled('b')];
- assert.deepEqual(results, ['a', 'a']);
- setTimeout(function() {
- var results = [throttled('c'), throttled('d')];
- assert.notEqual(results[0], 'a');
- assert.notStrictEqual(results[0], undefined);
- assert.notEqual(results[1], 'd');
- assert.notStrictEqual(results[1], undefined);
- done();
- }, 64);
- });
- QUnit.test('should clear timeout when `func` is called', function(assert) {
- assert.expect(1);
- var done = assert.async();
- if (!isModularize) {
- var callCount = 0,
- dateCount = 0;
- var lodash = _.runInContext({
- 'Date': {
- 'now': function() {
- return ++dateCount == 5 ? Infinity : +new Date;
- }
- }
- });
- var throttled = lodash.throttle(function() { callCount++; }, 32);
- throttled();
- throttled();
- setTimeout(function() {
- assert.strictEqual(callCount, 2);
- done();
- }, 64);
- }
- else {
- skipAssert(assert);
- done();
- }
- });
- QUnit.test('should not trigger a trailing call when invoked once', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var callCount = 0,
- throttled = _.throttle(function() { callCount++; }, 32);
- throttled();
- assert.strictEqual(callCount, 1);
- setTimeout(function() {
- assert.strictEqual(callCount, 1);
- done();
- }, 64);
- });
- lodashStable.times(2, function(index) {
- QUnit.test('should trigger a call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), function(assert) {
- assert.expect(1);
- var done = assert.async();
- var callCount = 0,
- limit = (argv || isPhantom) ? 1000 : 320,
- options = index ? { 'leading': false } : {},
- throttled = _.throttle(function() { callCount++; }, 32, options);
- var start = +new Date;
- while ((new Date - start) < limit) {
- throttled();
- }
- var actual = callCount > 1;
- setTimeout(function() {
- assert.ok(actual);
- done();
- }, 1);
- });
- });
- QUnit.test('should trigger a second throttled call as soon as possible', function(assert) {
- assert.expect(3);
- var done = assert.async();
- var callCount = 0;
- var throttled = _.throttle(function() {
- callCount++;
- }, 128, { 'leading': false });
- throttled();
- setTimeout(function() {
- assert.strictEqual(callCount, 1);
- throttled();
- }, 192);
- setTimeout(function() {
- assert.strictEqual(callCount, 1);
- }, 254);
- setTimeout(function() {
- assert.strictEqual(callCount, 2);
- done();
- }, 384);
- });
- QUnit.test('should apply default options', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var callCount = 0,
- throttled = _.throttle(function() { callCount++; }, 32, {});
- throttled();
- throttled();
- assert.strictEqual(callCount, 1);
- setTimeout(function() {
- assert.strictEqual(callCount, 2);
- done();
- }, 128);
- });
- QUnit.test('should support a `leading` option', function(assert) {
- assert.expect(2);
- var withLeading = _.throttle(identity, 32, { 'leading': true });
- assert.strictEqual(withLeading('a'), 'a');
- var withoutLeading = _.throttle(identity, 32, { 'leading': false });
- assert.strictEqual(withoutLeading('a'), undefined);
- });
- QUnit.test('should support a `trailing` option', function(assert) {
- assert.expect(6);
- var done = assert.async();
- var withCount = 0,
- withoutCount = 0;
- var withTrailing = _.throttle(function(value) {
- withCount++;
- return value;
- }, 64, { 'trailing': true });
- var withoutTrailing = _.throttle(function(value) {
- withoutCount++;
- return value;
- }, 64, { 'trailing': false });
- assert.strictEqual(withTrailing('a'), 'a');
- assert.strictEqual(withTrailing('b'), 'a');
- assert.strictEqual(withoutTrailing('a'), 'a');
- assert.strictEqual(withoutTrailing('b'), 'a');
- setTimeout(function() {
- assert.strictEqual(withCount, 2);
- assert.strictEqual(withoutCount, 1);
- done();
- }, 256);
- });
- QUnit.test('should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var callCount = 0;
- var throttled = _.throttle(function() {
- callCount++;
- }, 64, { 'trailing': false });
- throttled();
- throttled();
- setTimeout(function() {
- throttled();
- throttled();
- }, 96);
- setTimeout(function() {
- assert.ok(callCount > 1);
- done();
- }, 192);
- });
- QUnit.test('should work with a system time of `0`', function(assert) {
- assert.expect(3);
- var done = assert.async();
- if (!isModularize) {
- var callCount = 0,
- dateCount = 0;
- var lodash = _.runInContext({
- 'Date': {
- 'now': function() {
- return ++dateCount < 4 ? 0 : +new Date;
- }
- }
- });
- var throttled = lodash.throttle(function(value) {
- callCount++;
- return value;
- }, 32);
- var results = [throttled('a'), throttled('b'), throttled('c')];
- assert.deepEqual(results, ['a', 'a', 'a']);
- assert.strictEqual(callCount, 1);
- setTimeout(function() {
- assert.strictEqual(callCount, 2);
- done();
- }, 64);
- }
- else {
- skipAssert(assert, 3);
- done();
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.debounce and lodash.throttle');
- lodashStable.each(['debounce', 'throttle'], function(methodName) {
- var func = _[methodName],
- isDebounce = methodName == 'debounce';
- QUnit.test('`_.' + methodName + '` should not error for non-object `options` values', function(assert) {
- assert.expect(1);
- var pass = true;
- try {
- func(noop, 32, 1);
- } catch (e) {
- pass = false;
- }
- assert.ok(pass);
- });
- QUnit.test('`_.' + methodName + '` should use a default `wait` of `0`', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var callCount = 0,
- funced = func(function() { callCount++; });
- funced();
- setTimeout(function() {
- funced();
- assert.strictEqual(callCount, isDebounce ? 1 : 2);
- done();
- }, 32);
- });
- QUnit.test('`_.' + methodName + '` should invoke `func` with the correct `this` binding', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var actual = [],
- object = { 'funced': func(function() { actual.push(this); }, 32) },
- expected = lodashStable.times(isDebounce ? 1 : 2, lodashStable.constant(object));
- object.funced();
- if (!isDebounce) {
- object.funced();
- }
- setTimeout(function() {
- assert.deepEqual(actual, expected);
- done();
- }, 64);
- });
- QUnit.test('`_.' + methodName + '` supports recursive calls', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var actual = [],
- args = lodashStable.map(['a', 'b', 'c'], function(chr) { return [{}, chr]; }),
- expected = args.slice(),
- queue = args.slice();
- var funced = func(function() {
- var current = [this];
- push.apply(current, arguments);
- actual.push(current);
- var next = queue.shift();
- if (next) {
- funced.call(next[0], next[1]);
- }
- }, 32);
- var next = queue.shift();
- funced.call(next[0], next[1]);
- assert.deepEqual(actual, expected.slice(0, isDebounce ? 0 : 1));
- setTimeout(function() {
- assert.deepEqual(actual, expected.slice(0, actual.length));
- done();
- }, 256);
- });
- QUnit.test('`_.' + methodName + '` should work if the system time is set backwards', function(assert) {
- assert.expect(1);
- var done = assert.async();
- if (!isModularize) {
- var callCount = 0,
- dateCount = 0;
- var lodash = _.runInContext({
- 'Date': {
- 'now': function() {
- return ++dateCount == 4
- ? +new Date(2012, 3, 23, 23, 27, 18)
- : +new Date;
- }
- }
- });
- var funced = lodash[methodName](function() {
- callCount++;
- }, 32);
- funced();
- setTimeout(function() {
- funced();
- assert.strictEqual(callCount, isDebounce ? 1 : 2);
- done();
- }, 64);
- }
- else {
- skipAssert(assert);
- done();
- }
- });
- QUnit.test('`_.' + methodName + '` should support cancelling delayed calls', function(assert) {
- assert.expect(1);
- var done = assert.async();
- var callCount = 0;
- var funced = func(function() {
- callCount++;
- }, 32, { 'leading': false });
- funced();
- funced.cancel();
- setTimeout(function() {
- assert.strictEqual(callCount, 0);
- done();
- }, 64);
- });
- QUnit.test('`_.' + methodName + '` should reset `lastCalled` after cancelling', function(assert) {
- assert.expect(3);
- var done = assert.async();
- var callCount = 0;
- var funced = func(function() {
- return ++callCount;
- }, 32, { 'leading': true });
- assert.strictEqual(funced(), 1);
- funced.cancel();
- assert.strictEqual(funced(), 2);
- funced();
- setTimeout(function() {
- assert.strictEqual(callCount, 3);
- done();
- }, 64);
- });
- QUnit.test('`_.' + methodName + '` should support flushing delayed calls', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var callCount = 0;
- var funced = func(function() {
- return ++callCount;
- }, 32, { 'leading': false });
- funced();
- assert.strictEqual(funced.flush(), 1);
- setTimeout(function() {
- assert.strictEqual(callCount, 1);
- done();
- }, 64);
- });
- QUnit.test('`_.' + methodName + '` should noop `cancel` and `flush` when nothing is queued', function(assert) {
- assert.expect(2);
- var done = assert.async();
- var callCount = 0,
- funced = func(function() { callCount++; }, 32);
- funced.cancel();
- assert.strictEqual(funced.flush(), undefined);
- setTimeout(function() {
- assert.strictEqual(callCount, 0);
- done();
- }, 64);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.times');
- (function() {
- QUnit.test('should coerce non-finite `n` values to `0`', function(assert) {
- assert.expect(3);
- lodashStable.each([-Infinity, NaN, Infinity], function(n) {
- assert.deepEqual(_.times(n), []);
- });
- });
- QUnit.test('should coerce `n` to an integer', function(assert) {
- assert.expect(1);
- var actual = _.times(2.6, _.indentify);
- assert.deepEqual(actual, [0, 1]);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.times(1, function(assert) {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [0]);
- });
- QUnit.test('should use `_.identity` when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant([0, 1, 2]));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.times(3, value) : _.times(3);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return an array of the results of each `iteratee` execution', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.times(3, doubled), [0, 2, 4]);
- });
- QUnit.test('should return an empty array for falsey and negative `n` arguments', function(assert) {
- assert.expect(1);
- var values = falsey.concat(-1, -Infinity),
- expected = lodashStable.map(values, stubArray);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.times(value) : _.times();
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.deepEqual(_(3).times(), [0, 1, 2]);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- assert.ok(_(3).chain().times() instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.toArray');
- (function() {
- QUnit.test('should convert objects to arrays', function(assert) {
- assert.expect(1);
- assert.deepEqual(_.toArray({ 'a': 1, 'b': 2 }), [1, 2]);
- });
- QUnit.test('should convert iterables to arrays', function(assert) {
- assert.expect(1);
- if (Symbol && Symbol.iterator) {
- var object = { '0': 'a', 'length': 1 };
- object[Symbol.iterator] = arrayProto[Symbol.iterator];
- assert.deepEqual(_.toArray(object), ['a']);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should convert maps to arrays', function(assert) {
- assert.expect(1);
- if (Map) {
- var map = new Map;
- map.set('a', 1);
- map.set('b', 2);
- assert.deepEqual(_.toArray(map), [['a', 1], ['b', 2]]);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should convert strings to arrays', function(assert) {
- assert.expect(3);
- assert.deepEqual(_.toArray(''), []);
- assert.deepEqual(_.toArray('ab'), ['a', 'b']);
- assert.deepEqual(_.toArray(Object('ab')), ['a', 'b']);
- });
- QUnit.test('should work in a lazy sequence', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE + 1);
- var object = lodashStable.zipObject(lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
- return ['key' + index, index];
- }));
- var actual = _(array).slice(1).map(String).toArray().value();
- assert.deepEqual(actual, lodashStable.map(array.slice(1), String));
- actual = _(object).toArray().slice(1).map(String).value();
- assert.deepEqual(actual, _.map(_.toArray(object).slice(1), String));
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.toLower');
- (function() {
- QUnit.test('should convert whole string to lower case', function(assert) {
- assert.expect(3);
- assert.deepEqual(_.toLower('--Foo-Bar--'), '--foo-bar--');
- assert.deepEqual(_.toLower('fooBar'), 'foobar');
- assert.deepEqual(_.toLower('__FOO_BAR__'), '__foo_bar__');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.toUpper');
- (function() {
- QUnit.test('should convert whole string to upper case', function(assert) {
- assert.expect(3);
- assert.deepEqual(_.toUpper('--Foo-Bar'), '--FOO-BAR');
- assert.deepEqual(_.toUpper('fooBar'), 'FOOBAR');
- assert.deepEqual(_.toUpper('__FOO_BAR__'), '__FOO_BAR__');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.slice and lodash.toArray');
- lodashStable.each(['slice', 'toArray'], function(methodName) {
- var args = (function() { return arguments; }(1, 2, 3)),
- array = [1, 2, 3],
- func = _[methodName];
- QUnit.test('`_.' + methodName + '` should return a dense array', function(assert) {
- assert.expect(3);
- var sparse = Array(3);
- sparse[1] = 2;
- var actual = func(sparse);
- assert.ok('0' in actual);
- assert.ok('2' in actual);
- assert.deepEqual(actual, sparse);
- });
- QUnit.test('`_.' + methodName + '` should treat array-like objects like arrays', function(assert) {
- assert.expect(2);
- var object = { '0': 'a', 'length': 1 };
- assert.deepEqual(func(object), ['a']);
- assert.deepEqual(func(args), array);
- });
- QUnit.test('`_.' + methodName + '` should return a shallow clone of arrays', function(assert) {
- assert.expect(2);
- var actual = func(array);
- assert.deepEqual(actual, array);
- assert.notStrictEqual(actual, array);
- });
- QUnit.test('`_.' + methodName + '` should work with a node list for `collection`', function(assert) {
- assert.expect(1);
- if (document) {
- try {
- var actual = func(document.getElementsByTagName('body'));
- } catch (e) {}
- assert.deepEqual(actual, [body]);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('toInteger methods');
- lodashStable.each(['toInteger', 'toSafeInteger'], function(methodName) {
- var func = _[methodName],
- isSafe = methodName == 'toSafeInteger';
- QUnit.test('`_.' + methodName + '` should convert values to integers', function(assert) {
- assert.expect(6);
- assert.strictEqual(func(-5.6), -5);
- assert.strictEqual(func('5.6'), 5);
- assert.strictEqual(func(), 0);
- assert.strictEqual(func(NaN), 0);
- var expected = isSafe ? MAX_SAFE_INTEGER : MAX_INTEGER;
- assert.strictEqual(func(Infinity), expected);
- assert.strictEqual(func(-Infinity), -expected);
- });
- QUnit.test('`_.' + methodName + '` should support `value` of `-0`', function(assert) {
- assert.expect(1);
- assert.strictEqual(1 / func(-0), -Infinity);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.toLength');
- (function() {
- QUnit.test('should return a valid length', function(assert) {
- assert.expect(4);
- assert.strictEqual(_.toLength(-1), 0);
- assert.strictEqual(_.toLength('1'), 1);
- assert.strictEqual(_.toLength(1.1), 1);
- assert.strictEqual(_.toLength(MAX_INTEGER), MAX_ARRAY_LENGTH);
- });
- QUnit.test('should return `value` if a valid length', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.toLength(0), 0);
- assert.strictEqual(_.toLength(3), 3);
- assert.strictEqual(_.toLength(MAX_ARRAY_LENGTH), MAX_ARRAY_LENGTH);
- });
- QUnit.test('should convert `-0` to `0`', function(assert) {
- assert.expect(1);
- assert.strictEqual(1 / _.toLength(-0), Infinity);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('number coercion methods');
- lodashStable.each(['toFinite', 'toInteger', 'toNumber', 'toSafeInteger'], function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should preserve the sign of `0`', function(assert) {
- assert.expect(2);
- var values = [0, '0', -0, '-0'],
- expected = [[0, Infinity], [0, Infinity], [-0, -Infinity], [-0, -Infinity]];
- lodashStable.times(2, function(index) {
- var others = lodashStable.map(values, index ? Object : identity);
- var actual = lodashStable.map(others, function(value) {
- var result = func(value);
- return [result, 1 / result];
- });
- assert.deepEqual(actual, expected);
- });
- });
- });
- lodashStable.each(['toFinite', 'toInteger', 'toLength', 'toNumber', 'toSafeInteger'], function(methodName) {
- var func = _[methodName],
- isToFinite = methodName == 'toFinite',
- isToLength = methodName == 'toLength',
- isToNumber = methodName == 'toNumber',
- isToSafeInteger = methodName == 'toSafeInteger';
- function negative(string) {
- return '-' + string;
- }
- function pad(string) {
- return whitespace + string + whitespace;
- }
- function positive(string) {
- return '+' + string;
- }
- QUnit.test('`_.' + methodName + '` should pass thru primitive number values', function(assert) {
- assert.expect(1);
- var values = [0, 1, NaN];
- var expected = lodashStable.map(values, function(value) {
- return (!isToNumber && value !== value) ? 0 : value;
- });
- var actual = lodashStable.map(values, func);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should convert number primitives and objects to numbers', function(assert) {
- assert.expect(1);
- var values = [2, 1.2, MAX_SAFE_INTEGER, MAX_INTEGER, Infinity, NaN];
- var expected = lodashStable.map(values, function(value) {
- if (!isToNumber) {
- if (!isToFinite && value == 1.2) {
- value = 1;
- }
- else if (value == Infinity) {
- value = MAX_INTEGER;
- }
- else if (value !== value) {
- value = 0;
- }
- if (isToLength || isToSafeInteger) {
- value = Math.min(value, isToLength ? MAX_ARRAY_LENGTH : MAX_SAFE_INTEGER);
- }
- }
- var neg = isToLength ? 0 : -value;
- return [value, value, neg, neg];
- });
- var actual = lodashStable.map(values, function(value) {
- return [func(value), func(Object(value)), func(-value), func(Object(-value))];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should convert string primitives and objects to numbers', function(assert) {
- assert.expect(1);
- var transforms = [identity, pad, positive, negative];
- var values = [
- '10', '1.234567890', (MAX_SAFE_INTEGER + ''),
- '1e+308', '1e308', '1E+308', '1E308',
- '5e-324', '5E-324',
- 'Infinity', 'NaN'
- ];
- var expected = lodashStable.map(values, function(value) {
- var n = +value;
- if (!isToNumber) {
- if (!isToFinite && n == 1.234567890) {
- n = 1;
- }
- else if (n == Infinity) {
- n = MAX_INTEGER;
- }
- else if ((!isToFinite && n == Number.MIN_VALUE) || n !== n) {
- n = 0;
- }
- if (isToLength || isToSafeInteger) {
- n = Math.min(n, isToLength ? MAX_ARRAY_LENGTH : MAX_SAFE_INTEGER);
- }
- }
- var neg = isToLength ? 0 : -n;
- return [n, n, n, n, n, n, neg, neg];
- });
- var actual = lodashStable.map(values, function(value) {
- return lodashStable.flatMap(transforms, function(mod) {
- return [func(mod(value)), func(Object(mod(value)))];
- });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should convert binary/octal strings to numbers', function(assert) {
- assert.expect(1);
- var numbers = [42, 5349, 1715004],
- transforms = [identity, pad],
- values = ['0b101010', '0o12345', '0x1a2b3c'];
- var expected = lodashStable.map(numbers, function(n) {
- return lodashStable.times(8, lodashStable.constant(n));
- });
- var actual = lodashStable.map(values, function(value) {
- var upper = value.toUpperCase();
- return lodashStable.flatMap(transforms, function(mod) {
- return [func(mod(value)), func(Object(mod(value))), func(mod(upper)), func(Object(mod(upper)))];
- });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should convert invalid binary/octal strings to `' + (isToNumber ? 'NaN' : '0') + '`', function(assert) {
- assert.expect(1);
- var transforms = [identity, pad, positive, negative],
- values = ['0b', '0o', '0x', '0b1010102', '0o123458', '0x1a2b3x'];
- var expected = lodashStable.map(values, function(n) {
- return lodashStable.times(8, lodashStable.constant(isToNumber ? NaN : 0));
- });
- var actual = lodashStable.map(values, function(value) {
- return lodashStable.flatMap(transforms, function(mod) {
- return [func(mod(value)), func(Object(mod(value)))];
- });
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should convert symbols to `' + (isToNumber ? 'NaN' : '0') + '`', function(assert) {
- assert.expect(1);
- if (Symbol) {
- var object1 = Object(symbol),
- object2 = Object(symbol),
- values = [symbol, object1, object2],
- expected = lodashStable.map(values, lodashStable.constant(isToNumber ? NaN : 0));
- object2.valueOf = undefined;
- var actual = lodashStable.map(values, func);
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should convert empty values to `0` or `NaN`', function(assert) {
- assert.expect(1);
- var values = falsey.concat(whitespace);
- var expected = lodashStable.map(values, function(value) {
- return (isToNumber && value !== whitespace) ? Number(value) : 0;
- });
- var actual = lodashStable.map(values, function(value, index) {
- return index ? func(value) : func();
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should coerce objects to numbers', function(assert) {
- assert.expect(1);
- var values = [
- {},
- [],
- [1],
- [1, 2],
- { 'valueOf': '1.1' },
- { 'valueOf': '1.1', 'toString': lodashStable.constant('2.2') },
- { 'valueOf': lodashStable.constant('1.1'), 'toString': '2.2' },
- { 'valueOf': lodashStable.constant('1.1'), 'toString': lodashStable.constant('2.2') },
- { 'valueOf': lodashStable.constant('-0x1a2b3c') },
- { 'toString': lodashStable.constant('-0x1a2b3c') },
- { 'valueOf': lodashStable.constant('0o12345') },
- { 'toString': lodashStable.constant('0o12345') },
- { 'valueOf': lodashStable.constant('0b101010') },
- { 'toString': lodashStable.constant('0b101010') }
- ];
- var expected = [
- NaN, 0, 1, NaN,
- NaN, 2.2, 1.1, 1.1,
- NaN, NaN,
- 5349, 5349,
- 42, 42
- ];
- if (isToFinite) {
- expected = [
- 0, 0, 1, 0,
- 0, 2.2, 1.1, 1.1,
- 0, 0,
- 5349, 5349,
- 42, 42
- ];
- }
- else if (!isToNumber) {
- expected = [
- 0, 0, 1, 0,
- 0, 2, 1, 1,
- 0, 0,
- 5349, 5349,
- 42, 42
- ];
- }
- var actual = lodashStable.map(values, func);
- assert.deepEqual(actual, expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.toPairs');
- (function() {
- QUnit.test('should be aliased', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.entries, _.toPairs);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.toPairsIn');
- (function() {
- QUnit.test('should be aliased', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.entriesIn, _.toPairsIn);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('toPairs methods');
- lodashStable.each(['toPairs', 'toPairsIn'], function(methodName) {
- var func = _[methodName],
- isToPairs = methodName == 'toPairs';
- QUnit.test('`_.' + methodName + '` should create an array of string keyed-value pairs', function(assert) {
- assert.expect(1);
- var object = { 'a': 1, 'b': 2 },
- actual = lodashStable.sortBy(func(object), 0);
- assert.deepEqual(actual, [['a', 1], ['b', 2]]);
- });
- QUnit.test('`_.' + methodName + '` should ' + (isToPairs ? 'not ' : '') + 'include inherited string keyed property values', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var expected = isToPairs ? [['a', 1]] : [['a', 1], ['b', 2]],
- actual = lodashStable.sortBy(func(new Foo), 0);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should convert objects with a `length` property', function(assert) {
- assert.expect(1);
- var object = { '0': 'a', '1': 'b', 'length': 2 },
- actual = lodashStable.sortBy(func(object), 0);
- assert.deepEqual(actual, [['0', 'a'], ['1', 'b'], ['length', 2]]);
- });
- QUnit.test('`_.' + methodName + '` should convert maps', function(assert) {
- assert.expect(1);
- if (Map) {
- var map = new Map;
- map.set('a', 1);
- map.set('b', 2);
- assert.deepEqual(func(map), [['a', 1], ['b', 2]]);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should convert sets', function(assert) {
- assert.expect(1);
- if (Set) {
- var set = new Set;
- set.add(1);
- set.add(2);
- assert.deepEqual(func(set), [[1, 1], [2, 2]]);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should convert strings', function(assert) {
- assert.expect(2);
- lodashStable.each(['xo', Object('xo')], function(string) {
- var actual = lodashStable.sortBy(func(string), 0);
- assert.deepEqual(actual, [['0', 'x'], ['1', 'o']]);
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.toPath');
- (function() {
- QUnit.test('should convert a string to a path', function(assert) {
- assert.expect(2);
- assert.deepEqual(_.toPath('a.b.c'), ['a', 'b', 'c']);
- assert.deepEqual(_.toPath('a[0].b.c'), ['a', '0', 'b', 'c']);
- });
- QUnit.test('should coerce array elements to strings', function(assert) {
- assert.expect(4);
- var array = ['a', 'b', 'c'];
- lodashStable.each([array, lodashStable.map(array, Object)], function(value) {
- var actual = _.toPath(value);
- assert.deepEqual(actual, array);
- assert.notStrictEqual(actual, array);
- });
- });
- QUnit.test('should a new path array', function(assert) {
- assert.expect(1);
- assert.notStrictEqual(_.toPath('a.b.c'), _.toPath('a.b.c'));
- });
- QUnit.test('should not coerce symbols to strings', function(assert) {
- assert.expect(4);
- if (Symbol) {
- var object = Object(symbol);
- lodashStable.each([symbol, object, [symbol], [object]], function(value) {
- var actual = _.toPath(value);
- assert.ok(lodashStable.isSymbol(actual[0]));
- });
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should handle complex paths', function(assert) {
- assert.expect(1);
- var actual = _.toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g');
- assert.deepEqual(actual, ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']);
- });
- QUnit.test('should handle consecutive empty brackets and dots', function(assert) {
- assert.expect(12);
- var expected = ['', 'a'];
- assert.deepEqual(_.toPath('.a'), expected);
- assert.deepEqual(_.toPath('[].a'), expected);
- expected = ['', '', 'a'];
- assert.deepEqual(_.toPath('..a'), expected);
- assert.deepEqual(_.toPath('[][].a'), expected);
- expected = ['a', '', 'b'];
- assert.deepEqual(_.toPath('a..b'), expected);
- assert.deepEqual(_.toPath('a[].b'), expected);
- expected = ['a', '', '', 'b'];
- assert.deepEqual(_.toPath('a...b'), expected);
- assert.deepEqual(_.toPath('a[][].b'), expected);
- expected = ['a', ''];
- assert.deepEqual(_.toPath('a.'), expected);
- assert.deepEqual(_.toPath('a[]'), expected);
- expected = ['a', '', ''];
- assert.deepEqual(_.toPath('a..'), expected);
- assert.deepEqual(_.toPath('a[][]'), expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.toPlainObject');
- (function() {
- var args = arguments;
- QUnit.test('should flatten inherited string keyed properties', function(assert) {
- assert.expect(1);
- function Foo() {
- this.b = 2;
- }
- Foo.prototype.c = 3;
- var actual = lodashStable.assign({ 'a': 1 }, _.toPlainObject(new Foo));
- assert.deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
- });
- QUnit.test('should convert `arguments` objects to plain objects', function(assert) {
- assert.expect(1);
- var actual = _.toPlainObject(args),
- expected = { '0': 1, '1': 2, '2': 3 };
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should convert arrays to plain objects', function(assert) {
- assert.expect(1);
- var actual = _.toPlainObject(['a', 'b', 'c']),
- expected = { '0': 'a', '1': 'b', '2': 'c' };
- assert.deepEqual(actual, expected);
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.toString');
- (function() {
- QUnit.test('should treat nullish values as empty strings', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubString);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.toString(value) : _.toString();
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var values = [-0, Object(-0), 0, Object(0)],
- expected = ['-0', '-0', '0', '0'],
- actual = lodashStable.map(values, _.toString);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should not error on symbols', function(assert) {
- assert.expect(1);
- if (Symbol) {
- try {
- assert.strictEqual(_.toString(symbol), 'Symbol(a)');
- } catch (e) {
- assert.ok(false, e.message);
- }
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var wrapped = _([1, 2, 3]);
- assert.strictEqual(wrapped.toString(), '1,2,3');
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.transform');
- (function() {
- function Foo() {
- this.a = 1;
- this.b = 2;
- this.c = 3;
- }
- QUnit.test('should create an object with the same `[[Prototype]]` as `object` when `accumulator` is nullish', function(assert) {
- assert.expect(4);
- var accumulators = [, null, undefined],
- object = new Foo,
- expected = lodashStable.map(accumulators, stubTrue);
- var iteratee = function(result, value, key) {
- result[key] = square(value);
- };
- var mapper = function(accumulator, index) {
- return index ? _.transform(object, iteratee, accumulator) : _.transform(object, iteratee);
- };
- var results = lodashStable.map(accumulators, mapper);
- var actual = lodashStable.map(results, function(result) {
- return result instanceof Foo;
- });
- assert.deepEqual(actual, expected);
- expected = lodashStable.map(accumulators, lodashStable.constant({ 'a': 1, 'b': 4, 'c': 9 }));
- actual = lodashStable.map(results, lodashStable.toPlainObject);
- assert.deepEqual(actual, expected);
- object = { 'a': 1, 'b': 2, 'c': 3 };
- actual = lodashStable.map(accumulators, mapper);
- assert.deepEqual(actual, expected);
- object = [1, 2, 3];
- expected = lodashStable.map(accumulators, lodashStable.constant([1, 4, 9]));
- actual = lodashStable.map(accumulators, mapper);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should create regular arrays from typed arrays', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(typedArrays, stubTrue);
- var actual = lodashStable.map(typedArrays, function(type) {
- var Ctor = root[type],
- array = Ctor ? new Ctor(new ArrayBuffer(24)) : [];
- return lodashStable.isArray(_.transform(array, noop));
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should support an `accumulator` value', function(assert) {
- assert.expect(6);
- var values = [new Foo, [1, 2, 3], { 'a': 1, 'b': 2, 'c': 3 }],
- expected = lodashStable.map(values, lodashStable.constant([1, 4, 9]));
- var actual = lodashStable.map(values, function(value) {
- return _.transform(value, function(result, value) {
- result.push(square(value));
- }, []);
- });
- assert.deepEqual(actual, expected);
- var object = { 'a': 1, 'b': 4, 'c': 9 },
- expected = [object, { '0': 1, '1': 4, '2': 9 }, object];
- actual = lodashStable.map(values, function(value) {
- return _.transform(value, function(result, value, key) {
- result[key] = square(value);
- }, {});
- });
- assert.deepEqual(actual, expected);
- lodashStable.each([[], {}], function(accumulator) {
- var actual = lodashStable.map(values, function(value) {
- return _.transform(value, noop, accumulator);
- });
- assert.ok(lodashStable.every(actual, function(result) {
- return result === accumulator;
- }));
- assert.strictEqual(_.transform(null, null, accumulator), accumulator);
- });
- });
- QUnit.test('should treat sparse arrays as dense', function(assert) {
- assert.expect(1);
- var actual = _.transform(Array(1), function(result, value, index) {
- result[index] = String(value);
- });
- assert.deepEqual(actual, ['undefined']);
- });
- QUnit.test('should work without an `iteratee` argument', function(assert) {
- assert.expect(1);
- assert.ok(_.transform(new Foo) instanceof Foo);
- });
- QUnit.test('should ensure `object` is an object before using its `[[Prototype]]`', function(assert) {
- assert.expect(2);
- var Ctors = [Boolean, Boolean, Number, Number, Number, String, String],
- values = [false, true, 0, 1, NaN, '', 'a'],
- expected = lodashStable.map(values, stubObject);
- var results = lodashStable.map(values, function(value) {
- return _.transform(value);
- });
- assert.deepEqual(results, expected);
- expected = lodashStable.map(values, stubFalse);
- var actual = lodashStable.map(results, function(value, index) {
- return value instanceof Ctors[index];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should ensure `object` constructor is a function before using its `[[Prototype]]`', function(assert) {
- assert.expect(1);
- Foo.prototype.constructor = null;
- assert.notOk(_.transform(new Foo) instanceof Foo);
- Foo.prototype.constructor = Foo;
- });
- QUnit.test('should create an empty object when given a falsey `object` argument', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubObject);
- var actual = lodashStable.map(falsey, function(object, index) {
- return index ? _.transform(object) : _.transform();
- });
- assert.deepEqual(actual, expected);
- });
- lodashStable.each({
- 'array': [1, 2, 3],
- 'object': { 'a': 1, 'b': 2, 'c': 3 }
- },
- function(object, key) {
- QUnit.test('should provide correct `iteratee` arguments when transforming an ' + key, function(assert) {
- assert.expect(2);
- var args;
- _.transform(object, function() {
- args || (args = slice.call(arguments));
- });
- var first = args[0];
- if (key == 'array') {
- assert.ok(first !== object && lodashStable.isArray(first));
- assert.deepEqual(args, [first, 1, 0, object]);
- } else {
- assert.ok(first !== object && lodashStable.isPlainObject(first));
- assert.deepEqual(args, [first, 1, 'a', object]);
- }
- });
- });
- QUnit.test('should create an object from the same realm as `object`', function(assert) {
- assert.expect(1);
- var objects = lodashStable.filter(realm, function(value) {
- return lodashStable.isObject(value) && !lodashStable.isElement(value);
- });
- var expected = lodashStable.map(objects, stubTrue);
- var actual = lodashStable.map(objects, function(object) {
- var Ctor = object.constructor,
- result = _.transform(object);
- if (result === object) {
- return false;
- }
- if (lodashStable.isTypedArray(object)) {
- return result instanceof Array;
- }
- return result instanceof Ctor || !(new Ctor instanceof Ctor);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('trim methods');
- lodashStable.each(['trim', 'trimStart', 'trimEnd'], function(methodName, index) {
- var func = _[methodName],
- parts = [];
- if (index != 2) {
- parts.push('leading');
- }
- if (index != 1) {
- parts.push('trailing');
- }
- parts = parts.join(' and ');
- QUnit.test('`_.' + methodName + '` should remove ' + parts + ' whitespace', function(assert) {
- assert.expect(1);
- var string = whitespace + 'a b c' + whitespace,
- expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
- assert.strictEqual(func(string), expected);
- });
- QUnit.test('`_.' + methodName + '` should coerce `string` to a string', function(assert) {
- assert.expect(1);
- var object = { 'toString': lodashStable.constant(whitespace + 'a b c' + whitespace) },
- expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
- assert.strictEqual(func(object), expected);
- });
- QUnit.test('`_.' + methodName + '` should remove ' + parts + ' `chars`', function(assert) {
- assert.expect(1);
- var string = '-_-a-b-c-_-',
- expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
- assert.strictEqual(func(string, '_-'), expected);
- });
- QUnit.test('`_.' + methodName + '` should coerce `chars` to a string', function(assert) {
- assert.expect(1);
- var object = { 'toString': lodashStable.constant('_-') },
- string = '-_-a-b-c-_-',
- expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '');
- assert.strictEqual(func(string, object), expected);
- });
- QUnit.test('`_.' + methodName + '` should return an empty string for empty values and `chars`', function(assert) {
- assert.expect(6);
- lodashStable.each([null, '_-'], function(chars) {
- assert.strictEqual(func(null, chars), '');
- assert.strictEqual(func(undefined, chars), '');
- assert.strictEqual(func('', chars), '');
- });
- });
- QUnit.test('`_.' + methodName + '` should work with `undefined` or empty string values for `chars`', function(assert) {
- assert.expect(2);
- var string = whitespace + 'a b c' + whitespace,
- expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
- assert.strictEqual(func(string, undefined), expected);
- assert.strictEqual(func(string, ''), string);
- });
- QUnit.test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var string = Object(whitespace + 'a b c' + whitespace),
- trimmed = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : ''),
- actual = lodashStable.map([string, string, string], func);
- assert.deepEqual(actual, [trimmed, trimmed, trimmed]);
- });
- QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var string = whitespace + 'a b c' + whitespace,
- expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
- assert.strictEqual(_(string)[methodName](), expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var string = whitespace + 'a b c' + whitespace;
- assert.ok(_(string).chain()[methodName]() instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('uncommon symbols');
- (function() {
- var flag = '\ud83c\uddfa\ud83c\uddf8',
- heart = '\u2764' + emojiVar,
- hearts = '\ud83d\udc95',
- comboGlyph = '\ud83d\udc68\u200d' + heart + '\u200d\ud83d\udc8B\u200d\ud83d\udc68',
- hashKeycap = '#' + emojiVar + '\u20e3',
- leafs = '\ud83c\udf42',
- mic = '\ud83c\udf99',
- noMic = mic + '\u20e0',
- raisedHand = '\u270B' + emojiVar,
- rocket = '\ud83d\ude80',
- thumbsUp = '\ud83d\udc4d';
- QUnit.test('should account for astral symbols', function(assert) {
- assert.expect(34);
- var allHearts = _.repeat(hearts, 10),
- chars = hearts + comboGlyph,
- string = 'A ' + leafs + ', ' + comboGlyph + ', and ' + rocket,
- trimChars = comboGlyph + hearts,
- trimString = trimChars + string + trimChars;
- assert.strictEqual(_.camelCase(hearts + ' the ' + leafs), hearts + 'The' + leafs);
- assert.strictEqual(_.camelCase(string), 'a' + leafs + comboGlyph + 'And' + rocket);
- assert.strictEqual(_.capitalize(rocket), rocket);
- assert.strictEqual(_.pad(string, 16), ' ' + string + ' ');
- assert.strictEqual(_.padStart(string, 16), ' ' + string);
- assert.strictEqual(_.padEnd(string, 16), string + ' ');
- assert.strictEqual(_.pad(string, 16, chars), hearts + string + chars);
- assert.strictEqual(_.padStart(string, 16, chars), chars + hearts + string);
- assert.strictEqual(_.padEnd(string, 16, chars), string + chars + hearts);
- assert.strictEqual(_.size(string), 13);
- assert.deepEqual(_.split(string, ' '), ['A', leafs + ',', comboGlyph + ',', 'and', rocket]);
- assert.deepEqual(_.split(string, ' ', 3), ['A', leafs + ',', comboGlyph + ',']);
- assert.deepEqual(_.split(string, undefined), [string]);
- assert.deepEqual(_.split(string, undefined, -1), [string]);
- assert.deepEqual(_.split(string, undefined, 0), []);
- var expected = ['A', ' ', leafs, ',', ' ', comboGlyph, ',', ' ', 'a', 'n', 'd', ' ', rocket];
- assert.deepEqual(_.split(string, ''), expected);
- assert.deepEqual(_.split(string, '', 6), expected.slice(0, 6));
- assert.deepEqual(_.toArray(string), expected);
- assert.strictEqual(_.trim(trimString, chars), string);
- assert.strictEqual(_.trimStart(trimString, chars), string + trimChars);
- assert.strictEqual(_.trimEnd(trimString, chars), trimChars + string);
- assert.strictEqual(_.truncate(string, { 'length': 13 }), string);
- assert.strictEqual(_.truncate(string, { 'length': 6 }), 'A ' + leafs + '...');
- assert.deepEqual(_.words(string), ['A', leafs, comboGlyph, 'and', rocket]);
- assert.deepEqual(_.toArray(hashKeycap), [hashKeycap]);
- assert.deepEqual(_.toArray(noMic), [noMic]);
- lodashStable.times(2, function(index) {
- var separator = index ? RegExp(hearts) : hearts,
- options = { 'length': 4, 'separator': separator },
- actual = _.truncate(string, options);
- assert.strictEqual(actual, 'A...');
- assert.strictEqual(actual.length, 4);
- actual = _.truncate(allHearts, options);
- assert.strictEqual(actual, hearts + '...');
- assert.strictEqual(actual.length, 5);
- });
- });
- QUnit.test('should account for combining diacritical marks', function(assert) {
- assert.expect(1);
- var values = lodashStable.map(comboMarks, function(mark) {
- return 'o' + mark;
- });
- var expected = lodashStable.map(values, function(value) {
- return [1, [value], [value]];
- });
- var actual = lodashStable.map(values, function(value) {
- return [_.size(value), _.toArray(value), _.words(value)];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should account for fitzpatrick modifiers', function(assert) {
- assert.expect(1);
- var values = lodashStable.map(fitzModifiers, function(modifier) {
- return thumbsUp + modifier;
- });
- var expected = lodashStable.map(values, function(value) {
- return [1, [value], [value]];
- });
- var actual = lodashStable.map(values, function(value) {
- return [_.size(value), _.toArray(value), _.words(value)];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should account for regional symbols', function(assert) {
- assert.expect(6);
- var pair = flag.match(/\ud83c[\udde6-\uddff]/g),
- regionals = pair.join(' ');
- assert.strictEqual(_.size(flag), 1);
- assert.strictEqual(_.size(regionals), 3);
- assert.deepEqual(_.toArray(flag), [flag]);
- assert.deepEqual(_.toArray(regionals), [pair[0], ' ', pair[1]]);
- assert.deepEqual(_.words(flag), [flag]);
- assert.deepEqual(_.words(regionals), [pair[0], pair[1]]);
- });
- QUnit.test('should account for variation selectors', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.size(heart), 1);
- assert.deepEqual(_.toArray(heart), [heart]);
- assert.deepEqual(_.words(heart), [heart]);
- });
- QUnit.test('should account for variation selectors with fitzpatrick modifiers', function(assert) {
- assert.expect(1);
- var values = lodashStable.map(fitzModifiers, function(modifier) {
- return raisedHand + modifier;
- });
- var expected = lodashStable.map(values, function(value) {
- return [1, [value], [value]];
- });
- var actual = lodashStable.map(values, function(value) {
- return [_.size(value), _.toArray(value), _.words(value)];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should match lone surrogates', function(assert) {
- assert.expect(3);
- var pair = hearts.split(''),
- surrogates = pair[0] + ' ' + pair[1];
- assert.strictEqual(_.size(surrogates), 3);
- assert.deepEqual(_.toArray(surrogates), [pair[0], ' ', pair[1]]);
- assert.deepEqual(_.words(surrogates), []);
- });
- QUnit.test('should match side by side fitzpatrick modifiers separately ', function(assert) {
- assert.expect(1);
- var string = fitzModifiers[0] + fitzModifiers[0];
- assert.deepEqual(_.toArray(string), [fitzModifiers[0], fitzModifiers[0]]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.unary');
- (function() {
- function fn() {
- return slice.call(arguments);
- }
- QUnit.test('should cap the number of arguments provided to `func`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(['6', '8', '10'], _.unary(parseInt));
- assert.deepEqual(actual, [6, 8, 10]);
- });
- QUnit.test('should not force a minimum argument count', function(assert) {
- assert.expect(1);
- var capped = _.unary(fn);
- assert.deepEqual(capped(), []);
- });
- QUnit.test('should use `this` binding of function', function(assert) {
- assert.expect(1);
- var capped = _.unary(function(a, b) { return this; }),
- object = { 'capped': capped };
- assert.strictEqual(object.capped(), object);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.unescape');
- (function() {
- var escaped = '&<>"'\/',
- unescaped = '&<>"\'\/';
- escaped += escaped;
- unescaped += unescaped;
- QUnit.test('should unescape entities in order', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.unescape('&lt;'), '<');
- });
- QUnit.test('should unescape the proper entities', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.unescape(escaped), unescaped);
- });
- QUnit.test('should not unescape the "/" entity', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.unescape('/'), '/');
- });
- QUnit.test('should handle strings with nothing to unescape', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.unescape('abc'), 'abc');
- });
- QUnit.test('should unescape the same characters escaped by `_.escape`', function(assert) {
- assert.expect(1);
- assert.strictEqual(_.unescape(_.escape(unescaped)), unescaped);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('union methods');
- lodashStable.each(['union', 'unionBy', 'unionWith'], function(methodName) {
- var args = (function() { return arguments; }(1, 2, 3)),
- func = _[methodName];
- QUnit.test('`_.' + methodName + '` should return the union of two arrays', function(assert) {
- assert.expect(1);
- var actual = func([2], [1, 2]);
- assert.deepEqual(actual, [2, 1]);
- });
- QUnit.test('`_.' + methodName + '` should return the union of multiple arrays', function(assert) {
- assert.expect(1);
- var actual = func([2], [1, 2], [2, 3]);
- assert.deepEqual(actual, [2, 1, 3]);
- });
- QUnit.test('`_.' + methodName + '` should not flatten nested arrays', function(assert) {
- assert.expect(1);
- var actual = func([1, 3, 2], [1, [5]], [2, [4]]);
- assert.deepEqual(actual, [1, 3, 2, [5], [4]]);
- });
- QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
- assert.expect(3);
- var array = [0];
- assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
- assert.deepEqual(func(null, array, null, [2, 1]), [0, 2, 1]);
- assert.deepEqual(func(array, null, args, null), [0, 1, 2, 3]);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.unionBy');
- (function() {
- QUnit.test('should accept an `iteratee` argument', function(assert) {
- assert.expect(2);
- var actual = _.unionBy([2.1], [1.2, 2.3], Math.floor);
- assert.deepEqual(actual, [2.1, 1.2]);
- actual = _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
- assert.deepEqual(actual, [{ 'x': 1 }, { 'x': 2 }]);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.unionBy([2.1], [1.2, 2.3], function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [2.1]);
- });
- QUnit.test('should output values from the first possible array', function(assert) {
- assert.expect(1);
- var actual = _.unionBy([{ 'x': 1, 'y': 1 }], [{ 'x': 1, 'y': 2 }], 'x');
- assert.deepEqual(actual, [{ 'x': 1, 'y': 1 }]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.unionWith');
- (function() {
- QUnit.test('should work with a `comparator` argument', function(assert) {
- assert.expect(1);
- var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
- others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
- actual = _.unionWith(objects, others, lodashStable.isEqual);
- assert.deepEqual(actual, [objects[0], objects[1], others[0]]);
- });
- QUnit.test('should output values from the first possible array', function(assert) {
- assert.expect(1);
- var objects = [{ 'x': 1, 'y': 1 }],
- others = [{ 'x': 1, 'y': 2 }];
- var actual = _.unionWith(objects, others, function(a, b) {
- return a.x == b.x;
- });
- assert.deepEqual(actual, [{ 'x': 1, 'y': 1 }]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('uniq methods');
- lodashStable.each(['uniq', 'uniqBy', 'uniqWith', 'sortedUniq', 'sortedUniqBy'], function(methodName) {
- var func = _[methodName],
- isSorted = /^sorted/.test(methodName),
- objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
- if (isSorted) {
- objects = _.sortBy(objects, 'a');
- }
- else {
- QUnit.test('`_.' + methodName + '` should return unique values of an unsorted array', function(assert) {
- assert.expect(1);
- var array = [2, 1, 2];
- assert.deepEqual(func(array), [2, 1]);
- });
- }
- QUnit.test('`_.' + methodName + '` should return unique values of a sorted array', function(assert) {
- assert.expect(1);
- var array = [1, 2, 2];
- assert.deepEqual(func(array), [1, 2]);
- });
- QUnit.test('`_.' + methodName + '` should treat object instances as unique', function(assert) {
- assert.expect(1);
- assert.deepEqual(func(objects), objects);
- });
- QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
- assert.expect(1);
- var actual = lodashStable.map(func([-0, 0]), lodashStable.toString);
- assert.deepEqual(actual, ['0']);
- });
- QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
- assert.expect(1);
- assert.deepEqual(func([NaN, NaN]), [NaN]);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays', function(assert) {
- assert.expect(1);
- var largeArray = [],
- expected = [0, {}, 'a'],
- count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
- lodashStable.each(expected, function(value) {
- lodashStable.times(count, function() {
- largeArray.push(value);
- });
- });
- assert.deepEqual(func(largeArray), expected);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
- assert.expect(1);
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
- return isEven(index) ? -0 : 0;
- });
- var actual = lodashStable.map(func(largeArray), lodashStable.toString);
- assert.deepEqual(actual, ['0']);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of boolean, `NaN`, and nullish values', function(assert) {
- assert.expect(1);
- var largeArray = [],
- expected = [null, undefined, false, true, NaN],
- count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
- lodashStable.each(expected, function(value) {
- lodashStable.times(count, function() {
- largeArray.push(value);
- });
- });
- assert.deepEqual(func(largeArray), expected);
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of symbols', function(assert) {
- assert.expect(1);
- if (Symbol) {
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, Symbol);
- assert.deepEqual(func(largeArray), largeArray);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should work with large arrays of well-known symbols', function(assert) {
- assert.expect(1);
- // See http://www.ecma-international.org/ecma-262/6.0/#sec-well-known-symbols.
- if (Symbol) {
- var expected = [
- Symbol.hasInstance, Symbol.isConcatSpreadable, Symbol.iterator,
- Symbol.match, Symbol.replace, Symbol.search, Symbol.species,
- Symbol.split, Symbol.toPrimitive, Symbol.toStringTag, Symbol.unscopables
- ];
- var largeArray = [],
- count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
- expected = lodashStable.map(expected, function(symbol) {
- return symbol || {};
- });
- lodashStable.each(expected, function(value) {
- lodashStable.times(count, function() {
- largeArray.push(value);
- });
- });
- assert.deepEqual(func(largeArray), expected);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should distinguish between numbers and numeric strings', function(assert) {
- assert.expect(1);
- var largeArray = [],
- expected = ['2', 2, Object('2'), Object(2)],
- count = Math.ceil(LARGE_ARRAY_SIZE / expected.length);
- lodashStable.each(expected, function(value) {
- lodashStable.times(count, function() {
- largeArray.push(value);
- });
- });
- assert.deepEqual(func(largeArray), expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.uniq');
- (function() {
- QUnit.test('should perform an unsorted uniq when used as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var array = [[2, 1, 2], [1, 2, 1]],
- actual = lodashStable.map(array, lodashStable.uniq);
- assert.deepEqual(actual, [[2, 1], [1, 2]]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('uniqBy methods');
- lodashStable.each(['uniqBy', 'sortedUniqBy'], function(methodName) {
- var func = _[methodName],
- isSorted = methodName == 'sortedUniqBy',
- objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
- if (isSorted) {
- objects = _.sortBy(objects, 'a');
- }
- QUnit.test('`_.' + methodName + '` should work with an `iteratee` argument', function(assert) {
- assert.expect(1);
- var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3);
- var actual = func(objects, function(object) {
- return object.a;
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should work with large arrays', function(assert) {
- assert.expect(2);
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function() {
- return [1, 2];
- });
- var actual = func(largeArray, String);
- assert.strictEqual(actual[0], largeArray[0]);
- assert.deepEqual(actual, [[1, 2]]);
- });
- QUnit.test('`_.' + methodName + '` should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- func(objects, function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [objects[0]]);
- });
- QUnit.test('`_.' + methodName + '` should work with `_.property` shorthands', function(assert) {
- assert.expect(2);
- var expected = isSorted ? [{ 'a': 1 }, { 'a': 2 }, { 'a': 3 }] : objects.slice(0, 3),
- actual = func(objects, 'a');
- assert.deepEqual(actual, expected);
- var arrays = [[2], [3], [1], [2], [3], [1]];
- if (isSorted) {
- arrays = lodashStable.sortBy(arrays, 0);
- }
- expected = isSorted ? [[1], [2], [3]] : arrays.slice(0, 3);
- actual = func(arrays, 0);
- assert.deepEqual(actual, expected);
- });
- lodashStable.each({
- 'an array': [0, 'a'],
- 'an object': { '0': 'a' },
- 'a number': 0,
- 'a string': '0'
- },
- function(iteratee, key) {
- QUnit.test('`_.' + methodName + '` should work with ' + key + ' for `iteratee`', function(assert) {
- assert.expect(1);
- var actual = func([['a'], ['a'], ['b']], iteratee);
- assert.deepEqual(actual, [['a'], ['b']]);
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.uniqWith');
- (function() {
- QUnit.test('should work with a `comparator` argument', function(assert) {
- assert.expect(1);
- var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }],
- actual = _.uniqWith(objects, lodashStable.isEqual);
- assert.deepEqual(actual, [objects[0], objects[1]]);
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
- return isEven(index) ? -0 : 0;
- });
- var arrays = [[-0, 0], largeArray],
- expected = lodashStable.map(arrays, lodashStable.constant(['-0']));
- var actual = lodashStable.map(arrays, function(array) {
- return lodashStable.map(_.uniqWith(array, lodashStable.eq), lodashStable.toString);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.uniqueId');
- (function() {
- QUnit.test('should generate unique ids', function(assert) {
- assert.expect(1);
- var actual = lodashStable.times(1000, function(assert) {
- return _.uniqueId();
- });
- assert.strictEqual(lodashStable.uniq(actual).length, actual.length);
- });
- QUnit.test('should return a string value when not providing a prefix argument', function(assert) {
- assert.expect(1);
- assert.strictEqual(typeof _.uniqueId(), 'string');
- });
- QUnit.test('should coerce the prefix argument to a string', function(assert) {
- assert.expect(1);
- var actual = [_.uniqueId(3), _.uniqueId(2), _.uniqueId(1)];
- assert.ok(/3\d+,2\d+,1\d+/.test(actual));
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.unset');
- (function() {
- QUnit.test('should unset property values', function(assert) {
- assert.expect(4);
- lodashStable.each(['a', ['a']], function(path) {
- var object = { 'a': 1, 'c': 2 };
- assert.strictEqual(_.unset(object, path), true);
- assert.deepEqual(object, { 'c': 2 });
- });
- });
- QUnit.test('should preserve the sign of `0`', function(assert) {
- assert.expect(1);
- var props = [-0, Object(-0), 0, Object(0)],
- expected = lodashStable.map(props, lodashStable.constant([true, false]));
- var actual = lodashStable.map(props, function(key) {
- var object = { '-0': 'a', '0': 'b' };
- return [_.unset(object, key), lodashStable.toString(key) in object];
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should unset symbol keyed property values', function(assert) {
- assert.expect(2);
- if (Symbol) {
- var object = {};
- object[symbol] = 1;
- assert.strictEqual(_.unset(object, symbol), true);
- assert.notOk(symbol in object);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should unset deep property values', function(assert) {
- assert.expect(4);
- lodashStable.each(['a.b', ['a', 'b']], function(path) {
- var object = { 'a': { 'b': null } };
- assert.strictEqual(_.unset(object, path), true);
- assert.deepEqual(object, { 'a': {} });
- });
- });
- QUnit.test('should handle complex paths', function(assert) {
- assert.expect(4);
- var paths = [
- 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
- ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
- ];
- lodashStable.each(paths, function(path) {
- var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
- assert.strictEqual(_.unset(object, path), true);
- assert.notOk('g' in object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f);
- });
- });
- QUnit.test('should return `true` for nonexistent paths', function(assert) {
- assert.expect(5);
- var object = { 'a': { 'b': { 'c': null } } };
- lodashStable.each(['z', 'a.z', 'a.b.z', 'a.b.c.z'], function(path) {
- assert.strictEqual(_.unset(object, path), true);
- });
- assert.deepEqual(object, { 'a': { 'b': { 'c': null } } });
- });
- QUnit.test('should not error when `object` is nullish', function(assert) {
- assert.expect(1);
- var values = [null, undefined],
- expected = [[true, true], [true, true]];
- var actual = lodashStable.map(values, function(value) {
- try {
- return [_.unset(value, 'a.b'), _.unset(value, ['a', 'b'])];
- } catch (e) {
- return e.message;
- }
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should follow `path` over non-plain objects', function(assert) {
- assert.expect(8);
- var object = { 'a': '' },
- paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
- lodashStable.each(paths, function(path) {
- numberProto.a = 1;
- var actual = _.unset(0, path);
- assert.strictEqual(actual, true);
- assert.notOk('a' in numberProto);
- delete numberProto.a;
- });
- lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
- stringProto.replace.b = 1;
- var actual = _.unset(object, path);
- assert.strictEqual(actual, true);
- assert.notOk('a' in stringProto.replace);
- delete stringProto.replace.b;
- });
- });
- QUnit.test('should return `false` for non-configurable properties', function(assert) {
- assert.expect(1);
- var object = {};
- if (!isStrict) {
- defineProperty(object, 'a', {
- 'configurable': false,
- 'enumerable': true,
- 'writable': true,
- 'value': 1,
- });
- assert.strictEqual(_.unset(object, 'a'), false);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.unzipWith');
- (function() {
- QUnit.test('should unzip arrays combining regrouped elements with `iteratee`', function(assert) {
- assert.expect(1);
- var array = [[1, 4], [2, 5], [3, 6]];
- var actual = _.unzipWith(array, function(a, b, c) {
- return a + b + c;
- });
- assert.deepEqual(actual, [6, 15]);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.unzipWith([[1, 3, 5], [2, 4, 6]], function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [1, 2]);
- });
- QUnit.test('should perform a basic unzip when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var array = [[1, 3], [2, 4]],
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant(_.unzip(array)));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.unzipWith(array, value) : _.unzipWith(array);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.updateWith');
- (function() {
- QUnit.test('should work with a `customizer` callback', function(assert) {
- assert.expect(1);
- var actual = _.updateWith({ '0': {} }, '[0][1][2]', stubThree, function(value) {
- return lodashStable.isObject(value) ? undefined : {};
- });
- assert.deepEqual(actual, { '0': { '1': { '2': 3 } } });
- });
- QUnit.test('should work with a `customizer` that returns `undefined`', function(assert) {
- assert.expect(1);
- var actual = _.updateWith({}, 'a[0].b.c', stubFour, noop);
- assert.deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('update methods');
- lodashStable.each(['update', 'updateWith'], function(methodName) {
- var func = _[methodName],
- oldValue = 1;
- QUnit.test('`_.' + methodName + '` should invoke `updater` with the value on `path` of `object`', function(assert) {
- assert.expect(4);
- var object = { 'a': [{ 'b': { 'c': oldValue } }] },
- expected = oldValue + 1;
- lodashStable.each(['a[0].b.c', ['a', '0', 'b', 'c']], function(path) {
- func(object, path, function(n) {
- assert.strictEqual(n, oldValue);
- return ++n;
- });
- assert.strictEqual(object.a[0].b.c, expected);
- object.a[0].b.c = oldValue;
- });
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.upperCase');
- (function() {
- QUnit.test('should uppercase as space-separated words', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.upperCase('--foo-bar--'), 'FOO BAR');
- assert.strictEqual(_.upperCase('fooBar'), 'FOO BAR');
- assert.strictEqual(_.upperCase('__foo_bar__'), 'FOO BAR');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.upperFirst');
- (function() {
- QUnit.test('should uppercase only the first character', function(assert) {
- assert.expect(3);
- assert.strictEqual(_.upperFirst('fred'), 'Fred');
- assert.strictEqual(_.upperFirst('Fred'), 'Fred');
- assert.strictEqual(_.upperFirst('FRED'), 'FRED');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('values methods');
- lodashStable.each(['values', 'valuesIn'], function(methodName) {
- var args = (function() { return arguments; }(1, 2, 3)),
- strictArgs = (function() { 'use strict'; return arguments; }(1, 2, 3)),
- func = _[methodName],
- isValues = methodName == 'values';
- QUnit.test('`_.' + methodName + '` should get string keyed values of `object`', function(assert) {
- assert.expect(1);
- var object = { 'a': 1, 'b': 2 },
- actual = func(object).sort();
- assert.deepEqual(actual, [1, 2]);
- });
- QUnit.test('`_.' + methodName + '` should work with an object that has a `length` property', function(assert) {
- assert.expect(1);
- var object = { '0': 'a', '1': 'b', 'length': 2 },
- actual = func(object).sort();
- assert.deepEqual(actual, [2, 'a', 'b']);
- });
- QUnit.test('`_.' + methodName + '` should ' + (isValues ? 'not ' : '') + 'include inherited string keyed property values', function(assert) {
- assert.expect(1);
- function Foo() {
- this.a = 1;
- }
- Foo.prototype.b = 2;
- var expected = isValues ? [1] : [1, 2],
- actual = func(new Foo).sort();
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
- assert.expect(1);
- var values = [args, strictArgs],
- expected = lodashStable.map(values, lodashStable.constant([1, 2, 3]));
- var actual = lodashStable.map(values, function(value) {
- return func(value).sort();
- });
- assert.deepEqual(actual, expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.without');
- (function() {
- QUnit.test('should return the difference of values', function(assert) {
- assert.expect(1);
- var actual = _.without([2, 1, 2, 3], 1, 2);
- assert.deepEqual(actual, [3]);
- });
- QUnit.test('should use strict equality to determine the values to reject', function(assert) {
- assert.expect(2);
- var object1 = { 'a': 1 },
- object2 = { 'b': 2 },
- array = [object1, object2];
- assert.deepEqual(_.without(array, { 'a': 1 }), array);
- assert.deepEqual(_.without(array, object1), [object2]);
- });
- QUnit.test('should remove all occurrences of each value from an array', function(assert) {
- assert.expect(1);
- var array = [1, 2, 3, 1, 2, 3];
- assert.deepEqual(_.without(array, 1, 2), [3, 3]);
- });
- }(1, 2, 3));
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.words');
- (function() {
- QUnit.test('should match words containing Latin-1 Supplement letters', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(burredLetters, function(letter) {
- return [letter];
- });
- var actual = lodashStable.map(burredLetters, function(letter) {
- return _.words(letter);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should not treat mathematical operators as words', function(assert) {
- assert.expect(1);
- var operators = ['\xac', '\xb1', '\xd7', '\xf7'],
- expected = lodashStable.map(operators, stubArray),
- actual = lodashStable.map(operators, _.words);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should not treat punctuation as words', function(assert) {
- assert.expect(1);
- var marks = [
- '\u2012', '\u2013', '\u2014', '\u2015',
- '\u2024', '\u2025', '\u2026',
- '\u205d', '\u205e'
- ];
- var expected = lodashStable.map(marks, stubArray),
- actual = lodashStable.map(marks, _.words);
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should support a `pattern` argument', function(assert) {
- assert.expect(2);
- assert.deepEqual(_.words('abcd', /ab|cd/g), ['ab', 'cd']);
- assert.deepEqual(_.words('abcd', 'ab|cd'), ['ab']);
- });
- QUnit.test('should work with compound words', function(assert) {
- assert.expect(12);
- assert.deepEqual(_.words('12Feet'), ['12', 'Feet']);
- assert.deepEqual(_.words('aeiouAreVowels'), ['aeiou', 'Are', 'Vowels']);
- assert.deepEqual(_.words('enable 6h format'), ['enable', '6', 'h', 'format']);
- assert.deepEqual(_.words('enable 24H format'), ['enable', '24', 'H', 'format']);
- assert.deepEqual(_.words('isISO8601'), ['is', 'ISO', '8601']);
- assert.deepEqual(_.words('LETTERSAeiouAreVowels'), ['LETTERS', 'Aeiou', 'Are', 'Vowels']);
- assert.deepEqual(_.words('tooLegit2Quit'), ['too', 'Legit', '2', 'Quit']);
- assert.deepEqual(_.words('walk500Miles'), ['walk', '500', 'Miles']);
- assert.deepEqual(_.words('xhr2Request'), ['xhr', '2', 'Request']);
- assert.deepEqual(_.words('XMLHttp'), ['XML', 'Http']);
- assert.deepEqual(_.words('XmlHTTP'), ['Xml', 'HTTP']);
- assert.deepEqual(_.words('XmlHttp'), ['Xml', 'Http']);
- });
- QUnit.test('should work with compound words containing diacritical marks', function(assert) {
- assert.expect(3);
- assert.deepEqual(_.words('LETTERSÆiouAreVowels'), ['LETTERS', 'Æiou', 'Are', 'Vowels']);
- assert.deepEqual(_.words('æiouAreVowels'), ['æiou', 'Are', 'Vowels']);
- assert.deepEqual(_.words('æiou2Consonants'), ['æiou', '2', 'Consonants']);
- });
- QUnit.test('should work with contractions', function(assert) {
- assert.expect(2);
- var postfixes = ['d', 'll', 'm', 're', 's', 't', 've'];
- lodashStable.each(["'", '\u2019'], function(apos) {
- var actual = lodashStable.map(postfixes, function(postfix) {
- return _.words('a b' + apos + postfix + ' c');
- });
- var expected = lodashStable.map(postfixes, function(postfix) {
- return ['a', 'b' + apos + postfix, 'c'];
- });
- assert.deepEqual(actual, expected);
- });
- });
- QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
- assert.expect(1);
- var strings = lodashStable.map(['a', 'b', 'c'], Object),
- actual = lodashStable.map(strings, _.words);
- assert.deepEqual(actual, [['a'], ['b'], ['c']]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.wrap');
- (function() {
- QUnit.test('should create a wrapped function', function(assert) {
- assert.expect(1);
- var p = _.wrap(_.escape, function(func, text) {
- return '<p>' + func(text) + '</p>';
- });
- assert.strictEqual(p('fred, barney, & pebbles'), '<p>fred, barney, & pebbles</p>');
- });
- QUnit.test('should provide correct `wrapper` arguments', function(assert) {
- assert.expect(1);
- var args;
- var wrapped = _.wrap(noop, function() {
- args || (args = slice.call(arguments));
- });
- wrapped(1, 2, 3);
- assert.deepEqual(args, [noop, 1, 2, 3]);
- });
- QUnit.test('should use `_.identity` when `wrapper` is nullish', function(assert) {
- assert.expect(1);
- var values = [, null, undefined],
- expected = lodashStable.map(values, stubA);
- var actual = lodashStable.map(values, function(value, index) {
- var wrapped = index ? _.wrap('a', value) : _.wrap('a');
- return wrapped('b', 'c');
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('should use `this` binding of function', function(assert) {
- assert.expect(1);
- var p = _.wrap(_.escape, function(func) {
- return '<p>' + func(this.text) + '</p>';
- });
- var object = { 'p': p, 'text': 'fred, barney, & pebbles' };
- assert.strictEqual(object.p(), '<p>fred, barney, & pebbles</p>');
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('xor methods');
- lodashStable.each(['xor', 'xorBy', 'xorWith'], function(methodName) {
- var args = (function() { return arguments; }(1, 2, 3)),
- func = _[methodName];
- QUnit.test('`_.' + methodName + '` should return the symmetric difference of two arrays', function(assert) {
- assert.expect(1);
- var actual = func([2, 1], [2, 3]);
- assert.deepEqual(actual, [1, 3]);
- });
- QUnit.test('`_.' + methodName + '` should return the symmetric difference of multiple arrays', function(assert) {
- assert.expect(1);
- var actual = func([2, 1], [2, 3], [3, 4]);
- assert.deepEqual(actual, [1, 4]);
- });
- QUnit.test('`_.' + methodName + '` should return an array of unique values', function(assert) {
- assert.expect(2);
- var actual = func([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
- assert.deepEqual(actual, [1, 4, 5]);
- actual = func([1, 1]);
- assert.deepEqual(actual, [1]);
- });
- QUnit.test('`_.' + methodName + '` should return a new array when a single array is given', function(assert) {
- assert.expect(1);
- var array = [1];
- assert.notStrictEqual(func(array), array);
- });
- QUnit.test('`_.' + methodName + '` should ignore individual secondary arguments', function(assert) {
- assert.expect(1);
- var array = [0];
- assert.deepEqual(func(array, 3, null, { '0': 1 }), array);
- });
- QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
- assert.expect(3);
- var array = [1, 2];
- assert.deepEqual(func(array, 3, { '0': 1 }, null), array);
- assert.deepEqual(func(null, array, null, [2, 3]), [1, 3]);
- assert.deepEqual(func(array, null, args, null), [3]);
- });
- QUnit.test('`_.' + methodName + '` should return a wrapped value when chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var wrapped = _([1, 2, 3])[methodName]([5, 2, 1, 4]);
- assert.ok(wrapped instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_.' + methodName + '` should work when in a lazy sequence before `head` or `last`', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE + 1),
- wrapped = _(array).slice(1)[methodName]([LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE + 1]);
- var actual = lodashStable.map(['head', 'last'], function(methodName) {
- return wrapped[methodName]();
- });
- assert.deepEqual(actual, [1, LARGE_ARRAY_SIZE + 1]);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.xorBy');
- (function() {
- QUnit.test('should accept an `iteratee` argument', function(assert) {
- assert.expect(2);
- var actual = _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
- assert.deepEqual(actual, [1.2, 3.4]);
- actual = _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
- assert.deepEqual(actual, [{ 'x': 2 }]);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.xorBy([2.1, 1.2], [2.3, 3.4], function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [2.3]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.xorWith');
- (function() {
- QUnit.test('should work with a `comparator` argument', function(assert) {
- assert.expect(1);
- var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
- others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
- actual = _.xorWith(objects, others, lodashStable.isEqual);
- assert.deepEqual(actual, [objects[1], others[0]]);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('zipObject methods');
- lodashStable.each(['zipObject', 'zipObjectDeep'], function(methodName) {
- var func = _[methodName],
- object = { 'barney': 36, 'fred': 40 },
- isDeep = methodName == 'zipObjectDeep';
- QUnit.test('`_.' + methodName + '` should zip together key/value arrays into an object', function(assert) {
- assert.expect(1);
- var actual = func(['barney', 'fred'], [36, 40]);
- assert.deepEqual(actual, object);
- });
- QUnit.test('`_.' + methodName + '` should ignore extra `values`', function(assert) {
- assert.expect(1);
- assert.deepEqual(func(['a'], [1, 2]), { 'a': 1 });
- });
- QUnit.test('`_.' + methodName + '` should assign `undefined` values for extra `keys`', function(assert) {
- assert.expect(1);
- assert.deepEqual(func(['a', 'b'], [1]), { 'a': 1, 'b': undefined });
- });
- QUnit.test('`_.' + methodName + '` should ' + (isDeep ? '' : 'not ') + 'support deep paths', function(assert) {
- assert.expect(2);
- lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path, index) {
- var expected = isDeep ? ({ 'a': { 'b': { 'c': 1 } } }) : (index ? { 'a,b,c': 1 } : { 'a.b.c': 1 });
- assert.deepEqual(func([path], [1]), expected);
- });
- });
- QUnit.test('`_.' + methodName + '` should work in a lazy sequence', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var values = lodashStable.range(LARGE_ARRAY_SIZE),
- props = lodashStable.map(values, function(value) { return 'key' + value; }),
- actual = _(props)[methodName](values).map(square).filter(isEven).take().value();
- assert.deepEqual(actual, _.take(_.filter(_.map(func(props, values), square), isEven)));
- }
- else {
- skipAssert(assert);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.zipWith');
- (function() {
- QUnit.test('should zip arrays combining grouped elements with `iteratee`', function(assert) {
- assert.expect(2);
- var array1 = [1, 2, 3],
- array2 = [4, 5, 6],
- array3 = [7, 8, 9];
- var actual = _.zipWith(array1, array2, array3, function(a, b, c) {
- return a + b + c;
- });
- assert.deepEqual(actual, [12, 15, 18]);
- var actual = _.zipWith(array1, [], function(a, b) {
- return a + (b || 0);
- });
- assert.deepEqual(actual, [1, 2, 3]);
- });
- QUnit.test('should provide correct `iteratee` arguments', function(assert) {
- assert.expect(1);
- var args;
- _.zipWith([1, 2], [3, 4], [5, 6], function() {
- args || (args = slice.call(arguments));
- });
- assert.deepEqual(args, [1, 3, 5]);
- });
- QUnit.test('should perform a basic zip when `iteratee` is nullish', function(assert) {
- assert.expect(1);
- var array1 = [1, 2],
- array2 = [3, 4],
- values = [, null, undefined],
- expected = lodashStable.map(values, lodashStable.constant(_.zip(array1, array2)));
- var actual = lodashStable.map(values, function(value, index) {
- return index ? _.zipWith(array1, array2, value) : _.zipWith(array1, array2);
- });
- assert.deepEqual(actual, expected);
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash.unzip and lodash.zip');
- lodashStable.each(['unzip', 'zip'], function(methodName, index) {
- var func = _[methodName];
- func = lodashStable.bind(index ? func.apply : func.call, func, null);
- var object = {
- 'an empty array': [
- [],
- []
- ],
- '0-tuples': [
- [[], []],
- []
- ],
- '2-tuples': [
- [['barney', 'fred'], [36, 40]],
- [['barney', 36], ['fred', 40]]
- ],
- '3-tuples': [
- [['barney', 'fred'], [36, 40], [false, true]],
- [['barney', 36, false], ['fred', 40, true]]
- ]
- };
- lodashStable.forOwn(object, function(pair, key) {
- QUnit.test('`_.' + methodName + '` should work with ' + key, function(assert) {
- assert.expect(2);
- var actual = func(pair[0]);
- assert.deepEqual(actual, pair[1]);
- assert.deepEqual(func(actual), actual.length ? pair[0] : []);
- });
- });
- QUnit.test('`_.' + methodName + '` should work with tuples of different lengths', function(assert) {
- assert.expect(4);
- var pair = [
- [['barney', 36], ['fred', 40, false]],
- [['barney', 'fred'], [36, 40], [undefined, false]]
- ];
- var actual = func(pair[0]);
- assert.ok('0' in actual[2]);
- assert.deepEqual(actual, pair[1]);
- actual = func(actual);
- assert.ok('2' in actual[0]);
- assert.deepEqual(actual, [['barney', 36, undefined], ['fred', 40, false]]);
- });
- QUnit.test('`_.' + methodName + '` should treat falsey values as empty arrays', function(assert) {
- assert.expect(1);
- var expected = lodashStable.map(falsey, stubArray);
- var actual = lodashStable.map(falsey, function(value) {
- return func([value, value, value]);
- });
- assert.deepEqual(actual, expected);
- });
- QUnit.test('`_.' + methodName + '` should ignore values that are not arrays or `arguments` objects', function(assert) {
- assert.expect(1);
- var array = [[1, 2], [3, 4], null, undefined, { '0': 1 }];
- assert.deepEqual(func(array), [[1, 3], [2, 4]]);
- });
- QUnit.test('`_.' + methodName + '` should support consuming its return value', function(assert) {
- assert.expect(1);
- var expected = [['barney', 'fred'], [36, 40]];
- assert.deepEqual(func(func(func(func(expected)))), expected);
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).commit');
- (function() {
- QUnit.test('should execute the chained sequence and returns the wrapped result', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- var array = [1],
- wrapped = _(array).push(2).push(3);
- assert.deepEqual(array, [1]);
- var otherWrapper = wrapped.commit();
- assert.ok(otherWrapper instanceof _);
- assert.deepEqual(otherWrapper.value(), [1, 2, 3]);
- assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should track the `__chain__` value of a wrapper', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var wrapped = _([1]).chain().commit().head();
- assert.ok(wrapped instanceof _);
- assert.strictEqual(wrapped.value(), 1);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).next');
- lodashStable.each([false, true], function(implict) {
- function chain(value) {
- return implict ? _(value) : _.chain(value);
- }
- var chainType = 'in an ' + (implict ? 'implict' : 'explict') + ' chain';
- QUnit.test('should follow the iterator protocol ' + chainType, function(assert) {
- assert.expect(3);
- if (!isNpm) {
- var wrapped = chain([1, 2]);
- assert.deepEqual(wrapped.next(), { 'done': false, 'value': 1 });
- assert.deepEqual(wrapped.next(), { 'done': false, 'value': 2 });
- assert.deepEqual(wrapped.next(), { 'done': true, 'value': undefined });
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('should act as an iterable ' + chainType, function(assert) {
- assert.expect(2);
- if (!isNpm && Symbol && Symbol.iterator) {
- var array = [1, 2],
- wrapped = chain(array);
- assert.strictEqual(wrapped[Symbol.iterator](), wrapped);
- assert.deepEqual(lodashStable.toArray(wrapped), array);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should use `_.toArray` to generate the iterable result ' + chainType, function(assert) {
- assert.expect(3);
- if (!isNpm && Array.from) {
- var hearts = '\ud83d\udc95',
- values = [[1], { 'a': 1 }, hearts];
- lodashStable.each(values, function(value) {
- var wrapped = chain(value);
- assert.deepEqual(Array.from(wrapped), _.toArray(value));
- });
- }
- else {
- skipAssert(assert, 3);
- }
- });
- QUnit.test('should reset the iterator correctly ' + chainType, function(assert) {
- assert.expect(4);
- if (!isNpm && Symbol && Symbol.iterator) {
- var array = [1, 2],
- wrapped = chain(array);
- assert.deepEqual(lodashStable.toArray(wrapped), array);
- assert.deepEqual(lodashStable.toArray(wrapped), [], 'produces an empty array for exhausted iterator');
- var other = wrapped.filter();
- assert.deepEqual(lodashStable.toArray(other), array, 'reset for new chain segments');
- assert.deepEqual(lodashStable.toArray(wrapped), [], 'iterator is still exhausted');
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should work in a lazy sequence ' + chainType, function(assert) {
- assert.expect(3);
- if (!isNpm && Symbol && Symbol.iterator) {
- var array = lodashStable.range(LARGE_ARRAY_SIZE),
- predicate = function(value) { values.push(value); return isEven(value); },
- values = [],
- wrapped = chain(array);
- assert.deepEqual(lodashStable.toArray(wrapped), array);
- wrapped = wrapped.filter(predicate);
- assert.deepEqual(lodashStable.toArray(wrapped), _.filter(array, isEven), 'reset for new lazy chain segments');
- assert.deepEqual(values, array, 'memoizes iterator values');
- }
- else {
- skipAssert(assert, 3);
- }
- });
- });
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).plant');
- (function() {
- QUnit.test('should clone the chained sequence planting `value` as the wrapped value', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var array1 = [5, null, 3, null, 1],
- array2 = [10, null, 8, null, 6],
- wrapped1 = _(array1).thru(_.compact).map(square).takeRight(2).sort(),
- wrapped2 = wrapped1.plant(array2);
- assert.deepEqual(wrapped2.value(), [36, 64]);
- assert.deepEqual(wrapped1.value(), [1, 9]);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should clone `chainAll` settings', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var array1 = [2, 4],
- array2 = [6, 8],
- wrapped1 = _(array1).chain().map(square),
- wrapped2 = wrapped1.plant(array2);
- assert.deepEqual(wrapped2.head().value(), 36);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should reset iterator data on cloned sequences', function(assert) {
- assert.expect(3);
- if (!isNpm && Symbol && Symbol.iterator) {
- var array1 = [2, 4],
- array2 = [6, 8],
- wrapped1 = _(array1).map(square);
- assert.deepEqual(lodashStable.toArray(wrapped1), [4, 16]);
- assert.deepEqual(lodashStable.toArray(wrapped1), []);
- var wrapped2 = wrapped1.plant(array2);
- assert.deepEqual(lodashStable.toArray(wrapped2), [36, 64]);
- }
- else {
- skipAssert(assert, 3);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).pop');
- (function() {
- QUnit.test('should remove elements from the end of `array`', function(assert) {
- assert.expect(5);
- if (!isNpm) {
- var array = [1, 2],
- wrapped = _(array);
- assert.strictEqual(wrapped.pop(), 2);
- assert.deepEqual(wrapped.value(), [1]);
- assert.strictEqual(wrapped.pop(), 1);
- var actual = wrapped.value();
- assert.strictEqual(actual, array);
- assert.deepEqual(actual, []);
- }
- else {
- skipAssert(assert, 5);
- }
- });
- QUnit.test('should accept falsey arguments', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(value, index) {
- try {
- var result = index ? _(value).pop() : _().pop();
- return result === undefined;
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).push');
- (function() {
- QUnit.test('should append elements to `array`', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var array = [1],
- wrapped = _(array).push(2, 3),
- actual = wrapped.value();
- assert.strictEqual(actual, array);
- assert.deepEqual(actual, [1, 2, 3]);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should accept falsey arguments', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(value, index) {
- try {
- var result = index ? _(value).push(1).value() : _().push(1).value();
- return lodashStable.eq(result, value);
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).shift');
- (function() {
- QUnit.test('should remove elements from the front of `array`', function(assert) {
- assert.expect(5);
- if (!isNpm) {
- var array = [1, 2],
- wrapped = _(array);
- assert.strictEqual(wrapped.shift(), 1);
- assert.deepEqual(wrapped.value(), [2]);
- assert.strictEqual(wrapped.shift(), 2);
- var actual = wrapped.value();
- assert.strictEqual(actual, array);
- assert.deepEqual(actual, []);
- }
- else {
- skipAssert(assert, 5);
- }
- });
- QUnit.test('should accept falsey arguments', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(value, index) {
- try {
- var result = index ? _(value).shift() : _().shift();
- return result === undefined;
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).sort');
- (function() {
- QUnit.test('should return the wrapped sorted `array`', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var array = [3, 1, 2],
- wrapped = _(array).sort(),
- actual = wrapped.value();
- assert.strictEqual(actual, array);
- assert.deepEqual(actual, [1, 2, 3]);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should accept falsey arguments', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(value, index) {
- try {
- var result = index ? _(value).sort().value() : _().sort().value();
- return lodashStable.eq(result, value);
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).splice');
- (function() {
- QUnit.test('should support removing and inserting elements', function(assert) {
- assert.expect(5);
- if (!isNpm) {
- var array = [1, 2],
- wrapped = _(array);
- assert.deepEqual(wrapped.splice(1, 1, 3).value(), [2]);
- assert.deepEqual(wrapped.value(), [1, 3]);
- assert.deepEqual(wrapped.splice(0, 2).value(), [1, 3]);
- var actual = wrapped.value();
- assert.strictEqual(actual, array);
- assert.deepEqual(actual, []);
- }
- else {
- skipAssert(assert, 5);
- }
- });
- QUnit.test('should accept falsey arguments', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(value, index) {
- try {
- var result = index ? _(value).splice(0, 1).value() : _().splice(0, 1).value();
- return lodashStable.isEqual(result, []);
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).unshift');
- (function() {
- QUnit.test('should prepend elements to `array`', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var array = [3],
- wrapped = _(array).unshift(1, 2),
- actual = wrapped.value();
- assert.strictEqual(actual, array);
- assert.deepEqual(actual, [1, 2, 3]);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- QUnit.test('should accept falsey arguments', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var expected = lodashStable.map(falsey, stubTrue);
- var actual = lodashStable.map(falsey, function(value, index) {
- try {
- var result = index ? _(value).unshift(1).value() : _().unshift(1).value();
- return lodashStable.eq(result, value);
- } catch (e) {}
- });
- assert.deepEqual(actual, expected);
- }
- else {
- skipAssert(assert);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...).value');
- (function() {
- QUnit.test('should execute the chained sequence and extract the unwrapped value', function(assert) {
- assert.expect(4);
- if (!isNpm) {
- var array = [1],
- wrapped = _(array).push(2).push(3);
- assert.deepEqual(array, [1]);
- assert.deepEqual(wrapped.value(), [1, 2, 3]);
- assert.deepEqual(wrapped.value(), [1, 2, 3, 2, 3]);
- assert.deepEqual(array, [1, 2, 3, 2, 3]);
- }
- else {
- skipAssert(assert, 4);
- }
- });
- QUnit.test('should return the `valueOf` result of the wrapped value', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var wrapped = _(123);
- assert.strictEqual(Number(wrapped), 123);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should stringify the wrapped value when used by `JSON.stringify`', function(assert) {
- assert.expect(1);
- if (!isNpm && JSON) {
- var wrapped = _([1, 2, 3]);
- assert.strictEqual(JSON.stringify(wrapped), '[1,2,3]');
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('should be aliased', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var expected = _.prototype.value;
- assert.strictEqual(_.prototype.toJSON, expected);
- assert.strictEqual(_.prototype.valueOf, expected);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...) methods that return the wrapped modified array');
- (function() {
- var funcs = [
- 'push',
- 'reverse',
- 'sort',
- 'unshift'
- ];
- lodashStable.each(funcs, function(methodName) {
- QUnit.test('`_(...).' + methodName + '` should return a new wrapper', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var array = [1, 2, 3],
- wrapped = _(array),
- actual = wrapped[methodName]();
- assert.ok(actual instanceof _);
- assert.notStrictEqual(actual, wrapped);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...) methods that return new wrapped values');
- (function() {
- var funcs = [
- 'castArray',
- 'concat',
- 'difference',
- 'differenceBy',
- 'differenceWith',
- 'intersection',
- 'intersectionBy',
- 'intersectionWith',
- 'pull',
- 'pullAll',
- 'pullAt',
- 'sampleSize',
- 'shuffle',
- 'slice',
- 'splice',
- 'split',
- 'toArray',
- 'union',
- 'unionBy',
- 'unionWith',
- 'uniq',
- 'uniqBy',
- 'uniqWith',
- 'words',
- 'xor',
- 'xorBy',
- 'xorWith'
- ];
- lodashStable.each(funcs, function(methodName) {
- QUnit.test('`_(...).' + methodName + '` should return a new wrapped value', function(assert) {
- assert.expect(2);
- if (!isNpm) {
- var value = methodName == 'split' ? 'abc' : [1, 2, 3],
- wrapped = _(value),
- actual = wrapped[methodName]();
- assert.ok(actual instanceof _);
- assert.notStrictEqual(actual, wrapped);
- }
- else {
- skipAssert(assert, 2);
- }
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash(...) methods that return unwrapped values');
- (function() {
- var funcs = [
- 'add',
- 'camelCase',
- 'capitalize',
- 'ceil',
- 'clone',
- 'deburr',
- 'defaultTo',
- 'divide',
- 'endsWith',
- 'escape',
- 'escapeRegExp',
- 'every',
- 'find',
- 'floor',
- 'has',
- 'hasIn',
- 'head',
- 'includes',
- 'isArguments',
- 'isArray',
- 'isArrayBuffer',
- 'isArrayLike',
- 'isBoolean',
- 'isBuffer',
- 'isDate',
- 'isElement',
- 'isEmpty',
- 'isEqual',
- 'isError',
- 'isFinite',
- 'isFunction',
- 'isInteger',
- 'isMap',
- 'isNaN',
- 'isNative',
- 'isNil',
- 'isNull',
- 'isNumber',
- 'isObject',
- 'isObjectLike',
- 'isPlainObject',
- 'isRegExp',
- 'isSafeInteger',
- 'isSet',
- 'isString',
- 'isUndefined',
- 'isWeakMap',
- 'isWeakSet',
- 'join',
- 'kebabCase',
- 'last',
- 'lowerCase',
- 'lowerFirst',
- 'max',
- 'maxBy',
- 'min',
- 'minBy',
- 'multiply',
- 'nth',
- 'pad',
- 'padEnd',
- 'padStart',
- 'parseInt',
- 'pop',
- 'random',
- 'reduce',
- 'reduceRight',
- 'repeat',
- 'replace',
- 'round',
- 'sample',
- 'shift',
- 'size',
- 'snakeCase',
- 'some',
- 'startCase',
- 'startsWith',
- 'subtract',
- 'sum',
- 'toFinite',
- 'toInteger',
- 'toLower',
- 'toNumber',
- 'toSafeInteger',
- 'toString',
- 'toUpper',
- 'trim',
- 'trimEnd',
- 'trimStart',
- 'truncate',
- 'unescape',
- 'upperCase',
- 'upperFirst'
- ];
- lodashStable.each(funcs, function(methodName) {
- QUnit.test('`_(...).' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = _()[methodName]();
- assert.notOk(actual instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- QUnit.test('`_(...).' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) {
- assert.expect(1);
- if (!isNpm) {
- var actual = _().chain()[methodName]();
- assert.ok(actual instanceof _);
- }
- else {
- skipAssert(assert);
- }
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('"Arrays" category methods');
- (function() {
- var args = (function() { return arguments; }(1, null, [3], null, 5)),
- sortedArgs = (function() { return arguments; }(1, [3], 5, null, null)),
- array = [1, 2, 3, 4, 5, 6];
- QUnit.test('should work with `arguments` objects', function(assert) {
- assert.expect(30);
- function message(methodName) {
- return '`_.' + methodName + '` should work with `arguments` objects';
- }
- assert.deepEqual(_.difference(args, [null]), [1, [3], 5], message('difference'));
- assert.deepEqual(_.difference(array, args), [2, 3, 4, 6], '_.difference should work with `arguments` objects as secondary arguments');
- assert.deepEqual(_.union(args, [null, 6]), [1, null, [3], 5, 6], message('union'));
- assert.deepEqual(_.union(array, args), array.concat([null, [3]]), '_.union should work with `arguments` objects as secondary arguments');
- assert.deepEqual(_.compact(args), [1, [3], 5], message('compact'));
- assert.deepEqual(_.drop(args, 3), [null, 5], message('drop'));
- assert.deepEqual(_.dropRight(args, 3), [1, null], message('dropRight'));
- assert.deepEqual(_.dropRightWhile(args,identity), [1, null, [3], null], message('dropRightWhile'));
- assert.deepEqual(_.dropWhile(args,identity), [null, [3], null, 5], message('dropWhile'));
- assert.deepEqual(_.findIndex(args, identity), 0, message('findIndex'));
- assert.deepEqual(_.findLastIndex(args, identity), 4, message('findLastIndex'));
- assert.deepEqual(_.flatten(args), [1, null, 3, null, 5], message('flatten'));
- assert.deepEqual(_.head(args), 1, message('head'));
- assert.deepEqual(_.indexOf(args, 5), 4, message('indexOf'));
- assert.deepEqual(_.initial(args), [1, null, [3], null], message('initial'));
- assert.deepEqual(_.intersection(args, [1]), [1], message('intersection'));
- assert.deepEqual(_.last(args), 5, message('last'));
- assert.deepEqual(_.lastIndexOf(args, 1), 0, message('lastIndexOf'));
- assert.deepEqual(_.sortedIndex(sortedArgs, 6), 3, message('sortedIndex'));
- assert.deepEqual(_.sortedIndexOf(sortedArgs, 5), 2, message('sortedIndexOf'));
- assert.deepEqual(_.sortedLastIndex(sortedArgs, 5), 3, message('sortedLastIndex'));
- assert.deepEqual(_.sortedLastIndexOf(sortedArgs, 1), 0, message('sortedLastIndexOf'));
- assert.deepEqual(_.tail(args, 4), [null, [3], null, 5], message('tail'));
- assert.deepEqual(_.take(args, 2), [1, null], message('take'));
- assert.deepEqual(_.takeRight(args, 1), [5], message('takeRight'));
- assert.deepEqual(_.takeRightWhile(args, identity), [5], message('takeRightWhile'));
- assert.deepEqual(_.takeWhile(args, identity), [1], message('takeWhile'));
- assert.deepEqual(_.uniq(args), [1, null, [3], 5], message('uniq'));
- assert.deepEqual(_.without(args, null), [1, [3], 5], message('without'));
- assert.deepEqual(_.zip(args, args), [[1, 1], [null, null], [[3], [3]], [null, null], [5, 5]], message('zip'));
- });
- QUnit.test('should accept falsey primary arguments', function(assert) {
- assert.expect(4);
- function message(methodName) {
- return '`_.' + methodName + '` should accept falsey primary arguments';
- }
- assert.deepEqual(_.difference(null, array), [], message('difference'));
- assert.deepEqual(_.intersection(null, array), [], message('intersection'));
- assert.deepEqual(_.union(null, array), array, message('union'));
- assert.deepEqual(_.xor(null, array), array, message('xor'));
- });
- QUnit.test('should accept falsey secondary arguments', function(assert) {
- assert.expect(3);
- function message(methodName) {
- return '`_.' + methodName + '` should accept falsey secondary arguments';
- }
- assert.deepEqual(_.difference(array, null), array, message('difference'));
- assert.deepEqual(_.intersection(array, null), [], message('intersection'));
- assert.deepEqual(_.union(array, null), array, message('union'));
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('"Strings" category methods');
- (function() {
- var stringMethods = [
- 'camelCase',
- 'capitalize',
- 'escape',
- 'kebabCase',
- 'lowerCase',
- 'lowerFirst',
- 'pad',
- 'padEnd',
- 'padStart',
- 'repeat',
- 'snakeCase',
- 'toLower',
- 'toUpper',
- 'trim',
- 'trimEnd',
- 'trimStart',
- 'truncate',
- 'unescape',
- 'upperCase',
- 'upperFirst'
- ];
- lodashStable.each(stringMethods, function(methodName) {
- var func = _[methodName];
- QUnit.test('`_.' + methodName + '` should return an empty string for empty values', function(assert) {
- assert.expect(1);
- var values = [, null, undefined, ''],
- expected = lodashStable.map(values, stubString);
- var actual = lodashStable.map(values, function(value, index) {
- return index ? func(value) : func();
- });
- assert.deepEqual(actual, expected);
- });
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.module('lodash methods');
- (function() {
- var allMethods = lodashStable.reject(_.functions(_).sort(), function(methodName) {
- return lodashStable.startsWith(methodName, '_');
- });
- var checkFuncs = [
- 'after',
- 'ary',
- 'before',
- 'bind',
- 'curry',
- 'curryRight',
- 'debounce',
- 'defer',
- 'delay',
- 'flip',
- 'flow',
- 'flowRight',
- 'memoize',
- 'negate',
- 'once',
- 'partial',
- 'partialRight',
- 'rearg',
- 'rest',
- 'spread',
- 'throttle',
- 'unary'
- ];
- var noBinding = [
- 'flip',
- 'memoize',
- 'negate',
- 'once',
- 'overArgs',
- 'partial',
- 'partialRight',
- 'rearg',
- 'rest',
- 'spread'
- ];
- var rejectFalsey = [
- 'tap',
- 'thru'
- ].concat(checkFuncs);
- var returnArrays = [
- 'at',
- 'chunk',
- 'compact',
- 'difference',
- 'drop',
- 'filter',
- 'flatten',
- 'functions',
- 'initial',
- 'intersection',
- 'invokeMap',
- 'keys',
- 'map',
- 'orderBy',
- 'pull',
- 'pullAll',
- 'pullAt',
- 'range',
- 'rangeRight',
- 'reject',
- 'remove',
- 'shuffle',
- 'sortBy',
- 'tail',
- 'take',
- 'times',
- 'toArray',
- 'toPairs',
- 'toPairsIn',
- 'union',
- 'uniq',
- 'values',
- 'without',
- 'xor',
- 'zip'
- ];
- var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
- QUnit.test('should accept falsey arguments', function(assert) {
- assert.expect(316);
- var arrays = lodashStable.map(falsey, stubArray);
- lodashStable.each(acceptFalsey, function(methodName) {
- var expected = arrays,
- func = _[methodName],
- pass = true;
- var actual = lodashStable.map(falsey, function(value, index) {
- try {
- return index ? func(value) : func();
- } catch (e) {
- pass = false;
- }
- });
- if (methodName == 'noConflict') {
- root._ = oldDash;
- }
- else if (methodName == 'pull' || methodName == 'pullAll') {
- expected = falsey;
- }
- if (lodashStable.includes(returnArrays, methodName) && methodName != 'sample') {
- assert.deepEqual(actual, expected, '_.' + methodName + ' returns an array');
- }
- assert.ok(pass, '`_.' + methodName + '` accepts falsey arguments');
- });
- // Skip tests for missing methods of modularized builds.
- lodashStable.each(['chain', 'noConflict', 'runInContext'], function(methodName) {
- if (!_[methodName]) {
- skipAssert(assert);
- }
- });
- });
- QUnit.test('should return an array', function(assert) {
- assert.expect(70);
- var array = [1, 2, 3];
- lodashStable.each(returnArrays, function(methodName) {
- var actual,
- func = _[methodName];
- switch (methodName) {
- case 'invokeMap':
- actual = func(array, 'toFixed');
- break;
- case 'sample':
- actual = func(array, 1);
- break;
- default:
- actual = func(array);
- }
- assert.ok(lodashStable.isArray(actual), '_.' + methodName + ' returns an array');
- var isPull = methodName == 'pull' || methodName == 'pullAll';
- assert.strictEqual(actual === array, isPull, '_.' + methodName + ' should ' + (isPull ? '' : 'not ') + 'return the given array');
- });
- });
- QUnit.test('should throw an error for falsey arguments', function(assert) {
- assert.expect(24);
- lodashStable.each(rejectFalsey, function(methodName) {
- var expected = lodashStable.map(falsey, stubTrue),
- func = _[methodName];
- var actual = lodashStable.map(falsey, function(value, index) {
- var pass = !index && /^(?:backflow|compose|cond|flow(Right)?|over(?:Every|Some)?)$/.test(methodName);
- try {
- index ? func(value) : func();
- } catch (e) {
- pass = !pass && (e instanceof TypeError) &&
- (!lodashStable.includes(checkFuncs, methodName) || (e.message == FUNC_ERROR_TEXT));
- }
- return pass;
- });
- assert.deepEqual(actual, expected, '`_.' + methodName + '` rejects falsey arguments');
- });
- });
- QUnit.test('should use `this` binding of function', function(assert) {
- assert.expect(30);
- lodashStable.each(noBinding, function(methodName) {
- var fn = function() { return this.a; },
- func = _[methodName],
- isNegate = methodName == 'negate',
- object = { 'a': 1 },
- expected = isNegate ? false : 1;
- var wrapper = func(_.bind(fn, object));
- assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can consume a bound function');
- wrapper = _.bind(func(fn), object);
- assert.strictEqual(wrapper(), expected, '`_.' + methodName + '` can be bound');
- object.wrapper = func(fn);
- assert.strictEqual(object.wrapper(), expected, '`_.' + methodName + '` uses the `this` of its parent object');
- });
- });
- QUnit.test('should not contain minified method names (test production builds)', function(assert) {
- assert.expect(1);
- var shortNames = ['_', 'at', 'eq', 'gt', 'lt'];
- assert.ok(lodashStable.every(_.functions(_), function(methodName) {
- return methodName.length > 2 || lodashStable.includes(shortNames, methodName);
- }));
- });
- }());
- /*--------------------------------------------------------------------------*/
- QUnit.config.asyncRetries = 10;
- QUnit.config.hidepassed = true;
- if (!document) {
- QUnit.config.noglobals = true;
- QUnit.load();
- QUnit.start();
- }
- }.call(this));
|