chore: reformat with new rustfmt config

This commit is contained in:
Harsh Shandilya 2022-03-07 01:25:48 +05:30
parent 2ee2cdb107
commit 5d6b27249d
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
3 changed files with 158 additions and 152 deletions

View file

@ -1,45 +1,46 @@
use crate::config::{Act, Action, Match, Matcher, MatcherType, Replacements};
use assay::assay;
use crate::config::{Act, Action, Match, Matcher, MatcherType, Replacements};
#[assay]
fn regex_matcher() {
let matcher = Matcher::Regex {
pattern: "^https.*",
};
assert!(matcher.check_match("https://example.com"));
assert!(!matcher.check_match("example.com"));
let matcher = Matcher::Regex {
pattern: "^https.*",
};
assert!(matcher.check_match("https://example.com"));
assert!(!matcher.check_match("example.com"));
}
#[assay]
fn set_action() {
let action = Action::Set { content: "doe" };
assert_eq!("doe", action.apply_action("john"));
let action = Action::Set { content: "doe" };
assert_eq!("doe", action.apply_action("john"));
}
#[assay]
fn replace_action() {
let action = Action::Replace {
from: "doe",
to: "bow",
};
assert_eq!("john bow", action.apply_action("john doe"));
let action = Action::Replace {
from: "doe",
to: "bow",
};
assert_eq!("john bow", action.apply_action("john doe"));
}
#[assay]
fn prefix_action() {
let action = Action::Prefix { prefix: "hello " };
assert_eq!("hello john", action.apply_action("john"));
let action = Action::Prefix { prefix: "hello " };
assert_eq!("hello john", action.apply_action("john"));
}
#[assay]
fn suffix_action() {
let action = Action::Suffix { suffix: " doe" };
assert_eq!("john doe", action.apply_action("john"));
let action = Action::Suffix { suffix: " doe" };
assert_eq!("john doe", action.apply_action("john"));
}
#[assay]
fn parse_with_multiple_matchers() {
let config = r#"
let config = r#"
[[substitutor]]
name = "Example"
matcher = [
@ -48,26 +49,26 @@ 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 { .. }));
}