package com.cflint.integration;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;

import com.cflint.main.CFLintMain;

public class TestIntegrationFolder {

	@Test
	public void testFolder() throws Exception{
	    CFLintMain.main(
				new String[]{
				"--folder",
				"src/test/resources/com/cflint/integration",
				"--json",
				"--jsonfile",
				"src/test/resources/com/cflint/integration/output.json"
				});
        final String expected = loadFile(new File("src/test/resources/com/cflint/integration/output.expected.json"));
        final String actual = loadFile(new File("src/test/resources/com/cflint/integration/output.json"));
        assertEquals( 
                expected.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n").replaceAll("\\s\"file\".+\\R", ""),
                actual.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n").replaceAll("\\s\"file\".+\\R", ""));
	}

	   @Test
	    public void testRuleGroupFolder() throws Exception{
	        CFLintMain.main(
	                new String[]{
	                "--folder",
	                "src/test/resources/com/cflint/integration",
	                "--json",
                    "--jsonfile",
                    "src/test/resources/com/cflint/integration/output.rulegroup.json",
                    "--rulegroups",
                    "Naming"
                    });
	        final String expected = loadFile(new File("src/test/resources/com/cflint/integration/output.rulegroup.expected.json"));
	        final String actual = loadFile(new File("src/test/resources/com/cflint/integration/output.rulegroup.json"));
	        assertEquals( 
	                expected.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n").replaceAll("\\s\"file\".+\\R", ""),
	                actual.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n").replaceAll("\\s\"file\".+\\R", ""));
	    }

	   
	    @Test
	    public void test_194() throws Exception{
	    	File tempFile = File.createTempFile("test_194_", "json");
	    	tempFile.deleteOnExit();
	        CFLintMain.main(
	                new String[]{
	                "--folder",
	                "src/test/resources/com/cflint/integration",
	                "-includeRule",
	                "COMPONENT_INVALID_NAME",
	                "--json",
	                "--jsonfile",
	                tempFile.getAbsolutePath()
	                });
	        final String expected = loadFile(new File("src/test/resources/com/cflint/integration/output_194.expected.json"));
	        final String actual = loadFile(tempFile);
	        tempFile.delete();
	        assertEquals( 
	                expected.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n").replaceAll("\\s\"file\".+\n", ""),
	                actual.replaceAll("\\\\","/").replaceAll("/+","/").replaceAll("\r\n", "\n").replaceAll("\\s\"file\".+\n", ""));
	   }
	   public static String loadFile(File file) throws IOException {
	        InputStream is = new FileInputStream(file);
	        byte[] b = new byte[is.available()];
	        is.read(b);
	        is.close();
	        return new String(b);
	   }
}

@@ -896,34 +896,33 @@
 (%22%5C%5Cs%5C%22file%5C%22.+%5C
-%5CR
+n
 %22, %22%22),%0A        
@@ -1023,34 +1023,33 @@
 (%22%5C%5Cs%5C%22file%5C%22.+%5C
-%5CR
+n
 %22, %22%22));%0A%09%7D%0A%0A%09  
@@ -1885,26 +1885,25 @@
 s%5C%22file%5C%22.+%5C
-%5CR
+n
 %22, %22%22),%0A%09   
@@ -2021,10 +2021,9 @@
 %22.+%5C
-%5CR
+n
 %22, %22

Tweak test regex