test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ;(function() {
  2. var console = {},
  3. files = __TESTS__; // eslint-disable-line no-undef
  4. console.log = function(text) {
  5. var args = Array.prototype.slice.call(arguments, 1),
  6. i = 0;
  7. text = text.replace(/%\w/g, function() {
  8. return args[i++] || '';
  9. });
  10. if (window.console) window.console.log(text);
  11. document.body.innerHTML += '<pre>' + escape(text) + '</pre>';
  12. };
  13. if (!Object.keys) {
  14. Object.keys = function(obj) {
  15. var out = [],
  16. key;
  17. for (key in obj) {
  18. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  19. out.push(key);
  20. }
  21. }
  22. return out;
  23. };
  24. }
  25. if (!Array.prototype.forEach) {
  26. // eslint-disable-next-line no-extend-native
  27. Array.prototype.forEach = function(callback, context) {
  28. for (var i = 0; i < this.length; i++) {
  29. callback.call(context || null, this[i], i, this);
  30. }
  31. };
  32. }
  33. if (!String.prototype.trim) {
  34. // eslint-disable-next-line no-extend-native
  35. String.prototype.trim = function() {
  36. return this.replace(/^\s+|\s+$/g, '');
  37. };
  38. }
  39. // eslint-disable-next-line no-unused-vars
  40. function load() {
  41. return files;
  42. }
  43. function escape(html, encode) {
  44. return html
  45. .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&amp;')
  46. .replace(/</g, '&lt;')
  47. .replace(/>/g, '&gt;')
  48. .replace(/"/g, '&quot;')
  49. .replace(/'/g, '&#39;');
  50. }
  51. __LIBS__; // eslint-disable-line no-undef, no-unused-expressions
  52. (__MAIN__)(); // eslint-disable-line no-undef
  53. }).call(this);