ima-parse
Version:
Easy Simple Parser, that only requires a Grammar JSON to output an AST.
35 lines (34 loc) • 3.16 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const charCodeHelpers_1 = require("../charCodeHelpers");
describe("matchCharCodes", () => {
it("should match lowercase letters", () => {
expect((0, charCodeHelpers_1.matchCharCodes)("a".charCodeAt(0), charCodeHelpers_1.CharCodes.lettersLower)).toStrictEqual(true);
expect((0, charCodeHelpers_1.matchCharCodes)("n".charCodeAt(0), charCodeHelpers_1.CharCodes.lettersLower)).toStrictEqual(true);
expect((0, charCodeHelpers_1.matchCharCodes)("z".charCodeAt(0), charCodeHelpers_1.CharCodes.lettersLower)).toStrictEqual(true);
});
it("should match uppercase letters", () => {
expect((0, charCodeHelpers_1.matchCharCodes)("A".charCodeAt(0), charCodeHelpers_1.CharCodes.lettersUpper)).toStrictEqual(true);
expect((0, charCodeHelpers_1.matchCharCodes)("N".charCodeAt(0), charCodeHelpers_1.CharCodes.lettersUpper)).toStrictEqual(true);
expect((0, charCodeHelpers_1.matchCharCodes)("Z".charCodeAt(0), charCodeHelpers_1.CharCodes.lettersUpper)).toStrictEqual(true);
});
it("should match numbers", () => {
expect((0, charCodeHelpers_1.matchCharCodes)("0".charCodeAt(0), charCodeHelpers_1.CharCodes.numbers)).toStrictEqual(true);
expect((0, charCodeHelpers_1.matchCharCodes)("5".charCodeAt(0), charCodeHelpers_1.CharCodes.numbers)).toStrictEqual(true);
expect((0, charCodeHelpers_1.matchCharCodes)("9".charCodeAt(0), charCodeHelpers_1.CharCodes.numbers)).toStrictEqual(true);
});
it("should multiple character types", () => {
const matchers = [charCodeHelpers_1.CharCodes.tab, charCodeHelpers_1.CharCodes.numbers, charCodeHelpers_1.CharCodes.lettersUpper, charCodeHelpers_1.CharCodes.lettersLower];
expect((0, charCodeHelpers_1.matchCharCodes)("5".charCodeAt(0), ...matchers)).toStrictEqual(true);
expect((0, charCodeHelpers_1.matchCharCodes)("N".charCodeAt(0), ...matchers)).toStrictEqual(true);
expect((0, charCodeHelpers_1.matchCharCodes)("n".charCodeAt(0), ...matchers)).toStrictEqual(true);
expect((0, charCodeHelpers_1.matchCharCodes)("\t".charCodeAt(0), ...matchers)).toStrictEqual(true);
});
it("should return false when giving a non matching input", () => {
const matchers = [charCodeHelpers_1.CharCodes.tab, charCodeHelpers_1.CharCodes.numbers, charCodeHelpers_1.CharCodes.lettersUpper, charCodeHelpers_1.CharCodes.lettersLower];
expect((0, charCodeHelpers_1.matchCharCodes)("5".charCodeAt(0), charCodeHelpers_1.CharCodes.lettersUpper, charCodeHelpers_1.CharCodes.lettersLower)).toStrictEqual(false);
expect((0, charCodeHelpers_1.matchCharCodes)("N".charCodeAt(0), charCodeHelpers_1.CharCodes.tab, charCodeHelpers_1.CharCodes.numbers)).toStrictEqual(false);
expect((0, charCodeHelpers_1.matchCharCodes)("n".charCodeAt(0), charCodeHelpers_1.CharCodes.lettersUpper, charCodeHelpers_1.CharCodes.numbers)).toStrictEqual(false);
expect((0, charCodeHelpers_1.matchCharCodes)("\t".charCodeAt(0), charCodeHelpers_1.CharCodes.lettersUpper, charCodeHelpers_1.CharCodes.numbers)).toStrictEqual(false);
});
});
;