From 0e5cafa140080674434f90e804f3ffcd0b2018bf Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Tue, 12 Sep 2023 09:28:17 -0400 Subject: [PATCH] Add unit test for multiple occurrences in the same node --- test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test.js b/test.js index 240b431..4ef550f 100644 --- a/test.js +++ b/test.js @@ -464,6 +464,28 @@ test('findAndReplace', async function (t) { ]) ) }) + + await t.test( + 'should replace multiple matches in the same node', + async function () { + const tree = create() + + findAndReplace(tree, [/(emph|sis)/g, 'foo']) + + assert.deepEqual( + tree, + u('paragraph', [ + u('text', 'Some '), + u('emphasis', [u('text', 'foo'), u('text', 'a'), u('text', 'foo')]), + u('text', ', '), + u('strong', [u('text', 'importance')]), + u('text', ', and '), + u('inlineCode', 'code'), + u('text', '.') + ]) + ) + } + ) }) function create() {