@@ -132,7 +132,7 @@ pub enum Record {
132
132
} ,
133
133
Condition ( Condition ) ,
134
134
Comment ( Vec < String > ) ,
135
- Whitespace ( String ) ,
135
+ Newline ,
136
136
/// Internally injected record which should not occur in the test file.
137
137
Injected ( Injected ) ,
138
138
}
@@ -147,6 +147,9 @@ impl Record {
147
147
}
148
148
}
149
149
150
+ /// As is the standard for Display, does not print any trailing
151
+ /// newline except for records that always end with a blank line such
152
+ /// as Query and Statement.
150
153
impl std:: fmt:: Display for Record {
151
154
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
152
155
match self {
@@ -174,7 +177,8 @@ impl std::fmt::Display for Record {
174
177
( Some ( _) , Some ( _) ) => unreachable ! ( ) ,
175
178
}
176
179
writeln ! ( f) ?;
177
- write ! ( f, "{}" , sql)
180
+ // statement always end with a blank line
181
+ writeln ! ( f, "{}" , sql)
178
182
}
179
183
Record :: Query {
180
184
loc : _,
@@ -189,7 +193,7 @@ impl std::fmt::Display for Record {
189
193
write ! ( f, "query" ) ?;
190
194
if let Some ( err) = expected_error {
191
195
writeln ! ( f, " error {}" , err) ?;
192
- return write ! ( f, "{}" , sql) ;
196
+ return writeln ! ( f, "{}" , sql) ;
193
197
}
194
198
195
199
write ! (
@@ -210,7 +214,8 @@ impl std::fmt::Display for Record {
210
214
for result in expected_results {
211
215
write ! ( f, "\n {}" , result) ?;
212
216
}
213
- Ok ( ( ) )
217
+ // query always ends with a blank line
218
+ writeln ! ( f)
214
219
}
215
220
Record :: Sleep { loc : _, duration } => {
216
221
write ! ( f, "sleep {}" , humantime:: format_duration( * duration) )
@@ -243,9 +248,7 @@ impl std::fmt::Display for Record {
243
248
}
244
249
Ok ( ( ) )
245
250
}
246
- Record :: Whitespace ( w) => {
247
- write ! ( f, "{}" , w)
248
- }
251
+ Record :: Newline => Ok ( ( ) ) , // Display doesn't end with newline
249
252
Record :: Injected ( p) => panic ! ( "unexpected injected record: {:?}" , p) ,
250
253
}
251
254
}
@@ -401,7 +404,7 @@ fn parse_inner(loc: &Location, script: &str) -> Result<Vec<Record>, ParseError>
401
404
}
402
405
403
406
if line. is_empty ( ) {
404
- records. push ( Record :: Whitespace ( line . to_string ( ) ) ) ;
407
+ records. push ( Record :: Newline ) ;
405
408
continue ;
406
409
}
407
410
@@ -641,7 +644,7 @@ mod tests {
641
644
642
645
let unparsed = records
643
646
. iter ( )
644
- . map ( record_to_string )
647
+ . map ( |record| record . to_string ( ) )
645
648
. collect :: < Vec < _ > > ( ) ;
646
649
647
650
// Technically this will not always be the same due to some whitespace normalization
@@ -678,17 +681,6 @@ mod tests {
678
681
) ;
679
682
}
680
683
681
- fn record_to_string ( record : Record ) -> String {
682
- if matches ! ( & record, Record :: Statement { .. } | Record :: Query { .. } ) {
683
- // the statement parser includes a newline between the items but the display
684
- // output does not, so add it here
685
- // Not sure about this one
686
- format ! ( "{}\n " , record)
687
- } else {
688
- record. to_string ( )
689
- }
690
- }
691
-
692
684
/// returns true if there are no differences in the changeset
693
685
fn no_diffs ( changeset : & Changeset ) -> bool {
694
686
changeset
0 commit comments