From 618c8bc8a77c3070b56fd504b24e0958bff4d41d Mon Sep 17 00:00:00 2001
From: Bryan Housel
Date: Thu, 21 Dec 2023 15:30:28 -0500
Subject: [PATCH] Swap `tap` for `node:test` Node's built-in test runner works
great!
---
package.json | 7 +-
test/LCS.test.js | 36 +++---
test/diff3Merge.test.js | 121 +++++++++-----------
test/diff3MergeRegions.test.js | 100 ++++++++---------
test/diffComm.test.js | 52 +++++----
test/diffIndices.test.js | 34 +++---
test/diffPatch.test.js | 200 +++++++++++++++------------------
test/merge.test.js | 27 ++---
test/mergeDiff3.test.js | 25 ++---
test/mergeDigIn.test.js | 20 ++--
10 files changed, 288 insertions(+), 334 deletions(-)
diff --git a/package.json b/package.json
index 3bd7309..11946a6 100644
--- a/package.json
+++ b/package.json
@@ -43,16 +43,15 @@
"build:browser": "esbuild ./index.mjs --platform=browser --format=iife --global-name=Diff3 --bundle --sourcemap --outfile=./dist/index.iife.js",
"build:cjs": "esbuild ./index.mjs --platform=node --format=cjs --sourcemap --outfile=./dist/index.cjs",
"lint": "eslint index.mjs test/*.js",
- "tap": "c8 tap --reporter terse --no-cov test/*.js",
- "test": "run-s build lint tap"
+ "test": "run-s build test:node",
+ "test:node": "c8 node --test test/"
},
"devDependencies": {
"c8": "^8.0.1",
"esbuild": "^0.19.10",
"eslint": "^8.56.0",
"npm-run-all": "^4.1.5",
- "shx": "^0.3.4",
- "tap": "^16.3.10"
+ "shx": "^0.3.4"
},
"sideEffects": false,
"publishConfig": {
diff --git a/test/LCS.test.js b/test/LCS.test.js
index 1eaf8ac..1cc4116 100644
--- a/test/LCS.test.js
+++ b/test/LCS.test.js
@@ -1,35 +1,33 @@
-import { test } from 'tap';
+import { test } from 'node:test';
+import { strict as assert } from 'node:assert';
import * as Diff3 from '../index.mjs';
-test('LCS', t => {
+test('LCS', async t => {
- t.test('returns the LCS of two arrays', t => {
+ await t.test('returns the LCS of two arrays', t => {
const a = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
const b = ['AA', 'a', 'd', 'c', 'ZZ', '11', 'M', 'z', 'z', '99'];
const result = Diff3.LCS(a, b);
const NULLRESULT = { buffer1index: -1, buffer2index: -1, chain: null };
- t.same(result.buffer1index, 10); // '99'
- t.same(result.buffer2index, 9);
+ assert.deepEqual(result.buffer1index, 10); // '99'
+ assert.deepEqual(result.buffer2index, 9);
- t.same(result.chain.buffer1index, 9); // 'M'
- t.same(result.chain.buffer2index, 6);
+ assert.deepEqual(result.chain.buffer1index, 9); // 'M'
+ assert.deepEqual(result.chain.buffer2index, 6);
- t.same(result.chain.chain.buffer1index, 4); // 'ZZ'
- t.same(result.chain.chain.buffer2index, 4);
+ assert.deepEqual(result.chain.chain.buffer1index, 4); // 'ZZ'
+ assert.deepEqual(result.chain.chain.buffer2index, 4);
- t.same(result.chain.chain.chain.buffer1index, 3); // 'c'
- t.same(result.chain.chain.chain.buffer2index, 3);
+ assert.deepEqual(result.chain.chain.chain.buffer1index, 3); // 'c'
+ assert.deepEqual(result.chain.chain.chain.buffer2index, 3);
- t.same(result.chain.chain.chain.chain.buffer1index, 1); // 'a'
- t.same(result.chain.chain.chain.chain.buffer2index, 1);
+ assert.deepEqual(result.chain.chain.chain.chain.buffer1index, 1); // 'a'
+ assert.deepEqual(result.chain.chain.chain.chain.buffer2index, 1);
- t.same(result.chain.chain.chain.chain.chain.buffer1index, 0); // 'AA'
- t.same(result.chain.chain.chain.chain.chain.buffer2index, 0);
- t.same(result.chain.chain.chain.chain.chain.chain, NULLRESULT);
-
- t.end();
+ assert.deepEqual(result.chain.chain.chain.chain.chain.buffer1index, 0); // 'AA'
+ assert.deepEqual(result.chain.chain.chain.chain.chain.buffer2index, 0);
+ assert.deepEqual(result.chain.chain.chain.chain.chain.chain, NULLRESULT);
});
- t.end();
});
diff --git a/test/diff3Merge.test.js b/test/diff3Merge.test.js
index 5b5c726..9a6d720 100644
--- a/test/diff3Merge.test.js
+++ b/test/diff3Merge.test.js
@@ -1,9 +1,10 @@
-import { test } from 'tap';
+import { test } from 'node:test';
+import { strict as assert } from 'node:assert';
import * as Diff3 from '../index.mjs';
-test('diff3Merge', t => {
+test('diff3Merge', async t => {
- t.test('performs diff3 merge on arrays', t => {
+ await t.test('performs diff3 merge on arrays', t => {
const o = ['AA', 'ZZ', '00', 'M', '99'];
const a = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
const b = ['AA', 'a', 'd', 'c', 'ZZ', '11', 'M', 'z', 'z', '99'];
@@ -38,115 +39,106 @@ test('diff3Merge', t => {
99
*/
- t.same(result[0].ok, ['AA']);
- t.same(result[0].conflict, undefined);
+ assert.deepEqual(result[0].ok, ['AA']);
+ assert.deepEqual(result[0].conflict, undefined);
- t.same(result[1].ok, undefined);
- t.same(result[1].conflict.o, []);
- t.same(result[1].conflict.a, ['a', 'b', 'c']);
- t.same(result[1].conflict.b, ['a', 'd', 'c']);
+ assert.deepEqual(result[1].ok, undefined);
+ assert.deepEqual(result[1].conflict.o, []);
+ assert.deepEqual(result[1].conflict.a, ['a', 'b', 'c']);
+ assert.deepEqual(result[1].conflict.b, ['a', 'd', 'c']);
- t.same(result[2].ok, ['ZZ']);
- t.same(result[2].conflict, undefined);
+ assert.deepEqual(result[2].ok, ['ZZ']);
+ assert.deepEqual(result[2].conflict, undefined);
- t.same(result[3].ok, undefined);
- t.same(result[3].conflict.o, ['00']);
- t.same(result[3].conflict.a, ['new', '00', 'a', 'a']);
- t.same(result[3].conflict.b, ['11']);
+ assert.deepEqual(result[3].ok, undefined);
+ assert.deepEqual(result[3].conflict.o, ['00']);
+ assert.deepEqual(result[3].conflict.a, ['new', '00', 'a', 'a']);
+ assert.deepEqual(result[3].conflict.b, ['11']);
- t.same(result[4].ok, ['M', 'z', 'z', '99']);
- t.same(result[4].conflict, undefined);
-
- t.end();
+ assert.deepEqual(result[4].ok, ['M', 'z', 'z', '99']);
+ assert.deepEqual(result[4].conflict, undefined);
});
- t.test('strings split on whitespace by default to avoid surprises - issue #9', t => {
+ await t.test('strings split on whitespace by default to avoid surprises - issue #9', t => {
const o = 'was touring';
const a = 'was here touring';
const b = 'was into touring';
const result = Diff3.diff3Merge(a, o, b);
- t.same(result[0].ok, ['was']);
- t.same(result[0].conflict, undefined);
-
- t.same(result[1].ok, undefined);
- t.same(result[1].conflict.o, []);
- t.same(result[1].conflict.a, ['here']);
- t.same(result[1].conflict.b, ['into']);
+ assert.deepEqual(result[0].ok, ['was']);
+ assert.deepEqual(result[0].conflict, undefined);
- t.same(result[2].ok, ['touring']);
- t.same(result[2].conflict, undefined);
+ assert.deepEqual(result[1].ok, undefined);
+ assert.deepEqual(result[1].conflict.o, []);
+ assert.deepEqual(result[1].conflict.a, ['here']);
+ assert.deepEqual(result[1].conflict.b, ['into']);
- t.end();
+ assert.deepEqual(result[2].ok, ['touring']);
+ assert.deepEqual(result[2].conflict, undefined);
});
- t.test('strings can optionally split on given separator', t => {
+ await t.test('strings can optionally split on given separator', t => {
const o = 'new hampshire, new mexico, north carolina';
const a = 'new hampshire, new jersey, north carolina';
const b = 'new hampshire, new york, north carolina';
const result = Diff3.diff3Merge(a, o, b, { stringSeparator: /,\s+/ });
- t.same(result[0].ok, ['new hampshire']);
- t.same(result[0].conflict, undefined);
+ assert.deepEqual(result[0].ok, ['new hampshire']);
+ assert.deepEqual(result[0].conflict, undefined);
- t.same(result[1].ok, undefined);
- t.same(result[1].conflict.o, ['new mexico']);
- t.same(result[1].conflict.a, ['new jersey']);
- t.same(result[1].conflict.b, ['new york']);
+ assert.deepEqual(result[1].ok, undefined);
+ assert.deepEqual(result[1].conflict.o, ['new mexico']);
+ assert.deepEqual(result[1].conflict.a, ['new jersey']);
+ assert.deepEqual(result[1].conflict.b, ['new york']);
- t.same(result[2].ok, ['north carolina']);
- t.same(result[2].conflict, undefined);
-
- t.end();
+ assert.deepEqual(result[2].ok, ['north carolina']);
+ assert.deepEqual(result[2].conflict, undefined);
});
- t.test('excludes false conflicts by default', t => {
+ await t.test('excludes false conflicts by default', t => {
const o = 'AA ZZ';
const a = 'AA a b c ZZ';
const b = 'AA a b c ZZ';
const result = Diff3.diff3Merge(a, o, b);
- t.same(result[0].ok, ['AA', 'a', 'b', 'c', 'ZZ']);
- t.same(result[0].conflict, undefined);
- t.end();
+ assert.deepEqual(result[0].ok, ['AA', 'a', 'b', 'c', 'ZZ']);
+ assert.deepEqual(result[0].conflict, undefined);
});
- t.test('can include false conflicts with option', t => {
+ await t.test('can include false conflicts with option', t => {
const o = 'AA ZZ';
const a = 'AA a b c ZZ';
const b = 'AA a b c ZZ';
const result = Diff3.diff3Merge(a, o, b, { excludeFalseConflicts: false });
- t.same(result[0].ok, ['AA']);
- t.same(result[0].conflict, undefined);
+ assert.deepEqual(result[0].ok, ['AA']);
+ assert.deepEqual(result[0].conflict, undefined);
- t.same(result[1].ok, undefined);
- t.same(result[1].conflict.o, []);
- t.same(result[1].conflict.a, ['a', 'b', 'c']);
- t.same(result[1].conflict.b, ['a', 'b', 'c']);
+ assert.deepEqual(result[1].ok, undefined);
+ assert.deepEqual(result[1].conflict.o, []);
+ assert.deepEqual(result[1].conflict.a, ['a', 'b', 'c']);
+ assert.deepEqual(result[1].conflict.b, ['a', 'b', 'c']);
- t.same(result[2].ok, ['ZZ']);
- t.same(result[2].conflict, undefined);
- t.end();
+ assert.deepEqual(result[2].ok, ['ZZ']);
+ assert.deepEqual(result[2].conflict, undefined);
});
- t.test('avoids improper hunk sorting - see openstreetmap/iD#3058', t => {
+ await t.test('avoids improper hunk sorting - see openstreetmap/iD#3058', t => {
const o = ['n4100522632', 'n4100697091', 'n4100697136', 'n4102671583', 'n4102671584', 'n4102671585', 'n4102671586', 'n4102671587', 'n4102671588', 'n4102677889', 'n4102677890', 'n4094374176'];
const a = ['n4100522632', 'n4100697091', 'n4100697136', 'n-10000', 'n4102671583', 'n4102671584', 'n4102671585', 'n4102671586', 'n4102671587', 'n4102671588', 'n4102677889', 'n4102677890', 'n4094374176'];
const b = ['n4100522632', 'n4100697091', 'n4100697136', 'n4102671583', 'n4102671584', 'n4102671585', 'n4102671586', 'n4102671587', 'n4102671588', 'n4102677889', 'n4105613618', 'n4102677890', 'n4105613617', 'n4094374176'];
const expected = ['n4100522632', 'n4100697091', 'n4100697136', 'n-10000', 'n4102671583', 'n4102671584', 'n4102671585', 'n4102671586', 'n4102671587', 'n4102671588', 'n4102677889', 'n4105613618', 'n4102677890', 'n4105613617', 'n4094374176'];
const result = Diff3.diff3Merge(a, o, b);
- t.same(result[0].ok, expected);
- t.end();
+ assert.deepEqual(result[0].ok, expected);
});
- t.test('yaml comparison - issue #46', t => {
+ await t.test('yaml comparison - issue #46', t => {
const o = `title: "title"
description: "description"`;
const a = `title: "title"
@@ -155,12 +147,9 @@ description: "description changed"`;
description: "description"`;
const result = Diff3.diff3Merge(a, o, b, { stringSeparator: /[\r\n]+/ });
- t.same(result[0].ok, undefined);
- t.same(result[0].conflict.o, ['title: "title"', 'description: "description"']);
- t.same(result[0].conflict.a, ['title: "title"', 'description: "description changed"']);
- t.same(result[0].conflict.b, ['title: "title changed"', 'description: "description"']);
- t.end();
+ assert.deepEqual(result[0].ok, undefined);
+ assert.deepEqual(result[0].conflict.o, ['title: "title"', 'description: "description"']);
+ assert.deepEqual(result[0].conflict.a, ['title: "title"', 'description: "description changed"']);
+ assert.deepEqual(result[0].conflict.b, ['title: "title changed"', 'description: "description"']);
});
-
- t.end();
});
diff --git a/test/diff3MergeRegions.test.js b/test/diff3MergeRegions.test.js
index c12cc46..5437f76 100644
--- a/test/diff3MergeRegions.test.js
+++ b/test/diff3MergeRegions.test.js
@@ -1,68 +1,66 @@
-import { test } from 'tap';
+import { test } from 'node:test';
+import { strict as assert } from 'node:assert';
import * as Diff3 from '../index.mjs';
-test('diff3MergeRegions', t => {
+test('diff3MergeRegions', async t => {
- t.test('returns results of 3-way diff from o,a,b arrays', t => {
+ await t.test('returns results of 3-way diff from o,a,b arrays', t => {
const o = ['AA', 'ZZ', '00', 'M', '99'];
const a = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
const b = ['AA', 'a', 'd', 'c', 'ZZ', '11', 'M', 'z', 'z', '99'];
const result = Diff3.diff3MergeRegions(a, o, b);
- t.same(result[0].stable, true);
- t.same(result[0].buffer, 'o');
- t.same(result[0].bufferStart, 0);
- t.same(result[0].bufferLength, 1);
- t.same(result[0].bufferContent, ['AA']);
+ assert.deepEqual(result[0].stable, true);
+ assert.deepEqual(result[0].buffer, 'o');
+ assert.deepEqual(result[0].bufferStart, 0);
+ assert.deepEqual(result[0].bufferLength, 1);
+ assert.deepEqual(result[0].bufferContent, ['AA']);
- t.same(result[1].stable, false);
- t.same(result[1].aStart, 1);
- t.same(result[1].aLength, 3);
- t.same(result[1].aContent, ['a', 'b', 'c']);
- t.same(result[1].oStart, 1);
- t.same(result[1].oLength, 0);
- t.same(result[1].oContent, []);
- t.same(result[1].bStart, 1);
- t.same(result[1].bLength, 3);
- t.same(result[1].bContent, ['a', 'd', 'c']);
+ assert.deepEqual(result[1].stable, false);
+ assert.deepEqual(result[1].aStart, 1);
+ assert.deepEqual(result[1].aLength, 3);
+ assert.deepEqual(result[1].aContent, ['a', 'b', 'c']);
+ assert.deepEqual(result[1].oStart, 1);
+ assert.deepEqual(result[1].oLength, 0);
+ assert.deepEqual(result[1].oContent, []);
+ assert.deepEqual(result[1].bStart, 1);
+ assert.deepEqual(result[1].bLength, 3);
+ assert.deepEqual(result[1].bContent, ['a', 'd', 'c']);
- t.same(result[2].stable, true);
- t.same(result[2].buffer, 'o');
- t.same(result[2].bufferStart, 1);
- t.same(result[2].bufferLength, 1);
- t.same(result[2].bufferContent, ['ZZ']);
+ assert.deepEqual(result[2].stable, true);
+ assert.deepEqual(result[2].buffer, 'o');
+ assert.deepEqual(result[2].bufferStart, 1);
+ assert.deepEqual(result[2].bufferLength, 1);
+ assert.deepEqual(result[2].bufferContent, ['ZZ']);
- t.same(result[3].stable, false);
- t.same(result[3].aStart, 5);
- t.same(result[3].aLength, 4);
- t.same(result[3].aContent, ['new', '00', 'a', 'a']);
- t.same(result[3].oStart, 2);
- t.same(result[3].oLength, 1);
- t.same(result[3].oContent, ['00']);
- t.same(result[3].bStart, 5);
- t.same(result[3].bLength, 1);
- t.same(result[3].bContent, ['11']);
+ assert.deepEqual(result[3].stable, false);
+ assert.deepEqual(result[3].aStart, 5);
+ assert.deepEqual(result[3].aLength, 4);
+ assert.deepEqual(result[3].aContent, ['new', '00', 'a', 'a']);
+ assert.deepEqual(result[3].oStart, 2);
+ assert.deepEqual(result[3].oLength, 1);
+ assert.deepEqual(result[3].oContent, ['00']);
+ assert.deepEqual(result[3].bStart, 5);
+ assert.deepEqual(result[3].bLength, 1);
+ assert.deepEqual(result[3].bContent, ['11']);
- t.same(result[4].stable, true);
- t.same(result[4].buffer, 'o');
- t.same(result[4].bufferStart, 3);
- t.same(result[4].bufferLength, 1);
- t.same(result[4].bufferContent, ['M']);
+ assert.deepEqual(result[4].stable, true);
+ assert.deepEqual(result[4].buffer, 'o');
+ assert.deepEqual(result[4].bufferStart, 3);
+ assert.deepEqual(result[4].bufferLength, 1);
+ assert.deepEqual(result[4].bufferContent, ['M']);
- t.same(result[5].stable, true);
- t.same(result[5].buffer, 'b');
- t.same(result[5].bufferStart, 7);
- t.same(result[5].bufferLength, 2);
- t.same(result[5].bufferContent, ['z', 'z']);
+ assert.deepEqual(result[5].stable, true);
+ assert.deepEqual(result[5].buffer, 'b');
+ assert.deepEqual(result[5].bufferStart, 7);
+ assert.deepEqual(result[5].bufferLength, 2);
+ assert.deepEqual(result[5].bufferContent, ['z', 'z']);
- t.same(result[6].stable, true);
- t.same(result[6].buffer, 'o');
- t.same(result[6].bufferStart, 4);
- t.same(result[6].bufferLength, 1);
- t.same(result[6].bufferContent, ['99']);
-
- t.end();
+ assert.deepEqual(result[6].stable, true);
+ assert.deepEqual(result[6].buffer, 'o');
+ assert.deepEqual(result[6].bufferStart, 4);
+ assert.deepEqual(result[6].bufferLength, 1);
+ assert.deepEqual(result[6].bufferContent, ['99']);
});
- t.end();
});
diff --git a/test/diffComm.test.js b/test/diffComm.test.js
index 5f5f7fe..6f25498 100644
--- a/test/diffComm.test.js
+++ b/test/diffComm.test.js
@@ -1,43 +1,41 @@
-import { test } from 'tap';
+import { test } from 'node:test';
+import { strict as assert } from 'node:assert';
import * as Diff3 from '../index.mjs';
-test('diffComm', t => {
+test('diffComm', async t => {
- t.test('returns a comm-style diff of two arrays', t => {
+ await t.test('returns a comm-style diff of two arrays', t => {
const a = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
const b = ['AA', 'a', 'd', 'c', 'ZZ', '11', 'M', 'z', 'z', '99'];
const result = Diff3.diffComm(a, b);
- t.same(result[0].common, ['AA', 'a']);
- t.same(result[0].buffer1, undefined);
- t.same(result[0].buffer2, undefined);
+ assert.deepEqual(result[0].common, ['AA', 'a']);
+ assert.deepEqual(result[0].buffer1, undefined);
+ assert.deepEqual(result[0].buffer2, undefined);
- t.same(result[1].common, undefined);
- t.same(result[1].buffer1, ['b']);
- t.same(result[1].buffer2, ['d']);
+ assert.deepEqual(result[1].common, undefined);
+ assert.deepEqual(result[1].buffer1, ['b']);
+ assert.deepEqual(result[1].buffer2, ['d']);
- t.same(result[2].common, ['c', 'ZZ']);
- t.same(result[2].buffer1, undefined);
- t.same(result[2].buffer2, undefined);
+ assert.deepEqual(result[2].common, ['c', 'ZZ']);
+ assert.deepEqual(result[2].buffer1, undefined);
+ assert.deepEqual(result[2].buffer2, undefined);
- t.same(result[3].common, undefined);
- t.same(result[3].buffer1, ['new', '00', 'a', 'a']);
- t.same(result[3].buffer2, ['11']);
+ assert.deepEqual(result[3].common, undefined);
+ assert.deepEqual(result[3].buffer1, ['new', '00', 'a', 'a']);
+ assert.deepEqual(result[3].buffer2, ['11']);
- t.same(result[4].common, ['M']);
- t.same(result[4].buffer1, undefined);
- t.same(result[4].buffer2, undefined);
+ assert.deepEqual(result[4].common, ['M']);
+ assert.deepEqual(result[4].buffer1, undefined);
+ assert.deepEqual(result[4].buffer2, undefined);
- t.same(result[5].common, undefined);
- t.same(result[5].buffer1, []);
- t.same(result[5].buffer2, ['z', 'z']);
+ assert.deepEqual(result[5].common, undefined);
+ assert.deepEqual(result[5].buffer1, []);
+ assert.deepEqual(result[5].buffer2, ['z', 'z']);
- t.same(result[6].common, ['99']);
- t.same(result[6].buffer1, undefined);
- t.same(result[6].buffer2, undefined);
-
- t.end();
+ assert.deepEqual(result[6].common, ['99']);
+ assert.deepEqual(result[6].buffer1, undefined);
+ assert.deepEqual(result[6].buffer2, undefined);
});
- t.end();
});
\ No newline at end of file
diff --git a/test/diffIndices.test.js b/test/diffIndices.test.js
index 0443c88..98fa66c 100644
--- a/test/diffIndices.test.js
+++ b/test/diffIndices.test.js
@@ -1,30 +1,28 @@
-import { test } from 'tap';
+import { test } from 'node:test';
+import { strict as assert } from 'node:assert';
import * as Diff3 from '../index.mjs';
-test('diffIndices', t => {
+test('diffIndices', async t => {
- t.test('returns array indices for differing regions of two arrays', t => {
+ await t.test('returns array indices for differing regions of two arrays', t => {
const a = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
const b = ['AA', 'a', 'd', 'c', 'ZZ', '11', 'M', 'z', 'z', '99'];
const result = Diff3.diffIndices(a, b);
- t.same(result[0].buffer1, [2, 1]);
- t.same(result[0].buffer1Content, ['b']);
- t.same(result[0].buffer2, [2, 1]);
- t.same(result[0].buffer2Content, ['d']);
+ assert.deepEqual(result[0].buffer1, [2, 1]);
+ assert.deepEqual(result[0].buffer1Content, ['b']);
+ assert.deepEqual(result[0].buffer2, [2, 1]);
+ assert.deepEqual(result[0].buffer2Content, ['d']);
- t.same(result[1].buffer1, [5, 4]);
- t.same(result[1].buffer1Content, ['new', '00', 'a', 'a']);
- t.same(result[1].buffer2, [5, 1]);
- t.same(result[1].buffer2Content, ['11']);
+ assert.deepEqual(result[1].buffer1, [5, 4]);
+ assert.deepEqual(result[1].buffer1Content, ['new', '00', 'a', 'a']);
+ assert.deepEqual(result[1].buffer2, [5, 1]);
+ assert.deepEqual(result[1].buffer2Content, ['11']);
- t.same(result[2].buffer1, [10, 0]);
- t.same(result[2].buffer1Content, []);
- t.same(result[2].buffer2, [7, 2]);
- t.same(result[2].buffer2Content, ['z', 'z']);
-
- t.end();
+ assert.deepEqual(result[2].buffer1, [10, 0]);
+ assert.deepEqual(result[2].buffer1Content, []);
+ assert.deepEqual(result[2].buffer2, [7, 2]);
+ assert.deepEqual(result[2].buffer2Content, ['z', 'z']);
});
- t.end();
});
\ No newline at end of file
diff --git a/test/diffPatch.test.js b/test/diffPatch.test.js
index 4e551a9..ea5fea6 100644
--- a/test/diffPatch.test.js
+++ b/test/diffPatch.test.js
@@ -1,4 +1,5 @@
-import { test } from 'tap';
+import { test } from 'node:test';
+import { strict as assert } from 'node:assert';
import * as Diff3 from '../index.mjs';
const a = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
@@ -6,151 +7,132 @@ const b = ['AA', 'a', 'd', 'c', 'ZZ', '11', 'M', 'z', 'z', '99'];
const a0 = a;
const b0 = b;
-test('diffPatch', t => {
- t.test('returns a patch-style diff of two arrays', t => {
+test('diffPatch', async t => {
+ await t.test('returns a patch-style diff of two arrays', t => {
const result = Diff3.diffPatch(a, b);
- t.same(result[0].buffer1.offset, 2);
- t.same(result[0].buffer1.length, 1);
- t.same(result[0].buffer1.chunk, ['b']);
- t.same(result[0].buffer2.offset, 2);
- t.same(result[0].buffer2.length, 1);
- t.same(result[0].buffer2.chunk, ['d']);
-
- t.same(result[1].buffer1.offset, 5);
- t.same(result[1].buffer1.length, 4);
- t.same(result[1].buffer1.chunk, ['new', '00', 'a', 'a']);
- t.same(result[1].buffer2.offset, 5);
- t.same(result[1].buffer2.length, 1);
- t.same(result[1].buffer2.chunk, ['11']);
-
- t.same(result[2].buffer1.offset, 10);
- t.same(result[2].buffer1.length, 0);
- t.same(result[2].buffer1.chunk, []);
- t.same(result[2].buffer2.offset, 7);
- t.same(result[2].buffer2.length, 2);
- t.same(result[2].buffer2.chunk, ['z', 'z']);
-
- t.end();
+ assert.deepEqual(result[0].buffer1.offset, 2);
+ assert.deepEqual(result[0].buffer1.length, 1);
+ assert.deepEqual(result[0].buffer1.chunk, ['b']);
+ assert.deepEqual(result[0].buffer2.offset, 2);
+ assert.deepEqual(result[0].buffer2.length, 1);
+ assert.deepEqual(result[0].buffer2.chunk, ['d']);
+
+ assert.deepEqual(result[1].buffer1.offset, 5);
+ assert.deepEqual(result[1].buffer1.length, 4);
+ assert.deepEqual(result[1].buffer1.chunk, ['new', '00', 'a', 'a']);
+ assert.deepEqual(result[1].buffer2.offset, 5);
+ assert.deepEqual(result[1].buffer2.length, 1);
+ assert.deepEqual(result[1].buffer2.chunk, ['11']);
+
+ assert.deepEqual(result[2].buffer1.offset, 10);
+ assert.deepEqual(result[2].buffer1.length, 0);
+ assert.deepEqual(result[2].buffer1.chunk, []);
+ assert.deepEqual(result[2].buffer2.offset, 7);
+ assert.deepEqual(result[2].buffer2.length, 2);
+ assert.deepEqual(result[2].buffer2.chunk, ['z', 'z']);
});
- t.test('did not modify buffer1 or buffer2', t => {
- t.strictSame(a0, a);
- t.strictSame(b0, b);
- t.end();
+ await t.test('did not modify buffer1 or buffer2', t => {
+ assert.equal(a0, a);
+ assert.equal(b0, b);
});
-
- t.end();
});
-test('patch', t => {
- t.test('applies a patch against buffer1 to get buffer2', t => {
+test('patch', async t => {
+ await t.test('applies a patch against buffer1 to get buffer2', t => {
const patch = Diff3.diffPatch(a, b);
const result = Diff3.patch(a, patch);
- t.same(result, b);
- t.end();
+ assert.deepEqual(result, b);
});
- t.test('did not modify buffer1 or buffer2', t => {
- t.strictSame(a0, a);
- t.strictSame(b0, b);
- t.end();
+ await t.test('did not modify buffer1 or buffer2', t => {
+ assert.equal(a0, a);
+ assert.equal(b0, b);
});
-
- t.end();
});
-test('stripPatch', t => {
+test('stripPatch', async t => {
const patch = Diff3.diffPatch(a, b);
const strip = Diff3.stripPatch(patch);
- t.test('removes extra information from the diffPatch result', t => {
- t.same(strip[0].buffer1.offset, 2);
- t.same(strip[0].buffer1.length, 1);
- t.same(strip[0].buffer1.chunk, undefined);
- t.same(strip[0].buffer2.offset, undefined);
- t.same(strip[0].buffer2.length, undefined);
- t.same(strip[0].buffer2.chunk, ['d']);
-
- t.same(strip[1].buffer1.offset, 5);
- t.same(strip[1].buffer1.length, 4);
- t.same(strip[1].buffer1.chunk, undefined);
- t.same(strip[1].buffer2.offset, undefined);
- t.same(strip[1].buffer2.length, undefined);
- t.same(strip[1].buffer2.chunk, ['11']);
-
- t.same(strip[2].buffer1.offset, 10);
- t.same(strip[2].buffer1.length, 0);
- t.same(strip[2].buffer1.chunk, undefined);
- t.same(strip[2].buffer2.offset, undefined);
- t.same(strip[2].buffer2.length, undefined);
- t.same(strip[2].buffer2.chunk, ['z', 'z']);
-
- t.end();
+ await t.test('removes extra information from the diffPatch result', t => {
+ assert.deepEqual(strip[0].buffer1.offset, 2);
+ assert.deepEqual(strip[0].buffer1.length, 1);
+ assert.deepEqual(strip[0].buffer1.chunk, undefined);
+ assert.deepEqual(strip[0].buffer2.offset, undefined);
+ assert.deepEqual(strip[0].buffer2.length, undefined);
+ assert.deepEqual(strip[0].buffer2.chunk, ['d']);
+
+ assert.deepEqual(strip[1].buffer1.offset, 5);
+ assert.deepEqual(strip[1].buffer1.length, 4);
+ assert.deepEqual(strip[1].buffer1.chunk, undefined);
+ assert.deepEqual(strip[1].buffer2.offset, undefined);
+ assert.deepEqual(strip[1].buffer2.length, undefined);
+ assert.deepEqual(strip[1].buffer2.chunk, ['11']);
+
+ assert.deepEqual(strip[2].buffer1.offset, 10);
+ assert.deepEqual(strip[2].buffer1.length, 0);
+ assert.deepEqual(strip[2].buffer1.chunk, undefined);
+ assert.deepEqual(strip[2].buffer2.offset, undefined);
+ assert.deepEqual(strip[2].buffer2.length, undefined);
+ assert.deepEqual(strip[2].buffer2.chunk, ['z', 'z']);
});
- t.test('applies a stripped patch against buffer1 to get buffer2', t => {
+ await t.test('applies a stripped patch against buffer1 to get buffer2', t => {
const result = Diff3.patch(a, strip);
- t.same(result, b);
- t.end();
+ assert.deepEqual(result, b);
});
- t.test('did not modify the original patch', t => {
- t.not(patch, strip);
- t.not(patch[0], strip[0]);
- t.not(patch[1], strip[1]);
- t.not(patch[2], strip[2]);
- t.end();
+ await t.test('did not modify the original patch', t => {
+ assert.notEqual(patch, strip);
+ assert.notEqual(patch[0], strip[0]);
+ assert.notEqual(patch[1], strip[1]);
+ assert.notEqual(patch[2], strip[2]);
});
- t.end();
});
-test('invertPatch', t => {
+test('invertPatch', async t => {
const patch = Diff3.diffPatch(a, b);
const invert = Diff3.invertPatch(patch);
- t.test('inverts the diffPatch result', t => {
- t.same(invert[0].buffer2.offset, 2);
- t.same(invert[0].buffer2.length, 1);
- t.same(invert[0].buffer2.chunk, ['b']);
- t.same(invert[0].buffer1.offset, 2);
- t.same(invert[0].buffer1.length, 1);
- t.same(invert[0].buffer1.chunk, ['d']);
-
- t.same(invert[1].buffer2.offset, 5);
- t.same(invert[1].buffer2.length, 4);
- t.same(invert[1].buffer2.chunk, ['new', '00', 'a', 'a']);
- t.same(invert[1].buffer1.offset, 5);
- t.same(invert[1].buffer1.length, 1);
- t.same(invert[1].buffer1.chunk, ['11']);
-
- t.same(invert[2].buffer2.offset, 10);
- t.same(invert[2].buffer2.length, 0);
- t.same(invert[2].buffer2.chunk, []);
- t.same(invert[2].buffer1.offset, 7);
- t.same(invert[2].buffer1.length, 2);
- t.same(invert[2].buffer1.chunk, ['z', 'z']);
-
- t.end();
+ await t.test('inverts the diffPatch result', t => {
+ assert.deepEqual(invert[0].buffer2.offset, 2);
+ assert.deepEqual(invert[0].buffer2.length, 1);
+ assert.deepEqual(invert[0].buffer2.chunk, ['b']);
+ assert.deepEqual(invert[0].buffer1.offset, 2);
+ assert.deepEqual(invert[0].buffer1.length, 1);
+ assert.deepEqual(invert[0].buffer1.chunk, ['d']);
+
+ assert.deepEqual(invert[1].buffer2.offset, 5);
+ assert.deepEqual(invert[1].buffer2.length, 4);
+ assert.deepEqual(invert[1].buffer2.chunk, ['new', '00', 'a', 'a']);
+ assert.deepEqual(invert[1].buffer1.offset, 5);
+ assert.deepEqual(invert[1].buffer1.length, 1);
+ assert.deepEqual(invert[1].buffer1.chunk, ['11']);
+
+ assert.deepEqual(invert[2].buffer2.offset, 10);
+ assert.deepEqual(invert[2].buffer2.length, 0);
+ assert.deepEqual(invert[2].buffer2.chunk, []);
+ assert.deepEqual(invert[2].buffer1.offset, 7);
+ assert.deepEqual(invert[2].buffer1.length, 2);
+ assert.deepEqual(invert[2].buffer1.chunk, ['z', 'z']);
});
- t.test('applies an inverted patch against buffer2 to get buffer1', t => {
+ await t.test('applies an inverted patch against buffer2 to get buffer1', t => {
const result = Diff3.patch(b, invert);
- t.same(result, a);
- t.end();
+ assert.deepEqual(result, a);
});
- t.test('did not modify the original patch', t => {
- t.not(patch, invert);
- t.not(patch[0], invert[0]);
- t.not(patch[1], invert[1]);
- t.not(patch[2], invert[2]);
- t.end();
+ await t.test('did not modify the original patch', t => {
+ assert.notEqual(patch, invert);
+ assert.notEqual(patch[0], invert[0]);
+ assert.notEqual(patch[1], invert[1]);
+ assert.notEqual(patch[2], invert[2]);
});
- t.end();
});
\ No newline at end of file
diff --git a/test/merge.test.js b/test/merge.test.js
index 0809c42..7069457 100644
--- a/test/merge.test.js
+++ b/test/merge.test.js
@@ -1,22 +1,22 @@
-import { test } from 'tap';
+import { test } from 'node:test';
+import { strict as assert } from 'node:assert';
import * as Diff3 from '../index.mjs';
-test('merge', t => {
+test('merge', async t => {
- t.test('returns conflict: false if no conflicts', t => {
+ await t.test('returns conflict: false if no conflicts', t => {
const o = ['AA'];
const a = ['AA'];
const b = ['AA'];
const expected = ['AA'];
const r = Diff3.merge(a, o, b);
- t.notOk(r.conflict);
- t.same(r.result, expected);
- t.end();
+ assert.equal(r.conflict, false);
+ assert.deepEqual(r.result, expected);
});
- t.test('returns a diff3-style merge result', t => {
+ await t.test('returns a diff3-style merge result', t => {
const o = ['AA', 'ZZ', '00', 'M', '99'];
const a = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
const b = ['AA', 'a', 'd', 'c', 'ZZ', '11', 'M', 'z', 'z', '99'];
@@ -47,13 +47,12 @@ test('merge', t => {
];
const r = Diff3.merge(a, o, b);
- t.ok(r.conflict);
- t.same(r.result, expected);
- t.end();
+ assert.equal(r.conflict, true);
+ assert.deepEqual(r.result, expected);
});
- t.test('yaml comparison - issue #46', t => {
+ await t.test('yaml comparison - issue #46', t => {
const o = `title: "title"
description: "description"`;
const a = `title: "title"
@@ -71,10 +70,8 @@ description: "description"`;
];
const r = Diff3.merge(a, o, b, { stringSeparator: /[\r\n]+/ });
- t.ok(r.conflict);
- t.same(r.result, expected);
- t.end();
+ assert.equal(r.conflict, true);
+ assert.deepEqual(r.result, expected);
});
- t.end();
});
diff --git a/test/mergeDiff3.test.js b/test/mergeDiff3.test.js
index 2f8dd68..46fbd3c 100644
--- a/test/mergeDiff3.test.js
+++ b/test/mergeDiff3.test.js
@@ -1,22 +1,22 @@
-import { test } from 'tap';
+import { test } from 'node:test';
+import { strict as assert } from 'node:assert';
import * as Diff3 from '../index.mjs';
-test('mergeDiff3', t => {
+test('mergeDiff3', async t => {
- t.test('returns conflict: false if no conflicts', t => {
+ await t.test('returns conflict: false if no conflicts', t => {
const o = ['AA'];
const a = ['AA'];
const b = ['AA'];
const expected = ['AA'];
const r = Diff3.mergeDiff3(a, o, b);
- t.notOk(r.conflict);
- t.same(r.result, expected);
- t.end();
+ assert.equal(r.conflict, false);
+ assert.deepEqual(r.result, expected);
});
- t.test('performs merge diff3 on arrays', t => {
+ await t.test('performs merge diff3 on arrays', t => {
const o = ['AA', 'ZZ', '00', 'M', '99'];
const a = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
const b = ['AA', 'a', 'd', 'c', 'ZZ', '11', 'M', 'z', 'z', '99'];
@@ -50,9 +50,8 @@ test('mergeDiff3', t => {
];
const r = Diff3.mergeDiff3(a, o, b, { label: { a: 'a', o: 'o', b: 'b' } });
- t.ok(r.conflict);
- t.same(r.result, expected);
- t.end();
+ assert.equal(r.conflict, true);
+ assert.deepEqual(r.result, expected);
});
@@ -77,10 +76,8 @@ description: "description"`;
];
const r = Diff3.mergeDiff3(a, o, b, { label: { a: 'a', o: 'o', b: 'b' }, stringSeparator: /[\r\n]+/ });
- t.ok(r.conflict);
- t.same(r.result, expected);
- t.end();
+ assert.equal(r.conflict, true);
+ assert.deepEqual(r.result, expected);
});
- t.end();
});
diff --git a/test/mergeDigIn.test.js b/test/mergeDigIn.test.js
index 0e00da1..8ee36ac 100644
--- a/test/mergeDigIn.test.js
+++ b/test/mergeDigIn.test.js
@@ -1,22 +1,22 @@
-import { test } from 'tap';
+import { test } from 'node:test';
+import { strict as assert } from 'node:assert';
import * as Diff3 from '../index.mjs';
-test('mergeDigIn', t => {
+test('mergeDigIn', async t => {
- t.test('returns conflict: false if no conflicts', t => {
+ await t.test('returns conflict: false if no conflicts', t => {
const o = ['AA'];
const a = ['AA'];
const b = ['AA'];
const expected = ['AA'];
const r = Diff3.mergeDigIn(a, o, b);
- t.notOk(r.conflict);
- t.same(r.result, expected);
- t.end();
+ assert.equal(r.conflict, false);
+ assert.deepEqual(r.result, expected);
});
- t.test('returns a digin-style merge result', t => {
+ await t.test('returns a digin-style merge result', t => {
const o = ['AA', 'ZZ', '00', 'M', '99'];
const a = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
const b = ['AA', 'a', 'd', 'c', 'ZZ', '11', 'M', 'z', 'z', '99'];
@@ -45,10 +45,8 @@ test('mergeDigIn', t => {
];
const r = Diff3.mergeDigIn(a, o, b);
- t.ok(r.conflict);
- t.same(r.result, expected);
- t.end();
+ assert.equal(r.conflict, true);
+ assert.deepEqual(r.result, expected);
});
- t.end();
});