<commit_before>/**
 * @module salep
 * @global
 *
 * @desc
 * salep is a singleton object that manages all tests and cases.
 * This object exposed to global scope as 'salep'.
 */
const salep = {
  tests: [],
  cases: [],
  isRunning: false,

  /**
   * @method on
   * 
   * @desc
   * This function enables adding callbacks to events. For one specific
   * event there may be many callbacks.
   * 
   * @param {String}    eventName Event name to add callback
   * @param {Function}  callback  Callback
   * 
   * @example
   * salep.on('fail', function(testCase) {
   *   console.log(testCase.name + ' has failed!');
   * });
   */
  on: function(eventName, callback) {
    if (!callbacks[eventName]) {
      callbacks[eventName] = [];
    }
    callbacks[eventName].push(callback);
  },

  /**
   * @method run
   *
   * @desc
   * Enables salep testing. All the tests and cases before salep.run method
   * executed will be counted and recorded as skipped.
   */
  run: function() {
    salep.isRunning = true;
  },

  /**
   * @method stop
   *
   * @desc
   * Disables salep testing and returns all the collected information starting
   * from last stop function invoked or the beginning of program (if stop function
   * not invoked ever). After stop function invoked all following tests and cases 
   * will be counted and recorded as skipped.
   * 
   * @returns {Object} result         JS object containing test information
   */
  stop: function() {
    salep.isRunning = false;
    var result =  {
      success: successCount,
      fail: failCount,
      skip: skipCount,
      total: totalCount,
      tests: salep.tests,
      cases: salep.cases
    };
    successCount = failCount = totalCount = skipCount = 0;
    return result;
  },

  /**
   * @method test
   * 
   * @desc
   * This function creates a new test inside salep scope with given name
   * and test function. Tests doesn't have success or fail status, they have
   * cases. All the cases written inside test function is belong to named test.
   * 
   * @param {String}    name  Name of the test
   * @param {Function}  func  Test function
   * 
   * @fires module:salep#testStart
   * @fires module:salep#skip
   * 
   * @example
   * salep.test('NewTest', function() {
   *   this.case('NewCase of NewTest', function() {
   *     // Case code goes here
   *   });
   * });
   */
  test: function(name, func) {
    var _test = new Test({
      name: name,
      level: level++
    });
    
    if (this instanceof Test) {
      this.tests.push(_test);
    } else {
      salep.tests.push(_test);
    }

    testStart(_test);
    if (salep.isRunning) {
      func.call(_test);
    } else {
      _test.skipped = true;
      skip(_test);
    }

    level--;
  },

  /**
   * @method case
   * 
   * @desc
   * This function creates a new case inside salep scope with given name
   * and case function. Cases created in salep scope doesn't have parent.
   * When case function invoked if exception is thrown case would marked
   * as failed otherwise case marked as succeded.
   * 
   * @param {String}    name  Name of the case
   * @param {Function}  func  Case function
   * 
   * @fires module:salep#caseStart
   * @fires module:salep#success
   * @fires module:salep#fail
   * @fires module:salep#skip
   * 
   * @example
   * salep.case('NewFailCaseInsalepScope', function() {
   *   throw "Exception goes here";
   * });
   */
  case: function(name, func) {
    var _case = new Case({
      name: name
    });

    if (this instanceof Test) {
      this.cases.push(_case);
      _case.parent = this;
    } else {
      salep.cases.push(_case);
      _case.parent = null;
    }

    caseStart(_case);
    if (salep.isRunning) {
      try {
        func();
        _case.success = true;
        success(_case);
      } catch (e) {
        _case.success = false;
        _case.reason = e;
        fail(_case);
      }
    } else {
      _case.skipped = true;
      _case.success = false;
      skip(_case);
    }
  }
};

global.salep = salep;<commit_msg>Remove parent property of Case<commit_after>/**
 * @module salep
 * @global
 *
 * @desc
 * salep is a singleton object that manages all tests and cases.
 * This object exposed to global scope as 'salep'.
 */
