'use strict';

const fs = require('fs');
const path = require('path');
const async = require('async');

// Enable should on Object prototype
const should = require('should');

const parser = require('../../build/grammar.js');

const BASE = './test/grammar/';

describe('The parser', function() {

  let files = [];

  // We want to compare compiled setlX files with matching js files
  const rfiles = fs.readdirSync(path.join(BASE, 'files')).map(path.parse);


  // Split setlX and JS files
  let setlx = rfiles
    .filter(e => e.ext === '.stlx')
    .map(e => e.name);
  let js = rfiles
    .filter(e => e.ext === '.js')
    .map(e => e.name);

  // add files to list, when both - setlX and JS - are present
  setlx.forEach(e => {
    if(js.indexOf(e) >= 0) {
      files.push( e );
    }
  });

  files.forEach(( file ) => {
    it('should transpile ' + file + ' correctly', done => {
      async.map([
          path.join(BASE, 'files', file + '.stlx'),
          path.join(BASE, 'files', file + '.js')
        ],
        fs.readFile,
        (err, arr) => {
          if ( err ) throw err;

          let setlxCode = arr[0].toString();
          let jsCode = arr[1].toString().replace(/\r\n/g, '\n');

          let parsed = parser.parse(setlxCode);

          parsed.should.be.ok().and.a.String();
          parsed.should.equal(jsCode);

          done();
        }
      );
    });
  });
});
@@ -138,23 +138,8 @@
 ype%0A
-const should = 
 requ
@@ -277,18 +277,20 @@
 () %7B%0A%0A  
-le
+cons
 t files 
@@ -473,18 +473,20 @@
 files%0A  
-le
+cons
 t setlx 
@@ -498,37 +498,44 @@
 les%0A    .filter(
+ fil
 e =%3E 
+fil
 e.ext === '.stlx
@@ -535,16 +535,17 @@
  '.stlx'
+ 
 )%0A    .m
@@ -551,26 +551,36 @@
 map(
+ fil
 e =%3E 
+fil
 e.name
+ 
 );%0A  
-le
+cons
 t js
@@ -601,21 +601,28 @@
 .filter(
+ fil
 e =%3E 
+fil
 e.ext ==
@@ -624,24 +624,25 @@
 xt === '.js'
+ 
 )%0A    .map(e
@@ -644,19 +644,27 @@
 map(
+ fil
 e =%3E 
+fil
 e.name
+ 
 );%0A%0A
@@ -742,16 +742,23 @@
 forEach(
+fileNam
 e =%3E %7B%0A 
@@ -762,17 +762,19 @@
 %7B%0A    if
-(
+ ( 
 js.index
@@ -780,15 +780,23 @@
 xOf(
+fileNam
 e) %3E= 0
+ 
 ) %7B%0A
@@ -813,16 +813,23 @@
 s.push( 
+fileNam
 e );%0A   
@@ -858,16 +858,12 @@
 ach(
-( 
 file
- )
  =%3E 
@@ -942,34 +942,32 @@
 c.map(%5B%0A        
- 
- 
 path.join(BASE, 
@@ -996,26 +996,24 @@
 '),%0A        
-  
 path.join(BA
@@ -1038,19 +1038,18 @@
 + '.js')
+,
 %0A
-  
       %5D,
@@ -1137,18 +1137,20 @@
         
-le
+cons
 t setlxC
@@ -1184,18 +1184,20 @@
         
-le
+cons
 t jsCode
@@ -1252,18 +1252,20 @@
         
-le
+cons
 t parsed
@@ -1435,8 +1435,9 @@
  %7D);%0A%7D);
+%0A

improve coding style and fix eslint errors