diff --git a/tests/test_regexp.rs b/tests/test_regexp.rs --- a/tests/test_regexp.rs +++ b/tests/test_regexp.rs @@ -69,6 +69,26 @@ fn test_eval_plus_dfa() { } #[test] +fn test_eval_alternative_nfa() { + let r = Regexp::new(&String::from("a|b|c")).unwrap(); + assert!(r.eval(String::from("a"))); + assert!(r.eval(String::from("b"))); + assert!(r.eval(String::from("c"))); + assert!(!r.eval(String::from(""))); + assert!(!r.eval(String::from("ab"))); +} + +#[test] +fn test_eval_alternative_dfa() { + let r = Regexp::new(&String::from("a|b|c")).unwrap().determinize(); + assert!(r.eval(String::from("a"))); + assert!(r.eval(String::from("b"))); + assert!(r.eval(String::from("c"))); + assert!(!r.eval(String::from(""))); + assert!(!r.eval(String::from("ab"))); +} + +#[test] fn test_invalid_asterisk() { let x = Regexp::new(&String::from("*")); assert!(matches!(x, Err(ParsingError::Asterisk{s: _, pos: 0}))); @@ -91,3 +111,21 @@ fn test_invalid_opening_parenthesis() { let x = Regexp::new(&String::from("a)")); assert!(matches!(x, Err(ParsingError::OpeningParenthesis{s: _, pos: 1}))); } + +#[test] +fn test_invalid_empty_variant_start() { + let x = Regexp::new(&String::from("a(|b)")); + assert!(matches!(x, Err(ParsingError::EmptyAlternativeVariant))); +} + +#[test] +fn test_invalid_empty_variant_end() { + let x = Regexp::new(&String::from("a|")); + assert!(matches!(x, Err(ParsingError::EmptyAlternativeVariant))); +} + +#[test] +fn test_invalid_empty_variant_middle() { + let x = Regexp::new(&String::from("a||b")); + assert!(matches!(x, Err(ParsingError::EmptyAlternativeVariant))); +}