Skip to content

Allow generic input and output #2

@zommiommy

Description

@zommiommy

Currently, minify_sql_to_string only works on file paths, to test it (and maybe fuzz it) it would be great to have a version that work on a generic input that implements std::io::Read and writes on something that implements std::io::Write.

Like:

pub fn minify_sql(input: impl std::io::Read, output: &mut impl std::io::Write) -> Result<(), std::io::Error> {
  ...
}

This would be great for tests, as you could use a std::io::Cursor to make a vector implement std::io::Read and std::io::Write like:

#[test]
fn test_sql() {
   let input = std::io::Cursor::new("SELECT * FROM table;".as_bytes());
   let mut output = std::io::Cursor::new(vec![]);
   minify_sql(input, &mut output).unwrap();
   assert_eq!(
       "SELECT * FROM table;",
       output.into_inner().as_slice()
   );
}

And you could still allow reading and writing to files if passed like:

#[test]
fn test_file_sql() {
   minify_sql(
       std::fs::File::open("input.sql"),
       &mut std::fs::File::create("output.sql"),
   ).unwrap();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions