Skip to content

Commit addc725

Browse files
authored
treat $$ as a reserved token that sits on its own line (#29)
1 parent 0f753f9 commit addc725

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/lib.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1415,4 +1415,23 @@ mod tests {
14151415

14161416
assert_eq!(format(input, &QueryParams::None, options), expected);
14171417
}
1418+
1419+
#[test]
1420+
fn it_keeps_double_dollar_signs_together() {
1421+
let input = "CREATE FUNCTION abc() AS $$ SELECT * FROM table $$ LANGUAGE plpgsql;";
1422+
let options = FormatOptions::default();
1423+
let expected = indoc!(
1424+
"
1425+
CREATE FUNCTION abc() AS
1426+
$$
1427+
SELECT
1428+
*
1429+
FROM
1430+
table
1431+
$$
1432+
LANGUAGE plpgsql;"
1433+
);
1434+
1435+
assert_eq!(format(input, &QueryParams::None, options), expected);
1436+
}
14181437
}

src/tokenizer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ fn get_top_level_reserved_token_no_indent(input: &str) -> IResult<&str, Token<'_
533533
terminated(tag("MINUS"), end_of_word),
534534
terminated(tag("UNION"), end_of_word),
535535
terminated(tag("UNION ALL"), end_of_word),
536+
terminated(tag("$$"), end_of_word),
536537
))(&uc_input);
537538
if let Ok((_, token)) = result {
538539
let final_word = token.split(' ').last().unwrap();

0 commit comments

Comments
 (0)