@@ -159,7 +159,8 @@ pub fn test_regex(regex_input: &DbEntry, code: &mut Code) -> anyhow::Result<Test
159159 let test_result = match & regex_input. samples_pass {
160160 SamplesPass :: WithSubstrs ( samples) => {
161161 // Random sample testing for substrings is only done for decomposed setting
162- let ( random_samples_correct, incorrect_substring_random_test) = match & regex_input. regex {
162+ let ( random_samples_correct, incorrect_substring_random_test) = match & regex_input. regex
163+ {
163164 RegexInput :: Decomposed ( parts) => {
164165 test_random_samples_gen_substrs ( parts, regex_input. input_size as u32 , code) ?
165166 }
@@ -306,38 +307,49 @@ fn test_random_samples_gen_substrs(
306307 for _ in 0 ..constants:: DEFAULT_SAMPLE_NUMBER {
307308 let mut substrings = Vec :: < String > :: new ( ) ;
308309 let mut total_string = String :: new ( ) ;
310+ let mut valid_sample = true ;
309311
310312 for part in regex_parts {
311313 // Create the regex for this part
312314 let regex_part = Regex :: compile ( & part. regex_def , max_inputsize) ;
313315 let sample = match regex_part {
314316 Ok ( regex_part) => regex_part. sample ( & mut rng) ,
315317 Err ( err) => {
316- log:: error !(
318+ log:: info !(
317319 "ignoring the random testing -
318320 the random samples were not generated due to the following error: {:?}" ,
319321 err
320322 ) ;
323+ valid_sample = false ;
321324 String :: new ( )
322325 }
323326 } ;
324327
325- if part. is_public {
326- substrings. push ( sample. clone ( ) ) ;
328+ // If any of the parts wasn't generated correctly we consider it an invalid sample and
329+ // it will be ignored
330+ if valid_sample {
331+ if part. is_public {
332+ substrings. push ( sample. clone ( ) ) ;
333+ }
334+ // Concatenate this sample to the total_string
335+ total_string. push_str ( & sample) ;
327336 }
328- // Concatenate this sample to the total_string
329- total_string. push_str ( & sample) ;
330337 }
331338
332339 let input_with_substring = InputWithSubstrs {
333340 input : total_string. clone ( ) ,
334- expected_substrings : substrings,
341+ // Don't pass empty substrings
342+ expected_substrings : substrings. into_iter ( ) . filter ( |s| !s. is_empty ( ) ) . collect ( ) ,
335343 } ;
336- let test_passed = run_single_gen_substr_test ( code, & input_with_substring) ?;
337- if test_passed {
338- random_samples_correct. push ( total_string) ;
339- } else {
340- incorrect_substring_tests. push ( total_string) ;
344+
345+ // Ignore empty samples
346+ if !input_with_substring. input . is_empty ( ) {
347+ let test_passed = run_single_gen_substr_test ( code, & input_with_substring) ?;
348+ if test_passed {
349+ random_samples_correct. push ( total_string) ;
350+ } else {
351+ incorrect_substring_tests. push ( total_string) ;
352+ }
341353 }
342354 }
343355
@@ -361,14 +373,18 @@ fn test_for_random_samples(
361373 . collect :: < Vec < String > > ( )
362374 }
363375 Err ( err) => {
364- log:: error !(
376+ log:: info !(
365377 "ignoring the random testing -
366378 the random samples were not generated due to the following error: {:?}" ,
367379 err
368380 ) ;
369381 Vec :: new ( )
370382 }
371- } ;
383+ }
384+ . into_iter ( )
385+ . filter ( |s| !s. is_empty ( ) ) // Filter out empty strings
386+ . collect ( ) ;
387+
372388 let ( random_samples_correct, random_samples_wrong) =
373389 evaluate_test_set ( code, & regex_input. regex . complete_regex ( ) , & random_samples) ?;
374390 Ok ( ( random_samples_correct, random_samples_wrong) )
0 commit comments