Skip to content

Commit

Permalink
[Breaking] only looseEqual/`deepEqual, and their inverses, are now …
Browse files Browse the repository at this point in the history
…non-strict.

Closes #495, for reals this time.
  • Loading branch information
ljharb committed Feb 25, 2020
1 parent 24240e2 commit d26c6a0
Show file tree
Hide file tree
Showing 19 changed files with 323 additions and 212 deletions.
107 changes: 55 additions & 52 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ Test.prototype.error
= Test.prototype.iferror
= error;

function equal(a, b, msg, extra) {
function strictEqual(a, b, msg, extra) {
if (arguments.length < 2) {
throw new TypeError('two arguments must be provided to compare');
}
this._assert(a == b, {
message: defined(msg, 'should be equal'),
this._assert(is(a, b), {
message: defined(msg, 'should be strictly equal'),
operator: 'equal',
actual: a,
expected: b,
Expand All @@ -432,103 +432,92 @@ function equal(a, b, msg, extra) {
Test.prototype.equal
= Test.prototype.equals
= Test.prototype.isEqual
= equal;

function strictEqual(a, b, msg, extra) {
if (arguments.length < 2) {
throw new TypeError('two arguments must be provided to compare');
}
this._assert(is(a, b), {
message: defined(msg, 'should be strictly equal'),
operator: 'strictEqual',
actual: a,
expected: b,
extra: extra
});
}
Test.prototype.strictEqual
= Test.prototype.strictEqual
= Test.prototype.strictEquals
= Test.prototype.is
= strictEqual;

function notEqual(a, b, msg, extra) {
function notStrictEqual(a, b, msg, extra) {
if (arguments.length < 2) {
throw new TypeError('two arguments must be provided to compare');
}
this._assert(a != b, {
message: defined(msg, 'should not be equal'),
this._assert(!is(a, b), {
message: defined(msg, 'should not be strictly equal'),
operator: 'notEqual',
actual: a,
expected: b,
extra: extra
});
}

Test.prototype.notEqual
= Test.prototype.notEquals
= Test.prototype.isNotEqual
= Test.prototype.doesNotEqual
= Test.prototype.isInequal
= notEqual;
= Test.prototype.notStrictEqual
= Test.prototype.notStrictEquals
= Test.prototype.isNot
= Test.prototype.not
= notStrictEqual;

function notStrictEqual(a, b, msg, extra) {
function looseEqual(a, b, msg, extra) {
if (arguments.length < 2) {
throw new TypeError('two arguments must be provided to compare');
}
this._assert(!is(a, b), {
message: defined(msg, 'should not be strictly equal'),
operator: 'notStrictEqual',
this._assert(a == b, {
message: defined(msg, 'should be loosely equal'),
operator: 'looseEqual',
actual: a,
expected: b,
extra: extra
});
}
Test.prototype.notStrictEqual
= Test.prototype.notStrictEquals
= Test.prototype.isNot
= Test.prototype.not
= notStrictEqual;

function tapeDeepEqual(a, b, msg, extra) {
Test.prototype.looseEqual
= Test.prototype.looseEquals
= looseEqual;

function notLooseEqual(a, b, msg, extra) {
if (arguments.length < 2) {
throw new TypeError('two arguments must be provided to compare');
}
this._assert(deepEqual(a, b, { strict: true }), {
message: defined(msg, 'should be equivalent'),
operator: 'deepEqual',
this._assert(a != b, {
message: defined(msg, 'should not be loosely equal'),
operator: 'notLooseEqual',
actual: a,
expected: b,
extra: extra
});
}
Test.prototype.deepEqual
= Test.prototype.deepEquals
= Test.prototype.isEquivalent
= Test.prototype.same
= tapeDeepEqual;
Test.prototype.notLooseEqual
= Test.prototype.notLooseEquals
= notLooseEqual;

function deepLooseEqual(a, b, msg, extra) {
function tapeDeepEqual(a, b, msg, extra) {
if (arguments.length < 2) {
throw new TypeError('two arguments must be provided to compare');
}
this._assert(deepEqual(a, b), {
message: defined(msg, 'should be equivalent'),
operator: 'deepLooseEqual',
this._assert(deepEqual(a, b, { strict: true }), {
message: defined(msg, 'should be deeply equivalent'),
operator: 'deepEqual',
actual: a,
expected: b,
extra: extra
});
}
Test.prototype.deepLooseEqual
= Test.prototype.looseEqual
= Test.prototype.looseEquals
= deepLooseEqual;
Test.prototype.deepEqual
= Test.prototype.deepEquals
= Test.prototype.isEquivalent
= Test.prototype.same
= tapeDeepEqual;

function notDeepEqual(a, b, msg, extra) {
if (arguments.length < 2) {
throw new TypeError('two arguments must be provided to compare');
}
this._assert(!deepEqual(a, b, { strict: true }), {
message: defined(msg, 'should not be equivalent'),
message: defined(msg, 'should not be deeply equivalent'),
operator: 'notDeepEqual',
actual: a,
expected: b,
Expand All @@ -546,21 +535,35 @@ Test.prototype.notDeepEqual
= Test.prototype.isInequivalent
= notDeepEqual;

function deepLooseEqual(a, b, msg, extra) {
if (arguments.length < 2) {
throw new TypeError('two arguments must be provided to compare');
}
this._assert(deepEqual(a, b), {
message: defined(msg, 'should be loosely deeply equivalent'),
operator: 'deepLooseEqual',
actual: a,
expected: b,
extra: extra
});
}

Test.prototype.deepLooseEqual
= deepLooseEqual;

function notDeepLooseEqual(a, b, msg, extra) {
if (arguments.length < 2) {
throw new TypeError('two arguments must be provided to compare');
}
this._assert(!deepEqual(a, b), {
message: defined(msg, 'should be equivalent'),
message: defined(msg, 'should not be loosely deeply equivalent'),
operator: 'notDeepLooseEqual',
actual: a,
expected: b,
extra: extra
});
}
Test.prototype.notDeepLooseEqual
= Test.prototype.notLooseEqual
= Test.prototype.notLooseEquals
= notDeepLooseEqual;

Test.prototype['throws'] = function (fn, expected, msg, extra) {
Expand Down
36 changes: 17 additions & 19 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ test('timing test', function (t) {
$ node example/timing.js
TAP version 13
# timing test
ok 1 should be equal
not ok 2 should be equal
ok 1 should be strictly equal
not ok 2 should be strictly equal
---
operator: equal
expected: 100
Expand Down Expand Up @@ -217,27 +217,27 @@ Aliases: `t.ifError()`, `t.ifErr()`, `t.iferror()`

## t.equal(actual, expected, msg)

Assert that `actual == expected` with an optional description of the assertion `msg`.
Assert that `Object.is(actual, expected)` with an optional description of the assertion `msg`.

Aliases: `t.equals()`, `t.isEqual()`
Aliases: `t.equals()`, `t.isEqual()`, `t.strictEqual()`, `t.strictEquals()`, `t.is()`

## t.strictEqual(actual, expected, msg)
## t.notEqual(actual, expected, msg)

Assert that `Object.is(actual, expected)` with an optional description of the assertion `msg`.
Assert that `!Object.is(actual, expected)` with an optional description of the assertion `msg`.

Aliases: `t.is()`, `t.strictEqual()`, `t.strictEquals()`
Aliases: `t.notEquals()`, `t.isNotEqual()`, `t.doesNotEqual()`, `t.isInequal()`, `t.notStrictEqual()`, `t.notStrictEquals()`, `t.isNot()`, `t.not()`

## t.notEqual(actual, expected, msg)
## t.looseEqual(actual, expected, msg)

Assert that `actual != expected` with an optional description of the assertion `msg`.
Assert that `actual == expected` with an optional description of the assertion `msg`.

Aliases: `t.notEquals()`, `t.isNotEqual()`, `t.doesNotEqual()`, `t.isInequal()`
Aliases: `t.looseEquals()`

## t.notStrictEqual(actual, expected, msg)
## t.notLooseEqual(actual, expected, msg)

Assert that `!Object.is(actual, expected)` with an optional description of the assertion `msg`.
Assert that `actual != expected` with an optional description of the assertion `msg`.

Aliases: `t.notStrictEqual()`, `t.notStrictEquals()`, `t.isNot()`, `t.not()`
Aliases: `t.notLooseEquals()`

## t.deepEqual(actual, expected, msg)

Expand All @@ -263,8 +263,6 @@ Assert that `actual` and `expected` have the same structure and nested values us
[node's deepEqual() algorithm](https://github.com/substack/node-deep-equal)
with loose comparisons (`==`) on leaf nodes and an optional description of the assertion `msg`.

Aliases: `t.looseEqual()`, `t.looseEquals()`

## t.notDeepLooseEqual(actual, expected, msg)

Assert that `actual` and `expected` do not have the same structure and nested values using
Expand Down Expand Up @@ -347,14 +345,14 @@ Pass in test files to run as arguments:
$ node tap.js test/x.js test/y.js
TAP version 13
# (anonymous)
not ok 1 should be equal
not ok 1 should be strictly equal
---
operator: equal
expected: "boop"
actual: "beep"
...
# (anonymous)
ok 2 should be equal
ok 2 should be strictly equal
ok 3 (unnamed assert)
# wheee
ok 4 (unnamed assert)
Expand Down Expand Up @@ -387,10 +385,10 @@ The output for this runner is:
```sh
$ node object.js test/x.js test/y.js
{"type":"test","name":"(anonymous)","id":0}
{"id":0,"ok":false,"name":"should be equal","operator":"equal","actual":"beep","expected":"boop","error":{},"test":0,"type":"assert"}
{"id":0,"ok":false,"name":"should be strictly equal","operator":"equal","actual":"beep","expected":"boop","error":{},"test":0,"type":"assert"}
{"type":"end","test":0}
{"type":"test","name":"(anonymous)","id":1}
{"id":0,"ok":true,"name":"should be equal","operator":"equal","actual":2,"expected":2,"test":1,"type":"assert"}
{"id":0,"ok":true,"name":"should be strictly equal","operator":"equal","actual":2,"expected":2,"test":1,"type":"assert"}
{"id":1,"ok":true,"name":"(unnamed assert)","operator":"ok","actual":true,"expected":true,"test":1,"type":"assert"}
{"type":"end","test":1}
{"type":"test","name":"wheee","id":2}
Expand Down
10 changes: 5 additions & 5 deletions test/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ tap.test('array test', function (tt) {
tt.same(rows.toString('utf8'), [
'TAP version 13',
'# array',
'ok 1 should be equivalent',
'ok 2 should be equivalent',
'ok 3 should be equivalent',
'ok 4 should be equivalent',
'ok 5 should be equivalent',
'ok 1 should be deeply equivalent',
'ok 2 should be deeply equivalent',
'ok 3 should be deeply equivalent',
'ok 4 should be deeply equivalent',
'ok 5 should be deeply equivalent',
'',
'1..5',
'# tests 5',
Expand Down
4 changes: 2 additions & 2 deletions test/circular-things.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tap.test('circular test', function (assert) {
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# circular\n'
+ 'not ok 1 should be equal\n'
+ 'not ok 1 should be strictly equal\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: |-\n'
Expand All @@ -24,7 +24,7 @@ tap.test('circular test', function (assert) {
+ ' { circular: [Circular] }\n'
+ ' at: Test.<anonymous> ($TEST/circular-things.js:$LINE:$COL)\n'
+ ' stack: |-\n'
+ ' Error: should be equal\n'
+ ' Error: should be strictly equal\n'
+ ' [... stack stripped ...]\n'
+ ' at Test.<anonymous> ($TEST/circular-things.js:$LINE:$COL)\n'
+ ' [... stack stripped ...]\n'
Expand Down
18 changes: 9 additions & 9 deletions test/deep-equal-failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tap.test('deep equal failure', function (assert) {
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# deep equal\n'
+ 'not ok 1 should be equal\n'
+ 'not ok 1 should be strictly equal\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: |-\n'
Expand All @@ -30,7 +30,7 @@ tap.test('deep equal failure', function (assert) {
+ ' { a: 1 }\n'
+ ' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' stack: |-\n'
+ ' Error: should be equal\n'
+ ' Error: should be strictly equal\n'
+ ' [... stack stripped ...]\n'
+ ' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' [... stack stripped ...]\n'
Expand All @@ -55,7 +55,7 @@ tap.test('deep equal failure', function (assert) {
assert.deepEqual(data, {
ok: false,
id: 1,
name: 'should be equal',
name: 'should be strictly equal',
diag: {
operator: 'equal',
expected: '{ b: 2 }',
Expand All @@ -82,7 +82,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# deep equal\n'
+ 'not ok 1 should be equal\n'
+ 'not ok 1 should be strictly equal\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: |-\n'
Expand All @@ -91,7 +91,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
+ ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n'
+ ' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' stack: |-\n'
+ ' Error: should be equal\n'
+ ' Error: should be strictly equal\n'
+ ' [... stack stripped ...]\n'
+ ' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' [... stack stripped ...]\n'
Expand All @@ -116,7 +116,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
assert.deepEqual(data, {
ok: false,
id: 1,
name: 'should be equal',
name: 'should be strictly equal',
diag: {
operator: 'equal',
expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }',
Expand All @@ -143,7 +143,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# deep equal\n'
+ 'not ok 1 should be equal\n'
+ 'not ok 1 should be strictly equal\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: |-\n'
Expand All @@ -152,7 +152,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
+ ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n'
+ ' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' stack: |-\n'
+ ' Error: should be equal\n'
+ ' Error: should be strictly equal\n'
+ ' [... stack stripped ...]\n'
+ ' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' [... stack stripped ...]\n'
Expand All @@ -177,7 +177,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
assert.deepEqual(data, {
ok: false,
id: 1,
name: 'should be equal',
name: 'should be strictly equal',
diag: {
operator: 'equal',
expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }',
Expand Down
Loading

0 comments on commit d26c6a0

Please sign in to comment.