numerics.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. 'use strict';
  2. var tape = require('../');
  3. var tap = require('tap');
  4. var concat = require('concat-stream');
  5. var stripFullStack = require('./common').stripFullStack;
  6. tap.test('numerics', function (tt) {
  7. tt.plan(1);
  8. var test = tape.createHarness();
  9. test.createStream().pipe(concat(function (body) {
  10. tt.same(stripFullStack(body.toString('utf8')), [
  11. 'TAP version 13',
  12. '# numeric strings',
  13. 'not ok 1 number equal to string',
  14. ' ---',
  15. ' operator: equal',
  16. ' expected: \'3\'',
  17. ' actual: 3',
  18. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  19. ' stack: |-',
  20. ' Error: number equal to string',
  21. ' [... stack stripped ...]',
  22. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  23. ' [... stack stripped ...]',
  24. ' ...',
  25. 'not ok 2 string equal to number',
  26. ' ---',
  27. ' operator: equal',
  28. ' expected: 3',
  29. ' actual: \'3\'',
  30. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  31. ' stack: |-',
  32. ' Error: string equal to number',
  33. ' [... stack stripped ...]',
  34. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  35. ' [... stack stripped ...]',
  36. ' ...',
  37. 'ok 3 number notEqual to string',
  38. 'ok 4 string notEqual to number',
  39. 'ok 5 number looseEqual to string',
  40. 'ok 6 string looseEqual to number',
  41. 'not ok 7 number notLooseEqual to string',
  42. ' ---',
  43. ' operator: notDeepLooseEqual',
  44. ' expected: \'3\'',
  45. ' actual: 3',
  46. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  47. ' stack: |-',
  48. ' Error: number notLooseEqual to string',
  49. ' [... stack stripped ...]',
  50. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  51. ' [... stack stripped ...]',
  52. ' ...',
  53. 'not ok 8 string notLooseEqual to number',
  54. ' ---',
  55. ' operator: notDeepLooseEqual',
  56. ' expected: 3',
  57. ' actual: \'3\'',
  58. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  59. ' stack: |-',
  60. ' Error: string notLooseEqual to number',
  61. ' [... stack stripped ...]',
  62. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  63. ' [... stack stripped ...]',
  64. ' ...',
  65. 'not ok 9 number strictEqual to string',
  66. ' ---',
  67. ' operator: equal',
  68. ' expected: \'3\'',
  69. ' actual: 3',
  70. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  71. ' stack: |-',
  72. ' Error: number strictEqual to string',
  73. ' [... stack stripped ...]',
  74. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  75. ' [... stack stripped ...]',
  76. ' ...',
  77. 'not ok 10 string strictEqual to number',
  78. ' ---',
  79. ' operator: equal',
  80. ' expected: 3',
  81. ' actual: \'3\'',
  82. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  83. ' stack: |-',
  84. ' Error: string strictEqual to number',
  85. ' [... stack stripped ...]',
  86. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  87. ' [... stack stripped ...]',
  88. ' ...',
  89. 'ok 11 number notStrictEqual to string',
  90. 'ok 12 string notStrictEqual to number',
  91. 'ok 13 number deepLooseEqual to string',
  92. 'ok 14 string deepLooseEqual to number',
  93. 'not ok 15 number notDeepLooseEqual to string',
  94. ' ---',
  95. ' operator: notDeepLooseEqual',
  96. ' expected: \'3\'',
  97. ' actual: 3',
  98. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  99. ' stack: |-',
  100. ' Error: number notDeepLooseEqual to string',
  101. ' [... stack stripped ...]',
  102. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  103. ' [... stack stripped ...]',
  104. ' ...',
  105. 'not ok 16 string notDeepLooseEqual to number',
  106. ' ---',
  107. ' operator: notDeepLooseEqual',
  108. ' expected: 3',
  109. ' actual: \'3\'',
  110. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  111. ' stack: |-',
  112. ' Error: string notDeepLooseEqual to number',
  113. ' [... stack stripped ...]',
  114. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  115. ' [... stack stripped ...]',
  116. ' ...',
  117. 'not ok 17 number deepEqual to string',
  118. ' ---',
  119. ' operator: deepEqual',
  120. ' expected: \'3\'',
  121. ' actual: 3',
  122. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  123. ' stack: |-',
  124. ' Error: number deepEqual to string',
  125. ' [... stack stripped ...]',
  126. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  127. ' [... stack stripped ...]',
  128. ' ...',
  129. 'not ok 18 string deepEqual to number',
  130. ' ---',
  131. ' operator: deepEqual',
  132. ' expected: 3',
  133. ' actual: \'3\'',
  134. ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  135. ' stack: |-',
  136. ' Error: string deepEqual to number',
  137. ' [... stack stripped ...]',
  138. ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
  139. ' [... stack stripped ...]',
  140. ' ...',
  141. 'ok 19 number notDeepEqual to string',
  142. 'ok 20 string notDeepEqual to number',
  143. '',
  144. '1..20',
  145. '# tests 20',
  146. '# pass 10',
  147. '# fail 10',
  148. ''
  149. ]);
  150. }));
  151. test('numeric strings', function (t) {
  152. t.equal(3, '3', 'number equal to string');
  153. t.equal('3', 3, 'string equal to number');
  154. t.notEqual(3, '3', 'number notEqual to string');
  155. t.notEqual('3', 3, 'string notEqual to number');
  156. t.looseEqual(3, '3', 'number looseEqual to string');
  157. t.looseEqual('3', 3, 'string looseEqual to number');
  158. t.notLooseEqual(3, '3', 'number notLooseEqual to string');
  159. t.notLooseEqual('3', 3, 'string notLooseEqual to number');
  160. t.strictEqual(3, '3', 'number strictEqual to string');
  161. t.strictEqual('3', 3, 'string strictEqual to number');
  162. t.notStrictEqual(3, '3', 'number notStrictEqual to string');
  163. t.notStrictEqual('3', 3, 'string notStrictEqual to number');
  164. t.deepLooseEqual(3, '3', 'number deepLooseEqual to string');
  165. t.deepLooseEqual('3', 3, 'string deepLooseEqual to number');
  166. t.notDeepLooseEqual(3, '3', 'number notDeepLooseEqual to string');
  167. t.notDeepLooseEqual('3', 3, 'string notDeepLooseEqual to number');
  168. t.deepEqual(3, '3', 'number deepEqual to string');
  169. t.deepEqual('3', 3, 'string deepEqual to number');
  170. t.notDeepEqual(3, '3', 'number notDeepEqual to string');
  171. t.notDeepEqual('3', 3, 'string notDeepEqual to number');
  172. t.end();
  173. });
  174. });