Skip to content

Commit

Permalink
fix: ON UPDATE with two many blank formatted incorrectly (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
wugeer authored Sep 6, 2024
1 parent 3b6e8e1 commit 3825b7f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ impl<'a> Formatter<'a> {

fn format_with_spaces(&self, token: &Token<'_>, query: &mut String) {
let value = if token.kind == TokenKind::Reserved {
self.format_reserved_word(token.value)
&self.equalize_whitespace(&self.format_reserved_word(token.value))
} else {
Cow::Borrowed(token.value)
token.value
};
query.push_str(&value);
query.push_str(value);
query.push(' ');
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ mod tests {
#[test]
fn it_recognizes_on_update_clause() {
let input = indoc!(
"CREATE TABLE a (b integer REFERENCES c (id) ON UPDATE RESTRICT, other integer);"
"CREATE TABLE a (b integer REFERENCES c (id) ON UPDATE RESTRICT, other integer);"
);
let options = FormatOptions::default();
let expected = indoc!(
Expand Down
3 changes: 2 additions & 1 deletion src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,8 @@ fn get_plain_reserved_two_token(input: &str) -> IResult<&str, Token<'_>> {
terminated(tag("ON UPDATE"), end_of_word),
))(&uc_input);
if let Ok((_, token)) = result {
let input_end_pos = token.len();
let final_word = token.split(' ').last().unwrap();
let input_end_pos = input.to_ascii_uppercase().find(final_word).unwrap() + final_word.len();
let (token, input) = input.split_at(input_end_pos);
Ok((
input,
Expand Down

0 comments on commit 3825b7f

Please sign in to comment.