Skip to content

Commit e298643

Browse files
committed
easysync tests: add some more smartOpAssembler tests
1 parent b5e0635 commit e298643

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

src/tests/frontend/specs/easysync-assembler.js

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const Changeset = require('../../../static/js/Changeset');
4+
const {poolOrArray} = require('../easysync-helper.js');
45

56
describe('easysync-assembler', function () {
67
it('opAssembler', async function () {
@@ -18,6 +19,171 @@ describe('easysync-assembler', function () {
1819
expect(assem.toString()).to.equal(x);
1920
});
2021

22+
it('smartOpAssembler ignore additional pure keeps (no attributes)', async function () {
23+
const x = '-c*3*4+6|1+1=5';
24+
const iter = Changeset.opIterator(x);
25+
const assem = Changeset.smartOpAssembler();
26+
while (iter.hasNext()) assem.append(iter.next());
27+
assem.endDocument();
28+
expect(assem.toString()).to.equal('-c*3*4+6|1+1');
29+
});
30+
31+
it('smartOpAssembler merge consecutive + ops without multiline', async function () {
32+
const x = '-c*3*4+6*3*4+1*3*4+9=5';
33+
const iter = Changeset.opIterator(x);
34+
const assem = Changeset.smartOpAssembler();
35+
while (iter.hasNext()) assem.append(iter.next());
36+
assem.endDocument();
37+
expect(assem.toString()).to.equal('-c*3*4+g');
38+
});
39+
40+
it('smartOpAssembler merge consecutive + ops with multiline', async function () {
41+
const x = '-c*3*4+6*3*4|1+1*3*4|9+f*3*4+k=5';
42+
const iter = Changeset.opIterator(x);
43+
const assem = Changeset.smartOpAssembler();
44+
while (iter.hasNext()) assem.append(iter.next());
45+
assem.endDocument();
46+
expect(assem.toString()).to.equal('-c*3*4|a+m*3*4+k');
47+
});
48+
49+
it('smartOpAssembler merge consecutive - ops without multiline', async function () {
50+
const x = '-c-6-1-9=5';
51+
const iter = Changeset.opIterator(x);
52+
const assem = Changeset.smartOpAssembler();
53+
while (iter.hasNext()) assem.append(iter.next());
54+
assem.endDocument();
55+
expect(assem.toString()).to.equal('-s');
56+
});
57+
58+
it('smartOpAssembler merge consecutive - ops with multiline', async function () {
59+
const x = '-c-6|1-1|9-f-k=5';
60+
const iter = Changeset.opIterator(x);
61+
const assem = Changeset.smartOpAssembler();
62+
while (iter.hasNext()) assem.append(iter.next());
63+
assem.endDocument();
64+
expect(assem.toString()).to.equal('|a-y-k');
65+
});
66+
67+
it('smartOpAssembler merge consecutive = ops without multiline', async function () {
68+
const x = '-c*3*4=6*2*4=1*3*4=f*3*4=2*3*4=a=k=5';
69+
const iter = Changeset.opIterator(x);
70+
const assem = Changeset.smartOpAssembler();
71+
while (iter.hasNext()) assem.append(iter.next());
72+
assem.endDocument();
73+
expect(assem.toString()).to.equal('-c*3*4=6*2*4=1*3*4=r');
74+
});
75+
76+
it('smartOpAssembler merge consecutive = ops with multiline', async function () {
77+
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';
78+
const iter = Changeset.opIterator(x);
79+
const assem = Changeset.smartOpAssembler();
80+
while (iter.hasNext()) assem.append(iter.next());
81+
assem.endDocument();
82+
expect(assem.toString()).to.equal('-c*3*4=6*2*4|1=1*3*4|b=h*3*4=b');
83+
});
84+
85+
it('smartOpAssembler ignore + ops with ops.chars === 0', async function () {
86+
const x = '-c*3*4+6*3*4+0*3*4+1+0*3*4+1';
87+
const iter = Changeset.opIterator(x);
88+
const assem = Changeset.smartOpAssembler();
89+
while (iter.hasNext()) assem.append(iter.next());
90+
assem.endDocument();
91+
expect(assem.toString()).to.equal('-c*3*4+8');
92+
});
93+
94+
it('smartOpAssembler ignore - ops with ops.chars === 0', async function () {
95+
const x = '-c-6-0-1-0-1';
96+
const iter = Changeset.opIterator(x);
97+
const assem = Changeset.smartOpAssembler();
98+
while (iter.hasNext()) assem.append(iter.next());
99+
assem.endDocument();
100+
expect(assem.toString()).to.equal('-k');
101+
});
102+
103+
it('smartOpAssembler append - op with text', async function () {
104+
const assem = Changeset.smartOpAssembler();
105+
const pool = poolOrArray([
106+
'attr1,1',
107+
'attr2,2',
108+
'attr3,3',
109+
'attr4,4',
110+
'attr5,5',
111+
]);
112+
113+
assem.appendOpWithText('-', 'test', '*3*4*5', pool);
114+
assem.appendOpWithText('-', 'test', '*3*4*5', pool);
115+
assem.appendOpWithText('-', 'test', '*1*4*5', pool);
116+
assem.endDocument();
117+
expect(assem.toString()).to.equal('*3*4*5-8*1*4*5-4');
118+
});
119+
120+
it('smartOpAssembler append - op with multiline text', async function () {
121+
const assem = Changeset.smartOpAssembler();
122+
const pool = poolOrArray([
123+
'attr1,1',
124+
'attr2,2',
125+
'attr3,3',
126+
'attr4,4',
127+
'attr5,5',
128+
]);
129+
130+
assem.appendOpWithText('-', 'test\ntest', '*3*4*5', pool);
131+
assem.appendOpWithText('-', '\ntest\n', '*3*4*5', pool);
132+
assem.appendOpWithText('-', '\ntest', '*1*4*5', pool);
133+
assem.endDocument();
134+
expect(assem.toString()).to.equal('*3*4*5|3-f*1*4*5|1-1*1*4*5-4');
135+
});
136+
137+
it('smartOpAssembler append + op with text', async function () {
138+
const assem = Changeset.smartOpAssembler();
139+
const pool = poolOrArray([
140+
'attr1,1',
141+
'attr2,2',
142+
'attr3,3',
143+
'attr4,4',
144+
'attr5,5',
145+
]);
146+
147+
assem.appendOpWithText('+', 'test', '*3*4*5', pool);
148+
assem.appendOpWithText('+', 'test', '*3*4*5', pool);
149+
assem.appendOpWithText('+', 'test', '*1*4*5', pool);
150+
assem.endDocument();
151+
expect(assem.toString()).to.equal('*3*4*5+8*1*4*5+4');
152+
});
153+
154+
it('smartOpAssembler append + op with multiline text', async function () {
155+
const assem = Changeset.smartOpAssembler();
156+
const pool = poolOrArray([
157+
'attr1,1',
158+
'attr2,2',
159+
'attr3,3',
160+
'attr4,4',
161+
'attr5,5',
162+
]);
163+
164+
assem.appendOpWithText('+', 'test\ntest', '*3*4*5', pool);
165+
assem.appendOpWithText('+', '\ntest\n', '*3*4*5', pool);
166+
assem.appendOpWithText('+', '\ntest', '*1*4*5', pool);
167+
assem.endDocument();
168+
expect(assem.toString()).to.equal('*3*4*5|3+f*1*4*5|1+1*1*4*5+4');
169+
});
170+
171+
it('smartOpAssembler clear should empty internal assemblers', async function () {
172+
const x = '-c*3*4+6|3=az*asdf0*1*2*3+1=1-1+1*0+1=1-1+1|c=c-1';
173+
const iter = Changeset.opIterator(x);
174+
const assem = Changeset.smartOpAssembler();
175+
assem.append(iter.next());
176+
assem.append(iter.next());
177+
assem.append(iter.next());
178+
assem.clear();
179+
assem.append(iter.next());
180+
assem.append(iter.next());
181+
assem.clear();
182+
while (iter.hasNext()) assem.append(iter.next());
183+
assem.endDocument();
184+
expect(assem.toString()).to.equal('-1+1*0+1=1-1+1|c=c-1');
185+
});
186+
21187
describe('append atext to assembler', function () {
22188
const testAppendATextToAssembler = (testId, atext, correctOps) => {
23189
it(`testAppendATextToAssembler#${testId}`, async function () {

0 commit comments

Comments
 (0)