@@ -100,81 +100,82 @@ describe('resolveAll', () => {
100100
101101describe ( 'repeat macro' , ( ) => {
102102 test ( 'repeats a simple token sequence' , ( ) => {
103- const program = parse ( '[triple_carbon] = repeat(\' [C]\' , 3)' )
103+ const program = parse ( '[triple_carbon] = repeat([C], 3)' )
104104 expect ( resolve ( program , 'triple_carbon' ) ) . toBe ( '[C][C][C]' )
105105 } )
106106
107107 test ( 'repeats a complex token sequence' , ( ) => {
108- const program = parse ( '[benzene] = repeat(\' [C][=C]\' , 3)[Ring1][=Branch1]' )
108+ const program = parse ( '[benzene] = repeat([C][=C], 3)[Ring1][=Branch1]' )
109109 expect ( resolve ( program , 'benzene' ) ) . toBe ( '[C][=C][C][=C][C][=C][Ring1][=Branch1]' )
110110 } )
111111
112112 test ( 'repeats with count of 1' , ( ) => {
113- const program = parse ( '[single] = repeat(\' [C][O]\' , 1)' )
113+ const program = parse ( '[single] = repeat([C][O], 1)' )
114114 expect ( resolve ( program , 'single' ) ) . toBe ( '[C][O]' )
115115 } )
116116
117117 test ( 'repeats with count of 0 produces empty sequence' , ( ) => {
118- const program = parse ( '[empty] = [C]repeat(\' [O]\' , 0)[C]' )
118+ const program = parse ( '[empty] = [C]repeat([O], 0)[C]' )
119119 expect ( resolve ( program , 'empty' ) ) . toBe ( '[C][C]' )
120120 } )
121121
122122 test ( 'repeat with reference to other definition' , ( ) => {
123- const source = '[unit] = [C][=C]\n[triple] = repeat(\' [unit]\' , 3)'
123+ const source = '[unit] = [C][=C]\n[triple] = repeat([unit], 3)'
124124 const program = parse ( source )
125125 expect ( resolve ( program , 'triple' ) ) . toBe ( '[C][=C][C][=C][C][=C]' )
126126 } )
127127
128128 test ( 'multiple repeat calls in one definition' , ( ) => {
129- const program = parse ( '[chain] = repeat(\' [C]\' , 2)repeat(\' [O]\' , 2)' )
129+ const program = parse ( '[chain] = repeat([C], 2)repeat([O], 2)' )
130130 expect ( resolve ( program , 'chain' ) ) . toBe ( '[C][C][O][O]' )
131131 } )
132132
133133 test ( 'repeat combined with regular tokens' , ( ) => {
134- const program = parse ( '[molecule] = [N]repeat(\' [C]\' , 3)[O]' )
134+ const program = parse ( '[molecule] = [N]repeat([C], 3)[O]' )
135135 expect ( resolve ( program , 'molecule' ) ) . toBe ( '[N][C][C][C][O]' )
136136 } )
137137
138138 test ( 'repeat with nested brackets in pattern' , ( ) => {
139- const program = parse ( '[branched] = repeat(\' [C][Branch1][C][O]\' , 2)' )
139+ const program = parse ( '[branched] = repeat([C][Branch1][C][O], 2)' )
140140 expect ( resolve ( program , 'branched' ) ) . toBe ( '[C][Branch1][C][O][C][Branch1][C][O]' )
141141 } )
142142
143143 test ( 'throws error on invalid repeat count' , ( ) => {
144- const program = parse ( '[bad] = repeat(\' [C]\' , -1)' )
144+ const program = parse ( '[bad] = repeat([C], -1)' )
145145 expect ( ( ) => resolve ( program , 'bad' ) ) . toThrow ( / c o u n t m u s t b e / )
146146 } )
147147
148148 test ( 'throws error on non-numeric count' , ( ) => {
149- const program = parse ( '[bad] = repeat(\' [C]\' , abc)' )
149+ const program = parse ( '[bad] = repeat([C], abc)' )
150150 expect ( ( ) => resolve ( program , 'bad' ) ) . toThrow ( )
151151 } )
152152
153153 test ( 'throws error on missing arguments' , ( ) => {
154- const program = parse ( '[bad] = repeat(\' [C]\' )' )
154+ const program = parse ( '[bad] = repeat([C])' )
155155 expect ( ( ) => resolve ( program , 'bad' ) ) . toThrow ( )
156156 } )
157157
158- test ( 'throws error on malformed repeat syntax' , ( ) => {
159- const program = parse ( '[bad] = repeat([C], 3)' )
160- expect ( ( ) => resolve ( program , 'bad' ) ) . toThrow ( )
158+ test ( 'throws error on empty pattern' , ( ) => {
159+ const program = parse ( '[bad] = repeat(, 3)' )
160+ // Parse error results in empty definition
161+ expect ( ( ) => resolve ( program , 'bad' ) ) . toThrow ( / n o t o k e n s / )
161162 } )
162163
163164 test ( 'simple polymer-like chain' , ( ) => {
164- const source = '[ch2] = [C]\n[polymer_chain] = repeat(\' [ch2]\' , 5)'
165+ const source = '[ch2] = [C]\n[polymer_chain] = repeat([ch2], 5)'
165166 const program = parse ( source )
166167 expect ( resolve ( program , 'polymer_chain' ) ) . toBe ( '[C][C][C][C][C]' )
167168 } )
168169
169170 test ( 'polymer chain with decode' , ( ) => {
170- const source = '[ch2] = [C]\n[polymer_chain] = repeat(\' [ch2]\' , 5)'
171+ const source = '[ch2] = [C]\n[polymer_chain] = repeat([ch2], 5)'
171172 const program = parse ( source )
172173 expect ( resolve ( program , 'polymer_chain' , { decode : true } ) ) . toBe ( 'CCCCC' )
173174 } )
174175
175176 test ( 'vinyl chloride monomer units' , ( ) => {
176177 // Each monomer as a branch structure for proper chemistry
177- const source = '[monomer] = [C][Branch1][C][Cl][C]\n[polymer] = repeat(\' [monomer]\' , 3)'
178+ const source = '[monomer] = [C][Branch1][C][Cl][C]\n[polymer] = repeat([monomer], 3)'
178179 const program = parse ( source )
179180 // This creates a branched structure: C(Cl)CC(Cl)CC(Cl)C
180181 expect ( resolve ( program , 'polymer' ) ) . toBe ( '[C][Branch1][C][Cl][C][C][Branch1][C][Cl][C][C][Branch1][C][Cl][C]' )
0 commit comments