Skip to content

Commit

Permalink
treat $$ as a reserved token that sits on its own line (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimfeld authored Dec 5, 2023
1 parent 0f753f9 commit addc725
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,4 +1415,23 @@ mod tests {

assert_eq!(format(input, &QueryParams::None, options), expected);
}

#[test]
fn it_keeps_double_dollar_signs_together() {
let input = "CREATE FUNCTION abc() AS $$ SELECT * FROM table $$ LANGUAGE plpgsql;";
let options = FormatOptions::default();
let expected = indoc!(
"
CREATE FUNCTION abc() AS
$$
SELECT
*
FROM
table
$$
LANGUAGE plpgsql;"
);

assert_eq!(format(input, &QueryParams::None, options), expected);
}
}
1 change: 1 addition & 0 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ fn get_top_level_reserved_token_no_indent(input: &str) -> IResult<&str, Token<'_
terminated(tag("MINUS"), end_of_word),
terminated(tag("UNION"), end_of_word),
terminated(tag("UNION ALL"), end_of_word),
terminated(tag("$$"), end_of_word),
))(&uc_input);
if let Ok((_, token)) = result {
let final_word = token.split(' ').last().unwrap();
Expand Down

0 comments on commit addc725

Please sign in to comment.