Add a script to dump an AST using docker.
All checks were successful
rust-test Build rust-test has succeeded
clippy Build clippy has succeeded
rustfmt Build rustfmt has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-build Build rust-build has succeeded

This commit is contained in:
Tom Alexander
2023-10-18 15:33:01 -04:00
parent f19d262825
commit c58b0e7c35
2 changed files with 81 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ use std::borrow::Cow;
/// Removes all whitespace from a string if any line breaks are present.
///
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foobar".
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foobar".
pub(crate) fn remove_whitespace_if_line_break(input: &str) -> Cow<'_, str> {
let mut state = RemoveWhitespaceIfLineBreakState::Normal;
for (offset, c) in input.char_indices() {
@@ -78,7 +78,7 @@ enum RemoveLineBreakState {
/// Removes all whitespace from a string if any line breaks are present.
///
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foobar".
/// Example: "foo bar" => "foo bar" but "foo \n bar" => "foo bar".
pub(crate) fn coalesce_whitespace_if_line_break(input: &str) -> Cow<'_, str> {
let mut state = CoalesceWhitespaceIfLineBreakState::Normal;
for (offset, c) in input.char_indices() {
@@ -515,4 +515,25 @@ mod tests {
assert!(matches!(output, Cow::Borrowed(_)));
Ok(())
}
#[test]
fn test_coalesce_whitespace_if_line_break() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!(coalesce_whitespace_if_line_break("foo bar"), "foo bar");
assert_eq!(coalesce_whitespace_if_line_break("foo \n bar"), "foo bar");
Ok(())
}
#[test]
fn test_remove_whitespace_if_line_break() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!(remove_whitespace_if_line_break("foo bar"), "foo bar");
assert_eq!(remove_whitespace_if_line_break("foo \n bar"), "foobar");
Ok(())
}
#[test]
fn test_remove_line_break() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!(remove_line_break("foo bar"), "foo bar");
assert_eq!(remove_line_break("foo \n bar"), "foo bar");
Ok(())
}
}