feat: add tests for actions

This commit is contained in:
Harsh Shandilya 2022-02-15 02:59:54 +05:30
parent 86cb0fde40
commit ff3a72968a
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80

View file

@ -1,4 +1,4 @@
use crate::config::{Match, Matcher}; use crate::config::{Act, Action, Match, Matcher};
#[test] #[test]
fn regex_matcher() { fn regex_matcher() {
@ -8,3 +8,30 @@ fn regex_matcher() {
assert!(matcher.check_match("https://example.com")); assert!(matcher.check_match("https://example.com"));
assert!(!matcher.check_match("example.com")); assert!(!matcher.check_match("example.com"));
} }
#[test]
fn set_action() {
let action = Action::Set { content: "doe" };
assert_eq!("doe", action.apply_action("john"));
}
#[test]
fn replace_action() {
let action = Action::Replace {
from: "doe",
to: "bow",
};
assert_eq!("john bow", action.apply_action("john doe"));
}
#[test]
fn prefix_action() {
let action = Action::Prefix { prefix: "hello " };
assert_eq!("hello john", action.apply_action("john"));
}
#[test]
fn suffix_action() {
let action = Action::Suffix { suffix: " doe" };
assert_eq!("john doe", action.apply_action("john"));
}