const CLIEngine = require("eslint").CLIEngine;
const path = require("path");
const assert = require('assert');

const LINE_ENDING_CONFIG = {
  plugins: ["self"],
  rules: {
    "self/notice": ["error",{ templateFile: path.join(__dirname, "./test-template.txt") }]
  },
  useEslintrc:false
};

const textLF = `/**
 * Copyright (c) 2020, Nick Deis
 */

function x(){
    return 1;
}
`

const textCRLF = textLF.replace(/\n/g,"\r\n");

describe("Staging", () => {
  describe("Line ending control character testing", () => {
    const cli = new CLIEngine(LINE_ENDING_CONFIG);
    it('Should work on files with CRLF and LF', () => {
        
        const {results} = cli.executeOnFiles([path.join(__dirname, "./test-crlf.js"), path.join(__dirname, "./test-lf.js")]);
        const [crlfResults,lfResults] = results;
        assert.equal(lfResults.errorCount,0,"Should work on LF");
        assert.equal(crlfResults.errorCount,0,"Should work on CRLF");        
    });
    it("Should work on CRLF text", () => {
        const report = cli.executeOnText(textCRLF);
        assert.equal(report.errorCount,0);    
    });
    it("Should work on LF text", () => {
      const report = cli.executeOnText(textLF);
      assert.equal(report.errorCount,0);    
    });
  });
});

@@ -379,33 +379,172 @@
 %0A%7D%0A%60
-%0A%0Aconst textCRLF = textLF
+;%0A%0A//TODO: Test fix%0A%0Aconst textLFNoHeader = %60%0Afunction x()%7B%0A  return 1;%0A%7D%0A%60;%0A%0Aconst textCRLF = textLF.replace(/%5Cn/g,%22%5Cr%5Cn%22);%0Aconst textCRLFNoHeader = textLFNoHeader
 .rep
@@ -1387,16 +1387,405 @@
     %7D);%0A
+    const clifix = new CLIEngine(Object.assign(%7B%7D,LINE_ENDING_CONFIG,%7Bfix:true%7D));%0A    it(%22Should correctly fix CRLF%22,() =%3E %7B%0A      const report = clifix.executeOnText(textCRLFNoHeader);%0A      assert.equal(report.errorCount,0);  %0A    %7D);%0A    it(%22Should correctly fix LF%22,() =%3E %7B%0A      const report = clifix.executeOnText(textLFNoHeader);%0A      assert.equal(report.errorCount,0);  %0A    %7D);%0A
   %7D);%0A%7D)

Test fix flag for line endings