<commit_before>/*
 * Optics test / subcommand.js
 * copyright (c) 2016 Susisu
 */

"use strict";

describe("subcommand", () => {
    describe("Subcommand", () => {
        describe("constructor(name, cmd)", () => {
            it("should create a new Subcommand instance");
            it("should throw a TypeError if 'name' is not a string");
            it("should throw a TypeError if 'cmd' is not an instance of CommandBase");
        });
    });

    describe("CommandGroup", () => {
        describe("constructor(desc, subcmds, defaultCmd)", () => {
            it("should create a new CommandGroup instance");
            it("should throw a TypeError if 'desc' is not a string");
            it("should throw a TypeError if 'subcmds' is not an array of Subcommand");
            it("should throw a TypeError if 'defaultCmd' is not an instance of CommandBase nor null");
        });
    });
});<commit_msg>Add tests for the Subcommand constructor<commit_after>/*
 * Optics test / subcommand.js
 * copyright (c) 2016 Susisu
 */

"use strict";

const chai   = require("chai");
const expect = chai.expect;

const command    = require("../lib/command.js");
const subcommand = require("../lib/subcommand.js");

describe("subcommand", () => {
    describe("Subcommand", () => {
        describe("constructor(name, cmd)", () => {
            it("should create a new Subcommand instance", () => {
                let cmd = new command.Command(
                    "test command",
                    [],
                    [],
                    (args, opts) => {}
                );
                let subcmd = new subcommand.Subcommand("test", cmd);
                expect(subcmd).to.be.an.instanceOf(subcommand.Subcommand);
            });

            it("should throw a TypeError if 'name' is not a string", () => {
                let cmd = new command.Command(
                    "test command",
                    [],
                    [],
                    (args, opts) => {}
                );
                function construct(name) {
                    return () => {
                        new subcommand.Subcommand(name, cmd);
                    };
                }
                expect(construct("test")).not.to.throw(TypeError);

                expect(construct(null)).to.throw(TypeError);
                expect(construct(undefined)).to.throw(TypeError);
                expect(construct(3.14)).to.throw(TypeError);
                expect(construct(true)).to.throw(TypeError);
                expect(construct({})).to.throw(TypeError);
                expect(construct(() => {})).to.throw(TypeError);
            });

            it("should throw a TypeError if 'cmd' is not an instance of CommandBase", () => {
                let cmd = new command.Command(
                    "test command",
                    [],
                    [],
                    (args, opts) => {}
                );
                function construct(cmd) {
                    return () => {
                        new subcommand.Subcommand("test", cmd);
                    };
                }
                expect(construct(cmd)).not.to.throw(TypeError);

                expect(construct(null)).to.throw(TypeError);
                expect(construct(undefined)).to.throw(TypeError);
                expect(construct("foobar")).to.throw(TypeError);
                expect(construct(3.14)).to.throw(TypeError);
                expect(construct(true)).to.throw(TypeError);
                expect(construct({})).to.throw(TypeError);
                expect(construct(() => {})).to.throw(TypeError);
            });
        });
    });

    describe("CommandGroup", () => {
        describe("constructor(desc, subcmds, defaultCmd)", () => {
            it("should create a new CommandGroup instance");
            it("should throw a TypeError if 'desc' is not a string");
            it("should throw a TypeError if 'subcmds' is not an array of Subcommand");
            it("should throw a TypeError if 'defaultCmd' is not an instance of CommandBase nor null");
        });
    });
});
{'fraction_non_alphanumeric': 0.1418474287106995, 'fraction_numerical': 0.003412137460394833, 'mean_word_length': 1.6736156351791531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5960163', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1006, 'n_words': 252}