const salep = {
  tests: [],
  cases: [],
  isRunning: false,

  /**
   * @method on
   * 
   * @desc
   * This function enables adding callbacks to events. For one specific
   * event there may be many callbacks.
   * 
   * @param {String}    eventName Event name to add callback
   * @param {Function}  callback  Callback
   * 
   * @example
   * salep.on('fail', function(testCase) {
   *   console.log(testCase.name + ' has failed!');
   * });
   */
  on: function(eventName, callback) {
    if (!callbacks[eventName]) {
      callbacks[eventName] = [];
    }
    callbacks[eventName].push(callback);
  },

  /**
   * @method run
   *
   * @desc
   * Enables salep testing. All the tests and cases before salep.run method
   * executed will be counted and recorded as skipped.
   */
  run: function() {
    salep.isRunning = true;
  },

  /**
   * @method stop
   *
   * @desc
   * Disables salep testing and returns all the collected information starting
   * from last stop function invoked or the beginning of program (if stop function
   * not invoked ever). After stop function invoked all following tests and cases 
   * will be counted and recorded as skipped.
   * 
   * @returns {Object} result         JS object containing test information
   */
  stop: function() {
    salep.isRunning = false;
    var result =  {
      success: successCount,
      fail: failCount,
      skip: skipCount,
      total: totalCount,
      tests: salep.tests,
      cases: salep.cases
    };
    successCount = failCount = totalCount = skipCount = 0;
    return result;
  },

  /**
   * @method test
   * 
   * @desc
   * This function creates a new test inside salep scope with given name
   * and test function. Tests doesn't have success or fail status, they have
   * cases. All the cases written inside test function is belong to named test.
   * 
   * @param {String}    name  Name of the test
   * @param {Function}  func  Test function
   * 
   * @fires module:salep#testStart
   * @fires module:salep#skip
   * 
   * @example
   * salep.test('NewTest', function() {
   *   this.case('NewCase of NewTest', function() {
   *     // Case code goes here
   *   });
   * });
   */
  test: function(name, func) {
    var _test = new Test({
      name: name,
      level: level++
    });
    
    if (this instanceof Test) {
      this.tests.push(_test);
    } else {
      salep.tests.push(_test);
    }

    testStart(_test);
    if (salep.isRunning) {
      func.call(_test);
    } else {
      _test.skipped = true;
      skip(_test);
    }

    level--;
  },

  /**
   * @method case
   * 
   * @desc
   * This function creates a new case inside salep scope with given name
   * and case function. Cases created in salep scope doesn't have parent.
   * When case function invoked if exception is thrown case would marked
   * as failed otherwise case marked as succeded.
   * 
   * @param {String}    name  Name of the case
   * @param {Function}  func  Case function
   * 
   * @fires module:salep#caseStart
   * @fires module:salep#success
   * @fires module:salep#fail
   * @fires module:salep#skip
   * 
   * @example
   * salep.case('NewFailCaseInsalepScope', function() {
   *   throw "Exception goes here";
   * });
   */
  case: function(name, func) {
    var _case = new Case({
      name: name
    });

    if (this instanceof Test) {
      this.cases.push(_case);
    } else {
      salep.cases.push(_case);
    }

    caseStart(_case);
    if (salep.isRunning) {
      try {
        func();
        _case.success = true;
        success(_case);
      } catch (e) {
        _case.success = false;
        _case.reason = e;
        fail(_case);
      }
    } else {
      _case.skipped = true;
      _case.success = false;
      skip(_case);
    }
  }
};

global.salep = salep;
{'fraction_non_alphanumeric': 0.11353168181252334, 'fraction_numerical': 0.00024897298643097225, 'mean_word_length': 2.2751732572360375, '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': '3642183', 'n_tokens_mistral': 2549, 'n_tokens_neox': 2471, 'n_words': 771}