mod classify;
mod error;
mod hygiene;
mod json;
mod markdown;
mod style;
mod toml;
mod yaml;
pub use classify::{FileKind, classify};
pub use error::FormatError;
pub use style::{Indent, LineEnding, Style};
pub fn format(kind: FileKind, source: &str, style: &Style) -> Result<String, FormatError> {
match kind {
FileKind::Json | FileKind::Jsonc => json::format(source, style),
FileKind::Toml => toml::format(source, style),
FileKind::Yaml => yaml::format(source, style),
FileKind::Markdown => markdown::format(source, style),
FileKind::Orphan => Ok(hygiene::hygiene(source, style)),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hygiene_kinds_return_ok() {
let style = Style::default();
assert_eq!(format(FileKind::Orphan, "x \n", &style).unwrap(), "x\n");
assert_eq!(format(FileKind::Markdown, "a\r\n", &style).unwrap(), "a\n");
}
}