chore: revert to default formatting style

This commit is contained in:
Harsh Shandilya 2025-01-19 17:55:01 +05:30
parent 142676ac1d
commit 6048f7a537
6 changed files with 169 additions and 185 deletions

View file

@ -4,49 +4,49 @@ use crate::config::{Act, Action, Match, Matcher, MatcherType, Replacements};
#[assay]
fn regex_matcher() {
let matcher = Matcher::Regex {
pattern: "^https.*".to_string(),
};
assert!(matcher.check_match("https://example.com"));
assert!(!matcher.check_match("example.com"));
let matcher = Matcher::Regex {
pattern: "^https.*".to_string(),
};
assert!(matcher.check_match("https://example.com"));
assert!(!matcher.check_match("example.com"));
}
#[assay]
fn set_action() {
let action = Action::Set {
content: "doe".to_string(),
};
assert_eq!("doe", &action.apply_action("john"));
let action = Action::Set {
content: "doe".to_string(),
};
assert_eq!("doe", &action.apply_action("john"));
}
#[assay]
fn replace_action() {
let action = Action::Replace {
from: "doe".to_string(),
to: "bow".to_string(),
};
assert_eq!("john bow", &action.apply_action("john doe"));
let action = Action::Replace {
from: "doe".to_string(),
to: "bow".to_string(),
};
assert_eq!("john bow", &action.apply_action("john doe"));
}
#[assay]
fn prefix_action() {
let action = Action::Prefix {
prefix: "hello ".to_string(),
};
assert_eq!("hello john", &action.apply_action("john"));
let action = Action::Prefix {
prefix: "hello ".to_string(),
};
assert_eq!("hello john", &action.apply_action("john"));
}
#[assay]
fn suffix_action() {
let action = Action::Suffix {
suffix: " doe".to_string(),
};
assert_eq!("john doe", &action.apply_action("john"));
let action = Action::Suffix {
suffix: " doe".to_string(),
};
assert_eq!("john doe", &action.apply_action("john"));
}
#[assay]
fn parse_with_multiple_matchers() {
let config = r#"
let config = r#"
[[substitutor]]
name = "Example"
matcher = [
@ -55,50 +55,50 @@ fn parse_with_multiple_matchers() {
]
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, MatcherType::Multiple(_)));
assert!(matches!(subst.action, Action::Prefix { .. }));
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, MatcherType::Multiple(_)));
assert!(matches!(subst.action, Action::Prefix { .. }));
}
#[assay]
fn parse_with_single_matcher() {
let config = r#"
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, MatcherType::Single(_)));
assert!(matches!(subst.action, Action::Prefix { .. }));
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, MatcherType::Single(_)));
assert!(matches!(subst.action, Action::Prefix { .. }));
}
#[assay]
fn config_validation_success() {
let config = r#"
let config = r#"
[[substitutor]]
name = "vxTwitter"
matcher = { regex = { pattern = "^https://(?P<host>(?:mobile.)?twitter.com)/.*/status/[0-9]+.*" } }
action = { replace = { from = "twitter.com", to = "vxtwitter.com" } }
"#;
let config: Replacements = toml::from_str(config)?;
assert!(config.validate().is_ok());
let config: Replacements = toml::from_str(config)?;
assert!(config.validate().is_ok());
}
#[assay]
fn config_validation_failure() {
let config = r#"
let config = r#"
[[substitutor]]
name = "vxTwitter"
matcher = { regex = { pattern = "^https://(?P<>(?:mobile.)?twitter.com)/.*/status/[0-9]+.*" } }
action = { replace = { from = "twitter.com", to = "vxtwitter.com" } }
"#;
let config: Replacements = toml::from_str(config)?;
assert!(config.validate().is_err());
let config: Replacements = toml::from_str(config)?;
assert!(config.validate().is_err());
}