a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*jslint browser:true plusplus:true */
  2. /*global require:true */
  3. function runTests() {
  4. 'use strict';
  5. function setText(el, str) {
  6. if (typeof el.innerText === 'string') {
  7. el.innerText = str;
  8. } else {
  9. el.textContent = str;
  10. }
  11. }
  12. function reportSuccess(code) {
  13. var report, e;
  14. report = document.getElementById('report');
  15. e = document.createElement('pre');
  16. e.setAttribute('class', 'code');
  17. setText(e, code);
  18. report.appendChild(e);
  19. }
  20. function reportFailure(code, expected, actual) {
  21. var report, e;
  22. report = document.getElementById('report');
  23. e = document.createElement('pre');
  24. e.setAttribute('class', 'code');
  25. setText(e, code);
  26. report.appendChild(e);
  27. e = document.createElement('p');
  28. setText(e, 'Expected type: ' + expected);
  29. report.appendChild(e);
  30. e = document.createElement('p');
  31. setText(e, 'Actual type: ' + actual);
  32. report.appendChild(e);
  33. }
  34. require(['../esprima'], function (ESParser) {
  35. var tick, total, failures, obj, variable, variables, i, entry, entries;
  36. // We check only the type of some members of ESParser.
  37. variables = {
  38. 'version': 'string',
  39. 'parse': 'function',
  40. 'Syntax': 'object',
  41. 'Syntax.AssignmentExpression': 'string',
  42. 'Syntax.ArrayExpression': 'string',
  43. 'Syntax.BlockStatement': 'string',
  44. 'Syntax.BinaryExpression': 'string',
  45. 'Syntax.BreakStatement': 'string',
  46. 'Syntax.CallExpression': 'string',
  47. 'Syntax.CatchClause': 'string',
  48. 'Syntax.ConditionalExpression': 'string',
  49. 'Syntax.ContinueStatement': 'string',
  50. 'Syntax.DoWhileStatement': 'string',
  51. 'Syntax.DebuggerStatement': 'string',
  52. 'Syntax.EmptyStatement': 'string',
  53. 'Syntax.ExpressionStatement': 'string',
  54. 'Syntax.ForStatement': 'string',
  55. 'Syntax.ForInStatement': 'string',
  56. 'Syntax.FunctionDeclaration': 'string',
  57. 'Syntax.FunctionExpression': 'string',
  58. 'Syntax.Identifier': 'string',
  59. 'Syntax.IfStatement': 'string',
  60. 'Syntax.Literal': 'string',
  61. 'Syntax.LabeledStatement': 'string',
  62. 'Syntax.LogicalExpression': 'string',
  63. 'Syntax.MemberExpression': 'string',
  64. 'Syntax.NewExpression': 'string',
  65. 'Syntax.ObjectExpression': 'string',
  66. 'Syntax.Program': 'string',
  67. 'Syntax.Property': 'string',
  68. 'Syntax.ReturnStatement': 'string',
  69. 'Syntax.SequenceExpression': 'string',
  70. 'Syntax.SwitchStatement': 'string',
  71. 'Syntax.SwitchCase': 'string',
  72. 'Syntax.ThisExpression': 'string',
  73. 'Syntax.ThrowStatement': 'string',
  74. 'Syntax.TryStatement': 'string',
  75. 'Syntax.UnaryExpression': 'string',
  76. 'Syntax.UpdateExpression': 'string',
  77. 'Syntax.VariableDeclaration': 'string',
  78. 'Syntax.VariableDeclarator': 'string',
  79. 'Syntax.WhileStatement': 'string',
  80. 'Syntax.WithStatement': 'string'
  81. };
  82. total = failures = 0;
  83. tick = new Date();
  84. for (variable in variables) {
  85. if (variables.hasOwnProperty(variable)) {
  86. entries = variable.split('.');
  87. obj = ESParser;
  88. for (i = 0; i < entries.length; ++i) {
  89. entry = entries[i];
  90. if (typeof obj[entry] !== 'undefined') {
  91. obj = obj[entry];
  92. } else {
  93. obj = undefined;
  94. break;
  95. }
  96. }
  97. total++;
  98. if (typeof obj === variables[variable]) {
  99. reportSuccess(variable);
  100. } else {
  101. failures++;
  102. reportFailure(variable, variables[variable], typeof obj);
  103. }
  104. }
  105. }
  106. tick = (new Date()) - tick;
  107. if (failures > 0) {
  108. document.getElementById('status').className = 'alert-box alert';
  109. setText(document.getElementById('status'), total + ' tests. ' +
  110. 'Failures: ' + failures + '. ' + tick + ' ms');
  111. } else {
  112. document.getElementById('status').className = 'alert-box success';
  113. setText(document.getElementById('status'), total + ' tests. ' +
  114. 'No failure. ' + tick + ' ms');
  115. }
  116. });
  117. }