<commit_before>var quiddity = require("../quiddity.js"),
    expect = require("expect.js");

describe("quiddity", function() {
    it("should decorate an object and return it", function() {
        var obj = {};
        expect(quiddity(obj)).to.be(obj);
        expect(obj.create).to.be.a("function");
        expect(obj.init).to.be.a("function");
    });

    it("should reject invalid arguments", function() {
        expect(quiddity).withArgs(21120).to.throwError(new Error());
        expect(quiddity).withArgs("foo").to.throwError(new Error());
        expect(quiddity).withArgs([2,3]).to.throwError(new Error());
    });

    describe("create", function() {
        it("should return a derivation of current prototype", function() {
            var obj = quiddity({}),
                derivation = obj.create();
            expect(obj.isPrototypeOf(derivation));
        });

        it("should call prototype init", function() {
            var init = function() {this.foo = 42;},
                obj = quiddity({}, init);

            expect(obj.foo).to.be(undefined);
            expect(obj.create().foo).to.be(42);
        });
    });
});<commit_msg>test init chaining<commit_after>var quiddity = require("../quiddity.js"),
    expect = require("expect.js");

describe("quiddity", function() {
    it("should decorate an object and return it", function() {
        var obj = {};
        expect(quiddity(obj)).to.be(obj);
        expect(obj.create).to.be.a("function");
        expect(obj.init).to.be.a("function");
    });

    it("should reject invalid arguments", function() {
        expect(quiddity).withArgs(21120).to.throwError(new Error());
        expect(quiddity).withArgs("foo").to.throwError(new Error());
        expect(quiddity).withArgs([2,3]).to.throwError(new Error());
    });

    describe("create", function() {
        it("should return a derivation of current prototype", function() {
            var obj = quiddity({}),
                derivation = obj.create();
            expect(obj.isPrototypeOf(derivation));
        });

        it("should call prototype init", function() {
            var init = function() {this.foo = 42;},
                obj = quiddity({}, init);

            expect(obj.foo).to.be(undefined);
            expect(obj.create().foo).to.be(42);
        });

        it("should be able to chain inits together", function() {
            var fnA = function() {this.value += "A";},
                fnB = function() {this.value += "B";},
                fnC = function() {this.value += "C";},
                obj = quiddity({value:""}, fnA);

            expect(obj.create(fnB).create(fnC).create().value).to.be("ABC");
        });
    });
});
{'fraction_non_alphanumeric': 0.18212166172106825, 'fraction_numerical': 0.008160237388724036, 'mean_word_length': 2.3967254408060454, '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': '6500970', 'n_tokens_mistral': 813, 'n_tokens_neox': 777, 'n_words': 151}