qunit.js 110 KB

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