Skip to content

Commit 44ee05a

Browse files
committed
Review feedback
Signed-off-by: Andrew Lamb <[email protected]>
1 parent 6f49f29 commit 44ee05a

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

sqllogictest/src/parser.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub enum Record {
132132
},
133133
Condition(Condition),
134134
Comment(Vec<String>),
135-
Whitespace(String),
135+
Newline,
136136
/// Internally injected record which should not occur in the test file.
137137
Injected(Injected),
138138
}
@@ -147,6 +147,9 @@ impl Record {
147147
}
148148
}
149149

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.
150153
impl std::fmt::Display for Record {
151154
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152155
match self {
@@ -174,7 +177,8 @@ impl std::fmt::Display for Record {
174177
(Some(_), Some(_)) => unreachable!(),
175178
}
176179
writeln!(f)?;
177-
write!(f, "{}", sql)
180+
// statement always end with a blank line
181+
writeln!(f, "{}", sql)
178182
}
179183
Record::Query {
180184
loc: _,
@@ -189,7 +193,7 @@ impl std::fmt::Display for Record {
189193
write!(f, "query")?;
190194
if let Some(err) = expected_error {
191195
writeln!(f, " error {}", err)?;
192-
return write!(f, "{}", sql);
196+
return writeln!(f, "{}", sql);
193197
}
194198

195199
write!(
@@ -210,7 +214,8 @@ impl std::fmt::Display for Record {
210214
for result in expected_results {
211215
write!(f, "\n{}", result)?;
212216
}
213-
Ok(())
217+
// query always ends with a blank line
218+
writeln!(f)
214219
}
215220
Record::Sleep { loc: _, duration } => {
216221
write!(f, "sleep {}", humantime::format_duration(*duration))
@@ -243,9 +248,7 @@ impl std::fmt::Display for Record {
243248
}
244249
Ok(())
245250
}
246-
Record::Whitespace(w) => {
247-
write!(f, "{}", w)
248-
}
251+
Record::Newline => Ok(()), // Display doesn't end with newline
249252
Record::Injected(p) => panic!("unexpected injected record: {:?}", p),
250253
}
251254
}
@@ -401,7 +404,7 @@ fn parse_inner(loc: &Location, script: &str) -> Result<Vec<Record>, ParseError>
401404
}
402405

403406
if line.is_empty() {
404-
records.push(Record::Whitespace(line.to_string()));
407+
records.push(Record::Newline);
405408
continue;
406409
}
407410

@@ -641,7 +644,7 @@ mod tests {
641644

642645
let unparsed = records
643646
.iter()
644-
.map(record_to_string)
647+
.map(|record| record.to_string())
645648
.collect::<Vec<_>>();
646649

647650
// Technically this will not always be the same due to some whitespace normalization
@@ -678,17 +681,6 @@ mod tests {
678681
);
679682
}
680683

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-
692684
/// returns true if there are no differences in the changeset
693685
fn no_diffs(changeset: &Changeset) -> bool {
694686
changeset

sqllogictest/src/runner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<D: AsyncDB> Runner<D> {
546546
}
547547
Record::Include { .. }
548548
| Record::Comment(_)
549-
| Record::Whitespace(_)
549+
| Record::Newline
550550
| Record::Subtest { .. }
551551
| Record::Halt { .. }
552552
| Record::Injected(_)

0 commit comments

Comments
 (0)