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