<commit_before>(function() {

  var allTests = [];
  var namespaces = [];
  var currentTest;
  var currentArgs;
  var currentMode;
  var currentMethod;
  var currentNamespace;

  // The global context
  var globalContext = typeof global !== 'undefined' ? global : this;

  // Has ability to use Object.defineProperty
  definePropertySupport = !!(Object.defineProperty && Object.defineProperties);

  testInternalToString = Object.prototype.toString;

  // Global methods.
  // BE CAREFUL HERE! If you declare these using window.xxx or
  // some form thereof they will not trigger errors in IE7!

  runTests = function(fn, mode, env) {
    var time = new Date;
    var tests = getTestsToRun();
    currentMode = mode;
    environment = env;
    for (var i = 0; i < tests.length; i++) {
      currentTest = tests[i];
      if (typeof currentTest.fn != 'function') {
        throw new Error('Test ' + currentTest.name + ' has no tests.');
        continue;
      }
      if (currentTest.namespace.setup) {
        currentTest.namespace.setup();
      }
      currentTest.fn();
      if (currentTest.namespace.teardown) {
        currentTest.namespace.teardown();
      }
      currentTest = null;
    }
    var runAll = arrayFilter(namespaces, function(p) {
      return p.assertions > 0;
    });
    fn(new Date() - time, runAll);
    allTests = [];
    namespaces = [];
  }

  namespace = function (name, fn, focused) {
    var split;
    split = name.split(' | ');
    currentNamespace = {
      name: split[0],
      subname: split[1],
      focused: !!focused,
      assertions: 0,
      skipped: [],
      failures: []
    };
    namespaces.push(currentNamespace);
    // Queue the tests...
    fn.call();
    currentNamespace = null;
  }

  fnamespace = function(name, fn) {
    namespace(name, fn, true);
  }

  // Noop
  xnamespace = function() {};

  equal = function (actual, expected, message, stack) {
    currentTest.namespace.assertions++;
    if (!isEqual(actual, expected)) {
      addFailure(actual, expected, getFullMessage(message), stack);
    }
  }

  equalWithMargin = function (actual, expected, margin, message) {
    equal((actual > expected - margin) && (actual < expected + margin), true, message, null, 1);
  }

  // Array content is equal, but order may differ
  assertArrayEquivalent = function (a, b, message) {
    equal(sortOnStringValue(a), sortOnStringValue(b), message);
  }

  notEqual = function (actual, expected, message) {
    equal(actual !== expected, true, message + ' | strict equality', 1);
  }

  raisesError = function (fn, message, errorType) {
    var err;
    try {
      fn.call();
    } catch(e) {
      err = e;
    }
    if (errorType) {
      equal(err instanceof errorType, true, message, 1);
    } else {
      if (err && err.message.match(/cannot read property/i)) {
        console.warn('Possible missing method. Error:\n', err.stack);
      }
      equal(!!err, true, message, 1);
    }
  }

  method = function (name, fn, focused, ignored) {
    allTests.push({
      fn: fn,
      name: name,
      focused: !!focused,
      ignored: !!ignored,
      namespace: currentNamespace
    });
  }

  fmethod = function(name, fn) {
    method(name, fn, true);
  }

  xmethod = function(name, fn) {
    method(name, fn, false, true);
  }

  // Alias
  group = method;
  fgroup = fmethod;
  xgroup = xmethod;

  setup = function(fn) {
    currentNamespace.setup = fn;
  }

  teardown = function(fn) {
    currentNamespace.teardown = fn;
  }

  withArgs = function(args, fn) {
    currentArgs = args;
    fn();
    currentArgs = null;
  }

  withMethod = function(name, fn) {
    var namespace = currentTest.namespace.name;
    if (!Sugar[namespace][name]) {
      var key = [namespace, currentTest.name, name].join(' | ')
      currentTest.namespace.skipped.push(key);
      return;
    }
    currentMethod = name;
    fn();
    currentMethod = null;
  }

  isExtendedMode = function() {
    return currentMode === 'extended';
  }

  test = function (subject) {
    var args, expected, message;
    switch(arguments.length) {
      case 2:
        expected = arguments[1];
        message  = subject;
        break;
      case 3:
        expected = arguments[1];
        message  = arguments[2];
        break;
      case 4:
        args     = arguments[1];
        expected = arguments[2];
        message  = arguments[3];
        break;
    }
    equal(run(subject, null, args), expected, message);
  }

  run = function (subject, methodName, args) {
    var namespace = currentTest.namespace.name;
    var isInstance = !objectIsClass(subject);
    methodName = methodName || currentMethod || currentTest.name;
    args = args || currentArgs || [];
    if (currentMode === 'extended') {
      var target = globalContext[namespace];
      if (!target.prototype[methodName]) {
        // Static methods are tested with the global first: test(Array, [1,2,3])
        // so if there is no method in the prototype chain then we know we are
        // testing the static method instead.
        return target[methodName].apply(subject, args);
      }
      return target.prototype[methodName].apply(subject, args);
    } else if (currentMode === 'chained' && isInstance) {
      subject = new Sugar[namespace](subject);
      return subject[methodName].apply(subject, args).raw;
    } else {
      if (isInstance) {
        args = [subject].concat(args);
      }
      return Sugar[namespace][methodName].apply(null, args);
    }
  }

  getCurrentTest = function() {
    return currentTest;
  }

  function getTestsToRun() {
    var focusedNamespacesExist = false;

    function namespaceIsActive(namespace) {
      if (!focusedNamespacesExist) {
        return true;
      }
      return namespace.focused;
    }

    for (var i = 0; i < namespaces.length; i++) {
      if (namespaces[i].focused) {
        focusedNamespacesExist = true;
        break;
      }
    }

    var focused = arrayFilter(allTests, function(t) {
      return t.focused && namespaceIsActive(t.namespace);
    });

    if (focused.length) {
      return focused;
    }

    return arrayFilter(allTests, function(t) {
      return !t.ignored && namespaceIsActive(t.namespace);
    });
  }

  function objectIsClass(obj) {
    switch(obj) {
      case Boolean:
      case Number:
      case String:
      case Array:
      case Object:
      case Date:
      case RegExp:
      case Function:
        return true;
    }
    return false;
  }

  function getGlobalName(global) {
    if (global && global.name) {
      return global.name;
    }
    // < IE9 environments do not have .name
    switch (global) {
      case Boolean:  return 'Boolean';
      case Number:   return 'Number';
      case String:   return 'String';
      case Array:    return 'Array';
      case Object:   return 'Object';
      case Date:     return 'Date';
      case RegExp:   return 'RegExp';
      case Function: return 'Function';
    }
  }

  function getFullMessage(tail) {
    var msg = '';
    var title = currentTest.name;
    if (title) {
      msg += title + ' | ';
    }
    msg += tail;
    return msg;
  }

  function addFailure(actual, expected, message, stack, warning) {
    var meta = getMeta(stack);
    currentTest.namespace.failures.push({
      actual: actual,
      expected: expected,
      message: message,
      file: meta.file,
      line: meta.line,
      col: meta.col,
      warning: !!warning
    });
  }

  function getMeta(stack) {
    var level = 4;
    if (stack !== undefined) {
      level += stack;
    }
    var e = new Error();
    if (!e.stack) {
      return {};
    }
    var s = e.stack.split(/@|^\s+at/m);
    var match = s[level].match(/(.+\.js):(\d+)(?::(\d+))?/);
    if (!match) match = [];
    return { file: match[1], line: match[2], col: match[3] };
  }

  // Equality test methods.

  function isEqual(one, two) {
    var type, klass;

    type = typeof one;

    if (type === 'string' || type === 'boolean' || one == null) {
      return one === two;
    } else if (type === 'number') {
      return typeof two === 'number' && ((isNaN(one) && isNaN(two)) || one === two);
    }

    klass = testInternalToString.call(one);

    if (klass === '[object Date]' && two.getTime) {
      return dateIsEqual(one, two);
    } else if (klass === '[object RegExp]') {
      return String(one) === String(two);
    } else if (klass === '[object Array]') {
      return arrayIsEqual(one, two);
    } else if ((klass === '[object Object]' || klass === '[object Arguments]') && ('hasOwnProperty' in one) && type === 'object') {
      return objectIsEqual(one, two) && klass === testInternalToString.call(two);
    } else if (klass === '[object Number]' && isNaN(one) && isNaN(two)) {
      return true;
    }

    return one === two;
  }

  // Arrays and objects must be treated separately here because in IE arrays with undefined
  // elements will not pass the .hasOwnProperty check. For example [undefined].hasOwnProperty('0')
  // will report false.
  function arrayIsEqual(one, two) {
    var i, result = true;
    if (!one || !two || typeof one !== 'object' || typeof two !== 'object') {
      return false;
    }<commit_msg>making the test suite slightly more Safari friendly<commit_after>(function() {

  var allTests = [];
  var namespaces = [];
  var currentTest;
  var currentArgs;
  var currentMode;
  var currentMethod;
  var currentNamespace;

  // The global context
  var globalContext = typeof global !== 'undefined' ? global : this;

  // Has ability to use Object.defineProperty
  definePropertySupport = !!(Object.defineProperty && Object.defineProperties);

  testInternalToString = Object.prototype.toString;

  // Global methods.
  // BE CAREFUL HERE! If you declare these using window.xxx or
  // some form thereof they will not trigger errors in IE7!

  runTests = function(fn, mode, env) {
    var time = new Date;
    var tests = getTestsToRun();
    currentMode = mode;
    environment = env;
    for (var i = 0; i < tests.length; i++) {
      currentTest = tests[i];
      if (typeof currentTest.fn != 'function') {
        throw new Error('Test ' + currentTest.name + ' has no tests.');
        continue;
      }
      if (currentTest.namespace.setup) {
        currentTest.namespace.setup();
      }
      currentTest.fn();
      if (currentTest.namespace.teardown) {
        currentTest.namespace.teardown();
      }
      currentTest = null;
    }
    var runAll = arrayFilter(namespaces, function(p) {
      return p.assertions > 0;
    });
    fn(new Date() - time, runAll);
    allTests = [];
    namespaces = [];
  }

  namespace = function (name, fn, focused) {
    var split;
    split = name.split(' | ');
    currentNamespace = {
      name: split[0],
      subname: split[1],
      focused: !!focused,
      assertions: 0,
      skipped: [],
      failures: []
    };
    namespaces.push(currentNamespace);
    // Queue the tests...
    fn.call();
    currentNamespace = null;
  }

  fnamespace = function(name, fn) {
    namespace(name, fn, true);
  }

  // Noop
  xnamespace = function() {};

  equal = function (actual, expected, message, stack) {
    currentTest.namespace.assertions++;
    if (!isEqual(actual, expected)) {
      addFailure(actual, expected, getFullMessage(message), stack);
    }
  }

  equalWithMargin = function (actual, expected, margin, message) {
    equal((actual > expected - margin) && (actual < expected + margin), true, message, null, 1);
  }

  // Array content is equal, but order may differ
  assertArrayEquivalent = function (a, b, message) {
    equal(sortOnStringValue(a), sortOnStringValue(b), message);
  }

  notEqual = function (actual, expected, message) {
    equal(actual !== expected, true, message + ' | strict equality', 1);
  }

  raisesError = function (fn, message, errorType) {
    var err;
    try {
      fn.call();
    } catch(e) {
      err = e;
    }
    if (errorType) {
      equal(err instanceof errorType, true, message, 1);
    } else {
      if (err && err.message.match(/cannot read property/i)) {
        console.warn('Possible missing method. Error:\n', err.stack);
      }
      equal(!!err, true, message, 1);
    }
  }

  method = function (name, fn, focused, ignored) {
    allTests.push({
      fn: fn,
      name: name,
      focused: !!focused,
      ignored: !!ignored,
      namespace: currentNamespace
    });
  }

  fmethod = function(name, fn) {
    method(name, fn, true);
  }

  xmethod = function(name, fn) {
    method(name, fn, false, true);
  }

  // Alias
  group = method;
  fgroup = fmethod;
  xgroup = xmethod;

  setup = function(fn) {
    currentNamespace.setup = fn;
  }

  teardown = function(fn) {
    currentNamespace.teardown = fn;
  }

  withArgs = function(args, fn) {
    currentArgs = args;
    fn();
    currentArgs = null;
  }

  withMethod = function(name, fn) {
    var namespace = currentTest.namespace.name;
    if (!Sugar[namespace][name]) {
      var key = [namespace, currentTest.name, name].join(' | ')
      currentTest.namespace.skipped.push(key);
      return;
    }
    currentMethod = name;
    fn();
    currentMethod = null;
  }

  isExtendedMode = function() {
    return currentMode === 'extended';
  }

  test = function (subject) {
    var args, expected, message;
    switch(arguments.length) {
      case 2:
        expected = arguments[1];
        message  = subject;
        break;
      case 3:
        expected = arguments[1];
        message  = arguments[2];
        break;
      case 4:
        args     = arguments[1];
        expected = arguments[2];
        message  = arguments[3];
        break;
    }
    equal(run(subject, null, args), expected, message);
  }

  run = function (subject, methodName, args) {
    var namespace = currentTest.namespace.name;
    var isInstance = !objectIsClass(subject);
    methodName = methodName || currentMethod || currentTest.name;
    args = args || currentArgs || [];
    if (currentMode === 'extended') {
      var target = globalContext[namespace];
      if (!target.prototype[methodName]) {
        // Static methods are tested with the global first: test(Array, [1,2,3])
        // so if there is no method in the prototype chain then we know we are
        // testing the static method instead.
        return target[methodName].apply(subject, args);
      }
      return target.prototype[methodName].apply(subject, args);
    } else if (currentMode === 'chained' && isInstance) {
      subject = new Sugar[namespace](subject);
      return subject[methodName].apply(subject, args).raw;
    } else {
      if (isInstance) {
        args = [subject].concat(args);
      }
      return Sugar[namespace][methodName].apply(null, args);
    }
  }

  getCurrentTest = function() {
    return currentTest;
  }

  function getTestsToRun() {
    var focusedNamespacesExist = false;

    function namespaceIsActive(namespace) {
      if (!focusedNamespacesExist) {
        return true;
      }
      return namespace.focused;
    }

    for (var i = 0; i < namespaces.length; i++) {
      if (namespaces[i].focused) {
        focusedNamespacesExist = true;
        break;
      }
    }

    var focused = arrayFilter(allTests, function(t) {
      return t.focused && namespaceIsActive(t.namespace);
    });

    if (focused.length) {
      return focused;
    }

    return arrayFilter(allTests, function(t) {
      return !t.ignored && namespaceIsActive(t.namespace);
    });
  }

  function objectIsClass(obj) {
    switch(obj) {
      case Boolean:
      case Number:
      case String:
      case Array:
      case Object:
      case Date:
      case RegExp:
      case Function:
        return true;
    }
    return false;
  }

  function getGlobalName(global) {
    if (global && global.name) {
      return global.name;
    }
    // < IE9 environments do not have .name
    switch (global) {
      case Boolean:  return 'Boolean';
      case Number:   return 'Number';
      case String:   return 'String';
      case Array:    return 'Array';
      case Object:   return 'Object';
      case Date:     return 'Date';
      case RegExp:   return 'RegExp';
      case Function: return 'Function';
    }
  }

  function getFullMessage(tail) {
    var msg = '';
    var title = currentTest.name;
    if (title) {
      msg += title + ' | ';
    }
    msg += tail;
    return msg;
  }

  function addFailure(actual, expected, message, stack, warning) {
    var meta = getMeta(stack);
    currentTest.namespace.failures.push({
      actual: actual,
      expected: expected,
      message: message,
      file: meta.file,
      line: meta.line,
      col: meta.col,
      warning: !!warning
    });
  }

  function getMeta(stack) {
    var level = 4;
    if (stack !== undefined) {
      level += stack;
    }
    var e = new Error();
    if (!e.stack) {
      return {};
    }
    var s = e.stack.split(/@|^\s+at/m);
    var match = s[level].match(/(.+\.js):(\d+)(?::(\d+))?/);
    if (!match) match = [];
    return { file: match[1], line: match[2], col: match[3] };
  }

  // Equality test methods.

  function isEqual(one, two) {
    var type, klass;

    type = typeof one;

    if (type === 'string' || type === 'boolean' || one == null) {
      return one === two;
    } else if (type === 'number') {
      return typeof two === 'number' && ((isNaN(one) && isNaN(two)) || one === two);
    }

    klass = testInternalToString.call(one);

    if (klass === '[object Date]' && two.getTime) {
      return dateIsEqual(one, two);
    } else if (klass === '[object RegExp]') {
      return String(one) === String(two);
    } else if (klass === '[object Array]' || klass === '[object Arguments]') {
      return arrayIsEqual(one, two) && klass === testInternalToString.call(two);
    } else if (klass === '[object Object]' && ('hasOwnProperty' in one) && type === 'object') {
      return objectIsEqual(one, two) && klass === testInternalToString.call(two);
    } else if (klass === '[object Number]' && isNaN(one) && isNaN(two)) {
      return true;
    }

    return one === two;
  }

  // Arrays and objects must be treated separately here because in IE arrays with undefined
  // elements will not pass the .hasOwnProperty check. For example [undefined].hasOwnProperty('0')
  // will report false.
  function arrayIsEqual(one, two) {
    var i, result = true, key;
    if (one === two) {
      return true;
    }
    if (!one || !two || typeof one !== 'object' || typeof two !== 'object') {
      return false;
    }
{'fraction_non_alphanumeric': 0.1389445196211096, 'fraction_numerical': 0.003139377537212449, 'mean_word_length': 2.499242424242424, 'pattern_counts': {'":': 0, '<': 11, '<?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': '6158866', 'n_tokens_mistral': 5677, 'n_tokens_neox': 5556, 'n_words': 1539}