Skip to content

Commit 1ef577a

Browse files
committed
easysync tests: add some more smartOpAssembler tests
1 parent 29048f9 commit 1ef577a

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
@@ -2,6 +2,7 @@
22

33
const Changeset = require('../../../static/js/Changeset');
44
const expect = require('../../../tests/frontend/lib/expect');
5+
const {poolOrArray} = require('./easysync-helper.js');
56

67
describe('easysync', function () {
78
it('opAssembler', async function () {
@@ -21,6 +22,171 @@ describe('easysync', function () {
2122
expect(assem.toString()).to.equal(x);
2223
});
2324

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

0 commit comments

Comments
 (0)