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