<commit_before>/*jslint maxlen: 88*/
var buster = buster || {};

(function (B) {
    var isNode = typeof require === "function" && typeof module === "object";
    var when, onUncaught;

    if (isNode) {
        B = require("buster-core");
        when = require("when");
    }

    var partial = B.partial, bind = B.bind;
    var each = B.each, map = B.map, series = B.series;

    // Events

    var errorEvents = {
        "TimeoutError": "test:timeout",
        "AssertionError": "test:failure",
        "DeferredTestError": "test:deferred"
    };

    function emit(runner, event, test, err, thisp) {
        var data = { name: test.name };
        if (err) { data.error = err; }
        if (typeof test.func === "string") { data.comment = test.func; }
        if (thisp) { data.testCase = thisp; }
        if (event === "test:success") { data.assertions = runner.assertionCount(); }
        runner.emit(event, data);
    }

    function testResult(runner, test, err) {
        if (!test) { return runner.emit("uncaughtException", err); }
        if (test.complete) { return; }
        test.complete = true;
        var event = err ? (errorEvents[err.name] || "test:error") : "test:success";
        emit(runner, event, test, err);

        if (event === "test:error") { runner.results.errors += 1; }
        if (event === "test:failure") { runner.results.failures += 1; }
        if (event === "test:timeout") { runner.results.timeouts += 1; }
        if (event === "test:deferred") {
            runner.results.deferred += 1;
        } else {
            runner.results.assertions += runner.assertionCount();
            runner.results.tests += 1;
        }
    }

    function emitTestAsync(runner, test) {
        if (!test.async && !test.deferred) {
            test.async = true;
            emit(runner, "test:async", test);
        }
    }

    function emitIfAsync(runner, test, isAsync) {
        if (isAsync) { emitTestAsync(runner, test); }
    }

    function emitUnsupported(runner, context, requirements) {
        runner.emit("context:unsupported", {
            context: context,
            unsupported: requirements
        });
    }

    // Data helper functions
    function byRandom() {
        return Math.round(Math.random() * 2) - 1;
    }

    function tests(context) {
        return context.tests.sort(byRandom);
    }

    function setUps(context) {
        var setUpFns = [];
        while (context) {
            if (context.setUp) {
                setUpFns.unshift(context.setUp);
            }
            context = context.parent;
        }
        return setUpFns;
    }

    function tearDowns(context) {
        var tearDownFns = [];
        while (context) {
            if (context.tearDown) {
                tearDownFns.push(context.tearDown);
            }
            context = context.parent;
        }
        return tearDownFns;
    }

    function satiesfiesRequirement(requirement) {
        if (typeof requirement === "function") {
            return !!requirement();
        }
        return !!requirement;
    }

    function unsatiesfiedRequirements(context) {
        var name, requirements = context.requiresSupportForAll || {};
        for (name in requirements) {
            if (!satiesfiesRequirement(requirements[name])) {
                return [name];
            }
        }
        var unsatiesfied = [];
        requirements = context.requiresSupportForAny || {};
        for (name in requirements) {
            if (satiesfiesRequirement(requirements[name])) {
                return [];
            } else {
                unsatiesfied.push(name);
            }
        }
        return unsatiesfied;
    }

    function isAssertionError(err) {
        return err && err.name === "AssertionError";
    }

    function prepareResults(results) {
        return B.extend(results, {
            ok: results.failures + results.errors + results.timeouts === 0
        });
    }

    function propWithDefault(obj, prop, defaultValue) {
        return obj && obj.hasOwnProperty(prop) ? obj[prop] : defaultValue;
    }

    // Async flow

    function promiseSeries(objects, fn) {
        var deferred = when.defer();
        B.series(map(objects, function (obj) {
            return function () {
                return fn(obj);
            };
        }), function (err) {
            if (err) {
                return deferred.resolver.reject(err);
            }
            deferred.resolver.resolve();
        });
        return deferred.promise;
    }

    function asyncDone(resolver) {
        function resolve(method, err) {
            try {
                resolver[method](err);
            } catch (e) {
                throw new Error("done() was already called");
            }
        }

        return function (fn) {
            if (!fn) { return resolve("resolve"); }
            return function () {
                try {
                    var retVal = fn.apply(this, arguments);
                    resolve("resolve");
                    return retVal;
                } catch (up) {
                    resolve("reject", up);
                }
            };
        };
    }

    function asyncFunction(fn, thisp) {
        if (fn.length > 0) {
            var deferred = when.defer();
            fn.call(thisp, asyncDone(deferred.resolver));<commit_msg>Only treat done callback as function if it is one<commit_after>/*jslint maxlen: 88*/
var buster = buster || {};

(function (B) {
    var isNode = typeof require === "function" && typeof module === "object";
    var when, onUncaught;

    if (isNode) {
        B = require("buster-core");
        when = require("when");
    }

    var partial = B.partial, bind = B.bind;
    var each = B.each, map = B.map, series = B.series;

    // Events

    var errorEvents = {
        "TimeoutError": "test:timeout",
        "AssertionError": "test:failure",
        "DeferredTestError": "test:deferred"
    };

    function emit(runner, event, test, err, thisp) {
        var data = { name: test.name };
        if (err) { data.error = err; }
        if (typeof test.func === "string") { data.comment = test.func; }
        if (thisp) { data.testCase = thisp; }
        if (event === "test:success") { data.assertions = runner.assertionCount(); }
        runner.emit(event, data);
    }

    function testResult(runner, test, err) {
        if (!test) { return runner.emit("uncaughtException", err); }
        if (test.complete) { return; }
        test.complete = true;
        var event = err ? (errorEvents[err.name] || "test:error") : "test:success";
        emit(runner, event, test, err);

        if (event === "test:error") { runner.results.errors += 1; }
        if (event === "test:failure") { runner.results.failures += 1; }
        if (event === "test:timeout") { runner.results.timeouts += 1; }
        if (event === "test:deferred") {
            runner.results.deferred += 1;
        } else {
            runner.results.assertions += runner.assertionCount();
            runner.results.tests += 1;
        }
    }

    function emitTestAsync(runner, test) {
        if (!test.async && !test.deferred) {
            test.async = true;
            emit(runner, "test:async", test);
        }
    }

    function emitIfAsync(runner, test, isAsync) {
        if (isAsync) { emitTestAsync(runner, test); }
    }

    function emitUnsupported(runner, context, requirements) {
        runner.emit("context:unsupported", {
            context: context,
            unsupported: requirements
        });
    }

    // Data helper functions
    function byRandom() {
        return Math.round(Math.random() * 2) - 1;
    }

    function tests(context) {
        return context.tests.sort(byRandom);
    }

    function setUps(context) {
        var setUpFns = [];
        while (context) {
            if (context.setUp) {
                setUpFns.unshift(context.setUp);
            }
            context = context.parent;
        }
        return setUpFns;
    }

    function tearDowns(context) {
        var tearDownFns = [];
        while (context) {
            if (context.tearDown) {
                tearDownFns.push(context.tearDown);
            }
            context = context.parent;
        }
        return tearDownFns;
    }

    function satiesfiesRequirement(requirement) {
        if (typeof requirement === "function") {
            return !!requirement();
        }
        return !!requirement;
    }

    function unsatiesfiedRequirements(context) {
        var name, requirements = context.requiresSupportForAll || {};
        for (name in requirements) {
            if (!satiesfiesRequirement(requirements[name])) {
                return [name];
            }
        }
        var unsatiesfied = [];
        requirements = context.requiresSupportForAny || {};
        for (name in requirements) {
            if (satiesfiesRequirement(requirements[name])) {
                return [];
            } else {
                unsatiesfied.push(name);
            }
        }
        return unsatiesfied;
    }

    function isAssertionError(err) {
        return err && err.name === "AssertionError";
    }

    function prepareResults(results) {
        return B.extend(results, {
            ok: results.failures + results.errors + results.timeouts === 0
        });
    }

    function propWithDefault(obj, prop, defaultValue) {
        return obj && obj.hasOwnProperty(prop) ? obj[prop] : defaultValue;
    }

    // Async flow

    function promiseSeries(objects, fn) {
        var deferred = when.defer();
        B.series(map(objects, function (obj) {
            return function () {
                return fn(obj);
            };
        }), function (err) {
            if (err) {
                return deferred.resolver.reject(err);
            }
            deferred.resolver.resolve();
        });
        return deferred.promise;
    }

    function asyncDone(resolver) {
        function resolve(method, err) {
            try {
                resolver[method](err);
            } catch (e) {
                throw new Error("done() was already called");
            }
        }

        return function (fn) {
            if (typeof fn != "function") { return resolve("resolve"); }
            return function () {
                try {
                    var retVal = fn.apply(this, arguments);
                    resolve("resolve");
                    return retVal;
                } catch (up) {
                    resolve("reject", up);
                }
            };
        };
    }

    function asyncFunction(fn, thisp) {
        if (fn.length > 0) {
            var deferred = when.defer();
            fn.call(thisp, asyncDone(deferred.resolver));
{'fraction_non_alphanumeric': 0.12890915860014893, 'fraction_numerical': 0.0020476545048399106, 'mean_word_length': 1.7347925680834817, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, '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': '2988884', 'n_tokens_mistral': 3070, 'n_tokens_neox': 2963, 'n_words': 664}