<commit_before>var traverse = require('traverse'),
    vows = require('vows');

/**
 * Parser of test objects
 * @param {Object} commands All commands that we can process by
 * @returns {Object} Processed set of commands
 */
function TestParser(commands) {
  this.commands = commands;
}
TestParser.prototype = {
  // The heartbeat of the engine
  'parse': function (batch) {
    // Traverse over the batch
    var commands = this.commands,
        that = this;
    traverse(batch).forEach(function traverseBatch (node) {
      var key = this.key;

      // If there is a key
      if (key) {
        // Look up the command for it
        var command = commands.get(key);

        // If there is a command
        if (command) {
          // If the node is an object
          if (typeof node === 'object') {
            // Add it as a topic
            // TODO: Why are we falling back node.topic -- that will never exist...
            var topic = node.topic || command;

            // If this is an array of commands
            if (Array.isArray(topic)) {
              // Create a new node as the last node
              var subNode = {},
                  lastNode = subNode;

              // Iterate over the topic chain
              var subTopics = topic;
              subTopics.forEach(function (subTopic) {
                // Generate our next node
                var name = subTopic.name,
                    fn = subTopic.fn,
                    nextNode = {'topic': fn};
                // Save our next node under the last node
                lastNode[name] = nextNode;

                // Save the next last node
                lastNode = nextNode;
              });

              // Parse the node
              var parsedNode = that.parse(node);

              // Displace node's children to the lastNode
              var keys = Object.getOwnPropertyNames(parsedNode);
              keys.forEach(function (key) {
                lastNode[key] = parsedNode[key];
              });

              // Overwrite node with subNode
              this.update(subNode, true);
              node = subNode;
            } else {
            // Otherwise, save the command as the topic
              // DEV: Wrap the topic inside of a try/catch for debugging
              node.topic = function () {
                var retVal;
                try {
                  retVal = topic.apply(this, arguments);
                } catch (e) {
                  console.error(e);
                }
                return retVal;
              };
            }
          } else {
            // Otherwise, save it over the node itself
            node = command;
          }
        }
      }

      // Return the node
      return node;
    });

    // Return the batch
    return batch;
  }
};

/**
 * Processor for vows
 * @param {Object} params
 * @param {String} [params.name] Name of the test suite
 * @param {Object} params.commands Commands to interpret with
 * @param {Object[]} params.tests Array of test objects to run
 * @param {Object} params.module Module to export onto
 */
function process(params) {
  // TODO: We could build a class for handling each part of this process but order is kind of critical
  // (i.e. createSuite, createParser, parseTests, export)
  // Grab options from params and create our suite
  var options = params.options,
      suiteName = options.name || '',
      suite = vows.describe(suiteName);

  // Generate a TestParser
  var commands = params.commands,
      parser = new TestParser(commands);

  // Iterate over the tests
  var tests = params.tests;
  tests.forEach(function (inBatch) {
    // Interpret the test
    var outBatch = parser.parse(inBatch);

    // Add it to the test suite
    suite.addBatch(outBatch);
  });

  // Export the test to module
  var module = params.module;
  suite['export'](module);
}

// TODO: Expose vows
// TODO: Expose traverse
// TODO: Expose process
// TODO: Expose parser

// Expose all the things
module.exports = {
  'process': process,
  'vows': vows,
  'traverse': traverse,
  'TestParser': TestParser
};<commit_msg>Removed dirty hack about stop walking objects<commit_after>var traverse = require('traverse'),
    vows = require('vows');

/**
 * Parser of test objects
 * @param {Object} commands All commands that we can process by
 * @returns {Object} Processed set of commands
 */
function TestParser(commands) {
  this.commands = commands;
}
TestParser.prototype = {
  // The heartbeat of the engine
  'parse': function (batch) {
    // Traverse over the batch
    var commands = this.commands,
        that = this;
    traverse(batch).forEach(function traverseBatch (node) {
      var key = this.key;

      // If there is a key
      if (key) {
        // Look up the command for it
        var command = commands.get(key);

        // If there is a command
        if (command) {
          // If the node is an object
          if (typeof node === 'object') {
            // Add it as a topic
            // TODO: Why are we falling back node.topic -- that will never exist...
            var topic = node.topic || command;

            // If this is an array of commands
            if (Array.isArray(topic)) {
              // TODO: Not sure how but this logic should be moved out
              // TODO: Make just create nested objects in a pre-batch processor?
              // Create a new node as the last node
              var subNode = {},
                  lastNode = subNode;

              // Iterate over the topic chain
              var subTopics = topic;
              subTopics.forEach(function (subTopic) {
                // Generate our next node
                var name = subTopic.name,
                    fn = subTopic.fn,
                    nextNode = {};

                // Save our next node under the last node
                lastNode[name] = nextNode;

                // Save the next last node
                lastNode = nextNode;
              });

              // Displace node's children to the lastNode
              var keys = Object.getOwnPropertyNames(node);
              keys.forEach(function (key) {
                lastNode[key] = node[key];
              });

              // Overwrite node with subNode
              node = subNode;
            } else {
            // Otherwise, save the command as the topic
              // DEV: Wrap the topic inside of a try/catch for debugging
              node.topic = function () {
                var retVal;
                try {
                  retVal = topic.apply(this, arguments);
                } catch (e) {
                  console.error(e);
                }
                return retVal;
              };
            }
          } else {
            // Otherwise, save it over the node itself
            node = command;
          }
        }
      }

      // Return the node
      return node;
    });

    // Return the batch
    return batch;
  }
};

/**
 * Processor for vows
 * @param {Object} params
 * @param {String} [params.name] Name of the test suite
 * @param {Object} params.commands Commands to interpret with
 * @param {Object[]} params.tests Array of test objects to run
 * @param {Object} params.module Module to export onto
 */
function process(params) {
  // TODO: We could build a class for handling each part of this process but order is kind of critical
  // (i.e. createSuite, createParser, parseTests, export)
  // Grab options from params and create our suite
  var options = params.options,
      suiteName = options.name || '',
      suite = vows.describe(suiteName);

  // Generate a TestParser
  var commands = params.commands,
      parser = new TestParser(commands);

  // Iterate over the tests
  var tests = params.tests;
  tests.forEach(function (inBatch) {
    // Interpret the test
    var outBatch = parser.parse(inBatch);

    // Add it to the test suite
    suite.addBatch(outBatch);
  });

  // Export the test to module
  var module = params.module;
  suite['export'](module);
}

// TODO: Expose vows
// TODO: Expose traverse
// TODO: Expose process
// TODO: Expose parser

// Expose all the things
module.exports = {
  'process': process,
  'vows': vows,
  'traverse': traverse,
  'TestParser': TestParser
};
{'fraction_non_alphanumeric': 0.09673123486682808, 'fraction_numerical': 0.0, 'mean_word_length': 1.6769280622164615, 'pattern_counts': {'":': 0, '<': 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': '3070847', 'n_tokens_mistral': 2191, 'n_tokens_neox': 2111, 'n_words': 791}