<commit_before>/*global suite,test*/
require('source-map-support').install()

var fs = require("fs")
var path = require("path")

var _ = require("lodash")
var chai = require("chai")
var devUtils = require("../../tacoscript-dev-utils")
chai.use(devUtils.chaiHelper)
var expect = chai.expect
var render = require("tacoscript-cst-utils").render
var saveAst = devUtils.saveAst

var horchata = require("horchata")
var plugin = require("../lib/horchata/index")

// TODO: should load parser and lexer from ../lib/index
horchata.registerPluginModule("logicalAssign", require("../lib/horchata/parser"), require("../lib/horchata/lexer"));

// TODO: rewrite mocha-fixtures-generic to be more generic, w.r.t directory structure

var fixtureRootBase = path.join(__dirname, "fixtures")
var fixtureRootDirs = fs.readdirSync(fixtureRootBase)

suite("tacoscript-logical-assign", function () {
  _.forEach(fixtureRootDirs, function(fixtureRootDir) { suite(fixtureRootDir, function () {

    var fixtureDirs = fs.readdirSync(path.join(fixtureRootBase, fixtureRootDir))
    .filter(function(fixtureDir) { return fs.statSync(path.join(fixtureRootBase, fixtureRootDir, fixtureDir)).isDirectory() })

    // var optionsPath = path.join(fixtureRootBase, fixtureRootDir, "options.json")
    var options = {plugins: {"logicalAssign": true}};

    _.forEach(fixtureDirs, function(fixtureDir) { test(fixtureDir, function () {

      var fixtureBase = path.join(fixtureRootBase, fixtureRootDir, fixtureDir)
      var fixtureAstPath = path.join(fixtureBase, "ast.json")
      var fixtureAst; try { fixtureAst = require(fixtureAstPath) } catch(e) {}
      var expectedErr; try { expectedErr = require(path.join(fixtureBase, "error.json")) } catch(e) {}
      var source = fs.readFileSync(path.join(fixtureBase, "source.taco"), "utf-8")

      if (expectedErr) {
        expect(horchata.parse.bind(horchata, source, options)).to.throw(expectedErr.message)
      } else {
        var ast = horchata.parse(source, options)
        if (fixtureAst) {
          expect(ast).matches(fixtureAst)
          // expect(render(ast)).to.equal(source)
        } else {
          saveAst(fixtureAstPath, ast)
        }
      }

    }) /* end test */ }) /* end forEach fixtureDirs */
  }) /* end suite */ }) /* end forEach fixtureRootDirs */
})
<commit_msg>Fix broken require for logical-assign<commit_after>/*global suite,test*/
require('source-map-support').install()

var fs = require("fs")
var path = require("path")

var _ = require("lodash")
var chai = require("chai")
var devUtils = require("../../tacoscript-dev-utils")
chai.use(devUtils.chaiHelper)
var expect = chai.expect
var render = require("tacoscript-cst-utils").render
var saveAst = devUtils.saveAst

var horchata = require("horchata")

// TODO: should load parser and lexer from ../lib/index
horchata.registerPluginModule("logicalAssign", require("../lib/horchata/parser"), require("../lib/horchata/lexer"));

// TODO: rewrite mocha-fixtures-generic to be more generic, w.r.t directory structure

var fixtureRootBase = path.join(__dirname, "fixtures")
var fixtureRootDirs = fs.readdirSync(fixtureRootBase)

suite("tacoscript-logical-assign", function () {
  _.forEach(fixtureRootDirs, function(fixtureRootDir) { suite(fixtureRootDir, function () {

    var fixtureDirs = fs.readdirSync(path.join(fixtureRootBase, fixtureRootDir))
    .filter(function(fixtureDir) { return fs.statSync(path.join(fixtureRootBase, fixtureRootDir, fixtureDir)).isDirectory() })

    // var optionsPath = path.join(fixtureRootBase, fixtureRootDir, "options.json")
    var options = {plugins: {"logicalAssign": true}};

    _.forEach(fixtureDirs, function(fixtureDir) { test(fixtureDir, function () {

      var fixtureBase = path.join(fixtureRootBase, fixtureRootDir, fixtureDir)
      var fixtureAstPath = path.join(fixtureBase, "ast.json")
      var fixtureAst; try { fixtureAst = require(fixtureAstPath) } catch(e) {}
      var expectedErr; try { expectedErr = require(path.join(fixtureBase, "error.json")) } catch(e) {}
      var source = fs.readFileSync(path.join(fixtureBase, "source.taco"), "utf-8")

      if (expectedErr) {
        expect(horchata.parse.bind(horchata, source, options)).to.throw(expectedErr.message)
      } else {
        var ast = horchata.parse(source, options)
        if (fixtureAst) {
          expect(ast).matches(fixtureAst)
          // expect(render(ast)).to.equal(source)
        } else {
          saveAst(fixtureAstPath, ast)
        }
      }

    }) /* end test */ }) /* end forEach fixtureDirs */
  }) /* end suite */ }) /* end forEach fixtureRootDirs */
})

{'fraction_non_alphanumeric': 0.14636798608090473, 'fraction_numerical': 0.00043497172683775554, 'mean_word_length': 4.03723986856517, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3102369', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1439, 'n_words': 289}