Skip to content

Commit

Permalink
Fix since we weren't catching the reverse filter!
Browse files Browse the repository at this point in the history
Add test to ensure this doesn't happen again.
  • Loading branch information
BritishWerewolf committed Apr 9, 2024
1 parent ea72dca commit b261d85
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ pub fn parse_filter(input: Span) -> IResult<Span, Filter> {
"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 "_".
Expand Down
27 changes: 27 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b261d85

Please sign in to comment.