underscore.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Underscore Test Suite</title>
  6. <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
  7. </head>
  8. <body>
  9. <div id="qunit"></div>
  10. <script>
  11. // Avoid reporting tests to Sauce Labs when script errors occur.
  12. if (location.port == '9001') {
  13. window.onerror = function(message) {
  14. if (window.QUnit) {
  15. QUnit.config.done.length = 0;
  16. }
  17. global_test_results = { 'message': message };
  18. };
  19. }
  20. </script>
  21. <script src="../node_modules/qunitjs/qunit/qunit.js"></script>
  22. <script src="../node_modules/qunit-extras/qunit-extras.js"></script>
  23. <script src="../node_modules/jquery/dist/jquery.js"></script>
  24. <script src="../node_modules/platform/platform.js"></script>
  25. <script src="./asset/test-ui.js"></script>
  26. <script src="../lodash.js"></script>
  27. <script>
  28. QUnit.config.asyncRetries = 10;
  29. QUnit.config.hidepassed = true;
  30. QUnit.config.excused = {
  31. 'Arrays': {
  32. 'chunk': [
  33. 'defaults to empty array (chunk size 0)'
  34. ],
  35. 'difference': [
  36. 'can perform an OO-style difference'
  37. ],
  38. 'drop': [
  39. 'is an alias for rest'
  40. ],
  41. 'first': [
  42. 'returns an empty array when n <= 0 (0 case)',
  43. 'returns an empty array when n <= 0 (negative case)',
  44. 'can fetch the first n elements',
  45. 'returns the whole array if n > length'
  46. ],
  47. 'findIndex': [
  48. 'called with context'
  49. ],
  50. 'findLastIndex': [
  51. 'called with context'
  52. ],
  53. 'flatten': [
  54. 'supports empty arrays',
  55. 'can flatten nested arrays',
  56. 'works on an arguments object',
  57. 'can handle very deep arrays'
  58. ],
  59. 'indexOf': [
  60. "sorted indexOf doesn't uses binary search",
  61. '0'
  62. ],
  63. 'initial': [
  64. 'returns all but the last n elements',
  65. 'returns an empty array when n > length',
  66. 'works on an arguments object'
  67. ],
  68. 'intersection': [
  69. 'can perform an OO-style intersection'
  70. ],
  71. 'last': [
  72. 'returns an empty array when n <= 0 (0 case)',
  73. 'returns an empty array when n <= 0 (negative case)',
  74. 'can fetch the last n elements',
  75. 'returns the whole array if n > length'
  76. ],
  77. 'lastIndexOf': [
  78. 'should treat falsey `fromIndex` values, except `0` and `NaN`, as `array.length`',
  79. 'should treat non-number `fromIndex` values as `array.length`',
  80. '[0,-1,-1]'
  81. ],
  82. 'object': [
  83. 'an array of pairs zipped together into an object',
  84. 'an object converted to pairs and back to an object'
  85. ],
  86. 'rest': [
  87. 'returns the whole array when index is 0',
  88. 'returns elements starting at the given index',
  89. 'works on an arguments object'
  90. ],
  91. 'sortedIndex': [
  92. '2',
  93. '3'
  94. ],
  95. 'tail': [
  96. 'is an alias for rest'
  97. ],
  98. 'take': [
  99. 'is an alias for first'
  100. ],
  101. 'uniq': [
  102. 'uses the result of `iterator` for uniqueness comparisons (unsorted case)',
  103. '`sorted` argument defaults to false when omitted',
  104. 'when `iterator` is a string, uses that key for comparisons (unsorted case)',
  105. 'uses the result of `iterator` for uniqueness comparisons (sorted case)',
  106. 'when `iterator` is a string, uses that key for comparisons (sorted case)',
  107. 'can use falsey pluck like iterator'
  108. ],
  109. 'union': [
  110. 'can perform an OO-style union'
  111. ]
  112. },
  113. 'Chaining': {
  114. 'pop': true,
  115. 'shift': true,
  116. 'splice': true,
  117. 'reverse/concat/unshift/pop/map': [
  118. 'can chain together array functions.'
  119. ]
  120. },
  121. 'Collections': {
  122. 'lookupIterator with contexts': true,
  123. 'Iterating objects with sketchy length properties': true,
  124. 'Resistant to collection length and properties changing while iterating': true,
  125. 'countBy': [
  126. '{}',
  127. '[{}]'
  128. ],
  129. 'each': [
  130. 'context object property accessed'
  131. ],
  132. 'every': [
  133. 'Can be called with object',
  134. 'Died on test #15',
  135. 'context works'
  136. ],
  137. 'filter': [
  138. 'given context',
  139. 'OO-filter'
  140. ],
  141. 'find': [
  142. 'called with context'
  143. ],
  144. 'findWhere': [
  145. 'checks properties given function'
  146. ],
  147. 'groupBy': [
  148. '{}',
  149. '[{}]'
  150. ],
  151. 'includes': [
  152. "doesn't delegate to binary search"
  153. ],
  154. 'invoke': [
  155. 'handles null & undefined'
  156. ],
  157. 'map': [
  158. 'tripled numbers with context',
  159. 'OO-style doubled numbers'
  160. ],
  161. 'max': [
  162. 'can handle null/undefined',
  163. 'can perform a computation-based max',
  164. 'Maximum value of an empty object',
  165. 'Maximum value of an empty array',
  166. 'Maximum value of a non-numeric collection',
  167. 'Finds correct max in array starting with num and containing a NaN',
  168. 'Finds correct max in array starting with NaN',
  169. 'Respects iterator return value of -Infinity',
  170. 'String keys use property iterator',
  171. 'Iterator context',
  172. 'Lookup falsy iterator'
  173. ],
  174. 'min': [
  175. 'can handle null/undefined',
  176. 'can perform a computation-based min',
  177. 'Minimum value of an empty object',
  178. 'Minimum value of an empty array',
  179. 'Minimum value of a non-numeric collection',
  180. 'Finds correct min in array starting with NaN',
  181. 'Respects iterator return value of Infinity',
  182. 'String keys use property iterator',
  183. 'Iterator context',
  184. 'Lookup falsy iterator'
  185. ],
  186. 'partition': [
  187. 'can reference the array index',
  188. 'Died on test #8',
  189. 'partition takes a context argument'
  190. ],
  191. 'pluck': [
  192. '[1]'
  193. ],
  194. 'reduce': [
  195. 'can reduce with a context object'
  196. ],
  197. 'reject': [
  198. 'Returns empty list given empty array'
  199. ],
  200. 'sample': [
  201. 'behaves correctly on negative n',
  202. 'Died on test #3'
  203. ],
  204. 'some': [
  205. 'Can be called with object',
  206. 'Died on test #17',
  207. 'context works'
  208. ],
  209. 'where': [
  210. 'checks properties given function'
  211. ],
  212. 'Can use various collection methods on NodeLists': [
  213. '<span id="id2"></span>'
  214. ]
  215. },
  216. 'Functions': {
  217. 'debounce asap': true,
  218. 'debounce asap cancel': true,
  219. 'debounce asap recursively': true,
  220. 'debounce after system time is set backwards': true,
  221. 'debounce re-entrant': true,
  222. 'throttle repeatedly with results': true,
  223. 'more throttle does not trigger leading call when leading is set to false': true,
  224. 'throttle does not trigger trailing call when trailing is set to false': true,
  225. 'before': [
  226. 'stores a memo to the last value',
  227. 'provides context'
  228. ],
  229. 'bind': [
  230. 'Died on test #2'
  231. ],
  232. 'bindAll': [
  233. 'throws an error for bindAll with no functions named'
  234. ],
  235. 'debounce': [
  236. 'incr was debounced'
  237. ],
  238. 'iteratee': [
  239. '"bbiz"',
  240. '"foo"',
  241. '1'
  242. ],
  243. 'memoize': [
  244. '{"bar":"BAR","foo":"FOO"}',
  245. 'Died on test #8'
  246. ]
  247. },
  248. 'Objects': {
  249. '#1929 Typed Array constructors are functions': true,
  250. 'allKeys': [
  251. 'is not fooled by sparse arrays; see issue #95',
  252. 'is not fooled by sparse arrays with additional properties',
  253. '[]'
  254. ],
  255. 'extend': [
  256. 'extending null results in null',
  257. 'extending undefined results in undefined'
  258. ],
  259. 'extendOwn': [
  260. 'extending non-objects results in returning the non-object value',
  261. 'extending undefined results in undefined'
  262. ],
  263. 'functions': [
  264. 'also looks up functions on the prototype'
  265. ],
  266. 'isEqual': [
  267. '`0` is not equal to `-0`',
  268. 'Commutative equality is implemented for `0` and `-0`',
  269. '`new Number(0)` and `-0` are not equal',
  270. 'Commutative equality is implemented for `new Number(0)` and `-0`',
  271. 'Invalid dates are not equal',
  272. 'false'
  273. ],
  274. 'isFinite': [
  275. 'Numeric strings are numbers',
  276. 'Number instances can be finite'
  277. ],
  278. 'isSet': [
  279. 'Died on test #9'
  280. ],
  281. 'findKey': [
  282. 'called with context'
  283. ],
  284. 'keys': [
  285. 'is not fooled by sparse arrays; see issue #95',
  286. '[]'
  287. ],
  288. 'mapObject': [
  289. 'keep context',
  290. 'called with context',
  291. 'mapValue identity'
  292. ],
  293. 'omit': [
  294. 'can accept a predicate',
  295. 'function is given context'
  296. ],
  297. 'pick': [
  298. 'can accept a predicate and context',
  299. 'function is given context'
  300. ]
  301. },
  302. 'Utility': {
  303. 'now': [
  304. 'Produces the correct time in milliseconds'
  305. ],
  306. 'times': [
  307. 'works as a wrapper'
  308. ]
  309. }
  310. };
  311. var mixinPrereqs = (function() {
  312. var aliasToReal = {
  313. 'all': 'every',
  314. 'allKeys': 'keysIn',
  315. 'any': 'some',
  316. 'collect': 'map',
  317. 'compose': 'flowRight',
  318. 'contains': 'includes',
  319. 'detect': 'find',
  320. 'extendOwn': 'assign',
  321. 'findWhere': 'find',
  322. 'foldl': 'reduce',
  323. 'foldr': 'reduceRight',
  324. 'include': 'includes',
  325. 'indexBy': 'keyBy',
  326. 'inject': 'reduce',
  327. 'invoke': 'invokeMap',
  328. 'mapObject': 'mapValues',
  329. 'matcher': 'matches',
  330. 'methods': 'functions',
  331. 'object': 'zipObject',
  332. 'pairs': 'toPairs',
  333. 'pluck': 'map',
  334. 'restParam': 'restArgs',
  335. 'select': 'filter',
  336. 'unique': 'uniq',
  337. 'where': 'filter'
  338. };
  339. var keyMap = {
  340. 'rest': 'tail',
  341. 'restArgs': 'rest'
  342. };
  343. var lodash = _.noConflict();
  344. return function(_) {
  345. lodash.defaultsDeep(_, { 'templateSettings': lodash.templateSettings });
  346. lodash.mixin(_, lodash.pick(lodash, lodash.difference(lodash.functions(lodash), lodash.functions(_))));
  347. lodash.forOwn(keyMap, function(realName, otherName) {
  348. _[otherName] = lodash[realName];
  349. _.prototype[otherName] = lodash.prototype[realName];
  350. });
  351. lodash.forOwn(aliasToReal, function(realName, alias) {
  352. _[alias] = _[realName];
  353. _.prototype[alias] = _.prototype[realName];
  354. });
  355. };
  356. }());
  357. // Only excuse in Sauce Labs.
  358. if (!ui.isSauceLabs) {
  359. delete QUnit.config.excused.Functions['throttle does not trigger trailing call when trailing is set to false'];
  360. delete QUnit.config.excused.Utility.now;
  361. }
  362. // Load prerequisite scripts.
  363. document.write(ui.urlParams.loader == 'none'
  364. ? '<script src="' + ui.buildPath + '"><\/script>'
  365. : '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
  366. );
  367. </script>
  368. <script>
  369. if (ui.urlParams.loader == 'none') {
  370. mixinPrereqs(_);
  371. document.write([
  372. '<script src="../vendor/underscore/test/collections.js"><\/script>',
  373. '<script src="../vendor/underscore/test/arrays.js"><\/script>',
  374. '<script src="../vendor/underscore/test/functions.js"><\/script>',
  375. '<script src="../vendor/underscore/test/objects.js"><\/script>',
  376. '<script src="../vendor/underscore/test/cross-document.js"><\/script>',
  377. '<script src="../vendor/underscore/test/utility.js"><\/script>',
  378. '<script src="../vendor/underscore/test/chaining.js"><\/script>'
  379. ].join('\n'));
  380. }
  381. </script>
  382. <script>
  383. (function() {
  384. if (window.curl) {
  385. curl.config({ 'apiName': 'require' });
  386. }
  387. if (!window.require) {
  388. return;
  389. }
  390. // Wrap to work around tests assuming Node `require` use.
  391. require = (function(func) {
  392. return function() {
  393. return arguments[0] === '..' ? window._ : func.apply(null, arguments);
  394. };
  395. }(require));
  396. var reBasename = /[\w.-]+$/,
  397. basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''),
  398. modulePath = ui.buildPath.replace(/\.js$/, ''),
  399. locationPath = modulePath.replace(reBasename, '').replace(/^\/|\/$/g, ''),
  400. moduleId = /\bunderscore\b/i.test(ui.buildPath) ? 'underscore' : 'lodash',
  401. moduleMain = modulePath.match(reBasename)[0],
  402. uid = +new Date;
  403. function getConfig() {
  404. var result = {
  405. 'baseUrl': './',
  406. 'urlArgs': 't=' + uid++,
  407. 'waitSeconds': 0,
  408. 'paths': {},
  409. 'packages': [{
  410. 'name': 'test',
  411. 'location': '../vendor/underscore/test',
  412. 'config': {
  413. // Work around no global being exported.
  414. 'exports': 'QUnit',
  415. 'loader': 'curl/loader/legacy'
  416. }
  417. }]
  418. };
  419. if (ui.isModularize) {
  420. result.packages.push({
  421. 'name': moduleId,
  422. 'location': locationPath,
  423. 'main': moduleMain
  424. });
  425. } else {
  426. result.paths[moduleId] = modulePath;
  427. }
  428. return result;
  429. }
  430. QUnit.config.autostart = false;
  431. require(getConfig(), [moduleId], function(lodash) {
  432. mixinPrereqs(lodash);
  433. require(getConfig(), [
  434. 'test/collections',
  435. 'test/arrays',
  436. 'test/functions',
  437. 'test/objects',
  438. 'test/cross-document',
  439. 'test/utility',
  440. 'test/chaining'
  441. ], function() {
  442. QUnit.start();
  443. });
  444. });
  445. }());
  446. </script>
  447. </body>
  448. </html>