easysync tests: add some more smartOpAssembler tests

This commit is contained in:
webzwo0i 2021-10-20 16:29:03 +02:00 committed by Richard Hansen
parent 12ebca897d
commit 55c47efd4c
1 changed files with 132 additions and 0 deletions

View File

@ -1,6 +1,7 @@
'use strict';
const Changeset = require('../../../static/js/Changeset');
const {poolOrArray} = require('../easysync-helper.js');
describe('easysync-assembler', function () {
it('opAssembler', async function () {
@ -18,6 +19,137 @@ describe('easysync-assembler', function () {
expect(assem.toString()).to.equal(x);
});
it('smartOpAssembler ignore additional pure keeps (no attributes)', async function () {
const x = '-c*3*4+6|1+1=5';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('-c*3*4+6|1+1');
});
it('smartOpAssembler merge consecutive + ops without multiline', async function () {
const x = '-c*3*4+6*3*4+1*3*4+9=5';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('-c*3*4+g');
});
it('smartOpAssembler merge consecutive + ops with multiline', async function () {
const x = '-c*3*4+6*3*4|1+1*3*4|9+f*3*4+k=5';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('-c*3*4|a+m*3*4+k');
});
it('smartOpAssembler merge consecutive - ops without multiline', async function () {
const x = '-c-6-1-9=5';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('-s');
});
it('smartOpAssembler merge consecutive - ops with multiline', async function () {
const x = '-c-6|1-1|9-f-k=5';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('|a-y-k');
});
it('smartOpAssembler merge consecutive = ops without multiline', async function () {
const x = '-c*3*4=6*2*4=1*3*4=f*3*4=2*3*4=a=k=5';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('-c*3*4=6*2*4=1*3*4=r');
});
it('smartOpAssembler merge consecutive = ops with multiline', async function () {
const x = '-c*3*4=6*2*4|1=1*3*4|9=f*3*4|2=2*3*4=a*3*4=1=k=5';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('-c*3*4=6*2*4|1=1*3*4|b=h*3*4=b');
});
it('smartOpAssembler ignore + ops with ops.chars === 0', async function () {
const x = '-c*3*4+6*3*4+0*3*4+1+0*3*4+1';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('-c*3*4+8');
});
it('smartOpAssembler ignore - ops with ops.chars === 0', async function () {
const x = '-c-6-0-1-0-1';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('-k');
});
it('smartOpAssembler append + op with text', async function () {
const assem = Changeset.smartOpAssembler();
const pool = poolOrArray([
'attr1,1',
'attr2,2',
'attr3,3',
'attr4,4',
'attr5,5',
]);
assem.appendOpWithText('+', 'test', '*3*4*5', pool);
assem.appendOpWithText('+', 'test', '*3*4*5', pool);
assem.appendOpWithText('+', 'test', '*1*4*5', pool);
assem.endDocument();
expect(assem.toString()).to.equal('*3*4*5+8*1*4*5+4');
});
it('smartOpAssembler append + op with multiline text', async function () {
const assem = Changeset.smartOpAssembler();
const pool = poolOrArray([
'attr1,1',
'attr2,2',
'attr3,3',
'attr4,4',
'attr5,5',
]);
assem.appendOpWithText('+', 'test\ntest', '*3*4*5', pool);
assem.appendOpWithText('+', '\ntest\n', '*3*4*5', pool);
assem.appendOpWithText('+', '\ntest', '*1*4*5', pool);
assem.endDocument();
expect(assem.toString()).to.equal('*3*4*5|3+f*1*4*5|1+1*1*4*5+4');
});
it('smartOpAssembler clear should empty internal assemblers', async function () {
const x = '-c*3*4+6|3=az*asdf0*1*2*3+1=1-1+1*0+1=1-1+1|c=c-1';
const iter = Changeset.opIterator(x);
const assem = Changeset.smartOpAssembler();
assem.append(iter.next());
assem.append(iter.next());
assem.append(iter.next());
assem.clear();
assem.append(iter.next());
assem.append(iter.next());
assem.clear();
while (iter.hasNext()) assem.append(iter.next());
assem.endDocument();
expect(assem.toString()).to.equal('-1+1*0+1=1-1+1|c=c-1');
});
describe('append atext to assembler', function () {
const testAppendATextToAssembler = (testId, atext, correctOps) => {
it(`testAppendATextToAssembler#${testId}`, async function () {