feat: add tests for config parsers

This commit is contained in:
Harsh Shandilya 2022-02-20 02:57:22 +05:30
parent 7be11d9a90
commit 8e2f68b9b7
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80

View file

@ -1,4 +1,4 @@
use crate::config::{Act, Action, Match, Matcher};
use crate::config::{Act, Action, Match, Matcher, MatcherType, Replacements};
use assay::assay;
#[assay]
@ -36,3 +36,38 @@ fn suffix_action() {
let action = Action::Suffix { suffix: " doe" };
assert_eq!("john doe", action.apply_action("john"));
}
#[assay]
fn parse_with_multiple_matchers() {
let config = r#"
[[substitutor]]
name = "Example"
matcher = [
{ starts_with = { prefix = "https://example.com" } },
{ ends_with = { suffix = ".mp4" } }
]
action = { prefix = { prefix = "/mirror" } }
"#;
let config: Replacements<'_> = toml::from_str(config)?;
assert_eq!(1, config.substitutors.len());
let subst = &config.substitutors[0];
assert_eq!("Example", subst.name);
assert!(matches!(subst.matcher_type, MatcherType::Multiple(_)));
assert!(matches!(subst.action, Action::Prefix { .. }));
}
#[assay]
fn parse_with_single_matcher() {
let config = r#"
[[substitutor]]
name = "Example"
matcher = { starts_with = { prefix = "https://example.com" } }
action = { prefix = { prefix = "/mirror" } }
"#;
let config: Replacements<'_> = toml::from_str(config)?;
assert_eq!(1, config.substitutors.len());
let subst = &config.substitutors[0];
assert_eq!("Example", subst.name);
assert!(matches!(subst.matcher_type, MatcherType::Single(_)));
assert!(matches!(subst.action, Action::Prefix { .. }));
}