diff --git a/.gitignore b/.gitignore index a233986..9421181 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,4 @@ package-lock.json yarn.lock index.node +.yarn/ diff --git a/.cargo/config b/config.toml similarity index 100% rename from .cargo/config rename to config.toml diff --git a/package.json b/package.json index cf9d72c..1da4fcd 100644 --- a/package.json +++ b/package.json @@ -51,5 +51,6 @@ }, "engines": { "yarn": "^1.22.0" - } -} \ No newline at end of file + }, + "packageManager": "yarn@1.22.22" +} diff --git a/packages/compiler/src/dfa_tests.json b/packages/compiler/src/dfa_tests.json index 056ebc7..0005fed 100644 --- a/packages/compiler/src/dfa_tests.json +++ b/packages/compiler/src/dfa_tests.json @@ -37,5 +37,21 @@ "regex": "^[a-zA-Z]{2,}\\s[a-zA-Z]{1,}'?-?[a-zA-Z]{2,}\\s?([a-zA-Z]{1,})?$", "pass": ["John Doe", "Mary Jane", "Robert O'Neill", "Sarah Jane-Smith"], "fail": ["J D", "John", "John Doe", "12John Doe"] + }, + { + "regex": "(\r\n|^)to:([^\r\n]+<)?([^@]{1,3})([^@]*)@([a-zA-Z0-9.-]+)>?\r\n", + "pass": [ + "to:user@example.com\r\n", + "to:\"John Doe\" \r\n", + "to:abc@domain.com\r\n", + "to:abcd@example.com\r\n", + "\r\nto:user+tag@example.com\r\n" + ], + "fail": [ + "to:@example.com\r\n", + "to:user@\r\n", + "from:user@example.com\r\n", + "to:user@example.com" + ] } ] diff --git a/packages/compiler/src/regex.rs b/packages/compiler/src/regex.rs index d3571b4..0f053e9 100644 --- a/packages/compiler/src/regex.rs +++ b/packages/compiler/src/regex.rs @@ -985,6 +985,11 @@ pub(crate) fn get_regex_and_dfa( .map(|regex| regex.regex_def.as_str()) .collect::(); + // Remove epsilon transitions + for state in &mut net_dfa_graph.states { + state.transitions.retain(|_, chars| !chars.is_empty()); + } + Ok(RegexAndDFA { regex_pattern: regex_str, dfa: net_dfa_graph, @@ -1033,6 +1038,7 @@ fn create_dfa_graph_from_regex(regex: &str) -> Result { /// # Returns /// /// A boolean indicating whether the input string matches the regex pattern. +#[cfg(test)] fn match_string_with_dfa_graph(graph: &DFAGraph, input: &str) -> bool { let mut current_state = 0; @@ -1132,10 +1138,12 @@ pub(crate) fn get_max_state(dfa: &DFAGraph) -> usize { .unwrap_or_default() } +#[cfg(test)] mod dfa_test { - use crate::regex::{create_dfa_graph_from_regex, match_string_with_dfa_graph}; + use super::create_dfa_graph_from_regex; + use crate::regex::match_string_with_dfa_graph; use serde::{Deserialize, Serialize}; - use std::{env, fs::File, io::BufReader, path::PathBuf}; + use std::{fs::File, io::BufReader, path::PathBuf}; #[derive(Debug, Deserialize, Serialize)] struct RegexTestCase {