edge-cases.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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('edge cases', 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. '# zeroes',
  13. 'ok 1 0 equal to -0',
  14. 'ok 2 -0 equal to 0',
  15. 'not ok 3 0 notEqual to -0',
  16. ' ---',
  17. ' operator: notEqual',
  18. ' expected: |-',
  19. ' -0',
  20. ' actual: |-',
  21. ' 0',
  22. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  23. ' stack: |-',
  24. ' Error: 0 notEqual to -0',
  25. ' [... stack stripped ...]',
  26. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  27. ' [... stack stripped ...]',
  28. ' ...',
  29. 'not ok 4 -0 notEqual to 0',
  30. ' ---',
  31. ' operator: notEqual',
  32. ' expected: |-',
  33. ' 0',
  34. ' actual: |-',
  35. ' -0',
  36. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  37. ' stack: |-',
  38. ' Error: -0 notEqual to 0',
  39. ' [... stack stripped ...]',
  40. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  41. ' [... stack stripped ...]',
  42. ' ...',
  43. 'ok 5 0 looseEqual to -0',
  44. 'ok 6 -0 looseEqual to 0',
  45. 'not ok 7 0 notLooseEqual to -0',
  46. ' ---',
  47. ' operator: notDeepLooseEqual',
  48. ' expected: |-',
  49. ' -0',
  50. ' actual: |-',
  51. ' 0',
  52. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  53. ' stack: |-',
  54. ' Error: 0 notLooseEqual to -0',
  55. ' [... stack stripped ...]',
  56. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  57. ' [... stack stripped ...]',
  58. ' ...',
  59. 'not ok 8 -0 notLooseEqual to 0',
  60. ' ---',
  61. ' operator: notDeepLooseEqual',
  62. ' expected: |-',
  63. ' 0',
  64. ' actual: |-',
  65. ' -0',
  66. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  67. ' stack: |-',
  68. ' Error: -0 notLooseEqual to 0',
  69. ' [... stack stripped ...]',
  70. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  71. ' [... stack stripped ...]',
  72. ' ...',
  73. 'ok 9 0 strictEqual to -0',
  74. 'ok 10 -0 strictEqual to 0',
  75. 'not ok 11 0 notStrictEqual to -0',
  76. ' ---',
  77. ' operator: notEqual',
  78. ' expected: |-',
  79. ' -0',
  80. ' actual: |-',
  81. ' 0',
  82. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  83. ' stack: |-',
  84. ' Error: 0 notStrictEqual to -0',
  85. ' [... stack stripped ...]',
  86. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  87. ' [... stack stripped ...]',
  88. ' ...',
  89. 'not ok 12 -0 notStrictEqual to 0',
  90. ' ---',
  91. ' operator: notEqual',
  92. ' expected: |-',
  93. ' 0',
  94. ' actual: |-',
  95. ' -0',
  96. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  97. ' stack: |-',
  98. ' Error: -0 notStrictEqual to 0',
  99. ' [... stack stripped ...]',
  100. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  101. ' [... stack stripped ...]',
  102. ' ...',
  103. 'ok 13 0 deepLooseEqual to -0',
  104. 'ok 14 -0 deepLooseEqual to 0',
  105. 'not ok 15 0 notDeepLooseEqual to -0',
  106. ' ---',
  107. ' operator: notDeepLooseEqual',
  108. ' expected: |-',
  109. ' -0',
  110. ' actual: |-',
  111. ' 0',
  112. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  113. ' stack: |-',
  114. ' Error: 0 notDeepLooseEqual to -0',
  115. ' [... stack stripped ...]',
  116. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  117. ' [... stack stripped ...]',
  118. ' ...',
  119. 'not ok 16 -0 notDeepLooseEqual to 0',
  120. ' ---',
  121. ' operator: notDeepLooseEqual',
  122. ' expected: |-',
  123. ' 0',
  124. ' actual: |-',
  125. ' -0',
  126. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  127. ' stack: |-',
  128. ' Error: -0 notDeepLooseEqual to 0',
  129. ' [... stack stripped ...]',
  130. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  131. ' [... stack stripped ...]',
  132. ' ...',
  133. 'not ok 17 0 deepEqual to -0',
  134. ' ---',
  135. ' operator: deepEqual',
  136. ' expected: |-',
  137. ' -0',
  138. ' actual: |-',
  139. ' 0',
  140. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  141. ' stack: |-',
  142. ' Error: 0 deepEqual to -0',
  143. ' [... stack stripped ...]',
  144. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  145. ' [... stack stripped ...]',
  146. ' ...',
  147. 'not ok 18 -0 deepEqual to 0',
  148. ' ---',
  149. ' operator: deepEqual',
  150. ' expected: |-',
  151. ' 0',
  152. ' actual: |-',
  153. ' -0',
  154. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  155. ' stack: |-',
  156. ' Error: -0 deepEqual to 0',
  157. ' [... stack stripped ...]',
  158. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  159. ' [... stack stripped ...]',
  160. ' ...',
  161. 'ok 19 0 notDeepEqual to -0',
  162. 'ok 20 -0 notDeepEqual to 0',
  163. '# NaNs',
  164. 'not ok 21 NaN equal to NaN',
  165. ' ---',
  166. ' operator: equal',
  167. ' expected: NaN',
  168. ' actual: NaN',
  169. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  170. ' stack: |-',
  171. ' Error: NaN equal to NaN',
  172. ' [... stack stripped ...]',
  173. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  174. ' [... stack stripped ...]',
  175. ' ...',
  176. 'ok 22 NaN notEqual to NaN',
  177. 'not ok 23 NaN looseEqual to NaN',
  178. ' ---',
  179. ' operator: deepLooseEqual',
  180. ' expected: NaN',
  181. ' actual: NaN',
  182. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  183. ' stack: |-',
  184. ' Error: NaN looseEqual to NaN',
  185. ' [... stack stripped ...]',
  186. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  187. ' [... stack stripped ...]',
  188. ' ...',
  189. 'ok 24 NaN notLooseEqual to NaN',
  190. 'not ok 25 NaN strictEqual to NaN',
  191. ' ---',
  192. ' operator: equal',
  193. ' expected: NaN',
  194. ' actual: NaN',
  195. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  196. ' stack: |-',
  197. ' Error: NaN strictEqual to NaN',
  198. ' [... stack stripped ...]',
  199. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  200. ' [... stack stripped ...]',
  201. ' ...',
  202. 'ok 26 NaN notStrictEqual to NaN',
  203. 'not ok 27 NaN deepLooseEqual to NaN',
  204. ' ---',
  205. ' operator: deepLooseEqual',
  206. ' expected: NaN',
  207. ' actual: NaN',
  208. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  209. ' stack: |-',
  210. ' Error: NaN deepLooseEqual to NaN',
  211. ' [... stack stripped ...]',
  212. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  213. ' [... stack stripped ...]',
  214. ' ...',
  215. 'ok 28 NaN notDeepLooseEqual to NaN',
  216. 'ok 29 NaN deepEqual to NaN',
  217. 'not ok 30 NaN notDeepEqual to NaN',
  218. ' ---',
  219. ' operator: notDeepEqual',
  220. ' expected: NaN',
  221. ' actual: NaN',
  222. ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  223. ' stack: |-',
  224. ' Error: NaN notDeepEqual to NaN',
  225. ' [... stack stripped ...]',
  226. ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
  227. ' [... stack stripped ...]',
  228. ' ...',
  229. '',
  230. '1..30',
  231. '# tests 30',
  232. '# pass 15',
  233. '# fail 15',
  234. ''
  235. ]);
  236. }));
  237. test('zeroes', function (t) {
  238. t.equal(0, -0, '0 equal to -0');
  239. t.equal(-0, 0, '-0 equal to 0');
  240. t.notEqual(0, -0, '0 notEqual to -0');
  241. t.notEqual(-0, 0, '-0 notEqual to 0');
  242. t.looseEqual(0, -0, '0 looseEqual to -0');
  243. t.looseEqual(-0, 0, '-0 looseEqual to 0');
  244. t.notLooseEqual(0, -0, '0 notLooseEqual to -0');
  245. t.notLooseEqual(-0, 0, '-0 notLooseEqual to 0');
  246. t.strictEqual(0, -0, '0 strictEqual to -0');
  247. t.strictEqual(-0, 0, '-0 strictEqual to 0');
  248. t.notStrictEqual(0, -0, '0 notStrictEqual to -0');
  249. t.notStrictEqual(-0, 0, '-0 notStrictEqual to 0');
  250. t.deepLooseEqual(0, -0, '0 deepLooseEqual to -0');
  251. t.deepLooseEqual(-0, 0, '-0 deepLooseEqual to 0');
  252. t.notDeepLooseEqual(0, -0, '0 notDeepLooseEqual to -0');
  253. t.notDeepLooseEqual(-0, 0, '-0 notDeepLooseEqual to 0');
  254. t.deepEqual(0, -0, '0 deepEqual to -0');
  255. t.deepEqual(-0, 0, '-0 deepEqual to 0');
  256. t.notDeepEqual(0, -0, '0 notDeepEqual to -0');
  257. t.notDeepEqual(-0, 0, '-0 notDeepEqual to 0');
  258. t.end();
  259. });
  260. test('NaNs', function (t) {
  261. t.equal(NaN, NaN, 'NaN equal to NaN');
  262. t.notEqual(NaN, NaN, 'NaN notEqual to NaN');
  263. t.looseEqual(NaN, NaN, 'NaN looseEqual to NaN');
  264. t.notLooseEqual(NaN, NaN, 'NaN notLooseEqual to NaN');
  265. t.strictEqual(NaN, NaN, 'NaN strictEqual to NaN');
  266. t.notStrictEqual(NaN, NaN, 'NaN notStrictEqual to NaN');
  267. t.deepLooseEqual(NaN, NaN, 'NaN deepLooseEqual to NaN');
  268. t.notDeepLooseEqual(NaN, NaN, 'NaN notDeepLooseEqual to NaN');
  269. t.deepEqual(NaN, NaN, 'NaN deepEqual to NaN');
  270. t.notDeepEqual(NaN, NaN, 'NaN notDeepEqual to NaN');
  271. t.end();
  272. });
  273. });