From 085dda4cbda260d05c0a089be4a48b30bc5fd8c2 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Thu, 14 Oct 2021 16:09:23 +0200 Subject: [PATCH] fix formatting test case #326 --- tests/encoding.tests.js | 25 ------------------------- tests/y-text.tests.js | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/encoding.tests.js b/tests/encoding.tests.js index 4c370ea2..6a191009 100644 --- a/tests/encoding.tests.js +++ b/tests/encoding.tests.js @@ -106,28 +106,3 @@ export const testDiffStateVectorOfUpdateIgnoresSkips = tc => { t.assert(state.get(ydoc.clientID) === 1) t.assert(state.size === 1) } - -/** - * Encode a document with a text and decode it into a new document. Then, test if - * the same change to both documents results in the same text deltas. - * - * @param {t.TestCase} tc - */ -export const testEncodeDecode = async tc => { - const ydoc1 = new Doc() - const ydoc2 = new Doc() - const text1 = ydoc1.getText() - text1.insert(0, "\n\n\n") - text1.format(0, 3, { url: 'http://example.com' }); - applyUpdate(ydoc2, encodeStateAsUpdate(ydoc1)) - ydoc1.getText().format(1, 1, { url: 'http://docs.yjs.dev' }); - ydoc2.getText().format(1, 1, { url: 'http://docs.yjs.dev' }); - const text2 = ydoc2.getText() - const expectedResult = [ - { insert: '\n', attributes: { url: 'http://example.com' } }, - { insert: '\n', attributes: { url: 'http://docs.yjs.dev' } }, - { insert: '\n', attributes: { url: 'http://example.com' } } - ] - t.compare(text1.toDelta(), expectedResult) - t.compare(text1.toDelta(), text2.toDelta()) -} diff --git a/tests/y-text.tests.js b/tests/y-text.tests.js index 159971a1..100d619a 100644 --- a/tests/y-text.tests.js +++ b/tests/y-text.tests.js @@ -516,6 +516,31 @@ export const testSearchMarkerBug1 = tc => { compare(users) } +/** + * Reported in https://github.com/yjs/yjs/pull/32 + * + * @param {t.TestCase} tc + */ +export const testFormattingBug = async tc => { + const ydoc1 = new Y.Doc() + const ydoc2 = new Y.Doc() + const text1 = ydoc1.getText() + text1.insert(0, '\n\n\n') + text1.format(0, 3, { url: 'http://example.com' }) + ydoc1.getText().format(1, 1, { url: 'http://docs.yjs.dev' }) + ydoc2.getText().format(1, 1, { url: 'http://docs.yjs.dev' }) + Y.applyUpdate(ydoc2, Y.encodeStateAsUpdate(ydoc1)) + const text2 = ydoc2.getText() + const expectedResult = [ + { insert: '\n', attributes: { url: 'http://example.com' } }, + { insert: '\n', attributes: { url: 'http://docs.yjs.dev' } }, + { insert: '\n', attributes: { url: 'http://example.com' } } + ] + t.compare(text1.toDelta(), expectedResult) + t.compare(text1.toDelta(), text2.toDelta()) + console.log(text1.toDelta()) +} + // RANDOM TESTS let charCounter = 0