Skip to content

v.0.6.1

Compare
Choose a tag to compare
@vitaly-t vitaly-t released this 26 Mar 19:45
· 2481 commits to master since this release

Changing as.csv() output to be consistent with that when formatting a function call, which means for one thing - supporting a single value, not just an array of values.

Tests have been updated extensively to consider every single situation:

    it("must correctly convert any Array of values into CSV", function () {

        expect(pgp.as.csv()).toBe(""); // test undefined;
        expect(pgp.as.csv([])).toBe(""); // test empty array;
        expect(pgp.as.csv(null)).toBe("null"); // test null;
        expect(pgp.as.csv([null])).toBe("null"); // test null in array;
        expect(pgp.as.csv([undefined])).toBe("null"); // test undefined in array;
        expect(pgp.as.csv([null, undefined])).toBe("null,null"); // test combination of null + undefined in array;

        expect(pgp.as.csv(0)).toBe("0"); // test zero;
        expect(pgp.as.csv([0])).toBe("0"); // test zero in array;
        expect(pgp.as.csv(-123.456)).toBe("-123.456"); // test a float;
        expect(pgp.as.csv([-123.456])).toBe("-123.456"); // test a float in array;

        expect(pgp.as.csv(true)).toBe("TRUE"); // test boolean True;
        expect(pgp.as.csv([true])).toBe("TRUE"); // test boolean True in array;

        expect(pgp.as.csv(false)).toBe("FALSE"); // test boolean False;
        expect(pgp.as.csv([false])).toBe("FALSE"); // test boolean False in array;

        expect(pgp.as.csv("")).toBe("''"); // empty text;
        expect(pgp.as.csv([""])).toBe("''"); // empty text in array;
        expect(pgp.as.csv("simple text")).toBe("'simple text'"); // simple text;
        expect(pgp.as.csv("don't break")).toBe("'don''t break'"); // text with one single-quote symbol;
        expect(pgp.as.csv("test ''")).toBe("'test '''''"); // text with two single-quote symbols;

        expect(pgp.as.csv(new Date(2015, 2, 8, 16, 24, 8))).toBe("'Sun, 08 Mar 2015 16:24:08 GMT'"); // test date;
        expect(pgp.as.csv([new Date(2015, 2, 8, 16, 24, 8)])).toBe("'Sun, 08 Mar 2015 16:24:08 GMT'"); // test date in array;

        // test a combination of all values types;
        expect(pgp.as.csv([12.34, true, "don't break", undefined, new Date(2015, 2, 8, 16, 24, 8)]))
            .toBe("12.34,TRUE,'don''t break',null,'Sun, 08 Mar 2015 16:24:08 GMT'");
    });

Minor code refactoring and documentation updates were made also.