
'use strict';

const assert = require('assert');
const eslint = require('eslint');

// This depends on presence of .eslintrc.json point to this repo

function assertReportContains(report, msg) {
  let message = report.results[0].messages.reduce((a, m) => {
    return (m.ruleId === msg) ? m : a;
  }, null);
  assert.notEqual(null, message, 'Report did not contain ' + msg);
}

describe('Good Lint', () => {
  it('should find nothing wrong with good files.', () => {
    const report = new eslint.CLIEngine().executeOnFiles(['./test/good/sample.js']);
    assert.equal(report.errorCount, 0);
    assert.equal(report.warningCount, 0);
    assert(report.results[0].filePath.endsWith('good/sample.js'));
  });
});

describe('Bad Lint', () => {
  it('should find camelcase errors', () => {
    const report = new eslint.CLIEngine().executeOnText("var my_favorite_color = '#112C85';");
    assertReportContains(report, 'camelcase');
  });
});

@@ -76,16 +76,42 @@
 slint');
+%0Aconst fs = require('fs');
 %0A%0A// Thi
@@ -479,32 +479,167 @@
 iles.', () =%3E %7B%0A
+    fs.realpath('./test/good', (err, path) =%3E %7B%0A      var files = fs.readdirSync(path).map((name) =%3E %7B return %60$%7Bpath%7D/$%7Bname%7D%60; %7D);%0A  
     const report
@@ -683,40 +683,22 @@
 les(
-%5B'./test/good/sample.js'%5D
+files
 );%0A    
+ 
+ 
 asse
@@ -721,32 +721,34 @@
 errorCount, 0);%0A
+  
     assert.equal
@@ -769,24 +769,67 @@
 gCount, 0);%0A
+      files.forEach((file, index) =%3E %7B%0A    
     assert(r
@@ -842,17 +842,21 @@
 results%5B
-0
+index
 %5D.filePa
@@ -871,25 +871,31 @@
 ith(
-'good/sample.js')
+file));%0A      %7D);%0A    %7D
 );%0A 
@@ -1034,17 +1034,17 @@
 eOnText(
-%22
+'
 var my_f
@@ -1063,16 +1063,17 @@
 r = 
+%5C
 '#112C85
 ';%22)
@@ -1072,11 +1072,12 @@
 2C85
+%5C
 ';
-%22
+'
 );%0A 
@@ -1119,21 +1119,213 @@
 melcase');%0A  %7D);
+%0A%0A  it('should complain about tab characters', () =%3E %7B%0A    const report = new eslint.CLIEngine().executeOnText('if (this) %7B%5Cn%5Ctthat();%5Cn%7D;');%0A    assertReportContains(report, 'no-tabs');%0A  %7D);
 %0A%7D);%0A

Test multiple good files.