qunit-2.2.0.js 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841
  1. /*!
  2. * QUnit 2.2.0
  3. * https://qunitjs.com/
  4. *
  5. * Copyright jQuery Foundation and other contributors
  6. * Released under the MIT license
  7. * https://jquery.org/license
  8. *
  9. * Date: 2017-03-11T16:19Z
  10. */
  11. (function (global$1) {
  12. 'use strict';
  13. global$1 = 'default' in global$1 ? global$1['default'] : global$1;
  14. var window = global$1.window;
  15. var console = global$1.console;
  16. var setTimeout = global$1.setTimeout;
  17. var clearTimeout = global$1.clearTimeout;
  18. var document = window && window.document;
  19. var navigator = window && window.navigator;
  20. var sessionStorage = function () {
  21. var x = "qunit-test-string";
  22. try {
  23. sessionStorage.setItem(x, x);
  24. sessionStorage.removeItem(x);
  25. return sessionStorage;
  26. } catch (e) {
  27. return undefined;
  28. }
  29. }();
  30. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  31. return typeof obj;
  32. } : function (obj) {
  33. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  34. };
  35. var classCallCheck = function (instance, Constructor) {
  36. if (!(instance instanceof Constructor)) {
  37. throw new TypeError("Cannot call a class as a function");
  38. }
  39. };
  40. var createClass = function () {
  41. function defineProperties(target, props) {
  42. for (var i = 0; i < props.length; i++) {
  43. var descriptor = props[i];
  44. descriptor.enumerable = descriptor.enumerable || false;
  45. descriptor.configurable = true;
  46. if ("value" in descriptor) descriptor.writable = true;
  47. Object.defineProperty(target, descriptor.key, descriptor);
  48. }
  49. }
  50. return function (Constructor, protoProps, staticProps) {
  51. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  52. if (staticProps) defineProperties(Constructor, staticProps);
  53. return Constructor;
  54. };
  55. }();
  56. var toConsumableArray = function (arr) {
  57. if (Array.isArray(arr)) {
  58. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  59. return arr2;
  60. } else {
  61. return Array.from(arr);
  62. }
  63. };
  64. var toString = Object.prototype.toString;
  65. var hasOwn = Object.prototype.hasOwnProperty;
  66. var now = Date.now || function () {
  67. return new Date().getTime();
  68. };
  69. var defined = {
  70. document: window && window.document !== undefined,
  71. setTimeout: setTimeout !== undefined
  72. };
  73. // Returns a new Array with the elements that are in a but not in b
  74. function diff(a, b) {
  75. var i,
  76. j,
  77. result = a.slice();
  78. for (i = 0; i < result.length; i++) {
  79. for (j = 0; j < b.length; j++) {
  80. if (result[i] === b[j]) {
  81. result.splice(i, 1);
  82. i--;
  83. break;
  84. }
  85. }
  86. }
  87. return result;
  88. }
  89. /**
  90. * Determines whether an element exists in a given array or not.
  91. *
  92. * @method inArray
  93. * @param {Any} elem
  94. * @param {Array} array
  95. * @return {Boolean}
  96. */
  97. function inArray(elem, array) {
  98. return array.indexOf(elem) !== -1;
  99. }
  100. /**
  101. * Makes a clone of an object using only Array or Object as base,
  102. * and copies over the own enumerable properties.
  103. *
  104. * @param {Object} obj
  105. * @return {Object} New object with only the own properties (recursively).
  106. */
  107. function objectValues(obj) {
  108. var key,
  109. val,
  110. vals = is("array", obj) ? [] : {};
  111. for (key in obj) {
  112. if (hasOwn.call(obj, key)) {
  113. val = obj[key];
  114. vals[key] = val === Object(val) ? objectValues(val) : val;
  115. }
  116. }
  117. return vals;
  118. }
  119. function extend(a, b, undefOnly) {
  120. for (var prop in b) {
  121. if (hasOwn.call(b, prop)) {
  122. if (b[prop] === undefined) {
  123. delete a[prop];
  124. } else if (!(undefOnly && typeof a[prop] !== "undefined")) {
  125. a[prop] = b[prop];
  126. }
  127. }
  128. }
  129. return a;
  130. }
  131. function objectType(obj) {
  132. if (typeof obj === "undefined") {
  133. return "undefined";
  134. }
  135. // Consider: typeof null === object
  136. if (obj === null) {
  137. return "null";
  138. }
  139. var match = toString.call(obj).match(/^\[object\s(.*)\]$/),
  140. type = match && match[1];
  141. switch (type) {
  142. case "Number":
  143. if (isNaN(obj)) {
  144. return "nan";
  145. }
  146. return "number";
  147. case "String":
  148. case "Boolean":
  149. case "Array":
  150. case "Set":
  151. case "Map":
  152. case "Date":
  153. case "RegExp":
  154. case "Function":
  155. case "Symbol":
  156. return type.toLowerCase();
  157. }
  158. if ((typeof obj === "undefined" ? "undefined" : _typeof(obj)) === "object") {
  159. return "object";
  160. }
  161. }
  162. // Safe object type checking
  163. function is(type, obj) {
  164. return objectType(obj) === type;
  165. }
  166. // Test for equality any JavaScript type.
  167. // Authors: Philippe Rathé <prathe@gmail.com>, David Chan <david@troi.org>
  168. var equiv = (function () {
  169. // Value pairs queued for comparison. Used for breadth-first processing order, recursion
  170. // detection and avoiding repeated comparison (see below for details).
  171. // Elements are { a: val, b: val }.
  172. var pairs = [];
  173. var getProto = Object.getPrototypeOf || function (obj) {
  174. return obj.__proto__;
  175. };
  176. function useStrictEquality(a, b) {
  177. // This only gets called if a and b are not strict equal, and is used to compare on
  178. // the primitive values inside object wrappers. For example:
  179. // `var i = 1;`
  180. // `var j = new Number(1);`
  181. // Neither a nor b can be null, as a !== b and they have the same type.
  182. if ((typeof a === "undefined" ? "undefined" : _typeof(a)) === "object") {
  183. a = a.valueOf();
  184. }
  185. if ((typeof b === "undefined" ? "undefined" : _typeof(b)) === "object") {
  186. b = b.valueOf();
  187. }
  188. return a === b;
  189. }
  190. function compareConstructors(a, b) {
  191. var protoA = getProto(a);
  192. var protoB = getProto(b);
  193. // Comparing constructors is more strict than using `instanceof`
  194. if (a.constructor === b.constructor) {
  195. return true;
  196. }
  197. // Ref #851
  198. // If the obj prototype descends from a null constructor, treat it
  199. // as a null prototype.
  200. if (protoA && protoA.constructor === null) {
  201. protoA = null;
  202. }
  203. if (protoB && protoB.constructor === null) {
  204. protoB = null;
  205. }
  206. // Allow objects with no prototype to be equivalent to
  207. // objects with Object as their constructor.
  208. if (protoA === null && protoB === Object.prototype || protoB === null && protoA === Object.prototype) {
  209. return true;
  210. }
  211. return false;
  212. }
  213. function getRegExpFlags(regexp) {
  214. return "flags" in regexp ? regexp.flags : regexp.toString().match(/[gimuy]*$/)[0];
  215. }
  216. function isContainer(val) {
  217. return ["object", "array", "map", "set"].indexOf(objectType(val)) !== -1;
  218. }
  219. function breadthFirstCompareChild(a, b) {
  220. // If a is a container not reference-equal to b, postpone the comparison to the
  221. // end of the pairs queue -- unless (a, b) has been seen before, in which case skip
  222. // over the pair.
  223. if (a === b) {
  224. return true;
  225. }
  226. if (!isContainer(a)) {
  227. return typeEquiv(a, b);
  228. }
  229. if (pairs.every(function (pair) {
  230. return pair.a !== a || pair.b !== b;
  231. })) {
  232. // Not yet started comparing this pair
  233. pairs.push({ a: a, b: b });
  234. }
  235. return true;
  236. }
  237. var callbacks = {
  238. "string": useStrictEquality,
  239. "boolean": useStrictEquality,
  240. "number": useStrictEquality,
  241. "null": useStrictEquality,
  242. "undefined": useStrictEquality,
  243. "symbol": useStrictEquality,
  244. "date": useStrictEquality,
  245. "nan": function nan() {
  246. return true;
  247. },
  248. "regexp": function regexp(a, b) {
  249. return a.source === b.source &&
  250. // Include flags in the comparison
  251. getRegExpFlags(a) === getRegExpFlags(b);
  252. },
  253. // abort (identical references / instance methods were skipped earlier)
  254. "function": function _function() {
  255. return false;
  256. },
  257. "array": function array(a, b) {
  258. var i, len;
  259. len = a.length;
  260. if (len !== b.length) {
  261. // Safe and faster
  262. return false;
  263. }
  264. for (i = 0; i < len; i++) {
  265. // Compare non-containers; queue non-reference-equal containers
  266. if (!breadthFirstCompareChild(a[i], b[i])) {
  267. return false;
  268. }
  269. }
  270. return true;
  271. },
  272. // Define sets a and b to be equivalent if for each element aVal in a, there
  273. // is some element bVal in b such that aVal and bVal are equivalent. Element
  274. // repetitions are not counted, so these are equivalent:
  275. // a = new Set( [ {}, [], [] ] );
  276. // b = new Set( [ {}, {}, [] ] );
  277. "set": function set$$1(a, b) {
  278. var innerEq,
  279. outerEq = true;
  280. if (a.size !== b.size) {
  281. // This optimization has certain quirks because of the lack of
  282. // repetition counting. For instance, adding the same
  283. // (reference-identical) element to two equivalent sets can
  284. // make them non-equivalent.
  285. return false;
  286. }
  287. a.forEach(function (aVal) {
  288. // Short-circuit if the result is already known. (Using for...of
  289. // with a break clause would be cleaner here, but it would cause
  290. // a syntax error on older Javascript implementations even if
  291. // Set is unused)
  292. if (!outerEq) {
  293. return;
  294. }
  295. innerEq = false;
  296. b.forEach(function (bVal) {
  297. var parentPairs;
  298. // Likewise, short-circuit if the result is already known
  299. if (innerEq) {
  300. return;
  301. }
  302. // Swap out the global pairs list, as the nested call to
  303. // innerEquiv will clobber its contents
  304. parentPairs = pairs;
  305. if (innerEquiv(bVal, aVal)) {
  306. innerEq = true;
  307. }
  308. // Replace the global pairs list
  309. pairs = parentPairs;
  310. });
  311. if (!innerEq) {
  312. outerEq = false;
  313. }
  314. });
  315. return outerEq;
  316. },
  317. // Define maps a and b to be equivalent if for each key-value pair (aKey, aVal)
  318. // in a, there is some key-value pair (bKey, bVal) in b such that
  319. // [ aKey, aVal ] and [ bKey, bVal ] are equivalent. Key repetitions are not
  320. // counted, so these are equivalent:
  321. // a = new Map( [ [ {}, 1 ], [ {}, 1 ], [ [], 1 ] ] );
  322. // b = new Map( [ [ {}, 1 ], [ [], 1 ], [ [], 1 ] ] );
  323. "map": function map(a, b) {
  324. var innerEq,
  325. outerEq = true;
  326. if (a.size !== b.size) {
  327. // This optimization has certain quirks because of the lack of
  328. // repetition counting. For instance, adding the same
  329. // (reference-identical) key-value pair to two equivalent maps
  330. // can make them non-equivalent.
  331. return false;
  332. }
  333. a.forEach(function (aVal, aKey) {
  334. // Short-circuit if the result is already known. (Using for...of
  335. // with a break clause would be cleaner here, but it would cause
  336. // a syntax error on older Javascript implementations even if
  337. // Map is unused)
  338. if (!outerEq) {
  339. return;
  340. }
  341. innerEq = false;
  342. b.forEach(function (bVal, bKey) {
  343. var parentPairs;
  344. // Likewise, short-circuit if the result is already known
  345. if (innerEq) {
  346. return;
  347. }
  348. // Swap out the global pairs list, as the nested call to
  349. // innerEquiv will clobber its contents
  350. parentPairs = pairs;
  351. if (innerEquiv([bVal, bKey], [aVal, aKey])) {
  352. innerEq = true;
  353. }
  354. // Replace the global pairs list
  355. pairs = parentPairs;
  356. });
  357. if (!innerEq) {
  358. outerEq = false;
  359. }
  360. });
  361. return outerEq;
  362. },
  363. "object": function object(a, b) {
  364. var i,
  365. aProperties = [],
  366. bProperties = [];
  367. if (compareConstructors(a, b) === false) {
  368. return false;
  369. }
  370. // Be strict: don't ensure hasOwnProperty and go deep
  371. for (i in a) {
  372. // Collect a's properties
  373. aProperties.push(i);
  374. // Skip OOP methods that look the same
  375. if (a.constructor !== Object && typeof a.constructor !== "undefined" && typeof a[i] === "function" && typeof b[i] === "function" && a[i].toString() === b[i].toString()) {
  376. continue;
  377. }
  378. // Compare non-containers; queue non-reference-equal containers
  379. if (!breadthFirstCompareChild(a[i], b[i])) {
  380. return false;
  381. }
  382. }
  383. for (i in b) {
  384. // Collect b's properties
  385. bProperties.push(i);
  386. }
  387. // Ensures identical properties name
  388. return typeEquiv(aProperties.sort(), bProperties.sort());
  389. }
  390. };
  391. function typeEquiv(a, b) {
  392. var type = objectType(a);
  393. // Callbacks for containers will append to the pairs queue to achieve breadth-first
  394. // search order. The pairs queue is also used to avoid reprocessing any pair of
  395. // containers that are reference-equal to a previously visited pair (a special case
  396. // this being recursion detection).
  397. //
  398. // Because of this approach, once typeEquiv returns a false value, it should not be
  399. // called again without clearing the pair queue else it may wrongly report a visited
  400. // pair as being equivalent.
  401. return objectType(b) === type && callbacks[type](a, b);
  402. }
  403. function innerEquiv(a, b) {
  404. var i, pair;
  405. // We're done when there's nothing more to compare
  406. if (arguments.length < 2) {
  407. return true;
  408. }
  409. // Clear the global pair queue and add the top-level values being compared
  410. pairs = [{ a: a, b: b }];
  411. for (i = 0; i < pairs.length; i++) {
  412. pair = pairs[i];
  413. // Perform type-specific comparison on any pairs that are not strictly
  414. // equal. For container types, that comparison will postpone comparison
  415. // of any sub-container pair to the end of the pair queue. This gives
  416. // breadth-first search order. It also avoids the reprocessing of
  417. // reference-equal siblings, cousins etc, which can have a significant speed
  418. // impact when comparing a container of small objects each of which has a
  419. // reference to the same (singleton) large object.
  420. if (pair.a !== pair.b && !typeEquiv(pair.a, pair.b)) {
  421. return false;
  422. }
  423. }
  424. // ...across all consecutive argument pairs
  425. return arguments.length === 2 || innerEquiv.apply(this, [].slice.call(arguments, 1));
  426. }
  427. return innerEquiv;
  428. })();
  429. /**
  430. * Config object: Maintain internal state
  431. * Later exposed as QUnit.config
  432. * `config` initialized at top of scope
  433. */
  434. var config = {
  435. // The queue of tests to run
  436. queue: [],
  437. // Block until document ready
  438. blocking: true,
  439. // By default, run previously failed tests first
  440. // very useful in combination with "Hide passed tests" checked
  441. reorder: true,
  442. // By default, modify document.title when suite is done
  443. altertitle: true,
  444. // HTML Reporter: collapse every test except the first failing test
  445. // If false, all failing tests will be expanded
  446. collapse: true,
  447. // By default, scroll to top of the page when suite is done
  448. scrolltop: true,
  449. // Depth up-to which object will be dumped
  450. maxDepth: 5,
  451. // When enabled, all tests must call expect()
  452. requireExpects: false,
  453. // Placeholder for user-configurable form-exposed URL parameters
  454. urlConfig: [],
  455. // Set of all modules.
  456. modules: [],
  457. // Stack of nested modules
  458. moduleStack: [],
  459. // The first unnamed module
  460. currentModule: {
  461. name: "",
  462. tests: [],
  463. childModules: [],
  464. testsRun: 0
  465. },
  466. callbacks: {},
  467. // The storage module to use for reordering tests
  468. storage: sessionStorage
  469. };
  470. // take a predefined QUnit.config and extend the defaults
  471. var globalConfig = window && window.QUnit && window.QUnit.config;
  472. // only extend the global config if there is no QUnit overload
  473. if (window && window.QUnit && !window.QUnit.version) {
  474. extend(config, globalConfig);
  475. }
  476. // Push a loose unnamed module to the modules collection
  477. config.modules.push(config.currentModule);
  478. // Based on jsDump by Ariel Flesler
  479. // http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html
  480. var dump = (function () {
  481. function quote(str) {
  482. return "\"" + str.toString().replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"";
  483. }
  484. function literal(o) {
  485. return o + "";
  486. }
  487. function join(pre, arr, post) {
  488. var s = dump.separator(),
  489. base = dump.indent(),
  490. inner = dump.indent(1);
  491. if (arr.join) {
  492. arr = arr.join("," + s + inner);
  493. }
  494. if (!arr) {
  495. return pre + post;
  496. }
  497. return [pre, inner + arr, base + post].join(s);
  498. }
  499. function array(arr, stack) {
  500. var i = arr.length,
  501. ret = new Array(i);
  502. if (dump.maxDepth && dump.depth > dump.maxDepth) {
  503. return "[object Array]";
  504. }
  505. this.up();
  506. while (i--) {
  507. ret[i] = this.parse(arr[i], undefined, stack);
  508. }
  509. this.down();
  510. return join("[", ret, "]");
  511. }
  512. function isArray(obj) {
  513. return (
  514. //Native Arrays
  515. toString.call(obj) === "[object Array]" ||
  516. // NodeList objects
  517. typeof obj.length === "number" && obj.item !== undefined && (obj.length ? obj.item(0) === obj[0] : obj.item(0) === null && obj[0] === undefined)
  518. );
  519. }
  520. var reName = /^function (\w+)/,
  521. dump = {
  522. // The objType is used mostly internally, you can fix a (custom) type in advance
  523. parse: function parse(obj, objType, stack) {
  524. stack = stack || [];
  525. var res,
  526. parser,
  527. parserType,
  528. objIndex = stack.indexOf(obj);
  529. if (objIndex !== -1) {
  530. return "recursion(" + (objIndex - stack.length) + ")";
  531. }
  532. objType = objType || this.typeOf(obj);
  533. parser = this.parsers[objType];
  534. parserType = typeof parser === "undefined" ? "undefined" : _typeof(parser);
  535. if (parserType === "function") {
  536. stack.push(obj);
  537. res = parser.call(this, obj, stack);
  538. stack.pop();
  539. return res;
  540. }
  541. return parserType === "string" ? parser : this.parsers.error;
  542. },
  543. typeOf: function typeOf(obj) {
  544. var type;
  545. if (obj === null) {
  546. type = "null";
  547. } else if (typeof obj === "undefined") {
  548. type = "undefined";
  549. } else if (is("regexp", obj)) {
  550. type = "regexp";
  551. } else if (is("date", obj)) {
  552. type = "date";
  553. } else if (is("function", obj)) {
  554. type = "function";
  555. } else if (obj.setInterval !== undefined && obj.document !== undefined && obj.nodeType === undefined) {
  556. type = "window";
  557. } else if (obj.nodeType === 9) {
  558. type = "document";
  559. } else if (obj.nodeType) {
  560. type = "node";
  561. } else if (isArray(obj)) {
  562. type = "array";
  563. } else if (obj.constructor === Error.prototype.constructor) {
  564. type = "error";
  565. } else {
  566. type = typeof obj === "undefined" ? "undefined" : _typeof(obj);
  567. }
  568. return type;
  569. },
  570. separator: function separator() {
  571. if (this.multiline) {
  572. return this.HTML ? "<br />" : "\n";
  573. } else {
  574. return this.HTML ? "&#160;" : " ";
  575. }
  576. },
  577. // Extra can be a number, shortcut for increasing-calling-decreasing
  578. indent: function indent(extra) {
  579. if (!this.multiline) {
  580. return "";
  581. }
  582. var chr = this.indentChar;
  583. if (this.HTML) {
  584. chr = chr.replace(/\t/g, " ").replace(/ /g, "&#160;");
  585. }
  586. return new Array(this.depth + (extra || 0)).join(chr);
  587. },
  588. up: function up(a) {
  589. this.depth += a || 1;
  590. },
  591. down: function down(a) {
  592. this.depth -= a || 1;
  593. },
  594. setParser: function setParser(name, parser) {
  595. this.parsers[name] = parser;
  596. },
  597. // The next 3 are exposed so you can use them
  598. quote: quote,
  599. literal: literal,
  600. join: join,
  601. depth: 1,
  602. maxDepth: config.maxDepth,
  603. // This is the list of parsers, to modify them, use dump.setParser
  604. parsers: {
  605. window: "[Window]",
  606. document: "[Document]",
  607. error: function error(_error) {
  608. return "Error(\"" + _error.message + "\")";
  609. },
  610. unknown: "[Unknown]",
  611. "null": "null",
  612. "undefined": "undefined",
  613. "function": function _function(fn) {
  614. var ret = "function",
  615. // Functions never have name in IE
  616. name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];
  617. if (name) {
  618. ret += " " + name;
  619. }
  620. ret += "(";
  621. ret = [ret, dump.parse(fn, "functionArgs"), "){"].join("");
  622. return join(ret, dump.parse(fn, "functionCode"), "}");
  623. },
  624. array: array,
  625. nodelist: array,
  626. "arguments": array,
  627. object: function object(map, stack) {
  628. var keys,
  629. key,
  630. val,
  631. i,
  632. nonEnumerableProperties,
  633. ret = [];
  634. if (dump.maxDepth && dump.depth > dump.maxDepth) {
  635. return "[object Object]";
  636. }
  637. dump.up();
  638. keys = [];
  639. for (key in map) {
  640. keys.push(key);
  641. }
  642. // Some properties are not always enumerable on Error objects.
  643. nonEnumerableProperties = ["message", "name"];
  644. for (i in nonEnumerableProperties) {
  645. key = nonEnumerableProperties[i];
  646. if (key in map && !inArray(key, keys)) {
  647. keys.push(key);
  648. }
  649. }
  650. keys.sort();
  651. for (i = 0; i < keys.length; i++) {
  652. key = keys[i];
  653. val = map[key];
  654. ret.push(dump.parse(key, "key") + ": " + dump.parse(val, undefined, stack));
  655. }
  656. dump.down();
  657. return join("{", ret, "}");
  658. },
  659. node: function node(_node) {
  660. var len,
  661. i,
  662. val,
  663. open = dump.HTML ? "&lt;" : "<",
  664. close = dump.HTML ? "&gt;" : ">",
  665. tag = _node.nodeName.toLowerCase(),
  666. ret = open + tag,
  667. attrs = _node.attributes;
  668. if (attrs) {
  669. for (i = 0, len = attrs.length; i < len; i++) {
  670. val = attrs[i].nodeValue;
  671. // IE6 includes all attributes in .attributes, even ones not explicitly
  672. // set. Those have values like undefined, null, 0, false, "" or
  673. // "inherit".
  674. if (val && val !== "inherit") {
  675. ret += " " + attrs[i].nodeName + "=" + dump.parse(val, "attribute");
  676. }
  677. }
  678. }
  679. ret += close;
  680. // Show content of TextNode or CDATASection
  681. if (_node.nodeType === 3 || _node.nodeType === 4) {
  682. ret += _node.nodeValue;
  683. }
  684. return ret + open + "/" + tag + close;
  685. },
  686. // Function calls it internally, it's the arguments part of the function
  687. functionArgs: function functionArgs(fn) {
  688. var args,
  689. l = fn.length;
  690. if (!l) {
  691. return "";
  692. }
  693. args = new Array(l);
  694. while (l--) {
  695. // 97 is 'a'
  696. args[l] = String.fromCharCode(97 + l);
  697. }
  698. return " " + args.join(", ") + " ";
  699. },
  700. // Object calls it internally, the key part of an item in a map
  701. key: quote,
  702. // Function calls it internally, it's the content of the function
  703. functionCode: "[code]",
  704. // Node calls it internally, it's a html attribute value
  705. attribute: quote,
  706. string: quote,
  707. date: quote,
  708. regexp: literal,
  709. number: literal,
  710. "boolean": literal,
  711. symbol: function symbol(sym) {
  712. return sym.toString();
  713. }
  714. },
  715. // If true, entities are escaped ( <, >, \t, space and \n )
  716. HTML: false,
  717. // Indentation unit
  718. indentChar: " ",
  719. // If true, items in a collection, are separated by a \n, else just a space.
  720. multiline: true
  721. };
  722. return dump;
  723. })();
  724. var LISTENERS = Object.create(null);
  725. var SUPPORTED_EVENTS = ["runStart", "suiteStart", "testStart", "assertion", "testEnd", "suiteEnd", "runEnd"];
  726. /**
  727. * Emits an event with the specified data to all currently registered listeners.
  728. * Callbacks will fire in the order in which they are registered (FIFO). This
  729. * function is not exposed publicly; it is used by QUnit internals to emit
  730. * logging events.
  731. *
  732. * @private
  733. * @method emit
  734. * @param {String} eventName
  735. * @param {Object} data
  736. * @return {Void}
  737. */
  738. function emit(eventName, data) {
  739. if (objectType(eventName) !== "string") {
  740. throw new TypeError("eventName must be a string when emitting an event");
  741. }
  742. // Clone the callbacks in case one of them registers a new callback
  743. var originalCallbacks = LISTENERS[eventName];
  744. var callbacks = originalCallbacks ? [].concat(toConsumableArray(originalCallbacks)) : [];
  745. for (var i = 0; i < callbacks.length; i++) {
  746. callbacks[i](data);
  747. }
  748. }
  749. /**
  750. * Registers a callback as a listener to the specified event.
  751. *
  752. * @public
  753. * @method on
  754. * @param {String} eventName
  755. * @param {Function} callback
  756. * @return {Void}
  757. */
  758. function on(eventName, callback) {
  759. if (objectType(eventName) !== "string") {
  760. throw new TypeError("eventName must be a string when registering a listener");
  761. } else if (!inArray(eventName, SUPPORTED_EVENTS)) {
  762. var events = SUPPORTED_EVENTS.join(", ");
  763. throw new Error("\"" + eventName + "\" is not a valid event; must be one of: " + events + ".");
  764. } else if (objectType(callback) !== "function") {
  765. throw new TypeError("callback must be a function when registering a listener");
  766. }
  767. if (!LISTENERS[eventName]) {
  768. LISTENERS[eventName] = [];
  769. }
  770. // Don't register the same callback more than once
  771. if (!inArray(callback, LISTENERS[eventName])) {
  772. LISTENERS[eventName].push(callback);
  773. }
  774. }
  775. // Register logging callbacks
  776. function registerLoggingCallbacks(obj) {
  777. var i,
  778. l,
  779. key,
  780. callbackNames = ["begin", "done", "log", "testStart", "testDone", "moduleStart", "moduleDone"];
  781. function registerLoggingCallback(key) {
  782. var loggingCallback = function loggingCallback(callback) {
  783. if (objectType(callback) !== "function") {
  784. throw new Error("QUnit logging methods require a callback function as their first parameters.");
  785. }
  786. config.callbacks[key].push(callback);
  787. };
  788. return loggingCallback;
  789. }
  790. for (i = 0, l = callbackNames.length; i < l; i++) {
  791. key = callbackNames[i];
  792. // Initialize key collection of logging callback
  793. if (objectType(config.callbacks[key]) === "undefined") {
  794. config.callbacks[key] = [];
  795. }
  796. obj[key] = registerLoggingCallback(key);
  797. }
  798. }
  799. function runLoggingCallbacks(key, args) {
  800. var i, l, callbacks;
  801. callbacks = config.callbacks[key];
  802. for (i = 0, l = callbacks.length; i < l; i++) {
  803. callbacks[i](args);
  804. }
  805. }
  806. // Doesn't support IE9, it will return undefined on these browsers
  807. // See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack
  808. var fileName = (sourceFromStacktrace(0) || "").replace(/(:\d+)+\)?/, "").replace(/.+\//, "");
  809. function extractStacktrace(e, offset) {
  810. offset = offset === undefined ? 4 : offset;
  811. var stack, include, i;
  812. if (e && e.stack) {
  813. stack = e.stack.split("\n");
  814. if (/^error$/i.test(stack[0])) {
  815. stack.shift();
  816. }
  817. if (fileName) {
  818. include = [];
  819. for (i = offset; i < stack.length; i++) {
  820. if (stack[i].indexOf(fileName) !== -1) {
  821. break;
  822. }
  823. include.push(stack[i]);
  824. }
  825. if (include.length) {
  826. return include.join("\n");
  827. }
  828. }
  829. return stack[offset];
  830. }
  831. }
  832. function sourceFromStacktrace(offset) {
  833. var error = new Error();
  834. // Support: Safari <=7 only, IE <=10 - 11 only
  835. // Not all browsers generate the `stack` property for `new Error()`, see also #636
  836. if (!error.stack) {
  837. try {
  838. throw error;
  839. } catch (err) {
  840. error = err;
  841. }
  842. }
  843. return extractStacktrace(error, offset);
  844. }
  845. var TestReport = function () {
  846. function TestReport(name, suite, options) {
  847. classCallCheck(this, TestReport);
  848. this.name = name;
  849. this.suiteName = suite.name;
  850. this.fullName = suite.fullName.concat(name);
  851. this.runtime = 0;
  852. this.assertions = [];
  853. this.skipped = !!options.skip;
  854. this.todo = !!options.todo;
  855. this._startTime = 0;
  856. this._endTime = 0;
  857. suite.pushTest(this);
  858. }
  859. createClass(TestReport, [{
  860. key: "start",
  861. value: function start(recordTime) {
  862. if (recordTime) {
  863. this._startTime = Date.now();
  864. }
  865. return {
  866. name: this.name,
  867. suiteName: this.suiteName,
  868. fullName: this.fullName.slice()
  869. };
  870. }
  871. }, {
  872. key: "end",
  873. value: function end(recordTime) {
  874. if (recordTime) {
  875. this._endTime = Date.now();
  876. }
  877. return extend(this.start(), {
  878. runtime: this.getRuntime(),
  879. status: this.getStatus(),
  880. errors: this.getFailedAssertions(),
  881. assertions: this.getAssertions()
  882. });
  883. }
  884. }, {
  885. key: "pushAssertion",
  886. value: function pushAssertion(assertion) {
  887. this.assertions.push(assertion);
  888. }
  889. }, {
  890. key: "getRuntime",
  891. value: function getRuntime() {
  892. return this._endTime - this._startTime;
  893. }
  894. }, {
  895. key: "getStatus",
  896. value: function getStatus() {
  897. if (this.skipped) {
  898. return "skipped";
  899. }
  900. var testPassed = this.getFailedAssertions().length > 0 ? this.todo : !this.todo;
  901. if (!testPassed) {
  902. return "failed";
  903. } else if (this.todo) {
  904. return "todo";
  905. } else {
  906. return "passed";
  907. }
  908. }
  909. }, {
  910. key: "getFailedAssertions",
  911. value: function getFailedAssertions() {
  912. return this.assertions.filter(function (assertion) {
  913. return !assertion.passed;
  914. });
  915. }
  916. }, {
  917. key: "getAssertions",
  918. value: function getAssertions() {
  919. return this.assertions.slice();
  920. }
  921. }]);
  922. return TestReport;
  923. }();
  924. var unitSampler;
  925. var focused = false;
  926. var priorityCount = 0;
  927. function Test(settings) {
  928. var i, l;
  929. ++Test.count;
  930. this.expected = null;
  931. extend(this, settings);
  932. this.assertions = [];
  933. this.semaphore = 0;
  934. this.usedAsync = false;
  935. this.module = config.currentModule;
  936. this.stack = sourceFromStacktrace(3);
  937. this.steps = [];
  938. this.testReport = new TestReport(settings.testName, this.module.suiteReport, {
  939. todo: settings.todo,
  940. skip: settings.skip
  941. });
  942. // Register unique strings
  943. for (i = 0, l = this.module.tests; i < l.length; i++) {
  944. if (this.module.tests[i].name === this.testName) {
  945. this.testName += " ";
  946. }
  947. }
  948. this.testId = generateHash(this.module.name, this.testName);
  949. this.module.tests.push({
  950. name: this.testName,
  951. testId: this.testId
  952. });
  953. if (settings.skip) {
  954. // Skipped tests will fully ignore any sent callback
  955. this.callback = function () {};
  956. this.async = false;
  957. this.expected = 0;
  958. } else {
  959. this.assert = new Assert(this);
  960. }
  961. }
  962. Test.count = 0;
  963. function getNotStartedModules(startModule) {
  964. var module = startModule,
  965. modules = [];
  966. while (module && module.testsRun === 0) {
  967. modules.push(module);
  968. module = module.parentModule;
  969. }
  970. return modules;
  971. }
  972. Test.prototype = {
  973. before: function before() {
  974. var i,
  975. startModule,
  976. module = this.module,
  977. notStartedModules = getNotStartedModules(module);
  978. for (i = notStartedModules.length - 1; i >= 0; i--) {
  979. startModule = notStartedModules[i];
  980. startModule.stats = { all: 0, bad: 0, started: now() };
  981. emit("suiteStart", startModule.suiteReport.start(true));
  982. runLoggingCallbacks("moduleStart", {
  983. name: startModule.name,
  984. tests: startModule.tests
  985. });
  986. }
  987. config.current = this;
  988. if (module.testEnvironment) {
  989. delete module.testEnvironment.before;
  990. delete module.testEnvironment.beforeEach;
  991. delete module.testEnvironment.afterEach;
  992. delete module.testEnvironment.after;
  993. }
  994. this.testEnvironment = extend({}, module.testEnvironment);
  995. this.started = now();
  996. emit("testStart", this.testReport.start(true));
  997. runLoggingCallbacks("testStart", {
  998. name: this.testName,
  999. module: module.name,
  1000. testId: this.testId,
  1001. previousFailure: this.previousFailure
  1002. });
  1003. if (!config.pollution) {
  1004. saveGlobal();
  1005. }
  1006. },
  1007. run: function run() {
  1008. var promise;
  1009. config.current = this;
  1010. this.callbackStarted = now();
  1011. if (config.notrycatch) {
  1012. runTest(this);
  1013. return;
  1014. }
  1015. try {
  1016. runTest(this);
  1017. } catch (e) {
  1018. this.pushFailure("Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + (e.message || e), extractStacktrace(e, 0));
  1019. // Else next test will carry the responsibility
  1020. saveGlobal();
  1021. // Restart the tests if they're blocking
  1022. if (config.blocking) {
  1023. internalRecover(this);
  1024. }
  1025. }
  1026. function runTest(test) {
  1027. promise = test.callback.call(test.testEnvironment, test.assert);
  1028. test.resolvePromise(promise);
  1029. }
  1030. },
  1031. after: function after() {
  1032. checkPollution();
  1033. },
  1034. queueHook: function queueHook(hook, hookName, hookOwner) {
  1035. var promise,
  1036. test = this;
  1037. return function runHook() {
  1038. if (hookName === "before") {
  1039. if (hookOwner.testsRun !== 0) {
  1040. return;
  1041. }
  1042. test.preserveEnvironment = true;
  1043. }
  1044. if (hookName === "after" && hookOwner.testsRun !== numberOfTests(hookOwner) - 1) {
  1045. return;
  1046. }
  1047. config.current = test;
  1048. if (config.notrycatch) {
  1049. callHook();
  1050. return;
  1051. }
  1052. try {
  1053. callHook();
  1054. } catch (error) {
  1055. test.pushFailure(hookName + " failed on " + test.testName + ": " + (error.message || error), extractStacktrace(error, 0));
  1056. }
  1057. function callHook() {
  1058. promise = hook.call(test.testEnvironment, test.assert);
  1059. test.resolvePromise(promise, hookName);
  1060. }
  1061. };
  1062. },
  1063. // Currently only used for module level hooks, can be used to add global level ones
  1064. hooks: function hooks(handler) {
  1065. var hooks = [];
  1066. function processHooks(test, module) {
  1067. if (module.parentModule) {
  1068. processHooks(test, module.parentModule);
  1069. }
  1070. if (module.testEnvironment && objectType(module.testEnvironment[handler]) === "function") {
  1071. hooks.push(test.queueHook(module.testEnvironment[handler], handler, module));
  1072. }
  1073. }
  1074. // Hooks are ignored on skipped tests
  1075. if (!this.skip) {
  1076. processHooks(this, this.module);
  1077. }
  1078. return hooks;
  1079. },
  1080. finish: function finish() {
  1081. config.current = this;
  1082. if (config.requireExpects && this.expected === null) {
  1083. this.pushFailure("Expected number of assertions to be defined, but expect() was " + "not called.", this.stack);
  1084. } else if (this.expected !== null && this.expected !== this.assertions.length) {
  1085. this.pushFailure("Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack);
  1086. } else if (this.expected === null && !this.assertions.length) {
  1087. this.pushFailure("Expected at least one assertion, but none were run - call " + "expect(0) to accept zero assertions.", this.stack);
  1088. }
  1089. var i,
  1090. module = this.module,
  1091. moduleName = module.name,
  1092. testName = this.testName,
  1093. skipped = !!this.skip,
  1094. todo = !!this.todo,
  1095. bad = 0,
  1096. storage = config.storage;
  1097. this.runtime = now() - this.started;
  1098. config.stats.all += this.assertions.length;
  1099. module.stats.all += this.assertions.length;
  1100. for (i = 0; i < this.assertions.length; i++) {
  1101. if (!this.assertions[i].result) {
  1102. bad++;
  1103. config.stats.bad++;
  1104. module.stats.bad++;
  1105. }
  1106. }
  1107. notifyTestsRan(module);
  1108. // Store result when possible
  1109. if (storage) {
  1110. if (bad) {
  1111. storage.setItem("qunit-test-" + moduleName + "-" + testName, bad);
  1112. } else {
  1113. storage.removeItem("qunit-test-" + moduleName + "-" + testName);
  1114. }
  1115. }
  1116. emit("testEnd", this.testReport.end(true));
  1117. runLoggingCallbacks("testDone", {
  1118. name: testName,
  1119. module: moduleName,
  1120. skipped: skipped,
  1121. todo: todo,
  1122. failed: bad,
  1123. passed: this.assertions.length - bad,
  1124. total: this.assertions.length,
  1125. runtime: skipped ? 0 : this.runtime,
  1126. // HTML Reporter use
  1127. assertions: this.assertions,
  1128. testId: this.testId,
  1129. // Source of Test
  1130. source: this.stack
  1131. });
  1132. if (module.testsRun === numberOfTests(module)) {
  1133. emit("suiteEnd", module.suiteReport.end(true));
  1134. runLoggingCallbacks("moduleDone", {
  1135. name: module.name,
  1136. tests: module.tests,
  1137. failed: module.stats.bad,
  1138. passed: module.stats.all - module.stats.bad,
  1139. total: module.stats.all,
  1140. runtime: now() - module.stats.started
  1141. });
  1142. }
  1143. config.current = undefined;
  1144. },
  1145. preserveTestEnvironment: function preserveTestEnvironment() {
  1146. if (this.preserveEnvironment) {
  1147. this.module.testEnvironment = this.testEnvironment;
  1148. this.testEnvironment = extend({}, this.module.testEnvironment);
  1149. }
  1150. },
  1151. queue: function queue() {
  1152. var priority,
  1153. previousFailCount,
  1154. test = this;
  1155. if (!this.valid()) {
  1156. return;
  1157. }
  1158. function run() {
  1159. // Each of these can by async
  1160. synchronize([function () {
  1161. test.before();
  1162. }, test.hooks("before"), function () {
  1163. test.preserveTestEnvironment();
  1164. }, test.hooks("beforeEach"), function () {
  1165. test.run();
  1166. }, test.hooks("afterEach").reverse(), test.hooks("after").reverse(), function () {
  1167. test.after();
  1168. }, function () {
  1169. test.finish();
  1170. }]);
  1171. }
  1172. previousFailCount = config.storage && +config.storage.getItem("qunit-test-" + this.module.name + "-" + this.testName);
  1173. // Prioritize previously failed tests, detected from storage
  1174. priority = config.reorder && previousFailCount;
  1175. this.previousFailure = !!previousFailCount;
  1176. return synchronize(run, priority, config.seed);
  1177. },
  1178. pushResult: function pushResult(resultInfo) {
  1179. // Destructure of resultInfo = { result, actual, expected, message, negative }
  1180. var source,
  1181. details = {
  1182. module: this.module.name,
  1183. name: this.testName,
  1184. result: resultInfo.result,
  1185. message: resultInfo.message,
  1186. actual: resultInfo.actual,
  1187. expected: resultInfo.expected,
  1188. testId: this.testId,
  1189. negative: resultInfo.negative || false,
  1190. runtime: now() - this.started,
  1191. todo: !!this.todo
  1192. };
  1193. if (!resultInfo.result) {
  1194. source = resultInfo.source || sourceFromStacktrace();
  1195. if (source) {
  1196. details.source = source;
  1197. }
  1198. }
  1199. this.logAssertion(details);
  1200. this.assertions.push({
  1201. result: !!resultInfo.result,
  1202. message: resultInfo.message
  1203. });
  1204. },
  1205. pushFailure: function pushFailure(message, source, actual) {
  1206. if (!(this instanceof Test)) {
  1207. throw new Error("pushFailure() assertion outside test context, was " + sourceFromStacktrace(2));
  1208. }
  1209. this.assert.pushResult({
  1210. result: false,
  1211. message: message || "error",
  1212. actual: actual || null,
  1213. expected: null,
  1214. source: source
  1215. });
  1216. },
  1217. /**
  1218. * Log assertion details using both the old QUnit.log interface and
  1219. * QUnit.on( "assertion" ) interface.
  1220. *
  1221. * @private
  1222. */
  1223. logAssertion: function logAssertion(details) {
  1224. runLoggingCallbacks("log", details);
  1225. var assertion = {
  1226. passed: details.result,
  1227. actual: details.actual,
  1228. expected: details.expected,
  1229. message: details.message,
  1230. stack: details.source,
  1231. todo: details.todo
  1232. };
  1233. this.testReport.pushAssertion(assertion);
  1234. emit("assertion", assertion);
  1235. },
  1236. resolvePromise: function resolvePromise(promise, phase) {
  1237. var then,
  1238. resume,
  1239. message,
  1240. test = this;
  1241. if (promise != null) {
  1242. then = promise.then;
  1243. if (objectType(then) === "function") {
  1244. resume = internalStop(test);
  1245. then.call(promise, function () {
  1246. resume();
  1247. }, function (error) {
  1248. message = "Promise rejected " + (!phase ? "during" : phase.replace(/Each$/, "")) + " \"" + test.testName + "\": " + (error && error.message || error);
  1249. test.pushFailure(message, extractStacktrace(error, 0));
  1250. // Else next test will carry the responsibility
  1251. saveGlobal();
  1252. // Unblock
  1253. resume();
  1254. });
  1255. }
  1256. }
  1257. },
  1258. valid: function valid() {
  1259. var filter = config.filter,
  1260. regexFilter = /^(!?)\/([\w\W]*)\/(i?$)/.exec(filter),
  1261. module = config.module && config.module.toLowerCase(),
  1262. fullName = this.module.name + ": " + this.testName;
  1263. function moduleChainNameMatch(testModule) {
  1264. var testModuleName = testModule.name ? testModule.name.toLowerCase() : null;
  1265. if (testModuleName === module) {
  1266. return true;
  1267. } else if (testModule.parentModule) {
  1268. return moduleChainNameMatch(testModule.parentModule);
  1269. } else {
  1270. return false;
  1271. }
  1272. }
  1273. function moduleChainIdMatch(testModule) {
  1274. return inArray(testModule.moduleId, config.moduleId) || testModule.parentModule && moduleChainIdMatch(testModule.parentModule);
  1275. }
  1276. // Internally-generated tests are always valid
  1277. if (this.callback && this.callback.validTest) {
  1278. return true;
  1279. }
  1280. if (config.moduleId && config.moduleId.length > 0 && !moduleChainIdMatch(this.module)) {
  1281. return false;
  1282. }
  1283. if (config.testId && config.testId.length > 0 && !inArray(this.testId, config.testId)) {
  1284. return false;
  1285. }
  1286. if (module && !moduleChainNameMatch(this.module)) {
  1287. return false;
  1288. }
  1289. if (!filter) {
  1290. return true;
  1291. }
  1292. return regexFilter ? this.regexFilter(!!regexFilter[1], regexFilter[2], regexFilter[3], fullName) : this.stringFilter(filter, fullName);
  1293. },
  1294. regexFilter: function regexFilter(exclude, pattern, flags, fullName) {
  1295. var regex = new RegExp(pattern, flags);
  1296. var match = regex.test(fullName);
  1297. return match !== exclude;
  1298. },
  1299. stringFilter: function stringFilter(filter, fullName) {
  1300. filter = filter.toLowerCase();
  1301. fullName = fullName.toLowerCase();
  1302. var include = filter.charAt(0) !== "!";
  1303. if (!include) {
  1304. filter = filter.slice(1);
  1305. }
  1306. // If the filter matches, we need to honour include
  1307. if (fullName.indexOf(filter) !== -1) {
  1308. return include;
  1309. }
  1310. // Otherwise, do the opposite
  1311. return !include;
  1312. }
  1313. };
  1314. function pushFailure() {
  1315. if (!config.current) {
  1316. throw new Error("pushFailure() assertion outside test context, in " + sourceFromStacktrace(2));
  1317. }
  1318. // Gets current test obj
  1319. var currentTest = config.current;
  1320. return currentTest.pushFailure.apply(currentTest, arguments);
  1321. }
  1322. // Based on Java's String.hashCode, a simple but not
  1323. // rigorously collision resistant hashing function
  1324. function generateHash(module, testName) {
  1325. var hex,
  1326. i = 0,
  1327. hash = 0,
  1328. str = module + "\x1C" + testName,
  1329. len = str.length;
  1330. for (; i < len; i++) {
  1331. hash = (hash << 5) - hash + str.charCodeAt(i);
  1332. hash |= 0;
  1333. }
  1334. // Convert the possibly negative integer hash code into an 8 character hex string, which isn't
  1335. // strictly necessary but increases user understanding that the id is a SHA-like hash
  1336. hex = (0x100000000 + hash).toString(16);
  1337. if (hex.length < 8) {
  1338. hex = "0000000" + hex;
  1339. }
  1340. return hex.slice(-8);
  1341. }
  1342. function synchronize(callback, priority, seed) {
  1343. var last = !priority,
  1344. index;
  1345. if (objectType(callback) === "array") {
  1346. while (callback.length) {
  1347. synchronize(callback.shift());
  1348. }
  1349. return;
  1350. }
  1351. if (priority) {
  1352. config.queue.splice(priorityCount++, 0, callback);
  1353. } else if (seed) {
  1354. if (!unitSampler) {
  1355. unitSampler = unitSamplerGenerator(seed);
  1356. }
  1357. // Insert into a random position after all priority items
  1358. index = Math.floor(unitSampler() * (config.queue.length - priorityCount + 1));
  1359. config.queue.splice(priorityCount + index, 0, callback);
  1360. } else {
  1361. config.queue.push(callback);
  1362. }
  1363. if (internalState.autorun && !config.blocking) {
  1364. process(last);
  1365. }
  1366. }
  1367. function unitSamplerGenerator(seed) {
  1368. // 32-bit xorshift, requires only a nonzero seed
  1369. // http://excamera.com/sphinx/article-xorshift.html
  1370. var sample = parseInt(generateHash(seed), 16) || -1;
  1371. return function () {
  1372. sample ^= sample << 13;
  1373. sample ^= sample >>> 17;
  1374. sample ^= sample << 5;
  1375. // ECMAScript has no unsigned number type
  1376. if (sample < 0) {
  1377. sample += 0x100000000;
  1378. }
  1379. return sample / 0x100000000;
  1380. };
  1381. }
  1382. function saveGlobal() {
  1383. config.pollution = [];
  1384. if (config.noglobals) {
  1385. for (var key in global$1) {
  1386. if (hasOwn.call(global$1, key)) {
  1387. // In Opera sometimes DOM element ids show up here, ignore them
  1388. if (/^qunit-test-output/.test(key)) {
  1389. continue;
  1390. }
  1391. config.pollution.push(key);
  1392. }
  1393. }
  1394. }
  1395. }
  1396. function checkPollution() {
  1397. var newGlobals,
  1398. deletedGlobals,
  1399. old = config.pollution;
  1400. saveGlobal();
  1401. newGlobals = diff(config.pollution, old);
  1402. if (newGlobals.length > 0) {
  1403. pushFailure("Introduced global variable(s): " + newGlobals.join(", "));
  1404. }
  1405. deletedGlobals = diff(old, config.pollution);
  1406. if (deletedGlobals.length > 0) {
  1407. pushFailure("Deleted global variable(s): " + deletedGlobals.join(", "));
  1408. }
  1409. }
  1410. // Will be exposed as QUnit.test
  1411. function test(testName, callback) {
  1412. if (focused) {
  1413. return;
  1414. }
  1415. var newTest = new Test({
  1416. testName: testName,
  1417. callback: callback
  1418. });
  1419. newTest.queue();
  1420. }
  1421. function todo(testName, callback) {
  1422. if (focused) {
  1423. return;
  1424. }
  1425. var newTest = new Test({
  1426. testName: testName,
  1427. callback: callback,
  1428. todo: true
  1429. });
  1430. newTest.queue();
  1431. }
  1432. // Will be exposed as QUnit.skip
  1433. function skip(testName) {
  1434. if (focused) {
  1435. return;
  1436. }
  1437. var test = new Test({
  1438. testName: testName,
  1439. skip: true
  1440. });
  1441. test.queue();
  1442. }
  1443. // Will be exposed as QUnit.only
  1444. function only(testName, callback) {
  1445. if (focused) {
  1446. return;
  1447. }
  1448. config.queue.length = 0;
  1449. focused = true;
  1450. var newTest = new Test({
  1451. testName: testName,
  1452. callback: callback
  1453. });
  1454. newTest.queue();
  1455. }
  1456. // Put a hold on processing and return a function that will release it.
  1457. function internalStop(test) {
  1458. var released = false;
  1459. test.semaphore += 1;
  1460. config.blocking = true;
  1461. // Set a recovery timeout, if so configured.
  1462. if (config.testTimeout && defined.setTimeout) {
  1463. clearTimeout(config.timeout);
  1464. config.timeout = setTimeout(function () {
  1465. pushFailure("Test timed out", sourceFromStacktrace(2));
  1466. internalRecover(test);
  1467. }, config.testTimeout);
  1468. }
  1469. return function resume() {
  1470. if (released) {
  1471. return;
  1472. }
  1473. released = true;
  1474. test.semaphore -= 1;
  1475. internalStart(test);
  1476. };
  1477. }
  1478. // Forcefully release all processing holds.
  1479. function internalRecover(test) {
  1480. test.semaphore = 0;
  1481. internalStart(test);
  1482. }
  1483. // Release a processing hold, scheduling a resumption attempt if no holds remain.
  1484. function internalStart(test) {
  1485. // If semaphore is non-numeric, throw error
  1486. if (isNaN(test.semaphore)) {
  1487. test.semaphore = 0;
  1488. pushFailure("Invalid value on test.semaphore", sourceFromStacktrace(2));
  1489. return;
  1490. }
  1491. // Don't start until equal number of stop-calls
  1492. if (test.semaphore > 0) {
  1493. return;
  1494. }
  1495. // Throw an Error if start is called more often than stop
  1496. if (test.semaphore < 0) {
  1497. test.semaphore = 0;
  1498. pushFailure("Tried to restart test while already started (test's semaphore was 0 already)", sourceFromStacktrace(2));
  1499. return;
  1500. }
  1501. // Add a slight delay to allow more assertions etc.
  1502. if (defined.setTimeout) {
  1503. if (config.timeout) {
  1504. clearTimeout(config.timeout);
  1505. }
  1506. config.timeout = setTimeout(function () {
  1507. if (test.semaphore > 0) {
  1508. return;
  1509. }
  1510. if (config.timeout) {
  1511. clearTimeout(config.timeout);
  1512. }
  1513. begin();
  1514. }, 13);
  1515. } else {
  1516. begin();
  1517. }
  1518. }
  1519. function numberOfTests(module) {
  1520. var count = module.tests.length,
  1521. modules = [].concat(toConsumableArray(module.childModules));
  1522. // Do a breadth-first traversal of the child modules
  1523. while (modules.length) {
  1524. var nextModule = modules.shift();
  1525. count += nextModule.tests.length;
  1526. modules.push.apply(modules, toConsumableArray(nextModule.childModules));
  1527. }
  1528. return count;
  1529. }
  1530. function notifyTestsRan(module) {
  1531. module.testsRun++;
  1532. while (module = module.parentModule) {
  1533. module.testsRun++;
  1534. }
  1535. }
  1536. /**
  1537. * Returns a function that proxies to the given method name on the globals
  1538. * console object. The proxy will also detect if the console doesn't exist and
  1539. * will appropriately no-op. This allows support for IE9, which doesn't have a
  1540. * console if the developer tools are not open.
  1541. */
  1542. function consoleProxy(method) {
  1543. return function () {
  1544. if (console) {
  1545. console[method].apply(console, arguments);
  1546. }
  1547. };
  1548. }
  1549. var Logger = {
  1550. warn: consoleProxy("warn")
  1551. };
  1552. var Assert = function () {
  1553. function Assert(testContext) {
  1554. classCallCheck(this, Assert);
  1555. this.test = testContext;
  1556. }
  1557. // Assert helpers
  1558. // Documents a "step", which is a string value, in a test as a passing assertion
  1559. createClass(Assert, [{
  1560. key: "step",
  1561. value: function step(message) {
  1562. var result = !!message;
  1563. this.test.steps.push(message);
  1564. return this.pushResult({
  1565. result: result,
  1566. message: message || "You must provide a message to assert.step"
  1567. });
  1568. }
  1569. // Verifies the steps in a test match a given array of string values
  1570. }, {
  1571. key: "verifySteps",
  1572. value: function verifySteps(steps, message) {
  1573. this.deepEqual(this.test.steps, steps, message);
  1574. }
  1575. // Specify the number of expected assertions to guarantee that failed test
  1576. // (no assertions are run at all) don't slip through.
  1577. }, {
  1578. key: "expect",
  1579. value: function expect(asserts) {
  1580. if (arguments.length === 1) {
  1581. this.test.expected = asserts;
  1582. } else {
  1583. return this.test.expected;
  1584. }
  1585. }
  1586. // Put a hold on processing and return a function that will release it a maximum of once.
  1587. }, {
  1588. key: "async",
  1589. value: function async(count) {
  1590. var test$$1 = this.test,
  1591. popped = false,
  1592. acceptCallCount = count;
  1593. if (typeof acceptCallCount === "undefined") {
  1594. acceptCallCount = 1;
  1595. }
  1596. test$$1.usedAsync = true;
  1597. var resume = internalStop(test$$1);
  1598. return function done() {
  1599. if (popped) {
  1600. test$$1.pushFailure("Too many calls to the `assert.async` callback", sourceFromStacktrace(2));
  1601. return;
  1602. }
  1603. acceptCallCount -= 1;
  1604. if (acceptCallCount > 0) {
  1605. return;
  1606. }
  1607. popped = true;
  1608. resume();
  1609. };
  1610. }
  1611. // Exports test.push() to the user API
  1612. // Alias of pushResult.
  1613. }, {
  1614. key: "push",
  1615. value: function push(result, actual, expected, message, negative) {
  1616. Logger.warn("assert.push is deprecated and will be removed in QUnit 3.0." + " Please use assert.pushResult instead (http://api.qunitjs.com/pushResult/).");
  1617. var currentAssert = this instanceof Assert ? this : config.current.assert;
  1618. return currentAssert.pushResult({
  1619. result: result,
  1620. actual: actual,
  1621. expected: expected,
  1622. message: message,
  1623. negative: negative
  1624. });
  1625. }
  1626. }, {
  1627. key: "pushResult",
  1628. value: function pushResult(resultInfo) {
  1629. // Destructure of resultInfo = { result, actual, expected, message, negative }
  1630. var assert = this,
  1631. currentTest = assert instanceof Assert && assert.test || config.current;
  1632. // Backwards compatibility fix.
  1633. // Allows the direct use of global exported assertions and QUnit.assert.*
  1634. // Although, it's use is not recommended as it can leak assertions
  1635. // to other tests from async tests, because we only get a reference to the current test,
  1636. // not exactly the test where assertion were intended to be called.
  1637. if (!currentTest) {
  1638. throw new Error("assertion outside test context, in " + sourceFromStacktrace(2));
  1639. }
  1640. if (currentTest.usedAsync === true && currentTest.semaphore === 0) {
  1641. currentTest.pushFailure("Assertion after the final `assert.async` was resolved", sourceFromStacktrace(2));
  1642. // Allow this assertion to continue running anyway...
  1643. }
  1644. if (!(assert instanceof Assert)) {
  1645. assert = currentTest.assert;
  1646. }
  1647. return assert.test.pushResult(resultInfo);
  1648. }
  1649. }, {
  1650. key: "ok",
  1651. value: function ok(result, message) {
  1652. if (!message) {
  1653. message = result ? "okay" : "failed, expected argument to be truthy, was: " + dump.parse(result);
  1654. }
  1655. this.pushResult({
  1656. result: !!result,
  1657. actual: result,
  1658. expected: true,
  1659. message: message
  1660. });
  1661. }
  1662. }, {
  1663. key: "notOk",
  1664. value: function notOk(result, message) {
  1665. if (!message) {
  1666. message = !result ? "okay" : "failed, expected argument to be falsy, was: " + dump.parse(result);
  1667. }
  1668. this.pushResult({
  1669. result: !result,
  1670. actual: result,
  1671. expected: false,
  1672. message: message
  1673. });
  1674. }
  1675. }, {
  1676. key: "equal",
  1677. value: function equal(actual, expected, message) {
  1678. // eslint-disable-next-line eqeqeq
  1679. var result = expected == actual;
  1680. this.pushResult({
  1681. result: result,
  1682. actual: actual,
  1683. expected: expected,
  1684. message: message
  1685. });
  1686. }
  1687. }, {
  1688. key: "notEqual",
  1689. value: function notEqual(actual, expected, message) {
  1690. // eslint-disable-next-line eqeqeq
  1691. var result = expected != actual;
  1692. this.pushResult({
  1693. result: result,
  1694. actual: actual,
  1695. expected: expected,
  1696. message: message,
  1697. negative: true
  1698. });
  1699. }
  1700. }, {
  1701. key: "propEqual",
  1702. value: function propEqual(actual, expected, message) {
  1703. actual = objectValues(actual);
  1704. expected = objectValues(expected);
  1705. this.pushResult({
  1706. result: equiv(actual, expected),
  1707. actual: actual,
  1708. expected: expected,
  1709. message: message
  1710. });
  1711. }
  1712. }, {
  1713. key: "notPropEqual",
  1714. value: function notPropEqual(actual, expected, message) {
  1715. actual = objectValues(actual);
  1716. expected = objectValues(expected);
  1717. this.pushResult({
  1718. result: !equiv(actual, expected),
  1719. actual: actual,
  1720. expected: expected,
  1721. message: message,
  1722. negative: true
  1723. });
  1724. }
  1725. }, {
  1726. key: "deepEqual",
  1727. value: function deepEqual(actual, expected, message) {
  1728. this.pushResult({
  1729. result: equiv(actual, expected),
  1730. actual: actual,
  1731. expected: expected,
  1732. message: message
  1733. });
  1734. }
  1735. }, {
  1736. key: "notDeepEqual",
  1737. value: function notDeepEqual(actual, expected, message) {
  1738. this.pushResult({
  1739. result: !equiv(actual, expected),
  1740. actual: actual,
  1741. expected: expected,
  1742. message: message,
  1743. negative: true
  1744. });
  1745. }
  1746. }, {
  1747. key: "strictEqual",
  1748. value: function strictEqual(actual, expected, message) {
  1749. this.pushResult({
  1750. result: expected === actual,
  1751. actual: actual,
  1752. expected: expected,
  1753. message: message
  1754. });
  1755. }
  1756. }, {
  1757. key: "notStrictEqual",
  1758. value: function notStrictEqual(actual, expected, message) {
  1759. this.pushResult({
  1760. result: expected !== actual,
  1761. actual: actual,
  1762. expected: expected,
  1763. message: message,
  1764. negative: true
  1765. });
  1766. }
  1767. }, {
  1768. key: "throws",
  1769. value: function throws(block, expected, message) {
  1770. var actual = void 0,
  1771. result = false,
  1772. currentTest = this instanceof Assert && this.test || config.current;
  1773. // 'expected' is optional unless doing string comparison
  1774. if (objectType(expected) === "string") {
  1775. if (message == null) {
  1776. message = expected;
  1777. expected = null;
  1778. } else {
  1779. throw new Error("throws/raises does not accept a string value for the expected argument.\n" + "Use a non-string object value (e.g. regExp) instead if it's necessary.");
  1780. }
  1781. }
  1782. currentTest.ignoreGlobalErrors = true;
  1783. try {
  1784. block.call(currentTest.testEnvironment);
  1785. } catch (e) {
  1786. actual = e;
  1787. }
  1788. currentTest.ignoreGlobalErrors = false;
  1789. if (actual) {
  1790. var expectedType = objectType(expected);
  1791. // We don't want to validate thrown error
  1792. if (!expected) {
  1793. result = true;
  1794. expected = null;
  1795. // Expected is a regexp
  1796. } else if (expectedType === "regexp") {
  1797. result = expected.test(errorString(actual));
  1798. // Expected is a constructor, maybe an Error constructor
  1799. } else if (expectedType === "function" && actual instanceof expected) {
  1800. result = true;
  1801. // Expected is an Error object
  1802. } else if (expectedType === "object") {
  1803. result = actual instanceof expected.constructor && actual.name === expected.name && actual.message === expected.message;
  1804. // Expected is a validation function which returns true if validation passed
  1805. } else if (expectedType === "function" && expected.call({}, actual) === true) {
  1806. expected = null;
  1807. result = true;
  1808. }
  1809. }
  1810. currentTest.assert.pushResult({
  1811. result: result,
  1812. actual: actual,
  1813. expected: expected,
  1814. message: message
  1815. });
  1816. }
  1817. }]);
  1818. return Assert;
  1819. }();
  1820. // Provide an alternative to assert.throws(), for environments that consider throws a reserved word
  1821. // Known to us are: Closure Compiler, Narwhal
  1822. // eslint-disable-next-line dot-notation
  1823. Assert.prototype.raises = Assert.prototype["throws"];
  1824. /**
  1825. * Converts an error into a simple string for comparisons.
  1826. *
  1827. * @param {Error} error
  1828. * @return {String}
  1829. */
  1830. function errorString(error) {
  1831. var resultErrorString = error.toString();
  1832. if (resultErrorString.substring(0, 7) === "[object") {
  1833. var name = error.name ? error.name.toString() : "Error";
  1834. var message = error.message ? error.message.toString() : "";
  1835. if (name && message) {
  1836. return name + ": " + message;
  1837. } else if (name) {
  1838. return name;
  1839. } else if (message) {
  1840. return message;
  1841. } else {
  1842. return "Error";
  1843. }
  1844. } else {
  1845. return resultErrorString;
  1846. }
  1847. }
  1848. /* global module, exports, define */
  1849. function exportQUnit(QUnit) {
  1850. if (defined.document) {
  1851. // QUnit may be defined when it is preconfigured but then only QUnit and QUnit.config may be defined.
  1852. if (window.QUnit && window.QUnit.version) {
  1853. throw new Error("QUnit has already been defined.");
  1854. }
  1855. window.QUnit = QUnit;
  1856. }
  1857. // For nodejs
  1858. if (typeof module !== "undefined" && module && module.exports) {
  1859. module.exports = QUnit;
  1860. // For consistency with CommonJS environments' exports
  1861. module.exports.QUnit = QUnit;
  1862. }
  1863. // For CommonJS with exports, but without module.exports, like Rhino
  1864. if (typeof exports !== "undefined" && exports) {
  1865. exports.QUnit = QUnit;
  1866. }
  1867. if (typeof define === "function" && define.amd) {
  1868. define(function () {
  1869. return QUnit;
  1870. });
  1871. QUnit.config.autostart = false;
  1872. }
  1873. }
  1874. var SuiteReport = function () {
  1875. function SuiteReport(name, parentSuite) {
  1876. classCallCheck(this, SuiteReport);
  1877. this.name = name;
  1878. this.fullName = parentSuite ? parentSuite.fullName.concat(name) : [];
  1879. this.tests = [];
  1880. this.childSuites = [];
  1881. if (parentSuite) {
  1882. parentSuite.pushChildSuite(this);
  1883. }
  1884. }
  1885. createClass(SuiteReport, [{
  1886. key: "start",
  1887. value: function start(recordTime) {
  1888. if (recordTime) {
  1889. this._startTime = Date.now();
  1890. }
  1891. return {
  1892. name: this.name,
  1893. fullName: this.fullName.slice(),
  1894. tests: this.tests.map(function (test) {
  1895. return test.start();
  1896. }),
  1897. childSuites: this.childSuites.map(function (suite) {
  1898. return suite.start();
  1899. }),
  1900. testCounts: {
  1901. total: this.getTestCounts().total
  1902. }
  1903. };
  1904. }
  1905. }, {
  1906. key: "end",
  1907. value: function end(recordTime) {
  1908. if (recordTime) {
  1909. this._endTime = Date.now();
  1910. }
  1911. return {
  1912. name: this.name,
  1913. fullName: this.fullName.slice(),
  1914. tests: this.tests.map(function (test) {
  1915. return test.end();
  1916. }),
  1917. childSuites: this.childSuites.map(function (suite) {
  1918. return suite.end();
  1919. }),
  1920. testCounts: this.getTestCounts(),
  1921. runtime: this.getRuntime(),
  1922. status: this.getStatus()
  1923. };
  1924. }
  1925. }, {
  1926. key: "pushChildSuite",
  1927. value: function pushChildSuite(suite) {
  1928. this.childSuites.push(suite);
  1929. }
  1930. }, {
  1931. key: "pushTest",
  1932. value: function pushTest(test) {
  1933. this.tests.push(test);
  1934. }
  1935. }, {
  1936. key: "getRuntime",
  1937. value: function getRuntime() {
  1938. return this._endTime - this._startTime;
  1939. }
  1940. }, {
  1941. key: "getTestCounts",
  1942. value: function getTestCounts() {
  1943. var counts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { passed: 0, failed: 0, skipped: 0, todo: 0, total: 0 };
  1944. counts = this.tests.reduce(function (counts, test) {
  1945. counts[test.getStatus()]++;
  1946. counts.total++;
  1947. return counts;
  1948. }, counts);
  1949. return this.childSuites.reduce(function (counts, suite) {
  1950. return suite.getTestCounts(counts);
  1951. }, counts);
  1952. }
  1953. }, {
  1954. key: "getStatus",
  1955. value: function getStatus() {
  1956. var _getTestCounts = this.getTestCounts(),
  1957. total = _getTestCounts.total,
  1958. failed = _getTestCounts.failed,
  1959. skipped = _getTestCounts.skipped,
  1960. todo = _getTestCounts.todo;
  1961. if (failed) {
  1962. return "failed";
  1963. } else {
  1964. if (skipped === total) {
  1965. return "skipped";
  1966. } else if (todo === total) {
  1967. return "todo";
  1968. } else {
  1969. return "passed";
  1970. }
  1971. }
  1972. }
  1973. }]);
  1974. return SuiteReport;
  1975. }();
  1976. // Handle an unhandled exception. By convention, returns true if further
  1977. // error handling should be suppressed and false otherwise.
  1978. // In this case, we will only suppress further error handling if the
  1979. // "ignoreGlobalErrors" configuration option is enabled.
  1980. function onError(error) {
  1981. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1982. args[_key - 1] = arguments[_key];
  1983. }
  1984. if (config.current) {
  1985. if (config.current.ignoreGlobalErrors) {
  1986. return true;
  1987. }
  1988. pushFailure.apply(undefined, [error.message, error.fileName + ":" + error.lineNumber].concat(args));
  1989. } else {
  1990. test("global failure", extend(function () {
  1991. pushFailure.apply(undefined, [error.message, error.fileName + ":" + error.lineNumber].concat(args));
  1992. }, { validTest: true }));
  1993. }
  1994. return false;
  1995. }
  1996. var QUnit = {};
  1997. var globalSuite = new SuiteReport();
  1998. // The initial "currentModule" represents the global (or top-level) module that
  1999. // is not explicitly defined by the user, therefore we add the "globalSuite" to
  2000. // it since each module has a suiteReport associated with it.
  2001. config.currentModule.suiteReport = globalSuite;
  2002. var globalStartCalled = false;
  2003. var runStarted = false;
  2004. var internalState = {
  2005. autorun: false
  2006. };
  2007. // Figure out if we're running the tests from a server or not
  2008. QUnit.isLocal = !(defined.document && window.location.protocol !== "file:");
  2009. // Expose the current QUnit version
  2010. QUnit.version = "2.2.0";
  2011. extend(QUnit, {
  2012. on: on,
  2013. // Call on start of module test to prepend name to all tests
  2014. module: function module(name, testEnvironment, executeNow) {
  2015. var module, moduleFns;
  2016. var currentModule = config.currentModule;
  2017. if (arguments.length === 2) {
  2018. if (objectType(testEnvironment) === "function") {
  2019. executeNow = testEnvironment;
  2020. testEnvironment = undefined;
  2021. }
  2022. }
  2023. module = createModule();
  2024. moduleFns = {
  2025. before: setHook(module, "before"),
  2026. beforeEach: setHook(module, "beforeEach"),
  2027. afterEach: setHook(module, "afterEach"),
  2028. after: setHook(module, "after")
  2029. };
  2030. if (objectType(executeNow) === "function") {
  2031. config.moduleStack.push(module);
  2032. setCurrentModule(module);
  2033. executeNow.call(module.testEnvironment, moduleFns);
  2034. config.moduleStack.pop();
  2035. module = module.parentModule || currentModule;
  2036. }
  2037. setCurrentModule(module);
  2038. function createModule() {
  2039. var parentModule = config.moduleStack.length ? config.moduleStack.slice(-1)[0] : null;
  2040. var moduleName = parentModule !== null ? [parentModule.name, name].join(" > ") : name;
  2041. var parentSuite = parentModule ? parentModule.suiteReport : globalSuite;
  2042. var module = {
  2043. name: moduleName,
  2044. parentModule: parentModule,
  2045. tests: [],
  2046. moduleId: generateHash(moduleName),
  2047. testsRun: 0,
  2048. childModules: [],
  2049. suiteReport: new SuiteReport(name, parentSuite)
  2050. };
  2051. var env = {};
  2052. if (parentModule) {
  2053. parentModule.childModules.push(module);
  2054. extend(env, parentModule.testEnvironment);
  2055. delete env.beforeEach;
  2056. delete env.afterEach;
  2057. }
  2058. extend(env, testEnvironment);
  2059. module.testEnvironment = env;
  2060. config.modules.push(module);
  2061. return module;
  2062. }
  2063. function setCurrentModule(module) {
  2064. config.currentModule = module;
  2065. }
  2066. },
  2067. test: test,
  2068. todo: todo,
  2069. skip: skip,
  2070. only: only,
  2071. start: function start(count) {
  2072. var globalStartAlreadyCalled = globalStartCalled;
  2073. if (!config.current) {
  2074. globalStartCalled = true;
  2075. if (runStarted) {
  2076. throw new Error("Called start() while test already started running");
  2077. } else if (globalStartAlreadyCalled || count > 1) {
  2078. throw new Error("Called start() outside of a test context too many times");
  2079. } else if (config.autostart) {
  2080. throw new Error("Called start() outside of a test context when " + "QUnit.config.autostart was true");
  2081. } else if (!config.pageLoaded) {
  2082. // The page isn't completely loaded yet, so we set autostart and then
  2083. // load if we're in Node or wait for the browser's load event.
  2084. config.autostart = true;
  2085. // Starts from Node even if .load was not previously called. We still return
  2086. // early otherwise we'll wind up "beginning" twice.
  2087. if (!defined.document) {
  2088. QUnit.load();
  2089. }
  2090. return;
  2091. }
  2092. } else {
  2093. throw new Error("QUnit.start cannot be called inside a test context.");
  2094. }
  2095. scheduleBegin();
  2096. },
  2097. config: config,
  2098. is: is,
  2099. objectType: objectType,
  2100. extend: extend,
  2101. load: function load() {
  2102. config.pageLoaded = true;
  2103. // Initialize the configuration options
  2104. extend(config, {
  2105. stats: { all: 0, bad: 0 },
  2106. started: 0,
  2107. updateRate: 1000,
  2108. autostart: true,
  2109. filter: ""
  2110. }, true);
  2111. if (!runStarted) {
  2112. config.blocking = false;
  2113. if (config.autostart) {
  2114. scheduleBegin();
  2115. }
  2116. }
  2117. },
  2118. stack: function stack(offset) {
  2119. offset = (offset || 0) + 2;
  2120. return sourceFromStacktrace(offset);
  2121. },
  2122. onError: onError
  2123. });
  2124. QUnit.pushFailure = pushFailure;
  2125. QUnit.assert = Assert.prototype;
  2126. QUnit.equiv = equiv;
  2127. QUnit.dump = dump;
  2128. registerLoggingCallbacks(QUnit);
  2129. function scheduleBegin() {
  2130. runStarted = true;
  2131. // Add a slight delay to allow definition of more modules and tests.
  2132. if (defined.setTimeout) {
  2133. setTimeout(function () {
  2134. begin();
  2135. }, 13);
  2136. } else {
  2137. begin();
  2138. }
  2139. }
  2140. function begin() {
  2141. var i,
  2142. l,
  2143. modulesLog = [];
  2144. // If the test run hasn't officially begun yet
  2145. if (!config.started) {
  2146. // Record the time of the test run's beginning
  2147. config.started = now();
  2148. // Delete the loose unnamed module if unused.
  2149. if (config.modules[0].name === "" && config.modules[0].tests.length === 0) {
  2150. config.modules.shift();
  2151. }
  2152. // Avoid unnecessary information by not logging modules' test environments
  2153. for (i = 0, l = config.modules.length; i < l; i++) {
  2154. modulesLog.push({
  2155. name: config.modules[i].name,
  2156. tests: config.modules[i].tests
  2157. });
  2158. }
  2159. // The test run is officially beginning now
  2160. emit("runStart", globalSuite.start(true));
  2161. runLoggingCallbacks("begin", {
  2162. totalTests: Test.count,
  2163. modules: modulesLog
  2164. });
  2165. }
  2166. config.blocking = false;
  2167. process(true);
  2168. }
  2169. function process(last) {
  2170. function next() {
  2171. process(last);
  2172. }
  2173. var start = now();
  2174. config.depth = (config.depth || 0) + 1;
  2175. while (config.queue.length && !config.blocking) {
  2176. if (!defined.setTimeout || config.updateRate <= 0 || now() - start < config.updateRate) {
  2177. if (config.current) {
  2178. // Reset async tracking for each phase of the Test lifecycle
  2179. config.current.usedAsync = false;
  2180. }
  2181. config.queue.shift()();
  2182. } else {
  2183. setTimeout(next, 13);
  2184. break;
  2185. }
  2186. }
  2187. config.depth--;
  2188. if (last && !config.blocking && !config.queue.length && config.depth === 0) {
  2189. done();
  2190. }
  2191. }
  2192. function done() {
  2193. var runtime,
  2194. passed,
  2195. i,
  2196. key,
  2197. storage = config.storage;
  2198. internalState.autorun = true;
  2199. runtime = now() - config.started;
  2200. passed = config.stats.all - config.stats.bad;
  2201. emit("runEnd", globalSuite.end(true));
  2202. runLoggingCallbacks("done", {
  2203. failed: config.stats.bad,
  2204. passed: passed,
  2205. total: config.stats.all,
  2206. runtime: runtime
  2207. });
  2208. // Clear own storage items if all tests passed
  2209. if (storage && config.stats.bad === 0) {
  2210. for (i = storage.length - 1; i >= 0; i--) {
  2211. key = storage.key(i);
  2212. if (key.indexOf("qunit-test-") === 0) {
  2213. storage.removeItem(key);
  2214. }
  2215. }
  2216. }
  2217. }
  2218. function setHook(module, hookName) {
  2219. if (module.testEnvironment === undefined) {
  2220. module.testEnvironment = {};
  2221. }
  2222. return function (callback) {
  2223. module.testEnvironment[hookName] = callback;
  2224. };
  2225. }
  2226. exportQUnit(QUnit);
  2227. (function () {
  2228. if (typeof window === "undefined" || typeof document === "undefined") {
  2229. return;
  2230. }
  2231. var config = QUnit.config,
  2232. hasOwn = Object.prototype.hasOwnProperty;
  2233. // Stores fixture HTML for resetting later
  2234. function storeFixture() {
  2235. // Avoid overwriting user-defined values
  2236. if (hasOwn.call(config, "fixture")) {
  2237. return;
  2238. }
  2239. var fixture = document.getElementById("qunit-fixture");
  2240. if (fixture) {
  2241. config.fixture = fixture.innerHTML;
  2242. }
  2243. }
  2244. QUnit.begin(storeFixture);
  2245. // Resets the fixture DOM element if available.
  2246. function resetFixture() {
  2247. if (config.fixture == null) {
  2248. return;
  2249. }
  2250. var fixture = document.getElementById("qunit-fixture");
  2251. if (fixture) {
  2252. fixture.innerHTML = config.fixture;
  2253. }
  2254. }
  2255. QUnit.testStart(resetFixture);
  2256. })();
  2257. (function () {
  2258. // Only interact with URLs via window.location
  2259. var location = typeof window !== "undefined" && window.location;
  2260. if (!location) {
  2261. return;
  2262. }
  2263. var urlParams = getUrlParams();
  2264. QUnit.urlParams = urlParams;
  2265. // Match module/test by inclusion in an array
  2266. QUnit.config.moduleId = [].concat(urlParams.moduleId || []);
  2267. QUnit.config.testId = [].concat(urlParams.testId || []);
  2268. // Exact case-insensitive match of the module name
  2269. QUnit.config.module = urlParams.module;
  2270. // Regular expression or case-insenstive substring match against "moduleName: testName"
  2271. QUnit.config.filter = urlParams.filter;
  2272. // Test order randomization
  2273. if (urlParams.seed === true) {
  2274. // Generate a random seed if the option is specified without a value
  2275. QUnit.config.seed = Math.random().toString(36).slice(2);
  2276. } else if (urlParams.seed) {
  2277. QUnit.config.seed = urlParams.seed;
  2278. }
  2279. // Add URL-parameter-mapped config values with UI form rendering data
  2280. QUnit.config.urlConfig.push({
  2281. id: "hidepassed",
  2282. label: "Hide passed tests",
  2283. tooltip: "Only show tests and assertions that fail. Stored as query-strings."
  2284. }, {
  2285. id: "noglobals",
  2286. label: "Check for Globals",
  2287. tooltip: "Enabling this will test if any test introduces new properties on the " + "global object (`window` in Browsers). Stored as query-strings."
  2288. }, {
  2289. id: "notrycatch",
  2290. label: "No try-catch",
  2291. tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging " + "exceptions in IE reasonable. Stored as query-strings."
  2292. });
  2293. QUnit.begin(function () {
  2294. var i,
  2295. option,
  2296. urlConfig = QUnit.config.urlConfig;
  2297. for (i = 0; i < urlConfig.length; i++) {
  2298. // Options can be either strings or objects with nonempty "id" properties
  2299. option = QUnit.config.urlConfig[i];
  2300. if (typeof option !== "string") {
  2301. option = option.id;
  2302. }
  2303. if (QUnit.config[option] === undefined) {
  2304. QUnit.config[option] = urlParams[option];
  2305. }
  2306. }
  2307. });
  2308. function getUrlParams() {
  2309. var i, param, name, value;
  2310. var urlParams = Object.create(null);
  2311. var params = location.search.slice(1).split("&");
  2312. var length = params.length;
  2313. for (i = 0; i < length; i++) {
  2314. if (params[i]) {
  2315. param = params[i].split("=");
  2316. name = decodeQueryParam(param[0]);
  2317. // Allow just a key to turn on a flag, e.g., test.html?noglobals
  2318. value = param.length === 1 || decodeQueryParam(param.slice(1).join("="));
  2319. if (name in urlParams) {
  2320. urlParams[name] = [].concat(urlParams[name], value);
  2321. } else {
  2322. urlParams[name] = value;
  2323. }
  2324. }
  2325. }
  2326. return urlParams;
  2327. }
  2328. function decodeQueryParam(param) {
  2329. return decodeURIComponent(param.replace(/\+/g, "%20"));
  2330. }
  2331. })();
  2332. var stats = {
  2333. passedTests: 0,
  2334. failedTests: 0,
  2335. skippedTests: 0,
  2336. todoTests: 0
  2337. };
  2338. // Escape text for attribute or text content.
  2339. function escapeText(s) {
  2340. if (!s) {
  2341. return "";
  2342. }
  2343. s = s + "";
  2344. // Both single quotes and double quotes (for attributes)
  2345. return s.replace(/['"<>&]/g, function (s) {
  2346. switch (s) {
  2347. case "'":
  2348. return "&#039;";
  2349. case "\"":
  2350. return "&quot;";
  2351. case "<":
  2352. return "&lt;";
  2353. case ">":
  2354. return "&gt;";
  2355. case "&":
  2356. return "&amp;";
  2357. }
  2358. });
  2359. }
  2360. (function () {
  2361. // Don't load the HTML Reporter on non-browser environments
  2362. if (typeof window === "undefined" || !window.document) {
  2363. return;
  2364. }
  2365. var config = QUnit.config,
  2366. document$$1 = window.document,
  2367. collapseNext = false,
  2368. hasOwn = Object.prototype.hasOwnProperty,
  2369. unfilteredUrl = setUrl({ filter: undefined, module: undefined,
  2370. moduleId: undefined, testId: undefined }),
  2371. modulesList = [];
  2372. function addEvent(elem, type, fn) {
  2373. elem.addEventListener(type, fn, false);
  2374. }
  2375. function removeEvent(elem, type, fn) {
  2376. elem.removeEventListener(type, fn, false);
  2377. }
  2378. function addEvents(elems, type, fn) {
  2379. var i = elems.length;
  2380. while (i--) {
  2381. addEvent(elems[i], type, fn);
  2382. }
  2383. }
  2384. function hasClass(elem, name) {
  2385. return (" " + elem.className + " ").indexOf(" " + name + " ") >= 0;
  2386. }
  2387. function addClass(elem, name) {
  2388. if (!hasClass(elem, name)) {
  2389. elem.className += (elem.className ? " " : "") + name;
  2390. }
  2391. }
  2392. function toggleClass(elem, name, force) {
  2393. if (force || typeof force === "undefined" && !hasClass(elem, name)) {
  2394. addClass(elem, name);
  2395. } else {
  2396. removeClass(elem, name);
  2397. }
  2398. }
  2399. function removeClass(elem, name) {
  2400. var set = " " + elem.className + " ";
  2401. // Class name may appear multiple times
  2402. while (set.indexOf(" " + name + " ") >= 0) {
  2403. set = set.replace(" " + name + " ", " ");
  2404. }
  2405. // Trim for prettiness
  2406. elem.className = typeof set.trim === "function" ? set.trim() : set.replace(/^\s+|\s+$/g, "");
  2407. }
  2408. function id(name) {
  2409. return document$$1.getElementById && document$$1.getElementById(name);
  2410. }
  2411. function abortTests() {
  2412. var abortButton = id("qunit-abort-tests-button");
  2413. if (abortButton) {
  2414. abortButton.disabled = true;
  2415. abortButton.innerHTML = "Aborting...";
  2416. }
  2417. QUnit.config.queue.length = 0;
  2418. return false;
  2419. }
  2420. function interceptNavigation(ev) {
  2421. applyUrlParams();
  2422. if (ev && ev.preventDefault) {
  2423. ev.preventDefault();
  2424. }
  2425. return false;
  2426. }
  2427. function getUrlConfigHtml() {
  2428. var i,
  2429. j,
  2430. val,
  2431. escaped,
  2432. escapedTooltip,
  2433. selection = false,
  2434. urlConfig = config.urlConfig,
  2435. urlConfigHtml = "";
  2436. for (i = 0; i < urlConfig.length; i++) {
  2437. // Options can be either strings or objects with nonempty "id" properties
  2438. val = config.urlConfig[i];
  2439. if (typeof val === "string") {
  2440. val = {
  2441. id: val,
  2442. label: val
  2443. };
  2444. }
  2445. escaped = escapeText(val.id);
  2446. escapedTooltip = escapeText(val.tooltip);
  2447. if (!val.value || typeof val.value === "string") {
  2448. urlConfigHtml += "<label for='qunit-urlconfig-" + escaped + "' title='" + escapedTooltip + "'><input id='qunit-urlconfig-" + escaped + "' name='" + escaped + "' type='checkbox'" + (val.value ? " value='" + escapeText(val.value) + "'" : "") + (config[val.id] ? " checked='checked'" : "") + " title='" + escapedTooltip + "' />" + escapeText(val.label) + "</label>";
  2449. } else {
  2450. urlConfigHtml += "<label for='qunit-urlconfig-" + escaped + "' title='" + escapedTooltip + "'>" + val.label + ": </label><select id='qunit-urlconfig-" + escaped + "' name='" + escaped + "' title='" + escapedTooltip + "'><option></option>";
  2451. if (QUnit.is("array", val.value)) {
  2452. for (j = 0; j < val.value.length; j++) {
  2453. escaped = escapeText(val.value[j]);
  2454. urlConfigHtml += "<option value='" + escaped + "'" + (config[val.id] === val.value[j] ? (selection = true) && " selected='selected'" : "") + ">" + escaped + "</option>";
  2455. }
  2456. } else {
  2457. for (j in val.value) {
  2458. if (hasOwn.call(val.value, j)) {
  2459. urlConfigHtml += "<option value='" + escapeText(j) + "'" + (config[val.id] === j ? (selection = true) && " selected='selected'" : "") + ">" + escapeText(val.value[j]) + "</option>";
  2460. }
  2461. }
  2462. }
  2463. if (config[val.id] && !selection) {
  2464. escaped = escapeText(config[val.id]);
  2465. urlConfigHtml += "<option value='" + escaped + "' selected='selected' disabled='disabled'>" + escaped + "</option>";
  2466. }
  2467. urlConfigHtml += "</select>";
  2468. }
  2469. }
  2470. return urlConfigHtml;
  2471. }
  2472. // Handle "click" events on toolbar checkboxes and "change" for select menus.
  2473. // Updates the URL with the new state of `config.urlConfig` values.
  2474. function toolbarChanged() {
  2475. var updatedUrl,
  2476. value,
  2477. tests,
  2478. field = this,
  2479. params = {};
  2480. // Detect if field is a select menu or a checkbox
  2481. if ("selectedIndex" in field) {
  2482. value = field.options[field.selectedIndex].value || undefined;
  2483. } else {
  2484. value = field.checked ? field.defaultValue || true : undefined;
  2485. }
  2486. params[field.name] = value;
  2487. updatedUrl = setUrl(params);
  2488. // Check if we can apply the change without a page refresh
  2489. if ("hidepassed" === field.name && "replaceState" in window.history) {
  2490. QUnit.urlParams[field.name] = value;
  2491. config[field.name] = value || false;
  2492. tests = id("qunit-tests");
  2493. if (tests) {
  2494. toggleClass(tests, "hidepass", value || false);
  2495. }
  2496. window.history.replaceState(null, "", updatedUrl);
  2497. } else {
  2498. window.location = updatedUrl;
  2499. }
  2500. }
  2501. function setUrl(params) {
  2502. var key,
  2503. arrValue,
  2504. i,
  2505. querystring = "?",
  2506. location = window.location;
  2507. params = QUnit.extend(QUnit.extend({}, QUnit.urlParams), params);
  2508. for (key in params) {
  2509. // Skip inherited or undefined properties
  2510. if (hasOwn.call(params, key) && params[key] !== undefined) {
  2511. // Output a parameter for each value of this key (but usually just one)
  2512. arrValue = [].concat(params[key]);
  2513. for (i = 0; i < arrValue.length; i++) {
  2514. querystring += encodeURIComponent(key);
  2515. if (arrValue[i] !== true) {
  2516. querystring += "=" + encodeURIComponent(arrValue[i]);
  2517. }
  2518. querystring += "&";
  2519. }
  2520. }
  2521. }
  2522. return location.protocol + "//" + location.host + location.pathname + querystring.slice(0, -1);
  2523. }
  2524. function applyUrlParams() {
  2525. var i,
  2526. selectedModules = [],
  2527. modulesList = id("qunit-modulefilter-dropdown-list").getElementsByTagName("input"),
  2528. filter = id("qunit-filter-input").value;
  2529. for (i = 0; i < modulesList.length; i++) {
  2530. if (modulesList[i].checked) {
  2531. selectedModules.push(modulesList[i].value);
  2532. }
  2533. }
  2534. window.location = setUrl({
  2535. filter: filter === "" ? undefined : filter,
  2536. moduleId: selectedModules.length === 0 ? undefined : selectedModules,
  2537. // Remove module and testId filter
  2538. module: undefined,
  2539. testId: undefined
  2540. });
  2541. }
  2542. function toolbarUrlConfigContainer() {
  2543. var urlConfigContainer = document$$1.createElement("span");
  2544. urlConfigContainer.innerHTML = getUrlConfigHtml();
  2545. addClass(urlConfigContainer, "qunit-url-config");
  2546. addEvents(urlConfigContainer.getElementsByTagName("input"), "change", toolbarChanged);
  2547. addEvents(urlConfigContainer.getElementsByTagName("select"), "change", toolbarChanged);
  2548. return urlConfigContainer;
  2549. }
  2550. function abortTestsButton() {
  2551. var button = document$$1.createElement("button");
  2552. button.id = "qunit-abort-tests-button";
  2553. button.innerHTML = "Abort";
  2554. addEvent(button, "click", abortTests);
  2555. return button;
  2556. }
  2557. function toolbarLooseFilter() {
  2558. var filter = document$$1.createElement("form"),
  2559. label = document$$1.createElement("label"),
  2560. input = document$$1.createElement("input"),
  2561. button = document$$1.createElement("button");
  2562. addClass(filter, "qunit-filter");
  2563. label.innerHTML = "Filter: ";
  2564. input.type = "text";
  2565. input.value = config.filter || "";
  2566. input.name = "filter";
  2567. input.id = "qunit-filter-input";
  2568. button.innerHTML = "Go";
  2569. label.appendChild(input);
  2570. filter.appendChild(label);
  2571. filter.appendChild(document$$1.createTextNode(" "));
  2572. filter.appendChild(button);
  2573. addEvent(filter, "submit", interceptNavigation);
  2574. return filter;
  2575. }
  2576. function moduleListHtml() {
  2577. var i,
  2578. checked,
  2579. html = "";
  2580. for (i = 0; i < config.modules.length; i++) {
  2581. if (config.modules[i].name !== "") {
  2582. checked = config.moduleId.indexOf(config.modules[i].moduleId) > -1;
  2583. html += "<li><label class='clickable" + (checked ? " checked" : "") + "'><input type='checkbox' " + "value='" + config.modules[i].moduleId + "'" + (checked ? " checked='checked'" : "") + " />" + escapeText(config.modules[i].name) + "</label></li>";
  2584. }
  2585. }
  2586. return html;
  2587. }
  2588. function toolbarModuleFilter() {
  2589. var allCheckbox,
  2590. commit,
  2591. reset,
  2592. moduleFilter = document$$1.createElement("form"),
  2593. label = document$$1.createElement("label"),
  2594. moduleSearch = document$$1.createElement("input"),
  2595. dropDown = document$$1.createElement("div"),
  2596. actions = document$$1.createElement("span"),
  2597. dropDownList = document$$1.createElement("ul"),
  2598. dirty = false;
  2599. moduleSearch.id = "qunit-modulefilter-search";
  2600. addEvent(moduleSearch, "input", searchInput);
  2601. addEvent(moduleSearch, "input", searchFocus);
  2602. addEvent(moduleSearch, "focus", searchFocus);
  2603. addEvent(moduleSearch, "click", searchFocus);
  2604. label.id = "qunit-modulefilter-search-container";
  2605. label.innerHTML = "Module: ";
  2606. label.appendChild(moduleSearch);
  2607. actions.id = "qunit-modulefilter-actions";
  2608. actions.innerHTML = "<button style='display:none'>Apply</button>" + "<button type='reset' style='display:none'>Reset</button>" + "<label class='clickable" + (config.moduleId.length ? "" : " checked") + "'><input type='checkbox'" + (config.moduleId.length ? "" : " checked='checked'") + ">All modules</label>";
  2609. allCheckbox = actions.lastChild.firstChild;
  2610. commit = actions.firstChild;
  2611. reset = commit.nextSibling;
  2612. addEvent(commit, "click", applyUrlParams);
  2613. dropDownList.id = "qunit-modulefilter-dropdown-list";
  2614. dropDownList.innerHTML = moduleListHtml();
  2615. dropDown.id = "qunit-modulefilter-dropdown";
  2616. dropDown.style.display = "none";
  2617. dropDown.appendChild(actions);
  2618. dropDown.appendChild(dropDownList);
  2619. addEvent(dropDown, "change", selectionChange);
  2620. selectionChange();
  2621. moduleFilter.id = "qunit-modulefilter";
  2622. moduleFilter.appendChild(label);
  2623. moduleFilter.appendChild(dropDown);
  2624. addEvent(moduleFilter, "submit", interceptNavigation);
  2625. addEvent(moduleFilter, "reset", function () {
  2626. // Let the reset happen, then update styles
  2627. window.setTimeout(selectionChange);
  2628. });
  2629. // Enables show/hide for the dropdown
  2630. function searchFocus() {
  2631. if (dropDown.style.display !== "none") {
  2632. return;
  2633. }
  2634. dropDown.style.display = "block";
  2635. addEvent(document$$1, "click", hideHandler);
  2636. addEvent(document$$1, "keydown", hideHandler);
  2637. // Hide on Escape keydown or outside-container click
  2638. function hideHandler(e) {
  2639. var inContainer = moduleFilter.contains(e.target);
  2640. if (e.keyCode === 27 || !inContainer) {
  2641. if (e.keyCode === 27 && inContainer) {
  2642. moduleSearch.focus();
  2643. }
  2644. dropDown.style.display = "none";
  2645. removeEvent(document$$1, "click", hideHandler);
  2646. removeEvent(document$$1, "keydown", hideHandler);
  2647. moduleSearch.value = "";
  2648. searchInput();
  2649. }
  2650. }
  2651. }
  2652. // Processes module search box input
  2653. function searchInput() {
  2654. var i,
  2655. item,
  2656. searchText = moduleSearch.value.toLowerCase(),
  2657. listItems = dropDownList.children;
  2658. for (i = 0; i < listItems.length; i++) {
  2659. item = listItems[i];
  2660. if (!searchText || item.textContent.toLowerCase().indexOf(searchText) > -1) {
  2661. item.style.display = "";
  2662. } else {
  2663. item.style.display = "none";
  2664. }
  2665. }
  2666. }
  2667. // Processes selection changes
  2668. function selectionChange(evt) {
  2669. var i,
  2670. item,
  2671. checkbox = evt && evt.target || allCheckbox,
  2672. modulesList = dropDownList.getElementsByTagName("input"),
  2673. selectedNames = [];
  2674. toggleClass(checkbox.parentNode, "checked", checkbox.checked);
  2675. dirty = false;
  2676. if (checkbox.checked && checkbox !== allCheckbox) {
  2677. allCheckbox.checked = false;
  2678. removeClass(allCheckbox.parentNode, "checked");
  2679. }
  2680. for (i = 0; i < modulesList.length; i++) {
  2681. item = modulesList[i];
  2682. if (!evt) {
  2683. toggleClass(item.parentNode, "checked", item.checked);
  2684. } else if (checkbox === allCheckbox && checkbox.checked) {
  2685. item.checked = false;
  2686. removeClass(item.parentNode, "checked");
  2687. }
  2688. dirty = dirty || item.checked !== item.defaultChecked;
  2689. if (item.checked) {
  2690. selectedNames.push(item.parentNode.textContent);
  2691. }
  2692. }
  2693. commit.style.display = reset.style.display = dirty ? "" : "none";
  2694. moduleSearch.placeholder = selectedNames.join(", ") || allCheckbox.parentNode.textContent;
  2695. moduleSearch.title = "Type to filter list. Current selection:\n" + (selectedNames.join("\n") || allCheckbox.parentNode.textContent);
  2696. }
  2697. return moduleFilter;
  2698. }
  2699. function appendToolbar() {
  2700. var toolbar = id("qunit-testrunner-toolbar");
  2701. if (toolbar) {
  2702. toolbar.appendChild(toolbarUrlConfigContainer());
  2703. toolbar.appendChild(toolbarModuleFilter());
  2704. toolbar.appendChild(toolbarLooseFilter());
  2705. toolbar.appendChild(document$$1.createElement("div")).className = "clearfix";
  2706. }
  2707. }
  2708. function appendHeader() {
  2709. var header = id("qunit-header");
  2710. if (header) {
  2711. header.innerHTML = "<a href='" + escapeText(unfilteredUrl) + "'>" + header.innerHTML + "</a> ";
  2712. }
  2713. }
  2714. function appendBanner() {
  2715. var banner = id("qunit-banner");
  2716. if (banner) {
  2717. banner.className = "";
  2718. }
  2719. }
  2720. function appendTestResults() {
  2721. var tests = id("qunit-tests"),
  2722. result = id("qunit-testresult"),
  2723. controls;
  2724. if (result) {
  2725. result.parentNode.removeChild(result);
  2726. }
  2727. if (tests) {
  2728. tests.innerHTML = "";
  2729. result = document$$1.createElement("p");
  2730. result.id = "qunit-testresult";
  2731. result.className = "result";
  2732. tests.parentNode.insertBefore(result, tests);
  2733. result.innerHTML = "<div id=\"qunit-testresult-display\">Running...<br />&#160;</div>" + "<div id=\"qunit-testresult-controls\"></div>" + "<div class=\"clearfix\"></div>";
  2734. controls = id("qunit-testresult-controls");
  2735. }
  2736. if (controls) {
  2737. controls.appendChild(abortTestsButton());
  2738. }
  2739. }
  2740. function appendFilteredTest() {
  2741. var testId = QUnit.config.testId;
  2742. if (!testId || testId.length <= 0) {
  2743. return "";
  2744. }
  2745. return "<div id='qunit-filteredTest'>Rerunning selected tests: " + escapeText(testId.join(", ")) + " <a id='qunit-clearFilter' href='" + escapeText(unfilteredUrl) + "'>Run all tests</a></div>";
  2746. }
  2747. function appendUserAgent() {
  2748. var userAgent = id("qunit-userAgent");
  2749. if (userAgent) {
  2750. userAgent.innerHTML = "";
  2751. userAgent.appendChild(document$$1.createTextNode("QUnit " + QUnit.version + "; " + navigator.userAgent));
  2752. }
  2753. }
  2754. function appendInterface() {
  2755. var qunit = id("qunit");
  2756. if (qunit) {
  2757. qunit.innerHTML = "<h1 id='qunit-header'>" + escapeText(document$$1.title) + "</h1>" + "<h2 id='qunit-banner'></h2>" + "<div id='qunit-testrunner-toolbar'></div>" + appendFilteredTest() + "<h2 id='qunit-userAgent'></h2>" + "<ol id='qunit-tests'></ol>";
  2758. }
  2759. appendHeader();
  2760. appendBanner();
  2761. appendTestResults();
  2762. appendUserAgent();
  2763. appendToolbar();
  2764. }
  2765. function appendTestsList(modules) {
  2766. var i, l, x, z, test, moduleObj;
  2767. for (i = 0, l = modules.length; i < l; i++) {
  2768. moduleObj = modules[i];
  2769. for (x = 0, z = moduleObj.tests.length; x < z; x++) {
  2770. test = moduleObj.tests[x];
  2771. appendTest(test.name, test.testId, moduleObj.name);
  2772. }
  2773. }
  2774. }
  2775. function appendTest(name, testId, moduleName) {
  2776. var title,
  2777. rerunTrigger,
  2778. testBlock,
  2779. assertList,
  2780. tests = id("qunit-tests");
  2781. if (!tests) {
  2782. return;
  2783. }
  2784. title = document$$1.createElement("strong");
  2785. title.innerHTML = getNameHtml(name, moduleName);
  2786. rerunTrigger = document$$1.createElement("a");
  2787. rerunTrigger.innerHTML = "Rerun";
  2788. rerunTrigger.href = setUrl({ testId: testId });
  2789. testBlock = document$$1.createElement("li");
  2790. testBlock.appendChild(title);
  2791. testBlock.appendChild(rerunTrigger);
  2792. testBlock.id = "qunit-test-output-" + testId;
  2793. assertList = document$$1.createElement("ol");
  2794. assertList.className = "qunit-assert-list";
  2795. testBlock.appendChild(assertList);
  2796. tests.appendChild(testBlock);
  2797. }
  2798. // HTML Reporter initialization and load
  2799. QUnit.begin(function (details) {
  2800. var i, moduleObj, tests;
  2801. // Sort modules by name for the picker
  2802. for (i = 0; i < details.modules.length; i++) {
  2803. moduleObj = details.modules[i];
  2804. if (moduleObj.name) {
  2805. modulesList.push(moduleObj.name);
  2806. }
  2807. }
  2808. modulesList.sort(function (a, b) {
  2809. return a.localeCompare(b);
  2810. });
  2811. // Initialize QUnit elements
  2812. appendInterface();
  2813. appendTestsList(details.modules);
  2814. tests = id("qunit-tests");
  2815. if (tests && config.hidepassed) {
  2816. addClass(tests, "hidepass");
  2817. }
  2818. });
  2819. QUnit.done(function (details) {
  2820. var banner = id("qunit-banner"),
  2821. tests = id("qunit-tests"),
  2822. abortButton = id("qunit-abort-tests-button"),
  2823. totalTests = stats.passedTests + stats.skippedTests + stats.todoTests + stats.failedTests,
  2824. html = [totalTests, " tests completed in ", details.runtime, " milliseconds, with ", stats.failedTests, " failed, ", stats.skippedTests, " skipped, and ", stats.todoTests, " todo.<br />", "<span class='passed'>", details.passed, "</span> assertions of <span class='total'>", details.total, "</span> passed, <span class='failed'>", details.failed, "</span> failed."].join(""),
  2825. test,
  2826. assertLi,
  2827. assertList;
  2828. // Update remaing tests to aborted
  2829. if (abortButton && abortButton.disabled) {
  2830. html = "Tests aborted after " + details.runtime + " milliseconds.";
  2831. for (var i = 0; i < tests.children.length; i++) {
  2832. test = tests.children[i];
  2833. if (test.className === "" || test.className === "running") {
  2834. test.className = "aborted";
  2835. assertList = test.getElementsByTagName("ol")[0];
  2836. assertLi = document$$1.createElement("li");
  2837. assertLi.className = "fail";
  2838. assertLi.innerHTML = "Test aborted.";
  2839. assertList.appendChild(assertLi);
  2840. }
  2841. }
  2842. }
  2843. if (banner && (!abortButton || abortButton.disabled === false)) {
  2844. banner.className = stats.failedTests ? "qunit-fail" : "qunit-pass";
  2845. }
  2846. if (abortButton) {
  2847. abortButton.parentNode.removeChild(abortButton);
  2848. }
  2849. if (tests) {
  2850. id("qunit-testresult-display").innerHTML = html;
  2851. }
  2852. if (config.altertitle && document$$1.title) {
  2853. // Show ✖ for good, ✔ for bad suite result in title
  2854. // use escape sequences in case file gets loaded with non-utf-8-charset
  2855. document$$1.title = [stats.failedTests ? "\u2716" : "\u2714", document$$1.title.replace(/^[\u2714\u2716] /i, "")].join(" ");
  2856. }
  2857. // Scroll back to top to show results
  2858. if (config.scrolltop && window.scrollTo) {
  2859. window.scrollTo(0, 0);
  2860. }
  2861. });
  2862. function getNameHtml(name, module) {
  2863. var nameHtml = "";
  2864. if (module) {
  2865. nameHtml = "<span class='module-name'>" + escapeText(module) + "</span>: ";
  2866. }
  2867. nameHtml += "<span class='test-name'>" + escapeText(name) + "</span>";
  2868. return nameHtml;
  2869. }
  2870. QUnit.testStart(function (details) {
  2871. var running, testBlock, bad;
  2872. testBlock = id("qunit-test-output-" + details.testId);
  2873. if (testBlock) {
  2874. testBlock.className = "running";
  2875. } else {
  2876. // Report later registered tests
  2877. appendTest(details.name, details.testId, details.module);
  2878. }
  2879. running = id("qunit-testresult-display");
  2880. if (running) {
  2881. bad = QUnit.config.reorder && details.previousFailure;
  2882. running.innerHTML = (bad ? "Rerunning previously failed test: <br />" : "Running: <br />") + getNameHtml(details.name, details.module);
  2883. }
  2884. });
  2885. function stripHtml(string) {
  2886. // Strip tags, html entity and whitespaces
  2887. return string.replace(/<\/?[^>]+(>|$)/g, "").replace(/\&quot;/g, "").replace(/\s+/g, "");
  2888. }
  2889. QUnit.log(function (details) {
  2890. var assertList,
  2891. assertLi,
  2892. message,
  2893. expected,
  2894. actual,
  2895. diff,
  2896. showDiff = false,
  2897. testItem = id("qunit-test-output-" + details.testId);
  2898. if (!testItem) {
  2899. return;
  2900. }
  2901. message = escapeText(details.message) || (details.result ? "okay" : "failed");
  2902. message = "<span class='test-message'>" + message + "</span>";
  2903. message += "<span class='runtime'>@ " + details.runtime + " ms</span>";
  2904. // The pushFailure doesn't provide details.expected
  2905. // when it calls, it's implicit to also not show expected and diff stuff
  2906. // Also, we need to check details.expected existence, as it can exist and be undefined
  2907. if (!details.result && hasOwn.call(details, "expected")) {
  2908. if (details.negative) {
  2909. expected = "NOT " + QUnit.dump.parse(details.expected);
  2910. } else {
  2911. expected = QUnit.dump.parse(details.expected);
  2912. }
  2913. actual = QUnit.dump.parse(details.actual);
  2914. message += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + escapeText(expected) + "</pre></td></tr>";
  2915. if (actual !== expected) {
  2916. message += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeText(actual) + "</pre></td></tr>";
  2917. // Don't show diff if actual or expected are booleans
  2918. if (!/^(true|false)$/.test(actual) && !/^(true|false)$/.test(expected)) {
  2919. diff = QUnit.diff(expected, actual);
  2920. showDiff = stripHtml(diff).length !== stripHtml(expected).length + stripHtml(actual).length;
  2921. }
  2922. // Don't show diff if expected and actual are totally different
  2923. if (showDiff) {
  2924. message += "<tr class='test-diff'><th>Diff: </th><td><pre>" + diff + "</pre></td></tr>";
  2925. }
  2926. } else if (expected.indexOf("[object Array]") !== -1 || expected.indexOf("[object Object]") !== -1) {
  2927. message += "<tr class='test-message'><th>Message: </th><td>" + "Diff suppressed as the depth of object is more than current max depth (" + QUnit.config.maxDepth + ").<p>Hint: Use <code>QUnit.dump.maxDepth</code> to " + " run with a higher max depth or <a href='" + escapeText(setUrl({ maxDepth: -1 })) + "'>" + "Rerun</a> without max depth.</p></td></tr>";
  2928. } else {
  2929. message += "<tr class='test-message'><th>Message: </th><td>" + "Diff suppressed as the expected and actual results have an equivalent" + " serialization</td></tr>";
  2930. }
  2931. if (details.source) {
  2932. message += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText(details.source) + "</pre></td></tr>";
  2933. }
  2934. message += "</table>";
  2935. // This occurs when pushFailure is set and we have an extracted stack trace
  2936. } else if (!details.result && details.source) {
  2937. message += "<table>" + "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText(details.source) + "</pre></td></tr>" + "</table>";
  2938. }
  2939. assertList = testItem.getElementsByTagName("ol")[0];
  2940. assertLi = document$$1.createElement("li");
  2941. assertLi.className = details.result ? "pass" : "fail";
  2942. assertLi.innerHTML = message;
  2943. assertList.appendChild(assertLi);
  2944. });
  2945. QUnit.testDone(function (details) {
  2946. var testTitle,
  2947. time,
  2948. testItem,
  2949. assertList,
  2950. good,
  2951. bad,
  2952. testCounts,
  2953. skipped,
  2954. sourceName,
  2955. tests = id("qunit-tests");
  2956. if (!tests) {
  2957. return;
  2958. }
  2959. testItem = id("qunit-test-output-" + details.testId);
  2960. assertList = testItem.getElementsByTagName("ol")[0];
  2961. good = details.passed;
  2962. bad = details.failed;
  2963. // This test passed if it has no unexpected failed assertions
  2964. var testPassed = details.failed > 0 ? details.todo : !details.todo;
  2965. if (testPassed) {
  2966. // Collapse the passing tests
  2967. addClass(assertList, "qunit-collapsed");
  2968. } else if (config.collapse) {
  2969. if (!collapseNext) {
  2970. // Skip collapsing the first failing test
  2971. collapseNext = true;
  2972. } else {
  2973. // Collapse remaining tests
  2974. addClass(assertList, "qunit-collapsed");
  2975. }
  2976. }
  2977. // The testItem.firstChild is the test name
  2978. testTitle = testItem.firstChild;
  2979. testCounts = bad ? "<b class='failed'>" + bad + "</b>, " + "<b class='passed'>" + good + "</b>, " : "";
  2980. testTitle.innerHTML += " <b class='counts'>(" + testCounts + details.assertions.length + ")</b>";
  2981. if (details.skipped) {
  2982. stats.skippedTests++;
  2983. testItem.className = "skipped";
  2984. skipped = document$$1.createElement("em");
  2985. skipped.className = "qunit-skipped-label";
  2986. skipped.innerHTML = "skipped";
  2987. testItem.insertBefore(skipped, testTitle);
  2988. } else {
  2989. addEvent(testTitle, "click", function () {
  2990. toggleClass(assertList, "qunit-collapsed");
  2991. });
  2992. testItem.className = testPassed ? "pass" : "fail";
  2993. if (details.todo) {
  2994. var todoLabel = document$$1.createElement("em");
  2995. todoLabel.className = "qunit-todo-label";
  2996. todoLabel.innerHTML = "todo";
  2997. testItem.insertBefore(todoLabel, testTitle);
  2998. }
  2999. time = document$$1.createElement("span");
  3000. time.className = "runtime";
  3001. time.innerHTML = details.runtime + " ms";
  3002. testItem.insertBefore(time, assertList);
  3003. if (!testPassed) {
  3004. stats.failedTests++;
  3005. } else if (details.todo) {
  3006. stats.todoTests++;
  3007. } else {
  3008. stats.passedTests++;
  3009. }
  3010. }
  3011. // Show the source of the test when showing assertions
  3012. if (details.source) {
  3013. sourceName = document$$1.createElement("p");
  3014. sourceName.innerHTML = "<strong>Source: </strong>" + details.source;
  3015. addClass(sourceName, "qunit-source");
  3016. if (testPassed) {
  3017. addClass(sourceName, "qunit-collapsed");
  3018. }
  3019. addEvent(testTitle, "click", function () {
  3020. toggleClass(sourceName, "qunit-collapsed");
  3021. });
  3022. testItem.appendChild(sourceName);
  3023. }
  3024. });
  3025. // Avoid readyState issue with phantomjs
  3026. // Ref: #818
  3027. var notPhantom = function (p) {
  3028. return !(p && p.version && p.version.major > 0);
  3029. }(window.phantom);
  3030. if (notPhantom && document$$1.readyState === "complete") {
  3031. QUnit.load();
  3032. } else {
  3033. addEvent(window, "load", QUnit.load);
  3034. }
  3035. // Wrap window.onerror. We will call the original window.onerror to see if
  3036. // the existing handler fully handles the error; if not, we will call the
  3037. // QUnit.onError function.
  3038. var originalWindowOnError = window.onerror;
  3039. // Cover uncaught exceptions
  3040. // Returning true will suppress the default browser handler,
  3041. // returning false will let it run.
  3042. window.onerror = function (message, fileName, lineNumber) {
  3043. var ret = false;
  3044. if (originalWindowOnError) {
  3045. for (var _len = arguments.length, args = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
  3046. args[_key - 3] = arguments[_key];
  3047. }
  3048. ret = originalWindowOnError.call.apply(originalWindowOnError, [this, message, fileName, lineNumber].concat(args));
  3049. }
  3050. // Treat return value as window.onerror itself does,
  3051. // Only do our handling if not suppressed.
  3052. if (ret !== true) {
  3053. var error = {
  3054. message: message,
  3055. fileName: fileName,
  3056. lineNumber: lineNumber
  3057. };
  3058. ret = QUnit.onError(error);
  3059. }
  3060. return ret;
  3061. };
  3062. })();
  3063. /*
  3064. * This file is a modified version of google-diff-match-patch's JavaScript implementation
  3065. * (https://code.google.com/p/google-diff-match-patch/source/browse/trunk/javascript/diff_match_patch_uncompressed.js),
  3066. * modifications are licensed as more fully set forth in LICENSE.txt.
  3067. *
  3068. * The original source of google-diff-match-patch is attributable and licensed as follows:
  3069. *
  3070. * Copyright 2006 Google Inc.
  3071. * https://code.google.com/p/google-diff-match-patch/
  3072. *
  3073. * Licensed under the Apache License, Version 2.0 (the "License");
  3074. * you may not use this file except in compliance with the License.
  3075. * You may obtain a copy of the License at
  3076. *
  3077. * https://www.apache.org/licenses/LICENSE-2.0
  3078. *
  3079. * Unless required by applicable law or agreed to in writing, software
  3080. * distributed under the License is distributed on an "AS IS" BASIS,
  3081. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3082. * See the License for the specific language governing permissions and
  3083. * limitations under the License.
  3084. *
  3085. * More Info:
  3086. * https://code.google.com/p/google-diff-match-patch/
  3087. *
  3088. * Usage: QUnit.diff(expected, actual)
  3089. *
  3090. */
  3091. QUnit.diff = function () {
  3092. function DiffMatchPatch() {}
  3093. // DIFF FUNCTIONS
  3094. /**
  3095. * The data structure representing a diff is an array of tuples:
  3096. * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
  3097. * which means: delete 'Hello', add 'Goodbye' and keep ' world.'
  3098. */
  3099. var DIFF_DELETE = -1,
  3100. DIFF_INSERT = 1,
  3101. DIFF_EQUAL = 0;
  3102. /**
  3103. * Find the differences between two texts. Simplifies the problem by stripping
  3104. * any common prefix or suffix off the texts before diffing.
  3105. * @param {string} text1 Old string to be diffed.
  3106. * @param {string} text2 New string to be diffed.
  3107. * @param {boolean=} optChecklines Optional speedup flag. If present and false,
  3108. * then don't run a line-level diff first to identify the changed areas.
  3109. * Defaults to true, which does a faster, slightly less optimal diff.
  3110. * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
  3111. */
  3112. DiffMatchPatch.prototype.DiffMain = function (text1, text2, optChecklines) {
  3113. var deadline, checklines, commonlength, commonprefix, commonsuffix, diffs;
  3114. // The diff must be complete in up to 1 second.
  3115. deadline = new Date().getTime() + 1000;
  3116. // Check for null inputs.
  3117. if (text1 === null || text2 === null) {
  3118. throw new Error("Null input. (DiffMain)");
  3119. }
  3120. // Check for equality (speedup).
  3121. if (text1 === text2) {
  3122. if (text1) {
  3123. return [[DIFF_EQUAL, text1]];
  3124. }
  3125. return [];
  3126. }
  3127. if (typeof optChecklines === "undefined") {
  3128. optChecklines = true;
  3129. }
  3130. checklines = optChecklines;
  3131. // Trim off common prefix (speedup).
  3132. commonlength = this.diffCommonPrefix(text1, text2);
  3133. commonprefix = text1.substring(0, commonlength);
  3134. text1 = text1.substring(commonlength);
  3135. text2 = text2.substring(commonlength);
  3136. // Trim off common suffix (speedup).
  3137. commonlength = this.diffCommonSuffix(text1, text2);
  3138. commonsuffix = text1.substring(text1.length - commonlength);
  3139. text1 = text1.substring(0, text1.length - commonlength);
  3140. text2 = text2.substring(0, text2.length - commonlength);
  3141. // Compute the diff on the middle block.
  3142. diffs = this.diffCompute(text1, text2, checklines, deadline);
  3143. // Restore the prefix and suffix.
  3144. if (commonprefix) {
  3145. diffs.unshift([DIFF_EQUAL, commonprefix]);
  3146. }
  3147. if (commonsuffix) {
  3148. diffs.push([DIFF_EQUAL, commonsuffix]);
  3149. }
  3150. this.diffCleanupMerge(diffs);
  3151. return diffs;
  3152. };
  3153. /**
  3154. * Reduce the number of edits by eliminating operationally trivial equalities.
  3155. * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
  3156. */
  3157. DiffMatchPatch.prototype.diffCleanupEfficiency = function (diffs) {
  3158. var changes, equalities, equalitiesLength, lastequality, pointer, preIns, preDel, postIns, postDel;
  3159. changes = false;
  3160. equalities = []; // Stack of indices where equalities are found.
  3161. equalitiesLength = 0; // Keeping our own length var is faster in JS.
  3162. /** @type {?string} */
  3163. lastequality = null;
  3164. // Always equal to diffs[equalities[equalitiesLength - 1]][1]
  3165. pointer = 0; // Index of current position.
  3166. // Is there an insertion operation before the last equality.
  3167. preIns = false;
  3168. // Is there a deletion operation before the last equality.
  3169. preDel = false;
  3170. // Is there an insertion operation after the last equality.
  3171. postIns = false;
  3172. // Is there a deletion operation after the last equality.
  3173. postDel = false;
  3174. while (pointer < diffs.length) {
  3175. // Equality found.
  3176. if (diffs[pointer][0] === DIFF_EQUAL) {
  3177. if (diffs[pointer][1].length < 4 && (postIns || postDel)) {
  3178. // Candidate found.
  3179. equalities[equalitiesLength++] = pointer;
  3180. preIns = postIns;
  3181. preDel = postDel;
  3182. lastequality = diffs[pointer][1];
  3183. } else {
  3184. // Not a candidate, and can never become one.
  3185. equalitiesLength = 0;
  3186. lastequality = null;
  3187. }
  3188. postIns = postDel = false;
  3189. // An insertion or deletion.
  3190. } else {
  3191. if (diffs[pointer][0] === DIFF_DELETE) {
  3192. postDel = true;
  3193. } else {
  3194. postIns = true;
  3195. }
  3196. /*
  3197. * Five types to be split:
  3198. * <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
  3199. * <ins>A</ins>X<ins>C</ins><del>D</del>
  3200. * <ins>A</ins><del>B</del>X<ins>C</ins>
  3201. * <ins>A</del>X<ins>C</ins><del>D</del>
  3202. * <ins>A</ins><del>B</del>X<del>C</del>
  3203. */
  3204. if (lastequality && (preIns && preDel && postIns && postDel || lastequality.length < 2 && preIns + preDel + postIns + postDel === 3)) {
  3205. // Duplicate record.
  3206. diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastequality]);
  3207. // Change second copy to insert.
  3208. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
  3209. equalitiesLength--; // Throw away the equality we just deleted;
  3210. lastequality = null;
  3211. if (preIns && preDel) {
  3212. // No changes made which could affect previous entry, keep going.
  3213. postIns = postDel = true;
  3214. equalitiesLength = 0;
  3215. } else {
  3216. equalitiesLength--; // Throw away the previous equality.
  3217. pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
  3218. postIns = postDel = false;
  3219. }
  3220. changes = true;
  3221. }
  3222. }
  3223. pointer++;
  3224. }
  3225. if (changes) {
  3226. this.diffCleanupMerge(diffs);
  3227. }
  3228. };
  3229. /**
  3230. * Convert a diff array into a pretty HTML report.
  3231. * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
  3232. * @param {integer} string to be beautified.
  3233. * @return {string} HTML representation.
  3234. */
  3235. DiffMatchPatch.prototype.diffPrettyHtml = function (diffs) {
  3236. var op,
  3237. data,
  3238. x,
  3239. html = [];
  3240. for (x = 0; x < diffs.length; x++) {
  3241. op = diffs[x][0]; // Operation (insert, delete, equal)
  3242. data = diffs[x][1]; // Text of change.
  3243. switch (op) {
  3244. case DIFF_INSERT:
  3245. html[x] = "<ins>" + escapeText(data) + "</ins>";
  3246. break;
  3247. case DIFF_DELETE:
  3248. html[x] = "<del>" + escapeText(data) + "</del>";
  3249. break;
  3250. case DIFF_EQUAL:
  3251. html[x] = "<span>" + escapeText(data) + "</span>";
  3252. break;
  3253. }
  3254. }
  3255. return html.join("");
  3256. };
  3257. /**
  3258. * Determine the common prefix of two strings.
  3259. * @param {string} text1 First string.
  3260. * @param {string} text2 Second string.
  3261. * @return {number} The number of characters common to the start of each
  3262. * string.
  3263. */
  3264. DiffMatchPatch.prototype.diffCommonPrefix = function (text1, text2) {
  3265. var pointermid, pointermax, pointermin, pointerstart;
  3266. // Quick check for common null cases.
  3267. if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) {
  3268. return 0;
  3269. }
  3270. // Binary search.
  3271. // Performance analysis: https://neil.fraser.name/news/2007/10/09/
  3272. pointermin = 0;
  3273. pointermax = Math.min(text1.length, text2.length);
  3274. pointermid = pointermax;
  3275. pointerstart = 0;
  3276. while (pointermin < pointermid) {
  3277. if (text1.substring(pointerstart, pointermid) === text2.substring(pointerstart, pointermid)) {
  3278. pointermin = pointermid;
  3279. pointerstart = pointermin;
  3280. } else {
  3281. pointermax = pointermid;
  3282. }
  3283. pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
  3284. }
  3285. return pointermid;
  3286. };
  3287. /**
  3288. * Determine the common suffix of two strings.
  3289. * @param {string} text1 First string.
  3290. * @param {string} text2 Second string.
  3291. * @return {number} The number of characters common to the end of each string.
  3292. */
  3293. DiffMatchPatch.prototype.diffCommonSuffix = function (text1, text2) {
  3294. var pointermid, pointermax, pointermin, pointerend;
  3295. // Quick check for common null cases.
  3296. if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) {
  3297. return 0;
  3298. }
  3299. // Binary search.
  3300. // Performance analysis: https://neil.fraser.name/news/2007/10/09/
  3301. pointermin = 0;
  3302. pointermax = Math.min(text1.length, text2.length);
  3303. pointermid = pointermax;
  3304. pointerend = 0;
  3305. while (pointermin < pointermid) {
  3306. if (text1.substring(text1.length - pointermid, text1.length - pointerend) === text2.substring(text2.length - pointermid, text2.length - pointerend)) {
  3307. pointermin = pointermid;
  3308. pointerend = pointermin;
  3309. } else {
  3310. pointermax = pointermid;
  3311. }
  3312. pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
  3313. }
  3314. return pointermid;
  3315. };
  3316. /**
  3317. * Find the differences between two texts. Assumes that the texts do not
  3318. * have any common prefix or suffix.
  3319. * @param {string} text1 Old string to be diffed.
  3320. * @param {string} text2 New string to be diffed.
  3321. * @param {boolean} checklines Speedup flag. If false, then don't run a
  3322. * line-level diff first to identify the changed areas.
  3323. * If true, then run a faster, slightly less optimal diff.
  3324. * @param {number} deadline Time when the diff should be complete by.
  3325. * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
  3326. * @private
  3327. */
  3328. DiffMatchPatch.prototype.diffCompute = function (text1, text2, checklines, deadline) {
  3329. var diffs, longtext, shorttext, i, hm, text1A, text2A, text1B, text2B, midCommon, diffsA, diffsB;
  3330. if (!text1) {
  3331. // Just add some text (speedup).
  3332. return [[DIFF_INSERT, text2]];
  3333. }
  3334. if (!text2) {
  3335. // Just delete some text (speedup).
  3336. return [[DIFF_DELETE, text1]];
  3337. }
  3338. longtext = text1.length > text2.length ? text1 : text2;
  3339. shorttext = text1.length > text2.length ? text2 : text1;
  3340. i = longtext.indexOf(shorttext);
  3341. if (i !== -1) {
  3342. // Shorter text is inside the longer text (speedup).
  3343. diffs = [[DIFF_INSERT, longtext.substring(0, i)], [DIFF_EQUAL, shorttext], [DIFF_INSERT, longtext.substring(i + shorttext.length)]];
  3344. // Swap insertions for deletions if diff is reversed.
  3345. if (text1.length > text2.length) {
  3346. diffs[0][0] = diffs[2][0] = DIFF_DELETE;
  3347. }
  3348. return diffs;
  3349. }
  3350. if (shorttext.length === 1) {
  3351. // Single character string.
  3352. // After the previous speedup, the character can't be an equality.
  3353. return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
  3354. }
  3355. // Check to see if the problem can be split in two.
  3356. hm = this.diffHalfMatch(text1, text2);
  3357. if (hm) {
  3358. // A half-match was found, sort out the return data.
  3359. text1A = hm[0];
  3360. text1B = hm[1];
  3361. text2A = hm[2];
  3362. text2B = hm[3];
  3363. midCommon = hm[4];
  3364. // Send both pairs off for separate processing.
  3365. diffsA = this.DiffMain(text1A, text2A, checklines, deadline);
  3366. diffsB = this.DiffMain(text1B, text2B, checklines, deadline);
  3367. // Merge the results.
  3368. return diffsA.concat([[DIFF_EQUAL, midCommon]], diffsB);
  3369. }
  3370. if (checklines && text1.length > 100 && text2.length > 100) {
  3371. return this.diffLineMode(text1, text2, deadline);
  3372. }
  3373. return this.diffBisect(text1, text2, deadline);
  3374. };
  3375. /**
  3376. * Do the two texts share a substring which is at least half the length of the
  3377. * longer text?
  3378. * This speedup can produce non-minimal diffs.
  3379. * @param {string} text1 First string.
  3380. * @param {string} text2 Second string.
  3381. * @return {Array.<string>} Five element Array, containing the prefix of
  3382. * text1, the suffix of text1, the prefix of text2, the suffix of
  3383. * text2 and the common middle. Or null if there was no match.
  3384. * @private
  3385. */
  3386. DiffMatchPatch.prototype.diffHalfMatch = function (text1, text2) {
  3387. var longtext, shorttext, dmp, text1A, text2B, text2A, text1B, midCommon, hm1, hm2, hm;
  3388. longtext = text1.length > text2.length ? text1 : text2;
  3389. shorttext = text1.length > text2.length ? text2 : text1;
  3390. if (longtext.length < 4 || shorttext.length * 2 < longtext.length) {
  3391. return null; // Pointless.
  3392. }
  3393. dmp = this; // 'this' becomes 'window' in a closure.
  3394. /**
  3395. * Does a substring of shorttext exist within longtext such that the substring
  3396. * is at least half the length of longtext?
  3397. * Closure, but does not reference any external variables.
  3398. * @param {string} longtext Longer string.
  3399. * @param {string} shorttext Shorter string.
  3400. * @param {number} i Start index of quarter length substring within longtext.
  3401. * @return {Array.<string>} Five element Array, containing the prefix of
  3402. * longtext, the suffix of longtext, the prefix of shorttext, the suffix
  3403. * of shorttext and the common middle. Or null if there was no match.
  3404. * @private
  3405. */
  3406. function diffHalfMatchI(longtext, shorttext, i) {
  3407. var seed, j, bestCommon, prefixLength, suffixLength, bestLongtextA, bestLongtextB, bestShorttextA, bestShorttextB;
  3408. // Start with a 1/4 length substring at position i as a seed.
  3409. seed = longtext.substring(i, i + Math.floor(longtext.length / 4));
  3410. j = -1;
  3411. bestCommon = "";
  3412. while ((j = shorttext.indexOf(seed, j + 1)) !== -1) {
  3413. prefixLength = dmp.diffCommonPrefix(longtext.substring(i), shorttext.substring(j));
  3414. suffixLength = dmp.diffCommonSuffix(longtext.substring(0, i), shorttext.substring(0, j));
  3415. if (bestCommon.length < suffixLength + prefixLength) {
  3416. bestCommon = shorttext.substring(j - suffixLength, j) + shorttext.substring(j, j + prefixLength);
  3417. bestLongtextA = longtext.substring(0, i - suffixLength);
  3418. bestLongtextB = longtext.substring(i + prefixLength);
  3419. bestShorttextA = shorttext.substring(0, j - suffixLength);
  3420. bestShorttextB = shorttext.substring(j + prefixLength);
  3421. }
  3422. }
  3423. if (bestCommon.length * 2 >= longtext.length) {
  3424. return [bestLongtextA, bestLongtextB, bestShorttextA, bestShorttextB, bestCommon];
  3425. } else {
  3426. return null;
  3427. }
  3428. }
  3429. // First check if the second quarter is the seed for a half-match.
  3430. hm1 = diffHalfMatchI(longtext, shorttext, Math.ceil(longtext.length / 4));
  3431. // Check again based on the third quarter.
  3432. hm2 = diffHalfMatchI(longtext, shorttext, Math.ceil(longtext.length / 2));
  3433. if (!hm1 && !hm2) {
  3434. return null;
  3435. } else if (!hm2) {
  3436. hm = hm1;
  3437. } else if (!hm1) {
  3438. hm = hm2;
  3439. } else {
  3440. // Both matched. Select the longest.
  3441. hm = hm1[4].length > hm2[4].length ? hm1 : hm2;
  3442. }
  3443. // A half-match was found, sort out the return data.
  3444. if (text1.length > text2.length) {
  3445. text1A = hm[0];
  3446. text1B = hm[1];
  3447. text2A = hm[2];
  3448. text2B = hm[3];
  3449. } else {
  3450. text2A = hm[0];
  3451. text2B = hm[1];
  3452. text1A = hm[2];
  3453. text1B = hm[3];
  3454. }
  3455. midCommon = hm[4];
  3456. return [text1A, text1B, text2A, text2B, midCommon];
  3457. };
  3458. /**
  3459. * Do a quick line-level diff on both strings, then rediff the parts for
  3460. * greater accuracy.
  3461. * This speedup can produce non-minimal diffs.
  3462. * @param {string} text1 Old string to be diffed.
  3463. * @param {string} text2 New string to be diffed.
  3464. * @param {number} deadline Time when the diff should be complete by.
  3465. * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
  3466. * @private
  3467. */
  3468. DiffMatchPatch.prototype.diffLineMode = function (text1, text2, deadline) {
  3469. var a, diffs, linearray, pointer, countInsert, countDelete, textInsert, textDelete, j;
  3470. // Scan the text on a line-by-line basis first.
  3471. a = this.diffLinesToChars(text1, text2);
  3472. text1 = a.chars1;
  3473. text2 = a.chars2;
  3474. linearray = a.lineArray;
  3475. diffs = this.DiffMain(text1, text2, false, deadline);
  3476. // Convert the diff back to original text.
  3477. this.diffCharsToLines(diffs, linearray);
  3478. // Eliminate freak matches (e.g. blank lines)
  3479. this.diffCleanupSemantic(diffs);
  3480. // Rediff any replacement blocks, this time character-by-character.
  3481. // Add a dummy entry at the end.
  3482. diffs.push([DIFF_EQUAL, ""]);
  3483. pointer = 0;
  3484. countDelete = 0;
  3485. countInsert = 0;
  3486. textDelete = "";
  3487. textInsert = "";
  3488. while (pointer < diffs.length) {
  3489. switch (diffs[pointer][0]) {
  3490. case DIFF_INSERT:
  3491. countInsert++;
  3492. textInsert += diffs[pointer][1];
  3493. break;
  3494. case DIFF_DELETE:
  3495. countDelete++;
  3496. textDelete += diffs[pointer][1];
  3497. break;
  3498. case DIFF_EQUAL:
  3499. // Upon reaching an equality, check for prior redundancies.
  3500. if (countDelete >= 1 && countInsert >= 1) {
  3501. // Delete the offending records and add the merged ones.
  3502. diffs.splice(pointer - countDelete - countInsert, countDelete + countInsert);
  3503. pointer = pointer - countDelete - countInsert;
  3504. a = this.DiffMain(textDelete, textInsert, false, deadline);
  3505. for (j = a.length - 1; j >= 0; j--) {
  3506. diffs.splice(pointer, 0, a[j]);
  3507. }
  3508. pointer = pointer + a.length;
  3509. }
  3510. countInsert = 0;
  3511. countDelete = 0;
  3512. textDelete = "";
  3513. textInsert = "";
  3514. break;
  3515. }
  3516. pointer++;
  3517. }
  3518. diffs.pop(); // Remove the dummy entry at the end.
  3519. return diffs;
  3520. };
  3521. /**
  3522. * Find the 'middle snake' of a diff, split the problem in two
  3523. * and return the recursively constructed diff.
  3524. * See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
  3525. * @param {string} text1 Old string to be diffed.
  3526. * @param {string} text2 New string to be diffed.
  3527. * @param {number} deadline Time at which to bail if not yet complete.
  3528. * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
  3529. * @private
  3530. */
  3531. DiffMatchPatch.prototype.diffBisect = function (text1, text2, deadline) {
  3532. var text1Length, text2Length, maxD, vOffset, vLength, v1, v2, x, delta, front, k1start, k1end, k2start, k2end, k2Offset, k1Offset, x1, x2, y1, y2, d, k1, k2;
  3533. // Cache the text lengths to prevent multiple calls.
  3534. text1Length = text1.length;
  3535. text2Length = text2.length;
  3536. maxD = Math.ceil((text1Length + text2Length) / 2);
  3537. vOffset = maxD;
  3538. vLength = 2 * maxD;
  3539. v1 = new Array(vLength);
  3540. v2 = new Array(vLength);
  3541. // Setting all elements to -1 is faster in Chrome & Firefox than mixing
  3542. // integers and undefined.
  3543. for (x = 0; x < vLength; x++) {
  3544. v1[x] = -1;
  3545. v2[x] = -1;
  3546. }
  3547. v1[vOffset + 1] = 0;
  3548. v2[vOffset + 1] = 0;
  3549. delta = text1Length - text2Length;
  3550. // If the total number of characters is odd, then the front path will collide
  3551. // with the reverse path.
  3552. front = delta % 2 !== 0;
  3553. // Offsets for start and end of k loop.
  3554. // Prevents mapping of space beyond the grid.
  3555. k1start = 0;
  3556. k1end = 0;
  3557. k2start = 0;
  3558. k2end = 0;
  3559. for (d = 0; d < maxD; d++) {
  3560. // Bail out if deadline is reached.
  3561. if (new Date().getTime() > deadline) {
  3562. break;
  3563. }
  3564. // Walk the front path one step.
  3565. for (k1 = -d + k1start; k1 <= d - k1end; k1 += 2) {
  3566. k1Offset = vOffset + k1;
  3567. if (k1 === -d || k1 !== d && v1[k1Offset - 1] < v1[k1Offset + 1]) {
  3568. x1 = v1[k1Offset + 1];
  3569. } else {
  3570. x1 = v1[k1Offset - 1] + 1;
  3571. }
  3572. y1 = x1 - k1;
  3573. while (x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1)) {
  3574. x1++;
  3575. y1++;
  3576. }
  3577. v1[k1Offset] = x1;
  3578. if (x1 > text1Length) {
  3579. // Ran off the right of the graph.
  3580. k1end += 2;
  3581. } else if (y1 > text2Length) {
  3582. // Ran off the bottom of the graph.
  3583. k1start += 2;
  3584. } else if (front) {
  3585. k2Offset = vOffset + delta - k1;
  3586. if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] !== -1) {
  3587. // Mirror x2 onto top-left coordinate system.
  3588. x2 = text1Length - v2[k2Offset];
  3589. if (x1 >= x2) {
  3590. // Overlap detected.
  3591. return this.diffBisectSplit(text1, text2, x1, y1, deadline);
  3592. }
  3593. }
  3594. }
  3595. }
  3596. // Walk the reverse path one step.
  3597. for (k2 = -d + k2start; k2 <= d - k2end; k2 += 2) {
  3598. k2Offset = vOffset + k2;
  3599. if (k2 === -d || k2 !== d && v2[k2Offset - 1] < v2[k2Offset + 1]) {
  3600. x2 = v2[k2Offset + 1];
  3601. } else {
  3602. x2 = v2[k2Offset - 1] + 1;
  3603. }
  3604. y2 = x2 - k2;
  3605. while (x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1)) {
  3606. x2++;
  3607. y2++;
  3608. }
  3609. v2[k2Offset] = x2;
  3610. if (x2 > text1Length) {
  3611. // Ran off the left of the graph.
  3612. k2end += 2;
  3613. } else if (y2 > text2Length) {
  3614. // Ran off the top of the graph.
  3615. k2start += 2;
  3616. } else if (!front) {
  3617. k1Offset = vOffset + delta - k2;
  3618. if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] !== -1) {
  3619. x1 = v1[k1Offset];
  3620. y1 = vOffset + x1 - k1Offset;
  3621. // Mirror x2 onto top-left coordinate system.
  3622. x2 = text1Length - x2;
  3623. if (x1 >= x2) {
  3624. // Overlap detected.
  3625. return this.diffBisectSplit(text1, text2, x1, y1, deadline);
  3626. }
  3627. }
  3628. }
  3629. }
  3630. }
  3631. // Diff took too long and hit the deadline or
  3632. // number of diffs equals number of characters, no commonality at all.
  3633. return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
  3634. };
  3635. /**
  3636. * Given the location of the 'middle snake', split the diff in two parts
  3637. * and recurse.
  3638. * @param {string} text1 Old string to be diffed.
  3639. * @param {string} text2 New string to be diffed.
  3640. * @param {number} x Index of split point in text1.
  3641. * @param {number} y Index of split point in text2.
  3642. * @param {number} deadline Time at which to bail if not yet complete.
  3643. * @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples.
  3644. * @private
  3645. */
  3646. DiffMatchPatch.prototype.diffBisectSplit = function (text1, text2, x, y, deadline) {
  3647. var text1a, text1b, text2a, text2b, diffs, diffsb;
  3648. text1a = text1.substring(0, x);
  3649. text2a = text2.substring(0, y);
  3650. text1b = text1.substring(x);
  3651. text2b = text2.substring(y);
  3652. // Compute both diffs serially.
  3653. diffs = this.DiffMain(text1a, text2a, false, deadline);
  3654. diffsb = this.DiffMain(text1b, text2b, false, deadline);
  3655. return diffs.concat(diffsb);
  3656. };
  3657. /**
  3658. * Reduce the number of edits by eliminating semantically trivial equalities.
  3659. * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
  3660. */
  3661. DiffMatchPatch.prototype.diffCleanupSemantic = function (diffs) {
  3662. var changes, equalities, equalitiesLength, lastequality, pointer, lengthInsertions2, lengthDeletions2, lengthInsertions1, lengthDeletions1, deletion, insertion, overlapLength1, overlapLength2;
  3663. changes = false;
  3664. equalities = []; // Stack of indices where equalities are found.
  3665. equalitiesLength = 0; // Keeping our own length var is faster in JS.
  3666. /** @type {?string} */
  3667. lastequality = null;
  3668. // Always equal to diffs[equalities[equalitiesLength - 1]][1]
  3669. pointer = 0; // Index of current position.
  3670. // Number of characters that changed prior to the equality.
  3671. lengthInsertions1 = 0;
  3672. lengthDeletions1 = 0;
  3673. // Number of characters that changed after the equality.
  3674. lengthInsertions2 = 0;
  3675. lengthDeletions2 = 0;
  3676. while (pointer < diffs.length) {
  3677. if (diffs[pointer][0] === DIFF_EQUAL) {
  3678. // Equality found.
  3679. equalities[equalitiesLength++] = pointer;
  3680. lengthInsertions1 = lengthInsertions2;
  3681. lengthDeletions1 = lengthDeletions2;
  3682. lengthInsertions2 = 0;
  3683. lengthDeletions2 = 0;
  3684. lastequality = diffs[pointer][1];
  3685. } else {
  3686. // An insertion or deletion.
  3687. if (diffs[pointer][0] === DIFF_INSERT) {
  3688. lengthInsertions2 += diffs[pointer][1].length;
  3689. } else {
  3690. lengthDeletions2 += diffs[pointer][1].length;
  3691. }
  3692. // Eliminate an equality that is smaller or equal to the edits on both
  3693. // sides of it.
  3694. if (lastequality && lastequality.length <= Math.max(lengthInsertions1, lengthDeletions1) && lastequality.length <= Math.max(lengthInsertions2, lengthDeletions2)) {
  3695. // Duplicate record.
  3696. diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastequality]);
  3697. // Change second copy to insert.
  3698. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
  3699. // Throw away the equality we just deleted.
  3700. equalitiesLength--;
  3701. // Throw away the previous equality (it needs to be reevaluated).
  3702. equalitiesLength--;
  3703. pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
  3704. // Reset the counters.
  3705. lengthInsertions1 = 0;
  3706. lengthDeletions1 = 0;
  3707. lengthInsertions2 = 0;
  3708. lengthDeletions2 = 0;
  3709. lastequality = null;
  3710. changes = true;
  3711. }
  3712. }
  3713. pointer++;
  3714. }
  3715. // Normalize the diff.
  3716. if (changes) {
  3717. this.diffCleanupMerge(diffs);
  3718. }
  3719. // Find any overlaps between deletions and insertions.
  3720. // e.g: <del>abcxxx</del><ins>xxxdef</ins>
  3721. // -> <del>abc</del>xxx<ins>def</ins>
  3722. // e.g: <del>xxxabc</del><ins>defxxx</ins>
  3723. // -> <ins>def</ins>xxx<del>abc</del>
  3724. // Only extract an overlap if it is as big as the edit ahead or behind it.
  3725. pointer = 1;
  3726. while (pointer < diffs.length) {
  3727. if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
  3728. deletion = diffs[pointer - 1][1];
  3729. insertion = diffs[pointer][1];
  3730. overlapLength1 = this.diffCommonOverlap(deletion, insertion);
  3731. overlapLength2 = this.diffCommonOverlap(insertion, deletion);
  3732. if (overlapLength1 >= overlapLength2) {
  3733. if (overlapLength1 >= deletion.length / 2 || overlapLength1 >= insertion.length / 2) {
  3734. // Overlap found. Insert an equality and trim the surrounding edits.
  3735. diffs.splice(pointer, 0, [DIFF_EQUAL, insertion.substring(0, overlapLength1)]);
  3736. diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlapLength1);
  3737. diffs[pointer + 1][1] = insertion.substring(overlapLength1);
  3738. pointer++;
  3739. }
  3740. } else {
  3741. if (overlapLength2 >= deletion.length / 2 || overlapLength2 >= insertion.length / 2) {
  3742. // Reverse overlap found.
  3743. // Insert an equality and swap and trim the surrounding edits.
  3744. diffs.splice(pointer, 0, [DIFF_EQUAL, deletion.substring(0, overlapLength2)]);
  3745. diffs[pointer - 1][0] = DIFF_INSERT;
  3746. diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlapLength2);
  3747. diffs[pointer + 1][0] = DIFF_DELETE;
  3748. diffs[pointer + 1][1] = deletion.substring(overlapLength2);
  3749. pointer++;
  3750. }
  3751. }
  3752. pointer++;
  3753. }
  3754. pointer++;
  3755. }
  3756. };
  3757. /**
  3758. * Determine if the suffix of one string is the prefix of another.
  3759. * @param {string} text1 First string.
  3760. * @param {string} text2 Second string.
  3761. * @return {number} The number of characters common to the end of the first
  3762. * string and the start of the second string.
  3763. * @private
  3764. */
  3765. DiffMatchPatch.prototype.diffCommonOverlap = function (text1, text2) {
  3766. var text1Length, text2Length, textLength, best, length, pattern, found;
  3767. // Cache the text lengths to prevent multiple calls.
  3768. text1Length = text1.length;
  3769. text2Length = text2.length;
  3770. // Eliminate the null case.
  3771. if (text1Length === 0 || text2Length === 0) {
  3772. return 0;
  3773. }
  3774. // Truncate the longer string.
  3775. if (text1Length > text2Length) {
  3776. text1 = text1.substring(text1Length - text2Length);
  3777. } else if (text1Length < text2Length) {
  3778. text2 = text2.substring(0, text1Length);
  3779. }
  3780. textLength = Math.min(text1Length, text2Length);
  3781. // Quick check for the worst case.
  3782. if (text1 === text2) {
  3783. return textLength;
  3784. }
  3785. // Start by looking for a single character match
  3786. // and increase length until no match is found.
  3787. // Performance analysis: https://neil.fraser.name/news/2010/11/04/
  3788. best = 0;
  3789. length = 1;
  3790. while (true) {
  3791. pattern = text1.substring(textLength - length);
  3792. found = text2.indexOf(pattern);
  3793. if (found === -1) {
  3794. return best;
  3795. }
  3796. length += found;
  3797. if (found === 0 || text1.substring(textLength - length) === text2.substring(0, length)) {
  3798. best = length;
  3799. length++;
  3800. }
  3801. }
  3802. };
  3803. /**
  3804. * Split two texts into an array of strings. Reduce the texts to a string of
  3805. * hashes where each Unicode character represents one line.
  3806. * @param {string} text1 First string.
  3807. * @param {string} text2 Second string.
  3808. * @return {{chars1: string, chars2: string, lineArray: !Array.<string>}}
  3809. * An object containing the encoded text1, the encoded text2 and
  3810. * the array of unique strings.
  3811. * The zeroth element of the array of unique strings is intentionally blank.
  3812. * @private
  3813. */
  3814. DiffMatchPatch.prototype.diffLinesToChars = function (text1, text2) {
  3815. var lineArray, lineHash, chars1, chars2;
  3816. lineArray = []; // E.g. lineArray[4] === 'Hello\n'
  3817. lineHash = {}; // E.g. lineHash['Hello\n'] === 4
  3818. // '\x00' is a valid character, but various debuggers don't like it.
  3819. // So we'll insert a junk entry to avoid generating a null character.
  3820. lineArray[0] = "";
  3821. /**
  3822. * Split a text into an array of strings. Reduce the texts to a string of
  3823. * hashes where each Unicode character represents one line.
  3824. * Modifies linearray and linehash through being a closure.
  3825. * @param {string} text String to encode.
  3826. * @return {string} Encoded string.
  3827. * @private
  3828. */
  3829. function diffLinesToCharsMunge(text) {
  3830. var chars, lineStart, lineEnd, lineArrayLength, line;
  3831. chars = "";
  3832. // Walk the text, pulling out a substring for each line.
  3833. // text.split('\n') would would temporarily double our memory footprint.
  3834. // Modifying text would create many large strings to garbage collect.
  3835. lineStart = 0;
  3836. lineEnd = -1;
  3837. // Keeping our own length variable is faster than looking it up.
  3838. lineArrayLength = lineArray.length;
  3839. while (lineEnd < text.length - 1) {
  3840. lineEnd = text.indexOf("\n", lineStart);
  3841. if (lineEnd === -1) {
  3842. lineEnd = text.length - 1;
  3843. }
  3844. line = text.substring(lineStart, lineEnd + 1);
  3845. lineStart = lineEnd + 1;
  3846. if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) : lineHash[line] !== undefined) {
  3847. chars += String.fromCharCode(lineHash[line]);
  3848. } else {
  3849. chars += String.fromCharCode(lineArrayLength);
  3850. lineHash[line] = lineArrayLength;
  3851. lineArray[lineArrayLength++] = line;
  3852. }
  3853. }
  3854. return chars;
  3855. }
  3856. chars1 = diffLinesToCharsMunge(text1);
  3857. chars2 = diffLinesToCharsMunge(text2);
  3858. return {
  3859. chars1: chars1,
  3860. chars2: chars2,
  3861. lineArray: lineArray
  3862. };
  3863. };
  3864. /**
  3865. * Rehydrate the text in a diff from a string of line hashes to real lines of
  3866. * text.
  3867. * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
  3868. * @param {!Array.<string>} lineArray Array of unique strings.
  3869. * @private
  3870. */
  3871. DiffMatchPatch.prototype.diffCharsToLines = function (diffs, lineArray) {
  3872. var x, chars, text, y;
  3873. for (x = 0; x < diffs.length; x++) {
  3874. chars = diffs[x][1];
  3875. text = [];
  3876. for (y = 0; y < chars.length; y++) {
  3877. text[y] = lineArray[chars.charCodeAt(y)];
  3878. }
  3879. diffs[x][1] = text.join("");
  3880. }
  3881. };
  3882. /**
  3883. * Reorder and merge like edit sections. Merge equalities.
  3884. * Any edit section can move as long as it doesn't cross an equality.
  3885. * @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples.
  3886. */
  3887. DiffMatchPatch.prototype.diffCleanupMerge = function (diffs) {
  3888. var pointer, countDelete, countInsert, textInsert, textDelete, commonlength, changes, diffPointer, position;
  3889. diffs.push([DIFF_EQUAL, ""]); // Add a dummy entry at the end.
  3890. pointer = 0;
  3891. countDelete = 0;
  3892. countInsert = 0;
  3893. textDelete = "";
  3894. textInsert = "";
  3895. while (pointer < diffs.length) {
  3896. switch (diffs[pointer][0]) {
  3897. case DIFF_INSERT:
  3898. countInsert++;
  3899. textInsert += diffs[pointer][1];
  3900. pointer++;
  3901. break;
  3902. case DIFF_DELETE:
  3903. countDelete++;
  3904. textDelete += diffs[pointer][1];
  3905. pointer++;
  3906. break;
  3907. case DIFF_EQUAL:
  3908. // Upon reaching an equality, check for prior redundancies.
  3909. if (countDelete + countInsert > 1) {
  3910. if (countDelete !== 0 && countInsert !== 0) {
  3911. // Factor out any common prefixes.
  3912. commonlength = this.diffCommonPrefix(textInsert, textDelete);
  3913. if (commonlength !== 0) {
  3914. if (pointer - countDelete - countInsert > 0 && diffs[pointer - countDelete - countInsert - 1][0] === DIFF_EQUAL) {
  3915. diffs[pointer - countDelete - countInsert - 1][1] += textInsert.substring(0, commonlength);
  3916. } else {
  3917. diffs.splice(0, 0, [DIFF_EQUAL, textInsert.substring(0, commonlength)]);
  3918. pointer++;
  3919. }
  3920. textInsert = textInsert.substring(commonlength);
  3921. textDelete = textDelete.substring(commonlength);
  3922. }
  3923. // Factor out any common suffixies.
  3924. commonlength = this.diffCommonSuffix(textInsert, textDelete);
  3925. if (commonlength !== 0) {
  3926. diffs[pointer][1] = textInsert.substring(textInsert.length - commonlength) + diffs[pointer][1];
  3927. textInsert = textInsert.substring(0, textInsert.length - commonlength);
  3928. textDelete = textDelete.substring(0, textDelete.length - commonlength);
  3929. }
  3930. }
  3931. // Delete the offending records and add the merged ones.
  3932. if (countDelete === 0) {
  3933. diffs.splice(pointer - countInsert, countDelete + countInsert, [DIFF_INSERT, textInsert]);
  3934. } else if (countInsert === 0) {
  3935. diffs.splice(pointer - countDelete, countDelete + countInsert, [DIFF_DELETE, textDelete]);
  3936. } else {
  3937. diffs.splice(pointer - countDelete - countInsert, countDelete + countInsert, [DIFF_DELETE, textDelete], [DIFF_INSERT, textInsert]);
  3938. }
  3939. pointer = pointer - countDelete - countInsert + (countDelete ? 1 : 0) + (countInsert ? 1 : 0) + 1;
  3940. } else if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) {
  3941. // Merge this equality with the previous one.
  3942. diffs[pointer - 1][1] += diffs[pointer][1];
  3943. diffs.splice(pointer, 1);
  3944. } else {
  3945. pointer++;
  3946. }
  3947. countInsert = 0;
  3948. countDelete = 0;
  3949. textDelete = "";
  3950. textInsert = "";
  3951. break;
  3952. }
  3953. }
  3954. if (diffs[diffs.length - 1][1] === "") {
  3955. diffs.pop(); // Remove the dummy entry at the end.
  3956. }
  3957. // Second pass: look for single edits surrounded on both sides by equalities
  3958. // which can be shifted sideways to eliminate an equality.
  3959. // e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
  3960. changes = false;
  3961. pointer = 1;
  3962. // Intentionally ignore the first and last element (don't need checking).
  3963. while (pointer < diffs.length - 1) {
  3964. if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
  3965. diffPointer = diffs[pointer][1];
  3966. position = diffPointer.substring(diffPointer.length - diffs[pointer - 1][1].length);
  3967. // This is a single edit surrounded by equalities.
  3968. if (position === diffs[pointer - 1][1]) {
  3969. // Shift the edit over the previous equality.
  3970. diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length);
  3971. diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
  3972. diffs.splice(pointer - 1, 1);
  3973. changes = true;
  3974. } else if (diffPointer.substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1]) {
  3975. // Shift the edit over the next equality.
  3976. diffs[pointer - 1][1] += diffs[pointer + 1][1];
  3977. diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1];
  3978. diffs.splice(pointer + 1, 1);
  3979. changes = true;
  3980. }
  3981. }
  3982. pointer++;
  3983. }
  3984. // If shifts were made, the diff needs reordering and another shift sweep.
  3985. if (changes) {
  3986. this.diffCleanupMerge(diffs);
  3987. }
  3988. };
  3989. return function (o, n) {
  3990. var diff, output, text;
  3991. diff = new DiffMatchPatch();
  3992. output = diff.DiffMain(o, n);
  3993. diff.diffCleanupEfficiency(output);
  3994. text = diff.diffPrettyHtml(output);
  3995. return text;
  3996. };
  3997. }();
  3998. }((function() { return this; }())));