Fix Display implementation for empty Groups (#1788)

This commit is contained in:
Rushmore Mushambi 2023-04-09 12:14:07 +02:00 committed by GitHub
parent 1d27273d7e
commit e075be16b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,7 +32,11 @@ impl IntoIterator for Groups {
impl Display for Groups {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "GROUP BY {}", Fmt::comma_separated(&self.0))
if self.0.is_empty() {
write!(f, "GROUP ALL")
} else {
write!(f, "GROUP BY {}", Fmt::comma_separated(&self.0))
}
}
}
@ -114,4 +118,12 @@ mod tests {
);
assert_eq!("GROUP BY field, other.field", format!("{}", out));
}
#[test]
fn group_statement_all() {
let sql = "GROUP ALL";
let out = group(sql).unwrap().1;
assert_eq!(out, Groups(Vec::new()));
assert_eq!(sql, out.to_string());
}
}