Skip to content

Commit b8924af

Browse files
lu-zeroshssoichiro
authored andcommitted
Fix formatting WITH as a single line
1 parent feae8cd commit b8924af

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/formatter.rs

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ impl<'a> Formatter<'a> {
244244
query.push_str(&self.equalize_whitespace(&self.format_reserved_word(token.value)));
245245
if newline_after {
246246
self.add_new_line(query);
247+
} else {
248+
query.push(' ');
247249
}
248250
}
249251

src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,26 @@ mod tests {
20532053
assert_eq!(format(input, &QueryParams::None, &options), expected);
20542054
}
20552055

2056+
#[test]
2057+
fn format_short_with() {
2058+
let input = "WITH a AS ( SELECT a, b, c FROM t WHERE a > 100 ) SELECT b, field FROM a, aa;";
2059+
let max_line = 80;
2060+
let options = FormatOptions {
2061+
max_inline_block: max_line,
2062+
max_inline_arguments: Some(max_line),
2063+
max_inline_top_level: Some(max_line),
2064+
joins_as_top_level: true,
2065+
..Default::default()
2066+
};
2067+
let expected = indoc! {
2068+
"
2069+
WITH a AS (SELECT a, b, c FROM t WHERE a > 100)
2070+
SELECT b, field
2071+
FROM a, aa;"
2072+
};
2073+
assert_eq!(format(input, &QueryParams::None, &options), expected);
2074+
}
2075+
20562076
#[test]
20572077
fn format_nested_select_nested_blocks() {
20582078
let input =

0 commit comments

Comments
 (0)