mirror of
https://github.com/msfjarvis/clipboard-substitutor
synced 2025-08-14 17:47:02 +05:30
feat: add tests for config parsers
This commit is contained in:
parent
7be11d9a90
commit
8e2f68b9b7
1 changed files with 36 additions and 1 deletions
37
src/test.rs
37
src/test.rs
|
@ -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 { .. }));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue