Skip to content

Commit 33e2c49

Browse files
webzwo0irhansen
authored andcommitted
easysync tests: add some more smartOpAssembler tests
1 parent 8cdd474 commit 33e2c49

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

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

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,171 @@ describe('easysync', function () {
2121
expect(assem.toString()).to.equal(x);
2222
});
2323

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

0 commit comments

Comments
 (0)