From 8e2f68b9b76e3d4f604d64d046e66de7202e36a9 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 20 Feb 2022 02:57:22 +0530 Subject: [PATCH] feat: add tests for config parsers --- src/test.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/test.rs b/src/test.rs index e765b38..ffa3eab 100644 --- a/src/test.rs +++ b/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 { .. })); +}