<commit_before>package de.uni.heidelberg.PlugIn;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import de.uni.heidelberg.Utils.DocumentReader;

public class CrashFinderImplExtractionNameFailedTest {
	
	public static ArrayList<String> extractClassNameFailedTest(String input)
	{
		ArrayList<String> listTest = new ArrayList<String>();
		ArrayList<String> listFailedTest = new ArrayList<String>();
		
		String regexEnd = "(?=" + "\\[INFO\\]" + ")";
		String regex = "[\\-]+\\n T E S T S\\n[\\-]+(.*?)" + regexEnd;
		Pattern pattern = Pattern.compile(regex,Pattern.DOTALL);
		Matcher matcher = pattern.matcher(input);
		
		if(matcher.find())
		{
			String content = matcher.group();
			listTest = CrashFinderImplExtractionNameFailedTest.extractAllTest(content);
			listFailedTest = CrashFinderImplExtractionNameFailedTest.getFullNameFailedTest(content,listTest);
		}
		
		return listFailedTest;
	}
	
	public static ArrayList<String> extractAllTest(String input)
	{
		ArrayList<String> listTests = new ArrayList<String>();
		String regex = "Running " + "(.*?)" + "\\n";
		Pattern pattern = Pattern.compile(regex,Pattern.DOTALL);
		Matcher matcher = pattern.matcher(input);
		while(matcher.find())
		{
			String fullNameTestClass = matcher.group(1);
			listTests.add(fullNameTestClass);
		}
		
		return listTests;
	}
	
	public static ArrayList<String> getFullNameFailedTest(String input, ArrayList<String> listTest)
	{
		ArrayList<String> listFailedTest = new ArrayList<String> ();
		String beginRegex = "Results\\s?:\\n+";
		//String regex = beginRegex + "Failed tests: " + "(.*?)" + "\\n";
		String regex = beginRegex  + "(.*?)" + ":\\s*" + "(.*?)" + "\\n";
		Pattern pattern = Pattern.compile(regex,Pattern.DOTALL);
		Matcher matcher = pattern.matcher(input);
		while(matcher.find())
		{
			String strFound = matcher.group(1);
			for ( int k = 0 ; k < listTest.size() ; k++)
			{
				String fullNameTest = listTest.get(k);
				if(strFound.contains(fullNameTest))
			    {
					listFailedTest.add(fullNameTest);
			    }
				
			}
			
		}
		
		return listFailedTest;
		
	}//end method
	
	
	/**
	public static void main(String[]args) throws IOException
	{<commit_msg>modification by search for the name of the only one failed test<commit_after>package de.uni.heidelberg.PlugIn;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import de.uni.heidelberg.Utils.DocumentReader;

public class CrashFinderImplExtractionNameFailedTest {
	
	public static ArrayList<String> extractClassNameFailedTest(String input)
	{
		ArrayList<String> listTest = new ArrayList<String>();
		ArrayList<String> listFailedTest = new ArrayList<String>();
		
		String regexEnd = "(?=" + "\\[INFO\\]" + ")";
		String regex = "[\\-]+\\n T E S T S\\n[\\-]+(.*?)" + regexEnd;
		Pattern pattern = Pattern.compile(regex,Pattern.DOTALL);
		Matcher matcher = pattern.matcher(input);
		
		if(matcher.find())
		{
			String content = matcher.group();
			listTest = CrashFinderImplExtractionNameFailedTest.extractAllTest(content);
			listFailedTest = CrashFinderImplExtractionNameFailedTest.getFullNameFailedTest(content,listTest);
		}
		
		return listFailedTest;
	}
	
	public static ArrayList<String> extractAllTest(String input)
	{
		ArrayList<String> listTests = new ArrayList<String>();
		String regex = "Running " + "(.*?)" + "\\n";
		Pattern pattern = Pattern.compile(regex,Pattern.DOTALL);
		Matcher matcher = pattern.matcher(input);
		while(matcher.find())
		{
			String fullNameTestClass = matcher.group(1);
			listTests.add(fullNameTestClass);
		}
		
		return listTests;
	}
	
	public static ArrayList<String> getFullNameFailedTest(String input, ArrayList<String> listTest)
	{
		ArrayList<String> listFailedTest = new ArrayList<String> ();
		String beginRegex = "Results\\s?:\\n+";
		//String regex = beginRegex + "Failed tests: " + "(.*?)" + "\\n";
		String regex = beginRegex  + "(.*?)" + ":\\s*" + "(.*?)" + "\\n";
		Pattern pattern = Pattern.compile(regex,Pattern.DOTALL);
		Matcher matcher = pattern.matcher(input);
		while(matcher.find())
		{
			String strFound = matcher.group(1);
			for ( int k = 0 ; k < listTest.size() ; k++)
			{
				String fullNameTest = listTest.get(k);
				if(strFound.contains(fullNameTest))
			    {
					listFailedTest.add(fullNameTest);
					return listFailedTest;
			    }
				
			}
			
		}
		
		return listFailedTest;
		
	}//end method
	
	
	/**
	public static void main(String[]args) throws IOException
	{
{'fraction_non_alphanumeric': 0.1468668407310705, 'fraction_numerical': 0.0013054830287206266, 'mean_word_length': 4.046103183315038, 'pattern_counts': {'":': 2, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3024570', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1437, 'n_words': 295}