use regex_generator::core::services::regex_generator::RegexGenerator; use regex_generator::core::services::regex_verificator::RegexVerificator; use regex_generator::prelude::models::regex::mode::Mode; #[test] fn regexes_split_should_generate_valid_regex_when_concat() { // given let word = "enveloppe"; let expected = true; // when let regex_generate = RegexGenerator::regexes_splited(word, None); let concat_regex = regex_generate .into_iter() .map(|regex_part| regex_part.regex) .collect::>() .join(""); let is_valid = RegexVerificator::r#match(concat_regex.as_str(), word); // then assert_eq!(is_valid, expected) } #[test] fn regexes_split_should_generate_valid_regex() { // given let word = "enveloppe"; let expected = false; // when let regex_generate = RegexGenerator::regexes_splited(word, None); let contain_wrong_regex = regex_generate .into_iter() .map(|regex_part| RegexVerificator::r#match(regex_part.regex.as_str(), regex_part.word_part.as_str())) .collect::>() .contains(&false); // then assert_eq!(contain_wrong_regex, expected) } #[test] fn full_regex_should_generate_valid_regex_from_simple_word() { // given let word = "brebis"; let expected = true; // when let regex_generate = RegexGenerator::full_regex(word, None); let is_valid = RegexVerificator::r#match(regex_generate.as_str(), word); // then assert_eq!(is_valid, expected) } #[test] fn generate_group_should_generate_valid_regex_from_simple_word() { // given let word = "hello"; let expected = true; // when let regex_generate = RegexGenerator::generate_rand_from_mode(word, &Mode::Group { size: 2 }); let is_valid = RegexVerificator::r#match(regex_generate.as_str(), word); // then assert_eq!(is_valid, expected) } #[test] fn generate_like_should_generate_valid_regex_from_simple_word() { // given let word = "sol"; let expected = true; // when let regex_generate = RegexGenerator::generate_rand_from_mode(word, &Mode::Like); let is_valid = RegexVerificator::r#match(regex_generate.as_str(), word); // then assert_eq!(is_valid, expected) } #[test] fn generate_not_like_should_generate_valid_regex_from_simple_word() { // given let word = "alloue"; let expected = true; // when let regex_generate = RegexGenerator::generate_rand_from_mode(word, &Mode::NotLike); let is_valid = RegexVerificator::r#match(regex_generate.as_str(), word); // then assert_eq!(is_valid, expected) } #[test] fn generate_any_should_generate_valid_regex_from_simple_word() { // given let word = "pouet"; let expected = true; // when let regex_generate = RegexGenerator::generate_rand_from_mode(word, &Mode::Any); let is_valid = RegexVerificator::r#match(regex_generate.as_str(), word); // then assert_eq!(is_valid, expected) }