<commit_before>var _ = require('lodash')
var λ = require('contra')
var fs = require('fs')
var diff = require('diff-lines')
var path = require('path')
var test = require('ava')
var compiler = require('./')

var filesDir = path.resolve(__dirname, '../../test-rulesets')

test.cb('compiler', function (t) {
  fs.readdir(filesDir, function (err, files) {
    if (err) return t.end(err)

    var basenames = _.uniq(_.map(files, function (file) {
      return path.basename(path.basename(file, '.krl'), '.js')
    }))

    λ.each(basenames, function (basename, next) {
      var jsFile = path.join(filesDir, basename) + '.js'
      var krlFile = path.join(filesDir, basename) + '.krl'
      λ.concurrent({
        js: λ.curry(fs.readFile, jsFile, 'utf8'),
        krl: λ.curry(fs.readFile, krlFile, 'utf8')
      }, function (err, srcs) {
        if (err) return t.end(err)

        var compiled
        try {
          compiled = compiler(srcs.krl).code
        } catch (e) {
          console.log(krlFile)
          console.log(e.stack)
          process.exit(1)// end asap, so they can easily see the error
        }
        compiled = compiled.trim()
        var expected = srcs.js.replace(/\r\n?/g, '\n').trim()

        if (compiled === expected) {
          t.true(true)
          next()
        } else {
          console.log('')
          console.log(path.basename(krlFile) + ' -> ' + path.basename(jsFile))
          console.log('')
          console.log(diff(expected, compiled, {
            n_surrounding: 3
          }))
          console.log('')
          console.log(path.basename(krlFile) + ' -> ' + path.basename(jsFile))
          process.exit(1)// end asap, so they can easily see the diff
        }

        next()
      })<commit_msg>fix for windows tests<commit_after>var _ = require('lodash')
var λ = require('contra')
var fs = require('fs')
var diff = require('diff-lines')
var path = require('path')
var test = require('ava')
var compiler = require('./')

var filesDir = path.resolve(__dirname, '../../test-rulesets')

test.cb('compiler', function (t) {
  fs.readdir(filesDir, function (err, files) {
    if (err) return t.end(err)

    var basenames = _.uniq(_.map(files, function (file) {
      return path.basename(path.basename(file, '.krl'), '.js')
    }))

    λ.each(basenames, function (basename, next) {
      var jsFile = path.join(filesDir, basename) + '.js'
      var krlFile = path.join(filesDir, basename) + '.krl'
      λ.concurrent({
        js: λ.curry(fs.readFile, jsFile, 'utf8'),
        krl: λ.curry(fs.readFile, krlFile, 'utf8')
      }, function (err, srcs) {
        if (err) return t.end(err)

        var compiled
        try {
          compiled = compiler(srcs.krl.replace(/\r\n?/g, '\n')).code
        } catch (e) {
          console.log(krlFile)
          console.log(e.stack)
          process.exit(1)// end asap, so they can easily see the error
        }
        compiled = compiled.trim()
        var expected = srcs.js.replace(/\r\n?/g, '\n').trim()

        if (compiled === expected) {
          t.true(true)
          next()
        } else {
          console.log('')
          console.log(path.basename(krlFile) + ' -> ' + path.basename(jsFile))
          console.log('')
          console.log(diff(expected, compiled, {
            n_surrounding: 3
          }))
          console.log('')
          console.log(path.basename(krlFile) + ' -> ' + path.basename(jsFile))
          process.exit(1)// end asap, so they can easily see the diff
        }

        next()
      })
{'fraction_non_alphanumeric': 0.1636466591166478, 'fraction_numerical': 0.0028312570781426952, 'mean_word_length': 2.162936436884512, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6318553', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1159, 'n_words': 258}