@@ -136,66 +136,67 @@ describe('dedentBlockStringLines', () => {
136136} ) ;
137137
138138describe ( 'printBlockString' , ( ) => {
139- function expectBlockString ( str : string , preferMultipleLines ?: boolean ) {
140- return expect ( printBlockString ( str , preferMultipleLines ) ) ;
139+ function expectBlockString ( str : string ) {
140+ return {
141+ toEqual ( expected : string | { readable : string ; minimize : string } ) {
142+ const { readable, minimize } =
143+ typeof expected === 'string'
144+ ? { readable : expected , minimize : expected }
145+ : expected ;
146+
147+ expect ( printBlockString ( str ) ) . to . equal ( readable ) ;
148+ expect ( printBlockString ( str , { minimize : true } ) ) . to . equal ( minimize ) ;
149+ } ,
150+ } ;
141151 }
142152
143153 it ( 'do not escape characters' , ( ) => {
144154 const str = '" \\ / \b \f \n \r \t' ;
145- expectBlockString ( str ) . to . equal ( '"""\n' + str + '\n"""' ) ;
155+ expectBlockString ( str ) . toEqual ( {
156+ readable : '"""\n' + str + '\n"""' ,
157+ minimize : '"""\n' + str + '"""' ,
158+ } ) ;
146159 } ) ;
147160
148161 it ( 'by default print block strings as single line' , ( ) => {
149162 const str = 'one liner' ;
150- expectBlockString ( str ) . to . equal ( '"""one liner"""' ) ;
151- expectBlockString ( str , true ) . to . equal ( '"""\none liner\n"""' ) ;
152- expectBlockString ( str , false ) . to . equal ( '"""one liner"""' ) ;
163+ expectBlockString ( str ) . toEqual ( '"""one liner"""' ) ;
153164 } ) ;
154165
155166 it ( 'by default print block strings ending with triple quotation as multi-line' , ( ) => {
156167 const str = 'triple quotation """' ;
157- expectBlockString ( str ) . to . equal ( '"""\ntriple quotation \\"""\n"""' ) ;
158- expectBlockString ( str , true ) . to . equal ( '"""\ntriple quotation \\"""\n"""' ) ;
159- expectBlockString ( str , false ) . to . equal ( '"""triple quotation \\""""""' ) ;
168+ expectBlockString ( str ) . toEqual ( {
169+ readable : '"""\ntriple quotation \\"""\n"""' ,
170+ minimize : '"""triple quotation \\""""""' ,
171+ } ) ;
160172 } ) ;
161173
162174 it ( 'correctly prints single-line with leading space' , ( ) => {
163175 const str = ' space-led string' ;
164- expectBlockString ( str ) . to . equal ( '""" space-led string"""' ) ;
165- expectBlockString ( str , true ) . to . equal ( '""" space-led string\n"""' ) ;
166- expectBlockString ( str , false ) . to . equal ( '""" space-led string"""' ) ;
176+ expectBlockString ( str ) . toEqual ( '""" space-led string"""' ) ;
167177 } ) ;
168178
169179 it ( 'correctly prints single-line with leading space and trailing quotation' , ( ) => {
170180 const str = ' space-led value "quoted string"' ;
171-
172- expectBlockString ( str ) . to . equal (
173- '""" space-led value "quoted string"\n"""' ,
174- ) ;
175-
176- expectBlockString ( str , true ) . to . equal (
177- '""" space-led value "quoted string"\n"""' ,
178- ) ;
179-
180- expectBlockString ( str , false ) . to . equal (
181+ expectBlockString ( str ) . toEqual (
181182 '""" space-led value "quoted string"\n"""' ,
182183 ) ;
183184 } ) ;
184185
185186 it ( 'correctly prints single-line with trailing backslash' , ( ) => {
186187 const str = 'backslash \\' ;
187-
188- expectBlockString ( str ) . to . equal ( '"""\nbackslash \\\n"""' ) ;
189- expectBlockString ( str , true ) . to . equal ( '"""\nbackslash \\\n"""' ) ;
190- expectBlockString ( str , false ) . to . equal ( '"""backslash \\\n"""' ) ;
188+ expectBlockString ( str ) . toEqual ( {
189+ readable : '"""\nbackslash \\\n"""' ,
190+ minimize : '"""backslash \\\n"""' ,
191+ } ) ;
191192 } ) ;
192193
193194 it ( 'correctly prints multi-line with internal indent' , ( ) => {
194195 const str = 'no indent\n with indent' ;
195-
196- expectBlockString ( str ) . to . equal ( '"""\nno indent\n with indent\n"""' ) ;
197- expectBlockString ( str , true ) . to . equal ( '"""\nno indent\n with indent\n """' ) ;
198- expectBlockString ( str , false ) . to . equal ( '"""\nno indent\n with indent"""' ) ;
196+ expectBlockString ( str ) . toEqual ( {
197+ readable : '"""\nno indent\n with indent\n"""' ,
198+ minimize : '"""\nno indent\n with indent"""' ,
199+ } ) ;
199200 } ) ;
200201
201202 it ( 'correctly prints string with a first line indentation' , ( ) => {
@@ -206,15 +207,21 @@ describe('printBlockString', () => {
206207 ' string' ,
207208 ) ;
208209
209- expectBlockString ( str ) . to . equal (
210- joinLines (
210+ expectBlockString ( str ) . toEqual ( {
211+ readable : joinLines (
211212 '"""' ,
212213 ' first ' ,
213214 ' line ' ,
214215 'indentation' ,
215216 ' string' ,
216217 '"""' ,
217218 ) ,
218- ) ;
219+ minimize : joinLines (
220+ '""" first ' ,
221+ ' line ' ,
222+ 'indentation' ,
223+ ' string"""' ,
224+ ) ,
225+ } ) ;
219226 } ) ;
220227} ) ;
0 commit comments