From 4526b39834db8061feeeb931dcf06047f29e9970 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 19 Feb 2020 16:24:57 -0800 Subject: [PATCH] [Tests] add tests for edge cases and numerics --- test/edge-cases.js | 237 +++++++++++++++++++++++++++++++++++++++++++++ test/numerics.js | 152 +++++++++++++++++++++++++++++ 2 files changed, 389 insertions(+) create mode 100644 test/edge-cases.js create mode 100644 test/numerics.js diff --git a/test/edge-cases.js b/test/edge-cases.js new file mode 100644 index 00000000..57c98d95 --- /dev/null +++ b/test/edge-cases.js @@ -0,0 +1,237 @@ +'use strict'; + +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +var stripFullStack = require('./common').stripFullStack; + +tap.test('edge cases', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.equal( + stripFullStack(body.toString('utf8')), + 'TAP version 13\n' + + '# zeroes\n' + + 'ok 1 0 equal to -0\n' + + 'ok 2 -0 equal to 0\n' + + 'not ok 3 0 notEqual to -0\n' + + ' ---\n' + + ' operator: notEqual\n' + + ' expected: |-\n' + + ' -0\n' + + ' actual: |-\n' + + ' 0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: 0 notEqual to -0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 4 -0 notEqual to 0\n' + + ' ---\n' + + ' operator: notEqual\n' + + ' expected: |-\n' + + ' 0\n' + + ' actual: |-\n' + + ' -0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: -0 notEqual to 0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'ok 5 0 strictEqual to -0\n' + + 'ok 6 -0 strictEqual to 0\n' + + 'not ok 7 0 notStrictEqual to -0\n' + + ' ---\n' + + ' operator: notEqual\n' + + ' expected: |-\n' + + ' -0\n' + + ' actual: |-\n' + + ' 0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: 0 notStrictEqual to -0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 8 -0 notStrictEqual to 0\n' + + ' ---\n' + + ' operator: notEqual\n' + + ' expected: |-\n' + + ' 0\n' + + ' actual: |-\n' + + ' -0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: -0 notStrictEqual to 0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'ok 9 0 deepLooseEqual to -0\n' + + 'ok 10 -0 deepLooseEqual to 0\n' + + 'not ok 11 0 notDeepLooseEqual to -0\n' + + ' ---\n' + + ' operator: notDeepLooseEqual\n' + + ' expected: |-\n' + + ' -0\n' + + ' actual: |-\n' + + ' 0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: 0 notDeepLooseEqual to -0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 12 -0 notDeepLooseEqual to 0\n' + + ' ---\n' + + ' operator: notDeepLooseEqual\n' + + ' expected: |-\n' + + ' 0\n' + + ' actual: |-\n' + + ' -0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: -0 notDeepLooseEqual to 0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 13 0 deepEqual to -0\n' + + ' ---\n' + + ' operator: deepEqual\n' + + ' expected: |-\n' + + ' -0\n' + + ' actual: |-\n' + + ' 0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: 0 deepEqual to -0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 14 -0 deepEqual to 0\n' + + ' ---\n' + + ' operator: deepEqual\n' + + ' expected: |-\n' + + ' 0\n' + + ' actual: |-\n' + + ' -0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: -0 deepEqual to 0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'ok 15 0 notDeepEqual to -0\n' + + 'ok 16 -0 notDeepEqual to 0\n' + + '# NaNs\n' + + 'not ok 17 NaN equal to NaN\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: NaN\n' + + ' actual: NaN\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: NaN equal to NaN\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'ok 18 NaN notEqual to NaN\n' + + 'not ok 19 NaN strictEqual to NaN\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: NaN\n' + + ' actual: NaN\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: NaN strictEqual to NaN\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'ok 20 NaN notStrictEqual to NaN\n' + + 'not ok 21 NaN deepLooseEqual to NaN\n' + + ' ---\n' + + ' operator: deepLooseEqual\n' + + ' expected: NaN\n' + + ' actual: NaN\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: NaN deepLooseEqual to NaN\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'ok 22 NaN notDeepLooseEqual to NaN\n' + + 'ok 23 NaN deepEqual to NaN\n' + + 'not ok 24 NaN notDeepEqual to NaN\n' + + ' ---\n' + + ' operator: notDeepEqual\n' + + ' expected: NaN\n' + + ' actual: NaN\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: NaN notDeepEqual to NaN\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + '\n1..24\n' + + '# tests 24\n' + + '# pass 12\n' + + '# fail 12\n' + ); + })); + + test('zeroes', function (t) { + t.equal(0, -0, '0 equal to -0'); + t.equal(-0, 0, '-0 equal to 0'); + t.notEqual(0, -0, '0 notEqual to -0'); + t.notEqual(-0, 0, '-0 notEqual to 0'); + + t.strictEqual(0, -0, '0 strictEqual to -0'); + t.strictEqual(-0, 0, '-0 strictEqual to 0'); + t.notStrictEqual(0, -0, '0 notStrictEqual to -0'); + t.notStrictEqual(-0, 0, '-0 notStrictEqual to 0'); + + t.deepLooseEqual(0, -0, '0 deepLooseEqual to -0'); + t.deepLooseEqual(-0, 0, '-0 deepLooseEqual to 0'); + t.notDeepLooseEqual(0, -0, '0 notDeepLooseEqual to -0'); + t.notDeepLooseEqual(-0, 0, '-0 notDeepLooseEqual to 0'); + + t.deepEqual(0, -0, '0 deepEqual to -0'); + t.deepEqual(-0, 0, '-0 deepEqual to 0'); + t.notDeepEqual(0, -0, '0 notDeepEqual to -0'); + t.notDeepEqual(-0, 0, '-0 notDeepEqual to 0'); + + t.end(); + }); + + test('NaNs', function (t) { + t.equal(NaN, NaN, 'NaN equal to NaN'); + t.notEqual(NaN, NaN, 'NaN notEqual to NaN'); + + t.strictEqual(NaN, NaN, 'NaN strictEqual to NaN'); + t.notStrictEqual(NaN, NaN, 'NaN notStrictEqual to NaN'); + + t.deepLooseEqual(NaN, NaN, 'NaN deepLooseEqual to NaN'); + t.notDeepLooseEqual(NaN, NaN, 'NaN notDeepLooseEqual to NaN'); + + t.deepEqual(NaN, NaN, 'NaN deepEqual to NaN'); + t.notDeepEqual(NaN, NaN, 'NaN notDeepEqual to NaN'); + + t.end(); + }); +}); diff --git a/test/numerics.js b/test/numerics.js new file mode 100644 index 00000000..5e080316 --- /dev/null +++ b/test/numerics.js @@ -0,0 +1,152 @@ +'use strict'; + +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +var stripFullStack = require('./common').stripFullStack; + +tap.test('numerics', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.equal( + stripFullStack(body.toString('utf8')), + 'TAP version 13\n' + + '# numeric strings\n' + + 'not ok 1 number equal to string\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: \'3\'\n' + + ' actual: 3\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: number equal to string\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 2 string equal to number\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: 3\n' + + ' actual: \'3\'\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: string equal to number\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'ok 3 number notEqual to string\n' + + 'ok 4 string notEqual to number\n' + + 'not ok 5 number strictEqual to string\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: \'3\'\n' + + ' actual: 3\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: number strictEqual to string\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 6 string strictEqual to number\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: 3\n' + + ' actual: \'3\'\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: string strictEqual to number\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'ok 7 number notStrictEqual to string\n' + + 'ok 8 string notStrictEqual to number\n' + + 'ok 9 number deepLooseEqual to string\n' + + 'ok 10 string deepLooseEqual to number\n' + + 'not ok 11 number notDeepLooseEqual to string\n' + + ' ---\n' + + ' operator: notDeepLooseEqual\n' + + ' expected: \'3\'\n' + + ' actual: 3\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: number notDeepLooseEqual to string\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 12 string notDeepLooseEqual to number\n' + + ' ---\n' + + ' operator: notDeepLooseEqual\n' + + ' expected: 3\n' + + ' actual: \'3\'\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: string notDeepLooseEqual to number\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 13 number deepEqual to string\n' + + ' ---\n' + + ' operator: deepEqual\n' + + ' expected: \'3\'\n' + + ' actual: 3\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: number deepEqual to string\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 14 string deepEqual to number\n' + + ' ---\n' + + ' operator: deepEqual\n' + + ' expected: 3\n' + + ' actual: \'3\'\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: string deepEqual to number\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'ok 15 number notDeepEqual to string\n' + + 'ok 16 string notDeepEqual to number\n' + + '\n1..16\n' + + '# tests 16\n' + + '# pass 8\n' + + '# fail 8\n' + ); + })); + + test('numeric strings', function (t) { + t.equal(3, '3', 'number equal to string'); + t.equal('3', 3, 'string equal to number'); + t.notEqual(3, '3', 'number notEqual to string'); + t.notEqual('3', 3, 'string notEqual to number'); + + t.strictEqual(3, '3', 'number strictEqual to string'); + t.strictEqual('3', 3, 'string strictEqual to number'); + t.notStrictEqual(3, '3', 'number notStrictEqual to string'); + t.notStrictEqual('3', 3, 'string notStrictEqual to number'); + + t.deepLooseEqual(3, '3', 'number deepLooseEqual to string'); + t.deepLooseEqual('3', 3, 'string deepLooseEqual to number'); + t.notDeepLooseEqual(3, '3', 'number notDeepLooseEqual to string'); + t.notDeepLooseEqual('3', 3, 'string notDeepLooseEqual to number'); + + t.deepEqual(3, '3', 'number deepEqual to string'); + t.deepEqual('3', 3, 'string deepEqual to number'); + t.notDeepEqual(3, '3', 'number notDeepEqual to string'); + t.notDeepEqual('3', 3, 'string notDeepEqual to number'); + + t.end(); + }); +});