@@ -129,3 +129,67 @@ describe('CQLTestResults.validateSchema', () => {
129129 expect ( ResultsValidator ) . toHaveBeenCalled ( ) ;
130130 } ) ;
131131} ) ;
132+
133+ describe ( 'CQLTestResults.toJSON actual serialization' , ( ) => {
134+ it ( 'renders list results in CQL list syntax and stringifies scalar results' , ( ) => {
135+ const results = new CQLTestResults ( new CQLEngine ( 'http://localhost:8080/fhir/$cql' ) ) ;
136+ results . add ( {
137+ testsName : 'CqlListOperatorsTest' ,
138+ groupName : 'Sort' ,
139+ testName : 'SortDatesAsc' ,
140+ expression : 'sort asc' ,
141+ testStatus : 'fail' ,
142+ invalid : 'false' ,
143+ actual : [ '@2012-01-01T' , '@2012-01-01T12' ] ,
144+ expected : '{ @2012-01-01T, @2012-01-01T12 }' ,
145+ } as any ) ;
146+ results . add ( {
147+ testsName : 'CqlArithmeticFunctionsTest' ,
148+ groupName : 'Power' ,
149+ testName : 'Power2To4' ,
150+ expression : '2^4' ,
151+ testStatus : 'pass' ,
152+ invalid : 'false' ,
153+ actual : 16 ,
154+ expected : '16' ,
155+ } as any ) ;
156+
157+ const json = results . toJSON ( ) ;
158+ expect ( json . results [ 0 ] . actual ) . toBe ( '{ @2012-01-01T, @2012-01-01T12 }' ) ;
159+ expect ( json . results [ 1 ] . actual ) . toBe ( '16' ) ;
160+ } ) ;
161+
162+ it ( 'equalizeValueTypes renders array actuals in CQL list syntax' , ( ) => {
163+ const results = new CQLTestResults ( new CQLEngine ( 'http://localhost:8080/fhir/$cql' ) ) ;
164+ results . add ( {
165+ testsName : 'T' ,
166+ groupName : 'G' ,
167+ testName : 'N' ,
168+ expression : 'e' ,
169+ testStatus : 'pass' ,
170+ invalid : 'false' ,
171+ actual : [ 1 , 2 , 3 ] ,
172+ expected : '{ 1, 2, 3 }' ,
173+ } as any ) ;
174+
175+ results . equalizeValueTypes ( ) ;
176+ expect ( results . results [ 0 ] . actual ) . toBe ( '{ 1, 2, 3 }' ) ;
177+ } ) ;
178+
179+ it ( 'renders nested lists and empty lists' , ( ) => {
180+ const results = new CQLTestResults ( new CQLEngine ( 'http://localhost:8080/fhir/$cql' ) ) ;
181+ results . add ( {
182+ testsName : 'T' ,
183+ groupName : 'G' ,
184+ testName : 'Nested' ,
185+ expression : 'e' ,
186+ testStatus : 'pass' ,
187+ invalid : 'false' ,
188+ actual : [ [ 1 , 2 ] , [ ] ] ,
189+ expected : '{ { 1, 2 }, {} }' ,
190+ } as any ) ;
191+
192+ const json = results . toJSON ( ) ;
193+ expect ( json . results [ 0 ] . actual ) . toBe ( '{ { 1, 2 }, {} }' ) ;
194+ } ) ;
195+ } ) ;
0 commit comments