qunit-1.21.0.js 109 KB

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