busterjs / buster

Abandoned - A powerful suite of automated test tools for JavaScript.

Home Page:http://docs.busterjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

posix-argv-parser fails when short option is combined with shorthand

samplx opened this issue · comments

For example if there is a short option "-t" and a shorthand "-1", both -1t and -t1 will generate errors.

The following tests show the issue.

    "test shorthand first followed by short option": function (done) {
        this.a.createOption(["-t", "--terse"]);
        this.a.createOption(["--width"], { hasValue: true });
        this.a.addShorthand("-1", ["--width", "1"]);

        this.a.parse(["-1t"], done(function (errors, options) {
            refute(errors);
            assert(options["-t"].isSet);
            assert.equals(options["--width"].value, "1");
        }));
    },

    "test short option followed by shorthand": function (done) {
        this.a.createOption(["-t", "--terse"]);
        this.a.createOption(["--width"], { hasValue: true });
        this.a.addShorthand("-1", ["--width", "1"]);

        this.a.parse(["-t1"], done(function (errors, options) {
            refute(errors);
            assert(options["-t"].isSet);
            assert.equals(options["--width"].value, "1");
        }));
    },

    "test two shorthands followed by short option": function (done) {
        this.a.createOption(["-t", "--terse"]);
        this.a.createOption(["--width"], { hasValue: true });
        this.a.createOption(["--depth"], { hasValue: true });
        this.a.addShorthand("-1", ["--width", "1"]);
        this.a.addShorthand("-2", ["--depth", "2"]);

        this.a.parse(["-12t"], done(function (errors, options) {
            refute(errors);
            assert(options["-t"].isSet);
            assert.equals(options["--width"].value, "1");
            assert.equals(options["--depth"].value, "2");
        }));
    },

Fixed by 73a9f0df95 and released with version 1.0.1 of posix-argv-parser.