diff --git a/Cargo.toml b/Cargo.toml index b6d7bbf..520f171 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "blogs-md-easy" description = "Iteratively convert a collection of Markdown files into a respective HTML template." -version = "0.3.1" +version = "0.3.2" edition = "2021" keywords = ["markdown", "html", "template", "blog"] categories = ["command-line-interface", "config", "web-programming"] diff --git a/src/lib.rs b/src/lib.rs index 6f7ba29..f1de50f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -569,6 +569,7 @@ pub fn parse_filter(input: Span) -> IResult { "lowercase" => Filter::Lowercase, "uppercase" => Filter::Uppercase, "markdown" => Filter::Markdown, + "reverse" => Filter::Reverse, "truncate" => Filter::Truncate { // Attempt to get the characters, but if we can't then we use // the unnamed value, defined as "_". diff --git a/tests/tests.rs b/tests/tests.rs index c008675..16fa39b 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -433,6 +433,33 @@ fn can_parse_two_filters() { } } +#[test] +fn can_parse_all_filters() { + // We need this test that we don't forget to create match the string to the + // filter. + let filters: Vec<(Filter, Filter)> = vec![ + (Filter::Lowercase, parse_filter(Span::new("lowercase")).expect("lowercase").1), + (Filter::Uppercase, parse_filter(Span::new("uppercase")).expect("uppercase").1), + (Filter::Markdown, parse_filter(Span::new("markdown")).expect("markdown").1), + (Filter::Reverse, parse_filter(Span::new("reverse")).expect("reverse").1), + (Filter::Truncate { characters: 20, trail: "...".to_string() }, parse_filter(Span::new("truncate")).expect("truncate").1), + ]; + + // Maybe a bit verbose, but this ensures that the compiler will catch new + // filters immediately. + for (expected_filter, actual_filter) in filters { + match actual_filter { + Filter::Lowercase => assert_eq!(expected_filter, Filter::Lowercase), + Filter::Uppercase => assert_eq!(expected_filter, Filter::Uppercase), + Filter::Markdown => assert_eq!(expected_filter, Filter::Markdown), + Filter::Reverse => assert_eq!(expected_filter, Filter::Reverse), + Filter::Truncate { characters, trail } => { + assert_eq!(expected_filter, Filter::Truncate { characters, trail }); + } + } + } +} + #[test] fn filter_lowercase_works() { let input = "HELLO, WORLD!".to_string();