use crate::EasyRegex;
impl EasyRegex {
pub fn start_of_line() -> Self {
EasyRegex("^".to_string())
}
pub fn or(self) -> Self {
let result = format!("{}|", self.0);
EasyRegex(result)
}
pub fn not(self, expression: &str) -> Self {
let result = format!("{}[^{}]", self.0, expression);
EasyRegex(result)
}
pub fn literal_space(self) -> Self {
let result = format!("{} ", self.0);
EasyRegex(result)
}
pub fn end_of_line(self) -> Self {
let result = format!("{}$", self.0);
EasyRegex(result)
}
pub fn insensitive() -> Self {
EasyRegex("(?i)".to_string())
}
pub fn multiline() -> Self {
EasyRegex("(?m)".to_string())
}
pub fn dot_match_newline() -> Self {
EasyRegex("(?s)".to_string())
}
pub fn ignore_whitespace() -> Self {
EasyRegex("(?x)".to_string())
}
}
#[cfg(test)]
mod tests {
use crate::{EasyRegex, settings::base::DEFAULT};
#[test]
fn end_of_line_works() {
let result = EasyRegex::new("abc").end_of_line();
assert_eq!("abc$", result.0);
}
#[test]
fn or_works() {
let result = EasyRegex::new_section()
.literal("abc", &DEFAULT)
.or()
.literal("efg", &DEFAULT)
.into_list(&DEFAULT);
assert_eq!("[abc|efg]", result.0);
}
}