<commit_before>if(!net) var net={};
if(!net.silverbucket) net.silverbucket={};
if(!net.silverbucket.always) net.silverbucket.always={};

net.silverbucket.always = function(undefined) {
    var sys = require('sys');
    var black = '\u001b[30m';
    var red = '\u001b[31m';
    var green = '\u001b[32m';
    var yellow = '\u001b[33m';
    var blue  = '\u001b[34m';
    var purple  = '\u001b[35m';
    var cyan  = '\u001b[36m';
    var greybg  = '\u001b[40m';
    var redbg  = '\u001b[41m';
    var greenbg  = '\u001b[42m';
    var yellowbg  = '\u001b[43m';
    var bluebg  = '\u001b[44m';
    var purplebg  = '\u001b[45m';
    var cyanbg  = '\u001b[46m';
    var reset = '\u001b[0m';
    console.log(reset); // reset colors
    var passed = green + 'passed' + reset;
    var failed = red + 'failed' + reset;

    var suites = [];
    var err_msg = {};
    var pub = {};
    var tools = {};
    var _ = {};
    _.onComplete = function() {};
    tools['jQuery'] = require('jquery');


    /**
     * load a single suite json object into the library
     *
     * @param  {object}   s   suite object from test file
     * @return {boolean}      success of loading
     */
    pub.loadSuite = function(s) {
        //if (! s.name ) {
        //    err_msg = "suite requires a 'name' property";
        //    return false;
        //} else if (! s.desc ) {
        if (! s.desc ) {
            err_msg = "suite requires a 'desc' property";
            return false;
        } else if (! s.tests ) {
            err_msg = "suite requires a 'tests' array";
            return false;
        }

        /*
         * class definitions for suites, tests, and scaffolding
         */
        var writeFunc = function(text) {
            console.log('    ' + yellow + '> ' + text + reset);
        };
        var resultFunc = function(result, message) {
            if(result !== undefined){this._result = result;}
            if(message !== undefined){this._message = message;}
            return this._result;
        };
        var runFunc = function(){this.result(true);};
        var envSetFunc = function(env) {
            if(env !== undefined){this._env = env;}
        };
        var envGetFunc = function() {
            return this._env;
        };
        var assertTypeFunc = function(data, type) {
            if (typeof data === type) {
                this.result(true);
                return true;
            } else {
                this.result(false);
                return false;
            }
        };
        var assertFunc = function(one, two) {
            function isEqual(a,b){
                for(var p in a){
                    var av = a[p], bv = b[p];
                    //recursion
                    if (typeof av === 'object' || typeof bv === 'object') {
                        if (Ext.ux.util.Object.compare(av,bv) !== true){
                            return false;
                        }
                    } else { //simple comparisons
                        if(a[p] !== b[p]){
                            return false;
                        }
                    }
                }
                return true;
            }

            function compareObjects(one, two) {
                //can't use json encoding in case objects contain functions - recursion will fail
                //can't compare non-objects

                if (isEqual(one,two) !== true) return false;
                if (isEqual(two,one) !== true) return false;

                return true;
            }

            if (typeof one === 'undefined') {
                if (typeof two === 'undefined') {
                    this.result(true);
                    return true;
                } else {
                    this.result(false, 'param one undefined');
                    return false;
                }
            }
            if ((typeof one === 'object') && (typeof two === 'object')) {
                if (compareObjects(one, two)) {
                    this.result(true);
                    return true;
                } else {
                    this.result(false, "objects don't match");
                    return false;
                }
            }

            if (one === two) {
                this.result(true);
                return true;
            } else {
                this.result(false, "param 1["+one+"] not equal to param 2["+two+"]");
                return false;
            }
            this.result(false);
            return false;
        };

        function Stub(returnFunc) {
            this.returnFunc = returnFunc;
        }
        Stub.prototype = {
            returnFunc: undefined,
            called: false,
            numCalled: 0,
            isCalled: function() {
                return this.called;
            },
            getNumCalled: function() {
                return this.numCalled;
            },
            getFunc: function() {
                var _this_stub = this;
                func = function(params) {
                    _this_stub.called = true;
                    _this_stub.numCalled = _this_stub.numCalled + 1;
                    return _this_stub.returnFunc(params);
                };
                return func;
            }
        };


        function Env() {}
        Env.prototype = {
            _env: {}, // environment to run tests in
            set: envSetFunc,
            get: envGetFunc
        };

        function Scaffolding() {}
        Scaffolding.prototype = {
            constructor: Scaffolding,
            type: "Scaffolding",
            tools: tools,
            write: writeFunc,
            status: undefined,
            assert: assertFunc,
            assertType: assertTypeFunc,
            Stub: Stub,
            timeout: 10000,
            env: undefined,
            run: runFunc,
            _result: undefined,
            _message: '',
            result: resultFunc
        };

        function Test() {}
        Test.prototype = {
            constructor: Test,
            type: "Test",
            name: "",
            desc: "",
            tools: tools,
            write: writeFunc,
            setup: undefined,
            takedown: undefined,
            actual: undefined,
            next: undefined,
            prev: undefined,
            parent: undefined,
            position: null
        };

        function Suite() {}
        Suite.prototype = {
            constructor: Suite,
            type: "Suite",
            name: "",
            desc: "",
            tools: tools,
            write: writeFunc,
            setup: undefined,
            takedown: undefined,
            beforeEach: undefined,
            afterEach: undefined,
            env: undefined,
            testIndex: 0,
            next: undefined,
            prev: undefined,
            position: null
        };

        /*
         * Create all the test objects from the JSON data
         */
        var tests = [];
        var suite = new Suite(); // we define this early so we can assign it as parent to test objects
        var env = new Env();
        if (typeof s.timeout === 'number') {
            Test.prototype.timeout = s.timeout; // override test timeouts with Suite timeout
            Scaffolding.prototype.timeout = s.timeout; // override test timeouts with Suite timeout
        }
        var num_tests = s.tests.length;
        for (var i = 0; i < num_tests; i++) {
            //if (! s.tests[i].name ) {
            //    err_msg = s.name + ": test[" + i + "] requires a 'name' property";
            //    return false;
            //} else if (! s.tests[i].desc ) {
            if (! s.tests[i].desc ) {
                err_msg = s.name + ": test '" + s.tests[i].name +<commit_msg>a little better output for this.write()<commit_after>if(!net) var net={};
if(!net.silverbucket) net.silverbucket={};
if(!net.silverbucket.always) net.silverbucket.always={};

net.silverbucket.always = function(undefined) {
    var sys = require('sys');
    var black = '\u001b[30m';
    var red = '\u001b[31m';
    var green = '\u001b[32m';
    var yellow = '\u001b[33m';
    var blue  = '\u001b[34m';
    var purple  = '\u001b[35m';
    var cyan  = '\u001b[36m';
    var greybg  = '\u001b[40m';
    var redbg  = '\u001b[41m';
    var greenbg  = '\u001b[42m';
    var yellowbg  = '\u001b[43m';
    var bluebg  = '\u001b[44m';
    var purplebg  = '\u001b[45m';
    var cyanbg  = '\u001b[46m';
    var reset = '\u001b[0m';
    console.log(reset); // reset colors
    var passed = green + 'passed' + reset;
    var failed = red + 'failed' + reset;

    var suites = [];
    var err_msg = {};
    var pub = {};
    var tools = {};
    var _ = {};
    _.onComplete = function() {};
    tools['jQuery'] = require('jquery');


    /**
     * load a single suite json object into the library
     *
     * @param  {object}   s   suite object from test file
     * @return {boolean}      success of loading
     */
    pub.loadSuite = function(s) {
        //if (! s.name ) {
        //    err_msg = "suite requires a 'name' property";
        //    return false;
        //} else if (! s.desc ) {
        if (! s.desc ) {
            err_msg = "suite requires a 'desc' property";
            return false;
        } else if (! s.tests ) {
            err_msg = "suite requires a 'tests' array";
            return false;
        }

        /*
         * class definitions for suites, tests, and scaffolding
         */
        var writeFunc = function(text) {
            if (!this._written) {
                // first output needs a newline
                sys.print("\n");
                this._written = false;
            }
            sys.print('    ' + yellow + '> ' + text + reset);
        };
        var resultFunc = function(result, message) {
            if(result !== undefined){this._result = result;}
            if(message !== undefined){this._message = message;}
            return this._result;
        };
        var runFunc = function(){this.result(true);};
        var envSetFunc = function(env) {
            if(env !== undefined){this._env = env;}
        };
        var envGetFunc = function() {
            return this._env;
        };
        var assertTypeFunc = function(data, type) {
            if (typeof data === type) {
                this.result(true);
                return true;
            } else {
                this.result(false);
                return false;
            }
        };
        var assertFunc = function(one, two) {
            function isEqual(a,b){
                for(var p in a){
                    var av = a[p], bv = b[p];
                    //recursion
                    if (typeof av === 'object' || typeof bv === 'object') {
                        if (Ext.ux.util.Object.compare(av,bv) !== true){
                            return false;
                        }
                    } else { //simple comparisons
                        if(a[p] !== b[p]){
                            return false;
                        }
                    }
                }
                return true;
            }

            function compareObjects(one, two) {
                //can't use json encoding in case objects contain functions - recursion will fail
                //can't compare non-objects

                if (isEqual(one,two) !== true) return false;
                if (isEqual(two,one) !== true) return false;

                return true;
            }

            if (typeof one === 'undefined') {
                if (typeof two === 'undefined') {
                    this.result(true);
                    return true;
                } else {
                    this.result(false, 'param one undefined');
                    return false;
                }
            }
            if ((typeof one === 'object') && (typeof two === 'object')) {
                if (compareObjects(one, two)) {
                    this.result(true);
                    return true;
                } else {
                    this.result(false, "objects don't match");
                    return false;
                }
            }

            if (one === two) {
                this.result(true);
                return true;
            } else {
                this.result(false, "param 1["+one+"] not equal to param 2["+two+"]");
                return false;
            }
            this.result(false);
            return false;
        };

        function Stub(returnFunc) {
            this.returnFunc = returnFunc;
        }
        Stub.prototype = {
            returnFunc: undefined,
            called: false,
            numCalled: 0,
            isCalled: function() {
                return this.called;
            },
            getNumCalled: function() {
                return this.numCalled;
            },
            getFunc: function() {
                var _this_stub = this;
                func = function(params) {
                    _this_stub.called = true;
                    _this_stub.numCalled = _this_stub.numCalled + 1;
                    return _this_stub.returnFunc(params);
                };
                return func;
            }
        };


        function Env() {}
        Env.prototype = {
            _env: {}, // environment to run tests in
            set: envSetFunc,
            get: envGetFunc
        };

        function Scaffolding() {}
        Scaffolding.prototype = {
            constructor: Scaffolding,
            type: "Scaffolding",
            tools: tools,
            write: writeFunc,
            _written: false,
            status: undefined,
            assert: assertFunc,
            assertType: assertTypeFunc,
            Stub: Stub,
            timeout: 10000,
            env: undefined,
            run: runFunc,
            _result: undefined,
            _message: '',
            result: resultFunc
        };

        function Test() {}
        Test.prototype = {
            constructor: Test,
            type: "Test",
            name: "",
            desc: "",
            tools: tools,
            write: writeFunc,
            setup: undefined,
            takedown: undefined,
            actual: undefined,
            next: undefined,
            prev: undefined,
            parent: undefined,
            position: null
        };

        function Suite() {}
        Suite.prototype = {
            constructor: Suite,
            type: "Suite",
            name: "",
            desc: "",
            tools: tools,
            write: writeFunc,
            setup: undefined,
            takedown: undefined,
            beforeEach: undefined,
            afterEach: undefined,
            env: undefined,
            testIndex: 0,
            next: undefined,
            prev: undefined,
            position: null
        };

        /*
         * Create all the test objects from the JSON data
         */
        var tests = [];
        var suite = new Suite(); // we define this early so we can assign it as parent to test objects
        var env = new Env();
        if (typeof s.timeout === 'number') {
            Test.prototype.timeout = s.timeout; // override test timeouts with Suite timeout
            Scaffolding.prototype.timeout = s.timeout; // override test timeouts with Suite timeout
        }
        var num_tests = s.tests.length;
        for (var i = 0; i < num_tests; i++) {
            if (! s.tests[i].desc ) {
                err_msg = s.name + ": test '" + s.tests[i].name +
{'fraction_non_alphanumeric': 0.11662483104846495, 'fraction_numerical': 0.010941623221986227, 'mean_word_length': 1.2311889718552556, 'pattern_counts': {'":': 3, '<': 5, '<?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': '599307', 'n_tokens_mistral': 4260, 'n_tokens_neox': 4012, 'n_words': 1084}